package cn.flightfeather.thirdapp.fragment; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.location.Location; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.provider.MediaStore; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v4.content.FileProvider; import android.support.v4.view.ViewPager; import android.support.v7.app.AlertDialog; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckedTextView; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdateFactory; import com.amap.api.maps.MapView; import com.amap.api.maps.TextureMapView; import com.amap.api.maps.model.BitmapDescriptorFactory; import com.amap.api.maps.model.LatLng; import com.amap.api.maps.model.Marker; import com.amap.api.maps.model.MarkerOptions; import com.amap.api.maps.model.MyLocationStyle; import com.haibin.calendarview.Calendar; import com.haibin.calendarview.CalendarView; import com.ping.greendao.gen.DaoSession; import com.ping.greendao.gen.DomaincatalogDao; import com.ping.greendao.gen.DomainitemDao; import com.ping.greendao.gen.EvaluationruleDao; import com.ping.greendao.gen.EvaluationsubruleDao; import com.ping.greendao.gen.GittypeDao; import com.ping.greendao.gen.MediafileDao; import com.ping.greendao.gen.ProblemtypeDao; import com.ping.greendao.gen.ScenseDao; import com.ping.greendao.gen.SiteDao; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import cn.flightfeather.thirdapp.CommonApplication; import cn.flightfeather.thirdapp.R; import cn.flightfeather.thirdapp.activity.GitDetailActivity; import cn.flightfeather.thirdapp.activity.GradeActivity; import cn.flightfeather.thirdapp.activity.MapActivity; import cn.flightfeather.thirdapp.activity.PhotoViewerActivity; import cn.flightfeather.thirdapp.activity.ProblemDetailActivity; import cn.flightfeather.thirdapp.activity.PromiseActivity; import cn.flightfeather.thirdapp.activity.SignActivity; import cn.flightfeather.thirdapp.activity.SubTaskMapActivity; import cn.flightfeather.thirdapp.activity.UploadMediaFilesActivity; import cn.flightfeather.thirdapp.adapter.DomainItemListAdapter; import cn.flightfeather.thirdapp.adapter.GitListAdapter; import cn.flightfeather.thirdapp.adapter.GitTypeListAdapter; import cn.flightfeather.thirdapp.adapter.IconsPageAdapter; import cn.flightfeather.thirdapp.adapter.PhotoListAdapter; import cn.flightfeather.thirdapp.adapter.ProblemListAdapter; import cn.flightfeather.thirdapp.adapter.ProblemTypeListAdapter; import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener; import cn.flightfeather.thirdapp.adapter.TaskListAdapter; import cn.flightfeather.thirdapp.bean.ChangeAdvice; import cn.flightfeather.thirdapp.bean.Domainitem; import cn.flightfeather.thirdapp.bean.Gitlist; import cn.flightfeather.thirdapp.bean.Gittype; import cn.flightfeather.thirdapp.bean.Inspection; import cn.flightfeather.thirdapp.bean.LastSubtaskPack; import cn.flightfeather.thirdapp.bean.Mediafile; import cn.flightfeather.thirdapp.bean.Problemlist; import cn.flightfeather.thirdapp.bean.Problemtype; import cn.flightfeather.thirdapp.bean.Scense; import cn.flightfeather.thirdapp.bean.Site; import cn.flightfeather.thirdapp.bean.Subtask; import cn.flightfeather.thirdapp.bean.TaskPack; import cn.flightfeather.thirdapp.bean.vo.GitlistVo; import cn.flightfeather.thirdapp.bean.vo.InspectionVo; import cn.flightfeather.thirdapp.bean.vo.ProblemlistVo; import cn.flightfeather.thirdapp.bean.vo.TaskVo; import cn.flightfeather.thirdapp.common.database.DbLink; import cn.flightfeather.thirdapp.common.database.DbSource; import cn.flightfeather.thirdapp.httpservice.InspectionImageService; import cn.flightfeather.thirdapp.httpservice.InspectionService; import cn.flightfeather.thirdapp.httpservice.SubTaskService; import cn.flightfeather.thirdapp.module.base.BaseTakePicActivity; import cn.flightfeather.thirdapp.module.task.SceneDetailActivity; import cn.flightfeather.thirdapp.task.SetImageTask; import cn.flightfeather.thirdapp.util.AmapNavi; import cn.flightfeather.thirdapp.util.Constant; import cn.flightfeather.thirdapp.util.DateFormatter; import cn.flightfeather.thirdapp.util.DialogUtil; import cn.flightfeather.thirdapp.util.ScreenUtils; import cn.flightfeather.thirdapp.util.UUIDGenerator; import cn.flightfeather.thirdapp.util.photo.PhotoUtil; import cn.flightfeather.thirdapp.util.slideswaphelper.OnDeleteListener; import cn.flightfeather.thirdapp.util.slideswaphelper.OnSwipeItemClickListener; import cn.flightfeather.thirdapp.util.slideswaphelper.PlusItemSlideCallback; import cn.flightfeather.thirdapp.util.slideswaphelper.WItemTouchHelperPlus; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import static android.app.Activity.RESULT_OK; /** * A simple {@link Fragment} subclass. */ public class InspectionFragment extends Fragment implements CalendarView.OnCalendarSelectListener, View.OnClickListener, AMap.OnMyLocationChangeListener { private static final String TAG = "InspectionFragment"; private CommonApplication application; //数据库相关 private SiteDao siteDao; private ScenseDao scenseDao; private DomaincatalogDao domaincatalogDao; private DomainitemDao domainitemDao; private EvaluationruleDao evaluationruleDao; private EvaluationsubruleDao evaluationsubruleDao; private GittypeDao gittypeDao; private ProblemtypeDao problemtypeDao; private MediafileDao mediafileDao; private DbSource dbSource; private List disposables = new ArrayList<>(); //网络相关 InspectionService inspectionService; InspectionImageService inspectionImageService; SubTaskService subTaskService; //任务选择部分 private RelativeLayout rl_selectTask; private CalendarView mCalendarView; private TextView tv_title; private Map schemes; private Spinner sp_selectMonthTask; private ArrayAdapter selectMonthTaskAdapter; private RecyclerView rv_subTaskList; //string:日期:yyyy-mm, private Map> taskAllMapList; private java.util.Calendar lastMonthCalender; private java.util.Calendar calendarCurrent; private List dayTaskTimeList; private Map> subTaskMapCurrent; private List monthTaskListCurrent; private List monthTaskStringListCurrent; private List subTaskListCurrent; private TaskListAdapter subTaskListAdapter; private boolean firstLoad = true; private boolean requestAgain = false; private TaskVo monthTaskSelected = null; private Subtask subTaskSelected = null; //现场巡查部分 private RelativeLayout rl_content; private TextureMapView tmv_main; private ViewPager vp_icons; private LinearLayout ll_show; private LinearLayout ll_hide; private LinearLayout ll_icons; private ImageView iv_pointer; private LinearLayout ll_showHideDetail; private ImageView iv_showHideDetail; private LinearLayout ll_taskDetail; private ImageView iv_back; private ImageView iv_startEndTask; private AMap aMap; private MapView mv_main; private boolean hidden = false; private TextView tv_subTaskNameBar; private TextView tv_subTaskStatusBar; private String subTaskStatusCurrent = ""; private final String subTaskNotStart = "未执行"; private final String subTaskRunning = "正在执行"; private final String subTaskEnd = "已结束"; private final float banAlpha = 0.2f; private Scense scenseCurrent; private Site siteCurrent; private Inspection inspectionCurrent; private String scenseType = ""; private final String site = "工地"; private InspectionVo inspectionVoCurrent; private double latitudeCurrent = -1; private double longitudeCurrent = -1; private List problemNowMarkerList; private List problemListVoListCurrent = new ArrayList<>(); private LinearLayout ll_problemRecheck; private LinearLayout ll_takeEvidence; private LinearLayout ll_problemList; private LinearLayout ll_problemChange; private LinearLayout ll_camera; private LinearLayout ll_newGit; private LinearLayout ll_promise; private LinearLayout ll_evaluation; private LinearLayout ll_navi; private LinearLayout ll_choseLatlng; private LinearLayout ll_editeScence; //任务和工地详情 private TextView tv_detailTaskName; private TextView tv_detailTaskType; private TextView tv_detailPlanTime; private TextView tv_detailExecuteTime; private TextView tv_detailExecutors; private TextView tv_detailScenseName; private TextView tv_detailScenseType; private TextView tv_detailScenseAddress; private TextView tv_detailContact1; private TextView tv_detailContact2; private TextView tv_callContact1; private TextView tv_callContact2; //问题取证相关 private ImageView miv_add_photo1; private ImageView miv_add_photo2; private ImageView miv_add_photo3; private List pathTempList; private final int PHOTO1 = 0; private final int PHOTO2 = 1; private final int PHOTO3 = 2; private final int TAKE_PHOTO1 = 0; private final int TAKE_PHOTO2 = 1; private final int TAKE_PHOTO3 = 2; private final int PICK_PHOTO1 = 10; private final int PICK_PHOTO2 = 11; private final int PICK_PHOTO3 = 12; private File tempFileCurrent; private final int SHOW_PHOTO = 87; private final int DELETE_SUCCESS = 88; public static final int PROBLEM_LIST = 100; public static final int PROBLEM_CHANGE = 101; public static final int PROBLEM_RECHECK = 102; private int OPEN_TYPE = PROBLEM_LIST; private final int PROBLEM_DETAIL = 105; private boolean problemEditable = false; private final int SIGN = 9; private final int BUSSINESS_TYPE_SIGN = 6; private final int BUSSINESS_TYPE_CAMERA = 5; private final int SUBTASK_MAP = 200; private final int CHOSE_LATLNG = 201; private final int PROMISE = 202; private ImageView iv_upload; private ProblemListAdapter problemListAdapter = null; //任意拍照 private ImageView iv_cameraPhoto1; private ImageView iv_cameraPhoto2; private ImageView iv_cameraPhoto3; private List ivCameraList; private final int CAMERA_PHOTO = 110; private final int TAKE_CAMERA_PHOTO = 111; private final int PICK_CAMERA_PHTOO = 112; //新增技防措施 private ImageView iv_gitPhoto1; private ImageView iv_gitPhoto2; private ImageView iv_gitPhoto3; private List ivGitList; private final int GIT_PHOTO = 113; private final int TAKE_GIT_PHOTO = 114; private final int PICK_GIT_PHOTO = 115; //图片浏览相关 private final int VIEW_CAMERA_PHOTO = 116; private final int VIEW_SIGN_PHOTO = 117; private final int VIEW_EVIDENCE_TEMP_PHOTO = 118; private final int VIEW_CAMERA_TEMP_PHOTO = 226; private final int VIEW_GIT_TEMP_PHOTO = 227; private Dialog cameraDialog; private FloatingActionButton fab_map; private int currentPage; private final int TASK_PAGE = 230; private final int INSPECTION_PAGE = 231; private final int EDITE_SCENSE = 232; //加载弹出框 private Dialog dialog; //滑动删除 private WItemTouchHelperPlus extension; public InspectionFragment() { // Required empty public constructor } public void loadInspection(Subtask task) { subTaskSelected = task; if (rl_content != null && !rl_content.isShown()) { rl_content.setVisibility(View.VISIBLE); } if (rl_selectTask != null && rl_selectTask.isShown()) { rl_selectTask.setVisibility(View.INVISIBLE); } loadInspectionData(subTaskSelected.getStguid()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment Log.e(TAG, "onCreateView()"); View view = inflater.inflate(R.layout.fragment_inspection, container, false); return view; } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Log.e(TAG, "onViewCreated()"); application = (CommonApplication) getActivity().getApplication(); currentPage = TASK_PAGE; initUI(view); initMarkPhotoList(); initDataBase(); initDate(); initData(); initRecyclerView(); initSpinnerData(); refreshUploadIconStatus(); initIconViewPager(); initMap(savedInstanceState); initLocation(); rl_selectTask.setVisibility(View.VISIBLE); rl_content.setVisibility(View.INVISIBLE); } /** * Called when the fragment is no longer attached to its activity. This * is called after {@link #onDestroy()}. */ @Override public void onDetach() { super.onDetach(); } //初始化带数字marker的列表 private void initMarkPhotoList() { problemNowMarkerList = new ArrayList<>(); problemNowMarkerList.add(R.drawable.icon_mark1_red); problemNowMarkerList.add(R.drawable.icon_mark2_red); problemNowMarkerList.add(R.drawable.icon_mark3_red); problemNowMarkerList.add(R.drawable.icon_mark4_red); problemNowMarkerList.add(R.drawable.icon_mark5_red); problemNowMarkerList.add(R.drawable.icon_mark6_red); problemNowMarkerList.add(R.drawable.icon_mark7_red); problemNowMarkerList.add(R.drawable.icon_mark8_red); problemNowMarkerList.add(R.drawable.icon_mark9_red); problemNowMarkerList.add(R.drawable.icon_mark10_red); problemNowMarkerList.add(R.drawable.icon_mark11_red); problemNowMarkerList.add(R.drawable.icon_mark12_red); problemNowMarkerList.add(R.drawable.icon_mark13_red); problemNowMarkerList.add(R.drawable.icon_mark14_red); problemNowMarkerList.add(R.drawable.icon_mark15_red); problemNowMarkerList.add(R.drawable.icon_mark16_red); problemNowMarkerList.add(R.drawable.icon_mark17_red); problemNowMarkerList.add(R.drawable.icon_mark18_red); problemNowMarkerList.add(R.drawable.icon_mark19_red); problemNowMarkerList.add(R.drawable.icon_mark20_red); problemNowMarkerList.add(R.drawable.icon_mark21_red); problemNowMarkerList.add(R.drawable.icon_mark22_red); problemNowMarkerList.add(R.drawable.icon_mark23_red); problemNowMarkerList.add(R.drawable.icon_mark24_red); problemNowMarkerList.add(R.drawable.icon_mark25_red); problemNowMarkerList.add(R.drawable.icon_mark26_red); problemNowMarkerList.add(R.drawable.icon_mark27_red); problemNowMarkerList.add(R.drawable.icon_mark28_red); problemNowMarkerList.add(R.drawable.icon_mark29_red); problemNowMarkerList.add(R.drawable.icon_mark30_red); } private void initUI(View view) { //任务选择部分 rl_selectTask = (RelativeLayout) view.findViewById(R.id.rl_select_Task); mCalendarView = (CalendarView) view.findViewById(R.id.calendarView); mCalendarView.setOnCalendarSelectListener(this); fab_map = (FloatingActionButton) view.findViewById(R.id.fab_map); fab_map.setOnClickListener(this); tv_title = (TextView) view.findViewById(R.id.tv_title); sp_selectMonthTask = (Spinner) view.findViewById(R.id.sp_select_month_task); rv_subTaskList = (RecyclerView) view.findViewById(R.id.recyclerView); //现场巡查部分 rl_content = (RelativeLayout) view.findViewById(R.id.rl_content); vp_icons = (ViewPager) view.findViewById(R.id.vp_patrol_icons); ll_icons = (LinearLayout) view.findViewById(R.id.ll_patrol_icons); ll_show = (LinearLayout) view.findViewById(R.id.ll_patrol_show); ll_hide = (LinearLayout) view.findViewById(R.id.ll_patrol_hide); iv_pointer = (ImageView) view.findViewById(R.id.iv_patrol_pointer); ll_showHideDetail = (LinearLayout) view.findViewById(R.id.ll_show_hide_detail); iv_showHideDetail = (ImageView) view.findViewById(R.id.iv_patrol_show_site_detail); ll_taskDetail = (LinearLayout) view.findViewById(R.id.ll_patrol_task_detail); iv_back = (ImageView) view.findViewById(R.id.iv_patrol_back); iv_startEndTask = (ImageView) view.findViewById(R.id.iv_start_end_task); mv_main = (MapView) view.findViewById(R.id.mv_main); tv_subTaskNameBar = (TextView) view.findViewById(R.id.tv_subtask_name_bar); tv_subTaskStatusBar = (TextView) view.findViewById(R.id.tv_subtask_status_bar); tv_detailTaskName = (TextView) view.findViewById(R.id.tv_subtask_name); tv_detailTaskType = (TextView) view.findViewById(R.id.tv_subtask_type); tv_detailPlanTime = (TextView) view.findViewById(R.id.tv_subtask_plan_time); tv_detailExecuteTime = (TextView) view.findViewById(R.id.tv_subtask_execute_time); tv_detailExecutors = (TextView) view.findViewById(R.id.tv_subtask_executors); tv_detailScenseName = (TextView) view.findViewById(R.id.tv_scense_name); tv_detailScenseType = (TextView) view.findViewById(R.id.tv_scense_type); tv_detailScenseAddress = (TextView) view.findViewById(R.id.tv_scense_address); tv_detailContact1 = (TextView) view.findViewById(R.id.tv_scense_contact1); tv_detailContact2 = (TextView) view.findViewById(R.id.tv_scense_contact2); iv_upload = (ImageView) view.findViewById(R.id.iv_upload); tv_callContact1 = (TextView) view.findViewById(R.id.tv_call_contact1); tv_callContact2 = (TextView) view.findViewById(R.id.tv_call_contact2); ll_show.setOnClickListener(this); ll_hide.setOnClickListener(this); ll_showHideDetail.setOnClickListener(this); iv_back.setOnClickListener(this); iv_upload.setOnClickListener(this); ll_taskDetail.setVisibility(View.GONE); } //初始化数据库 private void initDataBase() { DaoSession daoSession = application.getDaoSession(); scenseDao = daoSession.getScenseDao(); siteDao = daoSession.getSiteDao(); domaincatalogDao = daoSession.getDomaincatalogDao(); domainitemDao = daoSession.getDomainitemDao(); evaluationruleDao = daoSession.getEvaluationruleDao(); evaluationsubruleDao = daoSession.getEvaluationsubruleDao(); gittypeDao = daoSession.getGittypeDao(); problemtypeDao = daoSession.getProblemtypeDao(); mediafileDao = daoSession.getMediafileDao(); dbSource = DbLink.getDbSource(application); } //初始化时间和日历 private void initDate() { tv_title.setText(mCalendarView.getCurYear() + "年" + mCalendarView.getCurMonth() + "月"); lastMonthCalender = java.util.Calendar.getInstance(); calendarCurrent = java.util.Calendar.getInstance(); } //初始化数据 private void initData() { taskAllMapList = new HashMap<>(); subTaskListCurrent = new ArrayList<>(); inspectionService = application.getRetrofit().create(InspectionService.class); inspectionImageService = application.getRetrofitImage().create(InspectionImageService.class); subTaskService = application.getRetrofit().create(SubTaskService.class); String yearMonth = DateFormatter.YearMonthFormat.format(new Date()); getThreeMonthTask(yearMonth, "Middle", false); } //打电话 private View.OnClickListener callClikeListner(final String tele) { View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tele)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }; return onClickListener; } private void refreshUploadIconStatus() { List mediafileList = mediafileDao.queryBuilder().where(MediafileDao.Properties.Remark.eq("未上传")).list(); if (mediafileList != null && mediafileList.size() > 0) { iv_upload.setSelected(true); } else { iv_upload.setSelected(false); } } //联网获得三个月的任务信息 private void getThreeMonthTask(final String yearMonth, final String type, final boolean clearMap) { showLoadingDialog(); Call> loadThreeMonthTasks = inspectionService.loadThreeMonthTasks(yearMonth, application.getCurrentUser().getGuid(), type, String.valueOf(application.getCurrentUser().getUsertypeid())); loadThreeMonthTasks.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { if (response.body() != null) { requestAgain = false; List taskPackList = response.body(); if (clearMap) { taskAllMapList.clear(); } if (taskPackList != null && taskPackList.size() > 0) { for (TaskPack taskPack : taskPackList) { taskAllMapList.put(taskPack.getDate(), taskPack.getUpperTaskList()); } if (type.equals("Middle")) { showMonthAllTask(calendarCurrent); } } loadingOver(true); } else if (response.errorBody() != null) { if (!requestAgain) { requestAgain = true; getThreeMonthTask(yearMonth, type, clearMap); } else { loadingOver(false); Toast.makeText(application, "获取任务信息出错", Toast.LENGTH_SHORT).show(); showMonthAllTask(calendarCurrent); } System.out.println("ThreeMonthTask:" + response.errorBody()); } } @Override public void onFailure(Call> call, Throwable t) { if (!requestAgain) { requestAgain = true; getThreeMonthTask(yearMonth, type, clearMap); } else { loadingOver(false); Toast.makeText(application, "网络链接失败", Toast.LENGTH_SHORT).show(); showMonthAllTask(calendarCurrent); } System.out.println("ThreeMonthTask:" + t.toString()); } }); } //显示当前月的月任务列表(日历上的标注交给spinner操作) private void showMonthAllTask(java.util.Calendar calendarCurrent) { monthTaskListCurrent = new ArrayList<>(); monthTaskStringListCurrent = new ArrayList<>(); dayTaskTimeList = new ArrayList<>(); subTaskMapCurrent = new HashMap<>(); String currentMonth = DateFormatter.YearMonthFormat.format(calendarCurrent.getTime()); List taskVoList = taskAllMapList.get(currentMonth); if (taskVoList != null && taskVoList.size() > 0) { monthTaskStringListCurrent.add("全部任务"); monthTaskListCurrent.addAll(taskVoList); for (TaskVo monthTask : taskVoList) { // monthTaskListCurrent.add(monthTask); monthTaskStringListCurrent.add(monthTask.getName()); } } else { monthTaskStringListCurrent.add("无任务"); } selectMonthTaskAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, monthTaskStringListCurrent); sp_selectMonthTask.setAdapter(selectMonthTaskAdapter); } //显示当月日数据和历标注 private void showOneMonthAllTask2(java.util.Calendar calendarCurrent) { String currentMonth = DateFormatter.YearMonthFormat.format(calendarCurrent.getTime()); if (subTaskMapCurrent != null) { List taskVoList = taskAllMapList.get(currentMonth); if (taskVoList != null && taskVoList.size() > 0) { for (TaskVo monthTask : taskVoList) { getOneMonthTaskAllData(monthTask); } } addScheme(dayTaskTimeList); } } //显示一个月任务的数据和日历标注(Spinner选择一个月任务后的操作) private void showOneMonthTask(TaskVo monthTask) { getOneMonthTaskAllData(monthTask); addScheme(dayTaskTimeList); } //获取一个月任务的全部数据 private void getOneMonthTaskAllData(TaskVo monthTask) { List dayTaskList = monthTask.getDaytaskList(); if (dayTaskList != null && dayTaskList.size() > 0) { for (TaskVo dayTask : dayTaskList) { java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(dayTask.getStarttime()); int day = calendar.get(java.util.Calendar.DAY_OF_MONTH); dayTaskTimeList.add(day); List subTaskList = dayTask.getSubtaskList(); if (subTaskList != null && subTaskList.size() > 0) { if (subTaskMapCurrent.containsKey(day)) { subTaskMapCurrent.get(day).addAll(subTaskList); } else { List subtasks = new ArrayList<>(); subtasks.addAll(subTaskList); subTaskMapCurrent.put(day, subtasks); } } } } else { } } //跟据日期显示那天的子任务 private void showSubTaskByDay(int day) { if (application.isDebugMode()) { subTaskListCurrent.removeAll(subTaskListCurrent); Subtask subtask = new Subtask(); subtask.setStguid(UUIDGenerator.generate16ShortUUID()); subtask.setName("巡查长风生态商务区10号北地块二期(北区)新建工程"); int typeno = 1; subtask.setTypeno((byte) typeno); subtask.setType("巡查"); subtask.setScenseid("Y0TdY7cjFHcVJCIf"); subtask.setScensename("长风生态商务区10号北地块二期(北区)新建工程"); subtask.setScenseaddress("同普路 泸定路"); subtask.setProvincename("上海市"); subtask.setCityname("上海市"); subtask.setDistrictname("普陀区"); java.util.Calendar startTime = java.util.Calendar.getInstance(); startTime.set(2018, 1, 18); java.util.Calendar endTime = java.util.Calendar.getInstance(); endTime.set(2018, 1, 18); subtask.setPlanstarttime(startTime.getTime()); subtask.setPlanendtime(endTime.getTime()); subtask.setExecutorguids("Kmi6GJoee93KzWfm"); subtask.setExecutorusernames("chenchong"); subtask.setExecutorrealtimes("陈冲"); subtask.setStatus("未执行"); subTaskListCurrent.add(subtask); subtask = new Subtask(); subtask.setStguid(UUIDGenerator.generate16ShortUUID()); subtask.setName("巡查金山亭林大型居住区市政道路项目林吉路(车亭公路-红梓路)"); typeno = 1; subtask.setTypeno((byte) typeno); subtask.setType("巡查"); subtask.setScenseid("XvQio9lWSMFguTob"); subtask.setScensename("金山亭林大型居住区市政道路项目林吉路(车亭公路-红梓路)"); subtask.setScenseaddress("亭林镇林吉路"); subtask.setProvincename("上海市"); subtask.setCityname("上海市"); subtask.setDistrictname("金山区"); startTime = java.util.Calendar.getInstance(); startTime.set(2018, 1, 20, 10, 20); endTime = java.util.Calendar.getInstance(); endTime.set(2018, 1, 20, 11, 30); subtask.setPlanstarttime(startTime.getTime()); subtask.setPlanendtime(endTime.getTime()); subtask.setExecutorguids("Kmi6GJoee93KzWfm"); subtask.setExecutorusernames("chenchong"); subtask.setExecutorrealtimes("陈冲"); subtask.setStatus("正在执行"); subTaskListCurrent.add(subtask); subtask = new Subtask(); subtask.setStguid(UUIDGenerator.generate16ShortUUID()); subtask.setName("巡查静安区大宁路街道325街坊地块住宅项目"); typeno = 1; subtask.setTypeno((byte) typeno); subtask.setType("巡查"); subtask.setScenseid("ZjTy9pdMPUmAgltG"); subtask.setScensename("静安区大宁路街道325街坊地块住宅项目"); subtask.setScenseaddress("彭江路,平型关路交叉口"); subtask.setProvincename("上海市"); subtask.setCityname("上海市"); subtask.setDistrictname("静安区"); startTime = java.util.Calendar.getInstance(); startTime.set(2018, 1, 23, 15, 10); endTime = java.util.Calendar.getInstance(); endTime.set(2018, 1, 23, 16, 30); subtask.setPlanstarttime(startTime.getTime()); subtask.setPlanendtime(endTime.getTime()); subtask.setExecutorguids("Kmi6GJoee93KzWfm"); subtask.setExecutorusernames("chenchong"); subtask.setExecutorrealtimes("陈冲"); subtask.setStatus("已结束"); subTaskListCurrent.add(subtask); } else { if (subTaskMapCurrent != null) { List subTaskList = subTaskMapCurrent.get(day); subTaskListCurrent.clear(); if (subTaskList != null && subTaskList.size() > 0) { for (Subtask subtask : subTaskList) { if (!subTaskListCurrent.contains(subtask)) { subTaskListCurrent.add(subtask); } } } if (subTaskListCurrent.size() > 0) { if (rl_content.getVisibility() != View.VISIBLE) { fab_map.show(); } } else { fab_map.hide(); } } } subTaskListAdapter.notifyDataSetChanged(); } //设置spinner的点击事件 private void initSpinnerData() { sp_selectMonthTask.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { //将选中的文字变为白色 CheckedTextView tv = (CheckedTextView) view.findViewById(view.getId()); tv.setTextColor(getContext().getResources().getColor(R.color.white)); //选择后清空数据重新读取 dayTaskTimeList = new ArrayList(); subTaskMapCurrent = new HashMap>(); if (position == 0) { showOneMonthAllTask2(calendarCurrent); showSubTaskByDay(calendarCurrent.get(java.util.Calendar.DAY_OF_MONTH)); } else { monthTaskSelected = monthTaskListCurrent.get(position - 1); showOneMonthTask(monthTaskSelected); showSubTaskByDay(calendarCurrent.get(java.util.Calendar.DAY_OF_MONTH)); } } @Override public void onNothingSelected(AdapterView parent) { } }); } //初始化子任务列表 private void initRecyclerView() { LinearLayoutManager manager = new LinearLayoutManager(getContext()); rv_subTaskList.setLayoutManager(manager); subTaskListAdapter = new TaskListAdapter(getContext(), subTaskListCurrent); subTaskListAdapter.setOnDeleteListener(new OnDeleteListener() { @Override public void delete(final int position) { Call deleteSubTask = subTaskService.deleteSubTask(subTaskListCurrent.get(position).getStguid()); deleteSubTask.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { subTaskListAdapter.notifyItemRemoved(position); subTaskListAdapter.notifyItemRangeChanged(position, subTaskListCurrent.size() - position); subTaskListCurrent.remove(position); showToast("删除成功"); String yearMonth = DateFormatter.YearMonthFormat.format(new Date()); getThreeMonthTask(yearMonth, "Middle", false); } else { showToast("删除失败"); } } @Override public void onFailure(Call call, Throwable t) { } }); } }); subTaskListAdapter.setOnItemClickListener(new OnSwipeItemClickListener() { @Override public void click(int position) { subTaskSelected = subTaskListCurrent.get(position); loadInspectionData(subTaskSelected.getStguid()); } }); rv_subTaskList.setAdapter(subTaskListAdapter); //2019.1.23 by riku 添加滑动删除功能 if (application.getCurrentUser().getUsertypeid() == 0) { PlusItemSlideCallback callback = new PlusItemSlideCallback(WItemTouchHelperPlus.SLIDE_ITEM_TYPE_ITEMVIEW); extension = new WItemTouchHelperPlus(callback); extension.attachToRecyclerView(rv_subTaskList); } } //初始化功能面版viewpager private void initIconViewPager() { ll_show.setVisibility(View.INVISIBLE); View iconPage1 = View.inflate(getContext(), R.layout.page_patrol_icons_first, null); View iconPage2 = View.inflate(getContext(), R.layout.page_patrol_icons_second, null); ll_problemRecheck = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_problem_recheck); ll_takeEvidence = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_take_evidence); ll_problemList = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_problem_list); ll_problemChange = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_change); ll_camera = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_camera); ll_newGit = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_newgit); ll_promise = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_promiss); ll_evaluation = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_rate); ll_navi = (LinearLayout) iconPage2.findViewById(R.id.ln_patrol_navi); ll_choseLatlng = (LinearLayout) iconPage2.findViewById(R.id.ln_patrol_chose_latlng); ll_editeScence = (LinearLayout) iconPage2.findViewById(R.id.ln_patrol_edit); List viewList = new ArrayList<>(); viewList.add(iconPage1); viewList.add(iconPage2); IconsPageAdapter adapter = new IconsPageAdapter(viewList); vp_icons.setAdapter(adapter); vp_icons.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { //当页面改变时,切换到对应的小圆点 if (position == 0) { iv_pointer.setImageResource(R.drawable.select_first_point); } else if (position == 1) { iv_pointer.setImageResource(R.drawable.select_second_point); } } @Override public void onPageScrollStateChanged(int state) { } }); } //根据日期列表添加全部标记点 private void addScheme(List dayTaskTimeList) { schemes = new HashMap<>(); if (dayTaskTimeList != null && dayTaskTimeList.size() > 0) { for (Integer day : dayTaskTimeList) { Calendar c = getSchemeCalendar(calendarCurrent.get(java.util.Calendar.YEAR), (calendarCurrent.get(java.util.Calendar.MONTH) + 1), day, 0xFFdf1356, false); schemes.put(c.toString(), c); } } mCalendarView.setSchemeDate(schemes); } //添加标记点 private Calendar getSchemeCalendar(int year, int month, int day, int color, boolean schemeCompleted) { Calendar calendar = new Calendar(); calendar.setYear(year); calendar.setMonth(month); calendar.setDay(day); calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色 calendar.setScheme("记"); return calendar; } //初始化地图 private void initMap(Bundle savedInstanceState) { mv_main.onCreate(savedInstanceState); aMap = mv_main.getMap(); aMap.setRenderFps(60); aMap.getUiSettings().setZoomControlsEnabled(false); aMap.getUiSettings().setScaleControlsEnabled(true); //点击marker跳转到问题详情 aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { String guid = marker.getSnippet(); if (guid != null && guid.length() > 0) { Intent intent = new Intent(getActivity(), ProblemDetailActivity.class); ProblemlistVo problemlistVo = null; for (int i = 0; i < problemListVoListCurrent.size(); i++) { if (problemListVoListCurrent.get(i).getGuid().equals(guid)) { problemlistVo = problemListVoListCurrent.get(i); } } intent.putExtra("problemlistVo", problemlistVo); intent.putExtra("subTaskSelected", subTaskSelected); intent.putExtra("scenseLat", scenseCurrent.getLatitude()); intent.putExtra("scenseLng", scenseCurrent.getLongitude()); intent.putExtra("editable", problemEditable); intent.putExtra("type", PROBLEM_LIST); startActivity(intent); } return false; } }); } //联网加载巡查信息 private void loadInspectionData(final String subTaskId) { showLoadingDialog(); if (inspectionService == null) inspectionService = application.getRetrofit().create(InspectionService.class); Call loadallInspectionData = inspectionService.loadInspectionData(subTaskId); loadallInspectionData.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { inspectionVoCurrent = response.body(); inspectionCurrent = transInspectionVo(inspectionVoCurrent); initInspectionData(); fab_map.hide(); showIcons(); rl_content.setVisibility(View.VISIBLE); rl_selectTask.setVisibility(View.INVISIBLE); loadingOver(true); } else if (response.errorBody() != null) { if (!requestAgain) { requestAgain = true; loadInspectionData(subTaskId); } else { loadingOver(false); Toast.makeText(application, "获取巡查信息失败", Toast.LENGTH_SHORT).show(); System.out.println("loadInspectionData:" + response.errorBody().toString()); } } } @Override public void onFailure(Call call, Throwable t) { if (!requestAgain) { requestAgain = true; loadInspectionData(subTaskId); } else { loadingOver(false); Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show(); System.out.println("loadInspectionData:" + t.toString()); } } }); } private Inspection transInspectionVo(InspectionVo inspectionVo) { Inspection inspection = new Inspection(); inspection.setGuid(inspectionVo.getGuid()); inspection.setStguid(inspectionVo.getStguid()); inspection.setSguid(inspectionVo.getSguid()); inspection.setScensename(inspectionVo.getScensename()); inspection.setScenseaddress(inspectionVo.getScenseaddress()); inspection.setIstogether(inspectionVo.getIstogether()); inspection.setEntouraget(inspectionVo.getEntouraget()); inspection.setEntouragewx(inspectionVo.getEntouragewx()); inspection.setEntourage(inspectionVo.getEntourage()); inspection.setExecutionstarttime(inspectionVo.getExecutionstarttime()); inspection.setExecutionendtime(inspectionVo.getExecutionendtime()); inspection.setProblemcount(inspectionVo.getProblemcount()); inspection.setIsrechecked(inspectionVo.getIsrechecked()); inspection.setRecheckcount(inspectionVo.getRecheckcount()); inspection.setPromissednum(inspectionVo.getPromissednum()); inspection.setChangednum(inspectionVo.getChangednum()); inspection.setChangednum(inspectionVo.getChangednum()); inspection.setIschanged(inspectionVo.getIschanged()); inspection.setIsrvaluated(inspectionVo.getIsrvaluated()); inspection.setIspromissed(inspectionVo.getIspromissed()); inspection.setPromissedtime(inspectionVo.getPromissedtime()); inspection.setPromisseduserguid(inspectionVo.getPromisseduserguid()); inspection.setPromissedusername(inspectionVo.getPromissedusername()); inspection.setPromisseduserrealname(inspectionVo.getPromisseduserrealname()); inspection.setPromissedway(inspectionVo.getPromissedway()); inspection.setPromisseddeadline(inspectionVo.getPromisseddeadline()); inspection.setPromissbookpath(inspectionVo.getPromissbookpath()); inspection.setSignpath(inspectionVo.getSignpath()); inspection.setExtension1(inspectionVo.getExtension1()); inspection.setExtension2(inspectionVo.getExtension2()); inspection.setExtension3(inspectionVo.getExtension3()); inspection.setRemark(inspectionVo.getRemark()); return inspection; } //初始化巡查的基本信息 private void initInspectionData() { if (application.isDebugMode()) { inspectionCurrent = new Inspection(); inspectionCurrent.setGuid(UUIDGenerator.generate16ShortUUID()); inspectionCurrent.setStguid(subTaskSelected.getStguid()); inspectionCurrent.setSguid(subTaskSelected.getScenseid()); inspectionCurrent.setScensename(subTaskSelected.getScensename()); inspectionCurrent.setScenseaddress(subTaskSelected.getScenseaddress()); inspectionCurrent.setProblemcount(0); inspectionCurrent.setChangednum(0); } tv_subTaskNameBar.setText(subTaskSelected.getName()); currentPage = INSPECTION_PAGE; aMap.clear(); subTaskStatusCurrent = subTaskSelected.getStatus(); switch (subTaskStatusCurrent) { case subTaskNotStart: iv_startEndTask.setSelected(false); break; case subTaskRunning: iv_startEndTask.setSelected(true); break; case subTaskEnd: iv_startEndTask.setSelected(true); } updateStatus(); //2019.1.4 by riku: 添加 用户类型为“主管部门”或“管理员”,编号为2或0时,按钮iv_startEndTask没有点击事件 if (application.getCurrentUser().getUsertypeid() != 2 || application.getCurrentUser().getUsertypeid() != 0) { iv_startEndTask.setOnClickListener(this); } else { iv_startEndTask.setAlpha(0.5f); } scenseCurrent = scenseDao.queryBuilder().where(ScenseDao.Properties.Guid.eq(subTaskSelected.getScenseid())).unique(); scenseType = scenseCurrent.getType(); switch (scenseType) { case site: siteCurrent = siteDao.queryBuilder().where(SiteDao.Properties.Sguid.eq(subTaskSelected.getScenseid())).unique(); break; } tv_detailTaskName.setText(subTaskSelected.getName()); tv_detailTaskType.setText(subTaskSelected.getType()); java.util.Calendar planStartTime = java.util.Calendar.getInstance(); planStartTime.setTime(subTaskSelected.getPlanstarttime()); java.util.Calendar planEndTime = java.util.Calendar.getInstance(); planEndTime.setTime(subTaskSelected.getPlanendtime()); if (planStartTime.get(java.util.Calendar.YEAR) == planEndTime.get(java.util.Calendar.YEAR) && planStartTime.get(java.util.Calendar.MONTH) == planEndTime.get(java.util.Calendar.MONTH) && planStartTime.get(java.util.Calendar.DAY_OF_MONTH) == planEndTime.get(java.util.Calendar.DAY_OF_MONTH)) { String text = DateFormatter.dateFormat.format(planStartTime.getTime()); String startTime = DateFormatter.timeFormat.format(planStartTime.getTime()); if (startTime.equals("00:00")) { tv_detailPlanTime.setText(text); } else { String endTime = DateFormatter.timeFormat.format(planEndTime.getTime()); tv_detailPlanTime.setText(text + " " + startTime + " - " + endTime); } } else { String startTime = DateFormatter.dateTimeFormat.format(planStartTime.getTime()); String endTime = DateFormatter.dateTimeFormat.format(planEndTime.getTime()); tv_detailPlanTime.setText(startTime + " - " + endTime); } refreshExecutionTime(); tv_detailExecutors.setText(subTaskSelected.getExecutorrealtimes().replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW)); tv_detailScenseName.setText(scenseCurrent.getName()); tv_detailScenseType.setText(scenseCurrent.getType()); tv_detailScenseAddress.setText(scenseCurrent.getCityname() + scenseCurrent.getDistrictname() + " " + scenseCurrent.getLocation()); tv_detailContact1.setText(scenseCurrent.getContacts() + " " + scenseCurrent.getContactst()); tv_detailContact2.setText(""); tv_callContact1.setOnClickListener(callClikeListner(scenseCurrent.getContactst())); refreshProblemMarker(); //将场景位置添加到地图上 LatLng sourceLatLng = new LatLng(scenseCurrent.getLatitude(), scenseCurrent.getLongitude()); MarkerOptions options = new MarkerOptions().position(sourceLatLng); aMap.addMarker(options); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sourceLatLng, 15f)); } private void refreshExecutionTime() { String executeTime = ""; if (subTaskSelected.getExecutionstarttime() != null) { executeTime = DateFormatter.dateTimeFormat.format(subTaskSelected.getExecutionstarttime()); } else { executeTime = "未执行"; } if (subTaskSelected.getExecutionendtime() != null) { executeTime = executeTime + " - " + DateFormatter.timeFormat.format(subTaskSelected.getExecutionendtime()); } tv_detailExecuteTime.setText(executeTime); } //更新状态信息 private void updateStatus() { tv_subTaskStatusBar.setText(subTaskStatusCurrent); setIconsStatus(subTaskStatusCurrent); } //初始化位置 public void initLocation() { MyLocationStyle myLocationStyle; myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。 // myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。 myLocationStyle.showMyLocation(true); myLocationStyle.radiusFillColor(getResources().getColor(R.color.transparent)); myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,定位点依照设备方向旋转,并且蓝点会跟随设备移动 aMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style aMap.getUiSettings().setMyLocationButtonEnabled(false);//设置默认定位按钮是否显示,非必需设置。 aMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。 aMap.setOnMyLocationChangeListener(this); } //根据任务状态,设置图标面板功能开关 public void setIconsStatus(String subTaskStatus) { switch (subTaskStatus) { case subTaskNotStart: ll_problemRecheck.setAlpha(banAlpha); ll_problemRecheck.setOnClickListener(showNeedStartTaskListener()); ll_takeEvidence.setAlpha(banAlpha); ll_takeEvidence.setOnClickListener(showNeedStartTaskListener()); ll_problemList.setAlpha(banAlpha); ll_problemList.setOnClickListener(showNeedStartTaskListener()); ll_problemChange.setAlpha(banAlpha); ll_problemChange.setOnClickListener(showNeedStartTaskListener()); ll_camera.setAlpha(banAlpha); ll_camera.setOnClickListener(showNeedStartTaskListener()); ll_newGit.setAlpha(banAlpha); ll_newGit.setOnClickListener(showNeedStartTaskListener()); ll_promise.setAlpha(banAlpha); ll_promise.setOnClickListener(showNeedStartTaskListener()); ll_evaluation.setAlpha(banAlpha); ll_evaluation.setOnClickListener(showNeedStartTaskListener()); ll_navi.setOnClickListener(this); ll_choseLatlng.setOnClickListener(this); ll_editeScence.setOnClickListener(this); break; case subTaskRunning: ll_problemRecheck.setAlpha(1); ll_problemRecheck.setOnClickListener(this); ll_takeEvidence.setAlpha(1); ll_takeEvidence.setOnClickListener(this); ll_problemList.setAlpha(1); ll_problemList.setOnClickListener(this); ll_problemChange.setAlpha(1); ll_problemChange.setOnClickListener(this); ll_camera.setAlpha(1); ll_camera.setOnClickListener(this); ll_newGit.setAlpha(1); ll_newGit.setOnClickListener(this); ll_promise.setAlpha(1); ll_promise.setOnClickListener(this); ll_evaluation.setAlpha(1); ll_evaluation.setOnClickListener(this); ll_navi.setOnClickListener(this); ll_choseLatlng.setOnClickListener(this); ll_editeScence.setOnClickListener(this); break; case subTaskEnd: ll_problemRecheck.setAlpha(1); ll_problemRecheck.setOnClickListener(this); ll_takeEvidence.setAlpha(banAlpha); ll_takeEvidence.setOnClickListener(null); ll_problemList.setAlpha(1); ll_problemList.setOnClickListener(this); ll_problemChange.setAlpha(1); ll_problemChange.setOnClickListener(this); ll_camera.setAlpha(1); ll_camera.setOnClickListener(this); ll_newGit.setAlpha(1); ll_newGit.setOnClickListener(this); ll_promise.setAlpha(1); ll_promise.setOnClickListener(this); ll_evaluation.setAlpha(1); ll_evaluation.setOnClickListener(this); ll_navi.setOnClickListener(this); ll_choseLatlng.setOnClickListener(this); ll_editeScence.setOnClickListener(this); break; } if (application.getCurrentUser().getUsertypeid() == 2) { ll_takeEvidence.setAlpha(banAlpha); ll_takeEvidence.setOnClickListener(null); ll_problemChange.setAlpha(banAlpha); ll_problemChange.setOnClickListener(null); ll_camera.setAlpha(banAlpha); ll_camera.setOnClickListener(null); ll_evaluation.setAlpha(banAlpha); ll_evaluation.setOnClickListener(null); ll_navi.setAlpha(banAlpha); ll_navi.setOnClickListener(null); ll_choseLatlng.setAlpha(banAlpha); ll_choseLatlng.setOnClickListener(null); ll_editeScence.setAlpha(banAlpha); ll_editeScence.setOnClickListener(null); } } //显示请开始任务的OnClickListener public View.OnClickListener showNeedStartTaskListener() { View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); if (application.getCurrentUser().getUsertypeid() == 2) { dialog.setTitle("任务还未开始"); dialog.setMessage("无可查看的详细信息"); } else { dialog.setTitle("请先开始任务"); dialog.setMessage("点击界面右上角的'开始'按钮,来开始任务"); } dialog.setPositiveButton("确定", null); dialog.show(); } }; return listener; } //向下收缩图标面板 public void hideIcons() { ll_icons.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.bottom_menu_exit)); ll_icons.setVisibility(View.GONE); ll_show.setVisibility(View.VISIBLE); } //向上显示图标面板 public void showIcons() { ll_icons.setVisibility(View.VISIBLE); ll_icons.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.bottom_menu_enter)); ll_show.setVisibility(View.GONE); } //向上收缩任务详情 private void hideTaskDetail() { ll_taskDetail.setVisibility(View.VISIBLE); ll_taskDetail.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.top_menu_exit)); ll_taskDetail.setVisibility(View.GONE); } //向下显示任务详情 private void showTaskDetail() { refreshExecutionTime(); ll_taskDetail.setVisibility(View.VISIBLE); ll_taskDetail.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.top_menu_enter)); } //显示开始任务对话框 private void showStartTaskDialog() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle("要开始任务吗?"); dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { subTaskStatusCurrent = subTaskRunning; updateStatus(); subTaskSelected.setStatus(subTaskRunning); subTaskSelected.setExecutionstarttime(new Date()); inspectionCurrent.setExecutionstarttime(new Date()); updateSubtask(subTaskSelected); updateInspection(inspectionCurrent); iv_startEndTask.setSelected(true); } }); dialog.setNegativeButton("取消", null); dialog.show(); } //显示结束任务对话框 private void showEndTaskDialog() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle("要结束任务吗?"); dialog.setMessage("结束任务后问题取证功能将不可用"); dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { subTaskStatusCurrent = subTaskEnd; updateStatus(); subTaskSelected.setStatus(subTaskEnd); subTaskSelected.setExecutionendtime(new Date()); inspectionCurrent.setExecutionendtime(new Date()); updateSubtask(subTaskSelected); updateInspection(inspectionCurrent); } }); dialog.setNegativeButton("取消", null); dialog.show(); } //提交subtask信息 private void updateSubtask(Subtask subtask) { Call updateSubtask = inspectionService.updateSubTask(subtask); updateSubtask.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { System.out.println("SubTask:" + response.body().toString()); // showToast("提交subtask成功"); } else if (response.errorBody() != null) { System.out.println("SubTask:" + response.errorBody().toString()); showToast("提交subtask失败"); } } @Override public void onFailure(Call call, Throwable t) { System.out.println("SubTask:" + t.toString()); showToast("联网失败"); } }); } //提交inspection信息 private void updateInspection(Inspection inspection) { Call updateInspection = inspectionService.updateInspection(inspection); updateInspection.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { System.out.println("inspection:" + response.body().toString()); // showToast("提交inspection成功"); } else if (response.errorBody() != null) { System.out.println("inspection:" + response.errorBody().toString()); showToast("提交inspection失败"); } } @Override public void onFailure(Call call, Throwable t) { System.out.println("inspection:" + t.toString()); showToast("联网失败"); } }); } //刷新problem位置marker private void refreshProblemMarker() { Call> loadProblemList = inspectionService.loadProblemList(inspectionCurrent.getGuid()); loadProblemList.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { if (response.body() != null) { List problemlistVoList = response.body(); if (problemlistVoList != null) { addProblemMarkers(problemlistVoList); } } else if (response.errorBody() != null) { showToast("获取问题marker失败"); System.out.println("loadProblemList:" + response.errorBody().toString()); } } @Override public void onFailure(Call> call, Throwable t) { showToast("联网失败"); System.out.println("loadProblemList:" + t.toString()); } }); } //往地图上添加问题位置marker private void addProblemMarkers(List problemlistVoList) { problemListVoListCurrent = problemlistVoList; aMap.clear(); for (int i = 0; i < problemlistVoList.size(); i++) { ProblemlistVo problemlistVo = problemlistVoList.get(i); //添加marker到地图上 LatLng latLngNow = new LatLng(problemlistVo.getLatitude(), problemlistVo.getLongitude()); MarkerOptions options = new MarkerOptions(); //将marker放大 Bitmap bm = BitmapFactory.decodeResource(getResources(), problemNowMarkerList.get(i)); Matrix matrix = new Matrix(); matrix.setScale(0.7f, 0.7f); Bitmap bmBig = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); options.icon(BitmapDescriptorFactory.fromBitmap(bmBig)); options.position(latLngNow); options.snippet(problemlistVo.getGuid()); Marker marker = aMap.addMarker(options); marker.setInfoWindowEnable(false); } //将场景位置添加到地图上 LatLng sourceLatLng = new LatLng(scenseCurrent.getLatitude(), scenseCurrent.getLongitude()); MarkerOptions options = new MarkerOptions().position(sourceLatLng); aMap.addMarker(options); } //显示问题取证的dialog private void showTaskEvidenceDialog() { final Dialog dialog = new Dialog(getContext()); dialog.setContentView(R.layout.dialog_take_evidence); //设置dialog宽度 Window dialogWindow = dialog.getWindow(); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); final WindowManager.LayoutParams p = dialogWindow.getAttributes(); p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1); dialog.setCancelable(false); //初始化控件 final FloatingActionButton fab_ok = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_ok); FloatingActionButton fab_Close = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_close); miv_add_photo1 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo1); miv_add_photo2 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo2); miv_add_photo3 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo3); final Spinner sp_problemType = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem_type); final Spinner sp_problem = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem); final Spinner sp_location = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_location); final EditText et_locationRemark = (EditText) dialog.findViewById(R.id.et_take_evidence_location); final TextView tv_location = (TextView) dialog.findViewById(R.id.tv_location); final EditText et_problemDes = (EditText) dialog.findViewById(R.id.et_take_evidence_problem_des); //初始化变量 pathTempList = new ArrayList<>(); //2019.3.8 by riku 新增添加整改建议 LinearLayout ll_change_suggestion = dialog.findViewById(R.id.ll_change_suggestion); final Spinner sp_change_suggestion = dialog.findViewById(R.id.sp_take_evidence_select_suggestion); final EditText et_change_suggestion = dialog.findViewById(R.id.et_take_evidence_suggestion); final ArrayList suggestionList = new ArrayList<>(); final ArrayAdapter suggestionAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, suggestionList); //加载位置信息 List locationList = domainitemDao.queryBuilder().where(DomainitemDao.Properties.Catelogname.eq("工地位置结果集")).orderAsc(DomainitemDao.Properties.Value).list(); if (locationList != null && locationList.size() > 0) { DomainItemListAdapter domainItemListAdapter = new DomainItemListAdapter(locationList, getContext()); sp_location.setAdapter(domainItemListAdapter); } //加载问题数据 List problemtypeList = problemtypeDao.queryBuilder() .where(ProblemtypeDao.Properties.Tasktypeid.eq(subTaskSelected.getTypeno())) .where(ProblemtypeDao.Properties.Citycode.eq(subTaskSelected.getCitycode())) .where(ProblemtypeDao.Properties.Districtcode.eq(subTaskSelected.getDistrictcode())) .where(ProblemtypeDao.Properties.Scensetypeid.eq(scenseCurrent.getTypeid())) .orderAsc(ProblemtypeDao.Properties.Typeid).list(); if (problemtypeList.size() == 0) { Problemtype problemtype = new Problemtype(); problemtype.setGuid("0"); problemtype.setTypename("无"); problemtype.setName("无"); problemtypeList.add(problemtype); } final List problemTypeStringList = new ArrayList<>(); final Map> problemTypeMap = new HashMap<>(); for (Problemtype problemtype : problemtypeList) { if (problemTypeMap.containsKey(problemtype.getTypename())) { problemTypeMap.get(problemtype.getTypename()).add(problemtype); } else { problemTypeStringList.add(problemtype.getTypename()); List problemtypeList1 = new ArrayList<>(); problemtypeList1.add(problemtype); problemTypeMap.put(problemtype.getTypename(), problemtypeList1); } } ArrayAdapter problemTypeAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, problemTypeStringList); sp_problemType.setAdapter(problemTypeAdapter); final List problemtypes = new ArrayList<>(); final ProblemTypeListAdapter problemTypeListAdapter = new ProblemTypeListAdapter(problemtypes, getContext()); sp_problem.setAdapter(problemTypeListAdapter); sp_problemType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int i, long l) { //当选中一个分类时,从map加载问题列表,填充数据 problemtypes.removeAll(problemtypes); problemtypes.addAll(problemTypeMap.get(problemTypeStringList.get(i))); problemTypeListAdapter.notifyDataSetChanged(); if (problemTypeStringList.get(i).equals("态度")) { sp_location.setVisibility(View.GONE); et_locationRemark.setVisibility(View.GONE); miv_add_photo1.setVisibility(View.GONE); miv_add_photo2.setVisibility(View.GONE); miv_add_photo3.setVisibility(View.GONE); tv_location.setVisibility(View.GONE); } else { sp_location.setVisibility(View.VISIBLE); et_locationRemark.setVisibility(View.VISIBLE); miv_add_photo1.setVisibility(View.VISIBLE); miv_add_photo2.setVisibility(View.VISIBLE); miv_add_photo3.setVisibility(View.VISIBLE); tv_location.setVisibility(View.VISIBLE); } sp_problem.setSelection(0); //刷新对应问题的整改建议 refreshSuggestion(problemtypes.get(0).getGuid(), suggestionList, suggestionAdapter); } @Override public void onNothingSelected(AdapterView adapterView) { } }); ll_change_suggestion.setVisibility(View.VISIBLE); sp_change_suggestion.setAdapter(suggestionAdapter); sp_problem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { //当选中一个具体问题时,应该显示对应的整改建议 refreshSuggestion(problemtypes.get(position).getGuid(), suggestionList, suggestionAdapter); } @Override public void onNothingSelected(AdapterView parent) { } }); //设置确定按钮的点击事件 fab_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { fab_ok.setClickable(false); if (subTaskSelected != null && inspectionCurrent != null && scenseCurrent != null) { String problemType = sp_problemType.getSelectedItem().toString(); Problemlist problemlist = new Problemlist(); problemlist.setGuid(UUIDGenerator.generate16ShortUUID()); problemlist.setIguid(inspectionCurrent.getGuid()); problemlist.setStguid(subTaskSelected.getStguid()); problemlist.setSguid(scenseCurrent.getGuid()); problemlist.setSensename(scenseCurrent.getName()); problemlist.setSenseaddress(getScenceAddress()); Problemtype problemtypeSelected = (Problemtype) sp_problem.getSelectedItem(); problemlist.setPtguid(problemtypeSelected.getGuid()); String problemDes = ""; if (et_problemDes.getText().length() > 0) { problemDes = "(" + et_problemDes.getText().toString() + ")"; } problemlist.setProblemname(problemtypeSelected.getName() + problemDes); String adviceDes = ""; if (et_change_suggestion.getText().length() > 0) { adviceDes = "(" + et_change_suggestion.getText().toString() + ")"; } problemlist.setAdvise(sp_change_suggestion.getSelectedItem().toString() + adviceDes); problemlist.setLatitude(latitudeCurrent); problemlist.setLongitude(longitudeCurrent); Domainitem locationSelected = (Domainitem) sp_location.getSelectedItem(); if (!problemType.equals("态度")) { problemlist.setLocationid(intToByte(locationSelected.getIndex())); String locationRemark = et_locationRemark.getText().toString(); if (locationRemark.length() > 0) { locationRemark = "(" + locationRemark + ")"; } problemlist.setLocation(locationSelected.getText() + locationRemark); } else { problemlist.setLocation("无位置"); } problemlist.setTime(new Date()); problemlist.setIsrechecked(false); problemlist.setIschanged(false); if (!problemType.equals("态度") && pathTempList.size() > 0) { //保存照片到对应文件夹 List savePathList = new ArrayList(); java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(subTaskSelected.getExecutionstarttime()); String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/"; String fileName1 = problemlist.getProblemname() + " " + problemlist.getLocation() + " " + UUIDGenerator.generateUUID(4) + ".jpg"; String fileName2 = problemlist.getProblemname() + " " + problemlist.getLocation() + " " + UUIDGenerator.generateUUID(4) + ".jpg"; String fileName3 = problemlist.getProblemname() + " " + problemlist.getLocation() + " " + UUIDGenerator.generateUUID(4) + ".jpg"; File photo1 = new File(Environment.getExternalStorageDirectory(), (path + fileName1)); File photo2 = new File(Environment.getExternalStorageDirectory(), (path + fileName2)); File photo3 = new File(Environment.getExternalStorageDirectory(), (path + fileName3)); photo1.getParentFile().mkdirs(); savePathList.add(photo1); savePathList.add(photo2); savePathList.add(photo3); List fileNameList = new ArrayList(); fileNameList.add(fileName1); fileNameList.add(fileName2); fileNameList.add(fileName3); for (int i = 0; i < pathTempList.size(); i++) { File oldFile = pathTempList.get(i); File newFile = savePathList.get(i); //保存到mediaFile数据库 Mediafile mediaFile = new Mediafile(); mediaFile.setGuid(UUIDGenerator.generate16ShortUUID()); mediaFile.setIguid(inspectionCurrent.getGuid()); mediaFile.setBusinessguid(problemlist.getGuid()); mediaFile.setLongitude(longitudeCurrent); mediaFile.setLatitude(latitudeCurrent); mediaFile.setAddress(problemlist.getSenseaddress()); mediaFile.setFiletype(1); mediaFile.setBusinesstype("问题"); mediaFile.setBusinesstypeid(intToByte(1)); mediaFile.setPath(path); mediaFile.setDescription(fileNameList.get(i)); mediaFile.setSavetime(new Date()); mediaFile.setIschanged(false); String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/"; mediaFile.setExtension1(exetension1); mediaFile.setRemark("未上传"); mediafileDao.insert(mediaFile); try { copyfile(oldFile, newFile); } catch (IOException e) { e.printStackTrace(); showToast("拷贝出错" + i); } } //上传问题的基本数据 if (problemlist.getPtguid() == null) { Toast.makeText(application, "问题ID为空", Toast.LENGTH_SHORT).show(); AlertDialog.Builder d2 = new AlertDialog.Builder(getActivity()); d2.setTitle("问题ID为空"); d2.setPositiveButton("确定", null); d2.show(); } Call putOneProblemLsit = inspectionService.putOneProblemList(problemlist); putOneProblemLsit.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { System.out.println("problemList:" + response.body()); showToast("提交成功"); clearTemp(); refreshProblemMarker(); if (inspectionCurrent.getProblemcount() != null) { inspectionCurrent.setProblemcount(inspectionCurrent.getProblemcount() + 1); } else { inspectionCurrent.setProblemcount(1); } updateInspection(inspectionCurrent); dialog.dismiss(); } else if (response.errorBody() != null) { System.out.println("problemList:" + response.errorBody()); showToast("提交失败"); } } @Override public void onFailure(Call call, Throwable t) { System.out.println("problemList:" + t.toString()); showToast("联网失败"); } }); } else { showToast("至少拍一张照片"); } if (problemType.equals("态度")) { //上传问题的基本数据 Call putOneProblemLsit = inspectionService.putOneProblemList(problemlist); putOneProblemLsit.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { System.out.println("problemList:" + response.body()); showToast("提交成功"); clearTemp(); refreshProblemMarker(); dialog.dismiss(); } else if (response.errorBody() != null) { System.out.println("problemList:" + response.errorBody()); showToast("提交失败"); } } @Override public void onFailure(Call call, Throwable t) { System.out.println("problemList:" + t.toString()); showToast("联网失败"); } }); } } else { showToast("错误,Current数据缺失"); } } }); //设置取消按钮的点击事件 fab_Close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clearTemp(); dialog.dismiss(); } }); clearTemp(); refreshPhotoClickListener(pathTempList); dialog.show(); } //刷新问题对应的整改建议 private void refreshSuggestion(String ptGuid, final List list, final ArrayAdapter arrayAdapter) { dbSource.getAdviceByProblemType(ptGuid) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(List changeAdvices) { List advices = new ArrayList<>(); for (ChangeAdvice c : changeAdvices) { advices.add(c.getAdName()); } advices.add("暂无建议"); list.clear(); list.addAll(advices); arrayAdapter.notifyDataSetChanged(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); } //显示问题列表 public void showProblemList(final int type) { final Dialog dialog = new Dialog(getContext()); dialog.setContentView(R.layout.dialog_problem_list); //设置dialog宽度 Window dialogWindow = dialog.getWindow(); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); final WindowManager.LayoutParams p = dialogWindow.getAttributes(); p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1); p.height = (int) (ScreenUtils.getScreenHeight(getContext()) * 0.8); FloatingActionButton fab_close = (FloatingActionButton) dialog.findViewById(R.id.fab_problem_list_close); RecyclerView rv_main = (RecyclerView) dialog.findViewById(R.id.rv_dialog_problem_list_main); final TextView tv_titile = (TextView) dialog.findViewById(R.id.tv_title); final LinearLayout ll_lastSubTaskData = (LinearLayout) dialog.findViewById(R.id.ll_last_subTask_data); final TextView tv_executors = (TextView) dialog.findViewById(R.id.tv_executors); final TextView tv_startTime = (TextView) dialog.findViewById(R.id.tv_start_time); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); rv_main.setLayoutManager(linearLayoutManager); final List problemlistVoList = new ArrayList<>(); if (type == PROBLEM_LIST || type == PROBLEM_CHANGE) { problemListAdapter = new ProblemListAdapter(getActivity(), problemlistVoList, ProblemListAdapter.PROBLEM_LIST); } else if (type == PROBLEM_RECHECK) { problemListAdapter = new ProblemListAdapter(getActivity(), problemlistVoList, ProblemListAdapter.RECHECK_LIST); } rv_main.setAdapter(problemListAdapter); rv_main.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), rv_main, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent intent = new Intent(getActivity(), ProblemDetailActivity.class); intent.putExtra("problemlistVo", problemlistVoList.get(position)); intent.putExtra("subTaskSelected", subTaskSelected); intent.putExtra("scenseLat", scenseCurrent.getLatitude()); intent.putExtra("scenseLng", scenseCurrent.getLongitude()); intent.putExtra("editable", problemEditable); intent.putExtra("type", type); startActivityForResult(intent, PROBLEM_DETAIL); dialog.dismiss(); } @Override public void onItemLongClick(View view, int position) { } })); if (type == PROBLEM_LIST || type == PROBLEM_CHANGE) { if (type == PROBLEM_LIST) { tv_titile.setText("问题清单"); problemEditable = false; } else if (type == PROBLEM_CHANGE) { tv_titile.setText("现场整改"); problemEditable = true; } Call> loadProblemList = inspectionService.loadProblemList(inspectionCurrent.getGuid()); loadProblemList.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { if (response.body() != null) { problemlistVoList.addAll(response.body()); problemListAdapter.notifyDataSetChanged(); addProblemMarkers(problemlistVoList); tv_executors.setText("共" + problemlistVoList.size() + "个问题"); int changed = 0; for (ProblemlistVo problemlistVo : problemlistVoList) { if (problemlistVo.getIschanged()) { changed++; } } tv_startTime.setText(changed + "个已整改"); } else if (response.errorBody() != null) { System.out.println("loadProblemList:" + response.errorBody().toString()); tv_executors.setText("获取问题数据失败"); Toast.makeText(application, "获取问题数据失败", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(Call> call, Throwable t) { System.out.println("loadProblemList:" + t.toString()); tv_executors.setText("联网失败"); Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show(); } }); } else if (type == PROBLEM_RECHECK) { tv_titile.setText("问题复核"); problemEditable = true; ll_lastSubTaskData.setVisibility(View.INVISIBLE); String date = DateFormatter.dateTimeFormat2.format(subTaskSelected.getPlanstarttime()); Call loadLastProblemList = inspectionService.loadLastProblemList(subTaskSelected.getScenseid(), date); loadLastProblemList.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { int rechecked = 0; if (response.body().getProblemlistVo() != null && response.body().getProblemlistVo().size() > 0) { problemlistVoList.addAll(response.body().getProblemlistVo()); List changedList = new ArrayList(); for (int i = 0; i < problemlistVoList.size(); i++) { ProblemlistVo problemlistVo = problemlistVoList.get(i); if (problemlistVo.getIschanged()) { changedList.add(problemlistVo); } if (problemlistVo.getIsrechecked()) { rechecked++; } } problemlistVoList.removeAll(changedList); problemListAdapter.notifyDataSetChanged(); } try { if (response.body().getSubtaskVo() != null) { tv_executors.setText("" + response.body().getSubtaskVo().getExecutorrealtimes().replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW) + "\n共" + problemlistVoList.size() + "个问题"); tv_startTime.setText("" + DateFormatter.dateTimeFormat.format(response.body().getSubtaskVo().getExecutionstarttime()) + "\n" + rechecked + "个已复核"); } else { tv_executors.setText("共" + problemlistVoList.size() + "个问题"); tv_startTime.setText(rechecked + "个已复核"); } } catch (Exception e) { e.printStackTrace(); } ll_lastSubTaskData.setVisibility(View.VISIBLE); } else if (response.errorBody() != null) { showToast("获取上一次任务信息失败"); tv_executors.setText("获取上一次任务信息失败"); System.out.println("loadLastProblemList:" + response.errorBody().toString()); } } @Override public void onFailure(Call call, Throwable t) { showToast("联网失败"); tv_executors.setText("联网失败"); System.out.println("loadLastProblemList:" + t.toString()); } }); } fab_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.show(); } //显示任意拍照的dialog private void showCameraDialog() { final Dialog dialog = new Dialog(getContext()); dialog.setContentView(R.layout.dialog_camera); //设置dialog宽度 Window dialogWindow = dialog.getWindow(); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); final WindowManager.LayoutParams p = dialogWindow.getAttributes(); p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1); p.height = (int) (ScreenUtils.getScreenHeight(getContext()) * 0.8); FloatingActionButton fab_close = (FloatingActionButton) dialog.findViewById(R.id.fab_problem_list_close); final RecyclerView rv_main = (RecyclerView) dialog.findViewById(R.id.rv_photo_list); ImageView iv_newPhoto = (ImageView) dialog.findViewById(R.id.iv_new_photo); final TextView tv_count = (TextView) dialog.findViewById(R.id.tv_count); GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 4); rv_main.setLayoutManager(gridLayoutManager); Call> loadCameraMediaFileList = inspectionService.loadMediaFileList(inspectionCurrent.getGuid(), BUSSINESS_TYPE_CAMERA); loadCameraMediaFileList.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { List mediafilesList = new ArrayList<>(); if (response.body() != null) { mediafilesList.addAll(response.body()); } else if (response.errorBody() != null) { Toast.makeText(application, "获取在线图片列表失败", Toast.LENGTH_SHORT).show(); tv_count.setText("获取在线图片列表失败"); } mediafilesList.addAll(mediafileDao.queryBuilder().where(MediafileDao.Properties.Iguid.eq(inspectionCurrent.getGuid())).where(MediafileDao.Properties.Businesstypeid.eq(BUSSINESS_TYPE_CAMERA)).where(MediafileDao.Properties.Remark.eq("未上传")).list()); PhotoListAdapter photoListAdapter = new PhotoListAdapter(mediafilesList, getContext()); rv_main.setAdapter(photoListAdapter); rv_main.addOnItemTouchListener(imagelistListener(rv_main, mediafilesList)); tv_count.setText("共" + mediafilesList.size() + "张照片"); } @Override public void onFailure(Call> call, Throwable t) { Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show(); List mediafilesList = new ArrayList<>(); mediafilesList = mediafileDao.queryBuilder().where(MediafileDao.Properties.Iguid.eq(inspectionCurrent.getGuid())).where(MediafileDao.Properties.Businesstypeid.eq(BUSSINESS_TYPE_CAMERA)).where(MediafileDao.Properties.Remark.eq("未上传")).list(); PhotoListAdapter photoListAdapter = new PhotoListAdapter(mediafilesList, getContext()); rv_main.setAdapter(photoListAdapter); rv_main.addOnItemTouchListener(imagelistListener(rv_main, mediafilesList)); tv_count.setText("共" + mediafilesList.size() + "张照片"); } }); iv_newPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showNewPhotoDailog(); dialog.dismiss(); } }); fab_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); cameraDialog = dialog; dialog.show(); } //任意拍照图片列表的clicklistener private RecyclerView.OnItemTouchListener imagelistListener(RecyclerView rv_main, final List mediafilesList) { RecyclerView.OnItemTouchListener listerner = new RecyclerItemClickListener(getContext(), rv_main, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { List files = new ArrayList<>(); for (Mediafile m : mediafilesList) { File f = new File(Environment.getExternalStorageDirectory(), m.getPath() + m.getDescription()); files.add(f); } // File file = new File(Environment.getExternalStorageDirectory(), mediafilesList.get(position).getPath() + mediafilesList.get(position).getDescription()); Intent intent = new Intent(getActivity(), PhotoViewerActivity.class); // intent.putExtra("file", file); intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files); intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO); intent.putExtra("deletable", true); intent.putExtra("position", position); // intent.putExtra("mediaFile", mediafilesList.get(position)); intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediafilesList); startActivityForResult(intent, VIEW_CAMERA_PHOTO); } @Override public void onItemLongClick(View view, int position) { } }); return listerner; } //添加新的任意拍照照片 private void showNewPhotoDailog() { final Dialog dialog = new Dialog(getContext()); dialog.setContentView(R.layout.dialog_new_photo); //设置dialog宽度 Window dialogWindow = dialog.getWindow(); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); final WindowManager.LayoutParams p = dialogWindow.getAttributes(); p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1); dialog.setCancelable(false); //初始化控件 FloatingActionButton fab_ok = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_ok); FloatingActionButton fab_Close = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_close); final EditText et_description = (EditText) dialog.findViewById(R.id.et_description); iv_cameraPhoto1 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo1); iv_cameraPhoto2 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo2); iv_cameraPhoto3 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo3); ivCameraList = new ArrayList<>(); ivCameraList.add(iv_cameraPhoto1); ivCameraList.add(iv_cameraPhoto2); ivCameraList.add(iv_cameraPhoto3); pathTempList = new ArrayList<>(); refreshNewPhotoClickListener(); //确定按钮保存图片和数据库 fab_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (et_description.getText().toString().length() > 0) { java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(subTaskSelected.getExecutionstarttime()); String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/任意拍照/"; if (pathTempList != null && pathTempList.size() > 0) { for (int i = 0; i < pathTempList.size(); i++) { String fileName = et_description.getText().toString() + " " + UUIDGenerator.generateUUID(4) + ".jpg"; File newFile = new File(Environment.getExternalStorageDirectory(), path + fileName); newFile.getParentFile().mkdirs(); try { //把文件从temp复制到特定文件夹下 copyfile(pathTempList.get(i), newFile); Mediafile mediaFile = new Mediafile(); mediaFile.setGuid(UUIDGenerator.generate16ShortUUID()); mediaFile.setIguid(inspectionCurrent.getGuid()); mediaFile.setLongitude(longitudeCurrent); mediaFile.setLatitude(latitudeCurrent); mediaFile.setAddress(getScenceAddress()); mediaFile.setFiletype(1); mediaFile.setBusinesstype("常规记录"); mediaFile.setBusinesstypeid(intToByte(5)); mediaFile.setPath(path); mediaFile.setDescription(fileName); mediaFile.setSavetime(new Date()); mediaFile.setIschanged(false); String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/"; mediaFile.setExtension1(exetension1); mediaFile.setRemark("未上传"); mediafileDao.insert(mediaFile); } catch (IOException e) { e.printStackTrace(); Toast.makeText(application, "复制文件出错", Toast.LENGTH_SHORT).show(); return; } } Toast.makeText(application, "保存成功", Toast.LENGTH_SHORT).show(); clearTemp(); dialog.dismiss(); } else { Toast.makeText(application, "请至少拍一张照片", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(application, "请填写照片描述", Toast.LENGTH_SHORT).show(); } } }); fab_Close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { clearTemp(); dialog.dismiss(); } }); dialog.show(); } //清除拍照取证的缓存 public void clearTemp() { for (int i = 0; i < pathTempList.size(); i++) { File file = pathTempList.get(i); if (file.exists()) { file.delete(); } } } //刷新任意拍照的图片点击事件 public void refreshNewPhotoClickListener() { for (int i = 0; i < pathTempList.size(); i++) { SetImageTask task1 = new SetImageTask(pathTempList.get(i), ivCameraList.get(i)); task1.execute(); ivCameraList.get(i).setOnClickListener(showPhotoClicker(i, PhotoViewerActivity.CAMERA_PHOTO_TEMP, VIEW_CAMERA_TEMP_PHOTO)); } if (pathTempList.size() < 3) { ImageView iv_camera = ivCameraList.get(pathTempList.size()); iv_camera.setImageResource(R.drawable.icon_add_photo); iv_camera.setOnClickListener(addPhotoClickListener(CAMERA_PHOTO)); //将拍照的图片框前后位置设置为空图片框 if (pathTempList.size() < 2) { ivCameraList.get(pathTempList.size() + 1).setImageResource(R.drawable.icon_add_photo_blank); } } if (pathTempList.size() > 0) { ivCameraList.get(pathTempList.size() - 1).setImageResource(R.drawable.icon_add_photo_blank); } } //点击显示任意拍照的大图 private View.OnClickListener showPhotoClicker(final int position, final int type, final int requestCode) { View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getActivity(), PhotoViewerActivity.class); intent.putExtra("position", position); intent.putExtra("type", type); intent.putExtra("deletable", true); // intent.putExtra("file", pathTempList.get(position)); intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) pathTempList); startActivityForResult(intent, requestCode); } }; return listener; } //刷新列表点击事件状态 public void refreshPhotoClickListener(List files) { int a = files.size(); if (a == 0) { miv_add_photo1.setOnClickListener(addPhotoClickListener(PHOTO1)); miv_add_photo2.setOnClickListener(null); miv_add_photo3.setOnClickListener(null); miv_add_photo1.setImageResource(R.drawable.icon_add_photo); miv_add_photo2.setImageResource(R.drawable.icon_add_photo_blank); miv_add_photo3.setImageResource(R.drawable.icon_add_photo_blank); } else if (a == 1) { miv_add_photo1.setOnClickListener(viewPhotoClickListener(PHOTO1)); miv_add_photo2.setOnClickListener(addPhotoClickListener(PHOTO2)); miv_add_photo3.setOnClickListener(null); SetImageTask task1 = new SetImageTask(files.get(PHOTO1), miv_add_photo1); task1.execute(); miv_add_photo2.setImageResource(R.drawable.icon_add_photo); miv_add_photo3.setImageResource(R.drawable.icon_add_photo_blank); } else if (a == 2) { miv_add_photo1.setOnClickListener(viewPhotoClickListener(PHOTO1)); miv_add_photo2.setOnClickListener(viewPhotoClickListener(PHOTO2)); miv_add_photo3.setOnClickListener(addPhotoClickListener(PHOTO3)); SetImageTask task1 = new SetImageTask(files.get(PHOTO1), miv_add_photo1); task1.execute(); SetImageTask task2 = new SetImageTask(files.get(PHOTO2), miv_add_photo2); task2.execute(); miv_add_photo3.setImageResource(R.drawable.icon_add_photo); } else if (a == 3) { miv_add_photo1.setOnClickListener(viewPhotoClickListener(PHOTO1)); miv_add_photo2.setOnClickListener(viewPhotoClickListener(PHOTO2)); miv_add_photo3.setOnClickListener(viewPhotoClickListener(PHOTO3)); SetImageTask task1 = new SetImageTask(files.get(PHOTO1), miv_add_photo1); task1.execute(); SetImageTask task2 = new SetImageTask(files.get(PHOTO2), miv_add_photo2); task2.execute(); SetImageTask task3 = new SetImageTask(files.get(PHOTO3), miv_add_photo3); task3.execute(); } } //添加图片用的点击事件 public View.OnClickListener addPhotoClickListener(final int position) { View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); int t = 3 - pathTempList.size(); final int picNum = t >= 0 ? t : 0; switch (position) { case PHOTO1: pickPhoto(PICK_PHOTO1, picNum); break; case PHOTO2: pickPhoto(PICK_PHOTO2, picNum); break; case PHOTO3: pickPhoto(PICK_PHOTO3, picNum); break; case CAMERA_PHOTO: pickPhoto(PICK_CAMERA_PHTOO, picNum); break; case GIT_PHOTO: pickPhoto(PICK_GIT_PHOTO, picNum); } } }; return listener; } //有图片时,查看图片的点击事件(temp) public View.OnClickListener viewPhotoClickListener(final int position) { View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), PhotoViewerActivity.class); if (position == PHOTO1 || position == PHOTO2 || position == PHOTO3) { intent.putExtra("position", position); intent.putExtra("type", PhotoViewerActivity.EVIDENCE_PHOTO_TEMP); intent.putExtra("deletable", true); // intent.putExtra("file", pathTempList.get(position)); intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) pathTempList); startActivityForResult(intent, VIEW_EVIDENCE_TEMP_PHOTO); } } }; return listener; } //显示技防措施列表 private void showGitListDialog() { final Dialog dialog = new Dialog(getContext()); dialog.setContentView(R.layout.dialog_camera); //设置dialog宽度 Window dialogWindow = dialog.getWindow(); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); final WindowManager.LayoutParams p = dialogWindow.getAttributes(); p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1); p.height = (int) (ScreenUtils.getScreenHeight(getContext()) * 0.8); TextView tv_title = (TextView) dialog.findViewById(R.id.tv_title); FloatingActionButton fab_close = (FloatingActionButton) dialog.findViewById(R.id.fab_problem_list_close); final RecyclerView rv_main = (RecyclerView) dialog.findViewById(R.id.rv_photo_list); ImageView iv_newPhoto = (ImageView) dialog.findViewById(R.id.iv_new_photo); final TextView tv_count = (TextView) dialog.findViewById(R.id.tv_count); tv_title.setText("技防措施"); final List gitlistVoList = new ArrayList<>(); final GitListAdapter gitListAdapter = new GitListAdapter(getContext(), gitlistVoList); LinearLayoutManager manager = new LinearLayoutManager(getContext()); rv_main.setLayoutManager(manager); rv_main.setAdapter(gitListAdapter); Call> loadGitList = inspectionService.loadGitList(inspectionCurrent.getGuid()); loadGitList.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { if (response.body() != null) { gitlistVoList.addAll(response.body()); gitListAdapter.notifyDataSetChanged(); tv_count.setText("共" + gitlistVoList.size() + "条技防措施"); } else if (response.errorBody() != null) { Toast.makeText(application, "获取技防措施数据失败", Toast.LENGTH_SHORT).show(); tv_count.setText("获取技防措施数据失败"); } } @Override public void onFailure(Call> call, Throwable t) { Toast.makeText(application, "网络连接失败", Toast.LENGTH_SHORT).show(); tv_count.setText("网络连接失败"); } }); rv_main.addOnItemTouchListener(new RecyclerItemClickListener(getContext(), rv_main, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent intent = new Intent(getActivity(), GitDetailActivity.class); intent.putExtra("gitlistVo", gitlistVoList.get(position)); intent.putExtra("subTask", subTaskSelected); intent.putExtra("inspectionGuid", inspectionCurrent.getGuid()); intent.putExtra("scenseAddress", getScenceAddress()); startActivity(intent); } @Override public void onItemLongClick(View view, int position) { } })); iv_newPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); showNewGitDialog(); } }); fab_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.show(); } //新增一条技防措施的dialog private void showNewGitDialog() { final Dialog dialog = new Dialog(getContext()); dialog.setContentView(R.layout.dialog_take_evidence); //设置dialog宽度 Window dialogWindow = dialog.getWindow(); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); final WindowManager.LayoutParams p = dialogWindow.getAttributes(); p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1); dialog.setCancelable(false); //初始化控件 TextView tv_title = (TextView) dialog.findViewById(R.id.tv_dialog_take_evidence_title); TextView tv_type = (TextView) dialog.findViewById(R.id.tv_type); TextView tv_chose = (TextView) dialog.findViewById(R.id.tv_chose); TextView tv_location = (TextView) dialog.findViewById(R.id.tv_location); FloatingActionButton fab_ok = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_ok); FloatingActionButton fab_Close = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_close); iv_gitPhoto1 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo1); iv_gitPhoto2 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo2); iv_gitPhoto3 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo3); Spinner sp_gitType = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem_type); final Spinner sp_git = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem); final Spinner sp_location = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_location); final EditText et_locationRemark = (EditText) dialog.findViewById(R.id.et_take_evidence_location); final EditText et_problemDes = (EditText) dialog.findViewById(R.id.et_take_evidence_problem_des); ivGitList = new ArrayList<>(); ivGitList.add(iv_gitPhoto1); ivGitList.add(iv_gitPhoto2); ivGitList.add(iv_gitPhoto3); //设置界面 tv_title.setText("新增技防措施"); tv_type.setText("措施类型"); tv_chose.setText("选择一个技防措施"); tv_location.setVisibility(View.GONE); sp_location.setVisibility(View.GONE); et_locationRemark.setVisibility(View.GONE); et_problemDes.setVisibility(View.GONE); //初始化变量 pathTempList = new ArrayList<>(); refreshNewGitPhotoClickListener(); //加载预置数据 List gittypeList = gittypeDao.queryBuilder().where(GittypeDao.Properties.Tasktype.eq(subTaskSelected.getType())).where(GittypeDao.Properties.Scensetype.eq(scenseCurrent.getType())).where(GittypeDao.Properties.Districtname.eq(subTaskSelected.getDistrictname())).orderAsc(GittypeDao.Properties.Typeid).list(); if (gittypeList.size() == 0) { Gittype gittype1 = new Gittype(); gittype1.setGuid("00"); gittype1.setName("无"); gittype1.setType("无"); gittype1.setDesc("无"); gittypeList.add(gittype1); } final List gitTypeStringList = new ArrayList<>(); final Map> gitTypeMap = new HashMap<>(); for (Gittype gittype : gittypeList) { if (gitTypeMap.containsKey(gittype.getType())) { gitTypeMap.get(gittype.getType()).add(gittype); } else { gitTypeStringList.add(gittype.getType()); List gittypeList1 = new ArrayList<>(); gittypeList1.add(gittype); gitTypeMap.put(gittype.getType(), gittypeList1); } } ArrayAdapter gittypeAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, gitTypeStringList); sp_gitType.setAdapter(gittypeAdapter); final List gittypeList1 = new ArrayList<>(); final GitTypeListAdapter gitTypeListAdapter = new GitTypeListAdapter(gittypeList1, getContext()); sp_git.setAdapter(gitTypeListAdapter); sp_gitType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int i, long l) { //当选中一个分类时,从map加载问题列表,填充数据 gittypeList1.removeAll(gittypeList1); gittypeList1.addAll(gitTypeMap.get(gitTypeStringList.get(i))); gitTypeListAdapter.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView adapterView) { } }); fab_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (pathTempList.size() > 0) { //准备gitlist final Gitlist gitlist = new Gitlist(); gitlist.setGuid(UUIDGenerator.generate16ShortUUID()); gitlist.setIguid(inspectionCurrent.getGuid()); gitlist.setStguid(subTaskSelected.getStguid()); gitlist.setSguid(scenseCurrent.getGuid()); gitlist.setScensename(scenseCurrent.getName()); gitlist.setScenseaddress(getScenceAddress()); final Gittype gitSelected = (Gittype) sp_git.getSelectedItem(); gitlist.setGtguid(gitSelected.getGuid()); gitlist.setName(gitSelected.getName()); gitlist.setType(gitSelected.getType()); gitlist.setDesc(gitSelected.getDesc()); gitlist.setCreatedate(new Date()); gitlist.setUpdatedate(new Date()); //准备mediaFIle final java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(subTaskSelected.getExecutionstarttime()); final String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/技防措施/"; Call putGit = inspectionService.putGitList(gitlist); putGit.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { Toast.makeText(application, "提交成功", Toast.LENGTH_SHORT).show(); for (File oldfile : pathTempList) { String fileName = gitSelected.getName() + " " + UUIDGenerator.generateUUID(4) + ".jpg"; Mediafile mediafile = new Mediafile(); mediafile.setGuid(UUIDGenerator.generate16ShortUUID()); mediafile.setBusinessguid(gitlist.getGuid()); mediafile.setIguid(inspectionCurrent.getGuid()); mediafile.setLongitude(longitudeCurrent); mediafile.setLatitude(latitudeCurrent); mediafile.setAddress(getScenceAddress()); mediafile.setFiletype(1); mediafile.setBusinesstype("2"); mediafile.setBusinesstype("技防措施"); mediafile.setPath(path); mediafile.setDescription(fileName); mediafile.setSavetime(new Date()); String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/"; mediafile.setExtension1(exetension1); mediafile.setRemark("未上传"); try { File newfile = new File(Environment.getExternalStorageDirectory(), (path + fileName)); newfile.getParentFile().mkdirs(); copyfile(oldfile, newfile); mediafileDao.insert(mediafile); } catch (IOException e) { e.printStackTrace(); } } dialog.dismiss(); } else if (response.errorBody() != null) { Log.e("putGit:", response.errorBody().toString()); Toast.makeText(application, "提交失败", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(Call call, Throwable t) { Log.e("putGit:", t.toString()); Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show(); } }); } else { Toast.makeText(application, "至少拍一张照片", Toast.LENGTH_SHORT).show(); } } }); fab_Close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.show(); } //刷新技防措施每个图片的点击事件 private void refreshNewGitPhotoClickListener() { for (int i = 0; i < pathTempList.size(); i++) { SetImageTask task1 = new SetImageTask(pathTempList.get(i), ivGitList.get(i)); task1.execute(); ivGitList.get(i).setOnClickListener(showPhotoClicker(i, PhotoViewerActivity.GIT_PHOTO_TEMP, VIEW_GIT_TEMP_PHOTO)); } if (pathTempList.size() < 3) { ImageView iv_camera = ivGitList.get(pathTempList.size()); iv_camera.setImageResource(R.drawable.icon_add_photo); iv_camera.setOnClickListener(addPhotoClickListener(GIT_PHOTO)); //将拍照的图片框前后位置设置为空图片框 if (pathTempList.size() < 2) { ivGitList.get(pathTempList.size() + 1).setImageResource(R.drawable.icon_add_photo_blank); } } if (pathTempList.size() > 0) { ivGitList.get(pathTempList.size() - 1).setImageResource(R.drawable.icon_add_photo_blank); } } //拍照 public void takePhoto(int type) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //判断要跳转的目的地是否为空 if (intent.resolveActivity(getContext().getPackageManager()) != null) { File path = null; if (type == TAKE_PHOTO1 || type == TAKE_PHOTO2 || type == TAKE_PHOTO3 || type == TAKE_CAMERA_PHOTO || type == TAKE_GIT_PHOTO) { path = new File(Environment.getExternalStorageDirectory(), "FlightFeather/Temp/" + UUIDGenerator.generateUUID(4) + ".jpg"); path.getParentFile().mkdirs(); tempFileCurrent = path; } //安卓7.0适配 Uri uri; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { uri = FileProvider.getUriForFile(getContext(), "cn.flightfeather.thirdapp.fileProvider", path); } else { uri = Uri.fromFile(path); } intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, type); } } //从相册中选择图片 public void pickPhoto(int type, int num) { // Intent intent = new Intent(); // intent.setAction(Intent.ACTION_PICK);//Pick an item from the data // intent.setType("image/*");//从所有图片中进行选择 // startActivityForResult(intent, type); PhotoUtil.pickPhoto(this, type, num); } //初始化整改承诺 private void initPromiss() { Toast.makeText(application, "加载中请稍后", Toast.LENGTH_SHORT).show(); Call> loadSignMediaFile = inspectionService.loadMediaFileList(inspectionCurrent.getGuid(), BUSSINESS_TYPE_SIGN); loadSignMediaFile.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { if (response.body() != null) { loadSignPhoto(response.body()); } else if (response.errorBody() != null) { Log.e("loadSignMediaFIle", response.errorBody().toString()); Toast.makeText(application, "获取签名图片失败", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(Call> call, Throwable t) { Log.e("loadSignMediaFIle", t.toString()); Toast.makeText(application, "网络连接失败", Toast.LENGTH_SHORT).show(); } }); } //加载签名照片 private void loadSignPhoto(List mediaFileList) { //如果联网传过来的签名mediaFile是空的,则查询本地的mediaFIle if (mediaFileList == null) { mediaFileList = new ArrayList<>(); } List mediaFilelocal = mediafileDao.queryBuilder().where(MediafileDao.Properties.Iguid.eq(inspectionCurrent.getGuid())).where(MediafileDao.Properties.Businesstypeid.eq(BUSSINESS_TYPE_SIGN)).where(MediafileDao.Properties.Remark.eq("未上传")).list(); mediaFileList.addAll(mediaFilelocal); //最终的mediafilelist中有数据就显示,没有就新增签名 if (mediaFileList.size() > 0) { List files = new ArrayList<>(); for (Mediafile m : mediaFileList) { File file = new File(Environment.getExternalStorageDirectory(), (m.getPath() + m.getDescription())); files.add(file); } if (files.get(0).exists()) { Intent intent = new Intent(getActivity(), PhotoViewerActivity.class); intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files); intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO); intent.putExtra("deletable", true); intent.putExtra("mediaFile", (Serializable) mediaFileList); startActivityForResult(intent, VIEW_SIGN_PHOTO); } else { if (mediaFileList.get(0).getRemark().equals("未上传")) { for (Mediafile m : mediaFileList) { mediafileDao.delete(m); } } else if (mediaFileList.get(0).getRemark().equals("已上传")) { for (Mediafile m : mediaFileList) { downloadAndSetImage(m); } } } } else { startActivityForResult(new Intent(getActivity(), SignActivity.class), SIGN); } } //下载并显示图片 private void downloadAndSetImage(final Mediafile mediafile) { String url = mediafile.getExtension1() + mediafile.getGuid() + ".jpg"; Call downloadImage = inspectionImageService.downloadImage(url); downloadImage.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { writeResponseBodyToDisk(mediafile, response.body()); } else if (response.errorBody() != null) { Toast.makeText(application, "获取图片失败", Toast.LENGTH_SHORT).show(); Log.e("downloadImage:", response.errorBody().toString()); } } @Override public void onFailure(Call call, Throwable t) { Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show(); Log.e("downloadImage:", t.toString()); } }); } //将下载的图片写入磁盘 public void writeResponseBodyToDisk(Mediafile mediafile, ResponseBody body) { if (body == null) { Toast.makeText(getActivity(), "图片源错误", Toast.LENGTH_SHORT).show(); return; } try { InputStream is = body.byteStream(); File fileDr = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath())); if (!fileDr.exists()) { fileDr.mkdir(); } File file = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath() + mediafile.getDescription())); if (file.exists()) { file.delete(); file = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath() + mediafile.getDescription())); } FileOutputStream fos = new FileOutputStream(file); BufferedInputStream bis = new BufferedInputStream(is); byte[] buffer = new byte[1024]; int len; while ((len = bis.read(buffer)) != -1) { fos.write(buffer, 0, len); } fos.flush(); fos.close(); bis.close(); is.close(); //显示图片 Intent intent = new Intent(getActivity(), PhotoViewerActivity.class); List files = new ArrayList<>(); files.add(file); List mediafiles = new ArrayList<>(); mediafiles.add(mediafile); // intent.putExtra("file", file); intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files); intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO); intent.putExtra("deletable", true); // intent.putExtra("mediaFile", mediafile); intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediafiles); startActivityForResult(intent, VIEW_SIGN_PHOTO); } catch (IOException e) { e.printStackTrace(); } } //开始导航 private void startNavi() { LatLng sourceLatLng = new LatLng(scenseCurrent.getLatitude(), scenseCurrent.getLongitude()); AmapNavi amapNavi = new AmapNavi(getContext()); amapNavi.startNavi(sourceLatLng.latitude, sourceLatLng.longitude); } private void backToTaskPage() { currentPage = TASK_PAGE; rl_selectTask.setVisibility(View.VISIBLE); rl_content.setVisibility(View.INVISIBLE); fab_map.show(); subTaskListAdapter.notifyDataSetChanged(); refreshUploadIconStatus(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.ll_patrol_hide: hideIcons(); break; case R.id.ll_patrol_show: showIcons(); break; case R.id.ll_show_hide_detail: if (iv_showHideDetail.isSelected()) { hideTaskDetail(); iv_showHideDetail.setSelected(false); } else { showTaskDetail(); iv_showHideDetail.setSelected(true); } break; case R.id.iv_patrol_back: backToTaskPage(); break; case R.id.iv_start_end_task: if (iv_startEndTask.isSelected()) { if (subTaskStatusCurrent.equals(subTaskRunning)) { showEndTaskDialog(); } } else { if (subTaskStatusCurrent.equals(subTaskNotStart)) { showStartTaskDialog(); } } break; case R.id.ln_patrol_take_evidence: showTaskEvidenceDialog(); break; case R.id.ln_patrol_problem_list: OPEN_TYPE = PROBLEM_LIST; showProblemList(PROBLEM_LIST); break; case R.id.ln_patrol_change: OPEN_TYPE = PROBLEM_CHANGE; showProblemList(PROBLEM_CHANGE); break; case R.id.ln_patrol_problem_recheck: OPEN_TYPE = PROBLEM_RECHECK; showProblemList(PROBLEM_RECHECK); break; case R.id.ln_patrol_camera: showCameraDialog(); break; case R.id.ln_patrol_newgit: showGitListDialog(); break; case R.id.ln_patrol_promiss: // initPromiss(); java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(subTaskSelected.getExecutionstarttime()); String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/签字/"; String fileName1 = "签字 " + UUIDGenerator.generateUUID(4) + ".jpg"; Mediafile mediaFile = new Mediafile(); mediaFile.setGuid(UUIDGenerator.generate16ShortUUID()); mediaFile.setIguid(inspectionCurrent.getGuid()); mediaFile.setLongitude(longitudeCurrent); mediaFile.setLatitude(latitudeCurrent); mediaFile.setAddress(getScenceAddress()); mediaFile.setFiletype(1); mediaFile.setBusinesstype("签字"); mediaFile.setBusinesstypeid(intToByte(6)); mediaFile.setPath(path); mediaFile.setDescription(fileName1); mediaFile.setSavetime(new Date()); mediaFile.setIschanged(false); String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/"; mediaFile.setExtension1(exetension1); mediaFile.setRemark("未上传"); Intent intent4 = new Intent(getActivity(), PromiseActivity.class); intent4.putExtra("problemlistVoList", (Serializable) problemListVoListCurrent); intent4.putExtra("mediaFilePreData", mediaFile); intent4.putExtra("inspectionCurrent", inspectionCurrent); startActivityForResult(intent4, PROMISE); break; case R.id.ln_patrol_rate: Intent intentEvaluation = new Intent(getActivity(), GradeActivity.class); intentEvaluation.putExtra("inspectionGuid", inspectionCurrent.getGuid()); intentEvaluation.putExtra("subtask", subTaskSelected); intentEvaluation.putExtra("scense", scenseCurrent); startActivity(intentEvaluation); // startActivity(intentEvaluation); break; case R.id.iv_upload: Intent intent = new Intent(getActivity(), UploadMediaFilesActivity.class); startActivity(intent); break; case R.id.ln_patrol_navi: startNavi(); break; case R.id.fab_map: Intent intent2 = new Intent(getActivity(), SubTaskMapActivity.class); intent2.putExtra("subTaskListCurrent", (Serializable) subTaskListCurrent); startActivityForResult(intent2, SUBTASK_MAP); break; case R.id.ln_patrol_chose_latlng: Intent intent3 = new Intent(getActivity(), MapActivity.class); startActivityForResult(intent3, CHOSE_LATLNG); break; case R.id.ln_patrol_edit: // if (scenseCurrent.getType().equals("工地")){ Intent intent1 = new Intent(getActivity(), SceneDetailActivity.class); intent1.putExtra("mode", 1); intent1.putExtra("updateScene", scenseCurrent); startActivityForResult(intent1, EDITE_SCENSE); // }else { // showToast("目前仅支持修改工地"); // } break; } } //滑动页面会选择当月1号 // @Override // public void onDateChange(Calendar calendar) { // tv_title.setText(calendar.getYear() + "年" + calendar.getMonth() + "月"); // calendarCurrent = trans2Calendar(calendar.getYear(), calendar.getMonth(), calendar.getDay()); // //如果切换月份,则查询该月的日任务并添加到日历上 // if (calendarCurrent.get(java.util.Calendar.YEAR) != lastMonthCalender.get(java.util.Calendar.YEAR) || calendarCurrent.get(java.util.Calendar.MONTH) != lastMonthCalender.get(java.util.Calendar.MONTH)) { // lastMonthCalender.set(java.util.Calendar.YEAR, calendarCurrent.get(java.util.Calendar.YEAR)); // lastMonthCalender.set(java.util.Calendar.MONTH, calendarCurrent.get(java.util.Calendar.MONTH)); // showMonthAllTask(calendarCurrent); // } // showSubTaskByDay(calendarCurrent.get(java.util.Calendar.DAY_OF_MONTH)); // } // // @Override // public void onYearChange(int year) { // // } // // @Override // public void onDateSelected(Calendar calendar) { // // } //将int的年月日转换为calendar对象 public java.util.Calendar trans2Calendar(int year, int month, int day) { java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.set(java.util.Calendar.YEAR, year); calendar.set(java.util.Calendar.MONTH, (month - 1)); calendar.set(java.util.Calendar.DAY_OF_MONTH, day); calendar.set(java.util.Calendar.HOUR_OF_DAY, 0); calendar.set(java.util.Calendar.MINUTE, 0); calendar.set(java.util.Calendar.SECOND, 0); calendar.set(java.util.Calendar.MILLISECOND, 0); return calendar; } @Override public void onHiddenChanged(boolean hidden) { this.hidden = hidden; if (hidden) { aMap.setMyLocationEnabled(false); } else { // String yearMonth = DateFormater.YearMonthFormat.format(new Date()); // getThreeMonthTask(yearMonth, "Middle", false); refreshUploadIconStatus(); initLocation(); } } @Override public void onMyLocationChange(Location location) { latitudeCurrent = location.getLatitude(); longitudeCurrent = location.getLongitude(); } @Override public void onDestroy() { super.onDestroy(); aMap.setMyLocationEnabled(false); mv_main.onDestroy(); for (Disposable d : disposables) { if (!d.isDisposed()) d.dispose(); } } @Override public void onResume() { super.onResume(); //在activity执行onResume时执行mMapView.onResume (),重新绘制加载地图 mv_main.onResume(); refreshUploadIconStatus(); if (!hidden) { initLocation(); } } @Override public void onPause() { super.onPause(); //在activity执行onPause时执行mMapView.onPause (),暂停地图的绘制 aMap.setMyLocationEnabled(false); mv_main.onPause(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),保存地图当前的状态 mv_main.onSaveInstanceState(outState); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == TAKE_PHOTO1 || requestCode == TAKE_PHOTO2 || requestCode == TAKE_PHOTO3 || requestCode == TAKE_CAMERA_PHOTO || requestCode == TAKE_GIT_PHOTO) { if (resultCode == RESULT_OK) { pathTempList.add(tempFileCurrent); if (requestCode == TAKE_PHOTO1 || requestCode == TAKE_PHOTO2 || requestCode == TAKE_PHOTO3) { refreshPhotoClickListener(pathTempList); } else if (requestCode == TAKE_CAMERA_PHOTO) { refreshNewPhotoClickListener(); } else if (requestCode == TAKE_GIT_PHOTO) { refreshNewGitPhotoClickListener(); } } } else if (requestCode == PICK_PHOTO1 || requestCode == PICK_PHOTO2 || requestCode == PICK_PHOTO3 || requestCode == PICK_CAMERA_PHTOO || requestCode == PICK_GIT_PHOTO) { if (resultCode == RESULT_OK) { List paths = data.getStringArrayListExtra(BaseTakePicActivity.EXTRA_SELECT_IMAGES); // Uri selectedImage = data.getData(); //获取系统返回的照片的Uri // // String[] filePathColumn = {MediaStore.Images.Media.DATA}; // // Cursor cursor = getContext().getContentResolver().query(selectedImage, // filePathColumn, null, null, null);//从系统表中查询指定Uri对应的照片 // if (cursor!=null){ // cursor.moveToFirst(); // int columnIndex = cursor.getColumnIndex(filePathColumn[0]); // String picturePath = cursor.getString(columnIndex); //获取照片路径 // oldFile = new File(picturePath); // cursor.close(); // }else { // String a =selectedImage.getPath(); // oldFile = new File(a); // } for (String p : paths) { File oldFile = new File(p); File newFile = new File(Environment.getExternalStorageDirectory(), "FlightFeather/Temp/" + UUIDGenerator.generateUUID(4) + ".jpg"); if (!newFile.getParentFile().exists()) { newFile.getParentFile().mkdirs(); } try { copyfile(oldFile, newFile); pathTempList.add(newFile); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getContext(), "复制文件失败", Toast.LENGTH_SHORT).show(); } } if (requestCode == PICK_PHOTO1 || requestCode == PICK_PHOTO2 || requestCode == PICK_PHOTO3) { refreshPhotoClickListener(pathTempList); } else if (requestCode == PICK_CAMERA_PHTOO) { refreshNewPhotoClickListener(); } else if (requestCode == PICK_GIT_PHOTO) { refreshNewGitPhotoClickListener(); } } } else if (requestCode == PROBLEM_DETAIL) { showProblemList(OPEN_TYPE); } else if (requestCode == VIEW_CAMERA_PHOTO) { if (resultCode == RESULT_OK) { cameraDialog.dismiss(); showCameraDialog(); } } else if (requestCode == VIEW_EVIDENCE_TEMP_PHOTO || requestCode == VIEW_CAMERA_TEMP_PHOTO || requestCode == VIEW_GIT_TEMP_PHOTO) { if (resultCode == RESULT_OK) { int position = data.getIntExtra("position", -1); if (position > -1) { if (pathTempList.get(position).exists()) { pathTempList.get(position).delete(); } pathTempList.remove(position); if (requestCode == VIEW_EVIDENCE_TEMP_PHOTO) { refreshPhotoClickListener(pathTempList); } else if (requestCode == VIEW_CAMERA_TEMP_PHOTO) { refreshNewPhotoClickListener(); } else if (requestCode == VIEW_GIT_TEMP_PHOTO) { refreshNewGitPhotoClickListener(); } } } } else if (requestCode == SIGN) { //保存签字照片 if (resultCode == RESULT_OK) { if (data != null) { byte[] bis = data.getByteArrayExtra(Constant.KEY_INTENT_SIGHPIC); Bitmap bitmap = BitmapFactory.decodeByteArray(bis, 0, bis.length); java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(subTaskSelected.getExecutionstarttime()); String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/签字/"; String fileName1 = "签字.jpg"; File file = new File(Environment.getExternalStorageDirectory(), (path + fileName1)); file.getParentFile().mkdirs(); if (file.exists()) { file.delete(); } try { FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 99, out); out.flush(); out.close(); //保存到mediaFile数据库 Mediafile mediaFile = new Mediafile(); mediaFile.setGuid(UUIDGenerator.generate16ShortUUID()); mediaFile.setIguid(inspectionCurrent.getGuid()); mediaFile.setLongitude(longitudeCurrent); mediaFile.setLatitude(latitudeCurrent); mediaFile.setAddress(getScenceAddress()); mediaFile.setFiletype(1); mediaFile.setBusinesstype("签字"); mediaFile.setBusinesstypeid(intToByte(6)); mediaFile.setPath(path); mediaFile.setDescription(fileName1); mediaFile.setSavetime(new Date()); mediaFile.setIschanged(false); String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/"; mediaFile.setExtension1(exetension1); mediaFile.setRemark("未上传"); mediafileDao.insert(mediaFile); Toast.makeText(application, "保存成功", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(application, "保存失败", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(application, "保存失败", Toast.LENGTH_SHORT).show(); } // } } } else if (requestCode == SUBTASK_MAP && resultCode == RESULT_OK) { int position = data.getIntExtra("position", -1); if (position > -1) { subTaskSelected = subTaskListCurrent.get(position); loadInspectionData(subTaskSelected.getStguid()); } } else if (requestCode == CHOSE_LATLNG && resultCode == RESULT_OK) { Double longitude = data.getDoubleExtra("Longitude", 0); Double latitude = data.getDoubleExtra("Latitude", 0); if (longitude != 0 && latitude != 0) { if (scenseCurrent.getType().equals("工地")) { scenseCurrent.setLongitude(longitude); scenseCurrent.setLatitude(latitude); if (siteCurrent != null) { siteCurrent.setSitelatitude(latitude); siteCurrent.setSitelongitude(longitude); Call updateSite = inspectionService.updateSite(siteCurrent); updateSite.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { showToast("修改成功"); if (siteCurrent != null) { siteDao.update(siteCurrent); } scenseDao.update(scenseCurrent); refreshProblemMarker(); } else if (response.errorBody() != null) { showToast("修改失败,请重试"); } } @Override public void onFailure(Call call, Throwable t) { showToast("网络连接错误"); } }); } else { Call updateScense = inspectionService.updateScense(scenseCurrent); updateScense.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { showToast("修改成功"); scenseDao.update(scenseCurrent); refreshProblemMarker(); } else if (response.errorBody() != null) { showToast("修改失败,请重试"); } } @Override public void onFailure(Call call, Throwable t) { showToast("网络连接错误"); } }); } } else { scenseCurrent.setLongitude(longitude); scenseCurrent.setLatitude(latitude); Call updateScense = inspectionService.updateScense(scenseCurrent); updateScense.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body() != null) { showToast("修改成功"); scenseDao.update(scenseCurrent); refreshProblemMarker(); } else if (response.errorBody() != null) { showToast("修改失败,请重试"); } } @Override public void onFailure(Call call, Throwable t) { showToast("网络连接错误"); } }); } } } else if (requestCode == PROMISE) { refreshProblemMarker(); } else if (requestCode == EDITE_SCENSE) { AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); dialog.setTitle("需要重启"); dialog.setMessage("app重启后才能更新修改后的场景信息,要现在退出吗?"); dialog.setPositiveButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { getActivity().finish(); } }); dialog.setNegativeButton("取消", null); dialog.show(); } } //获取string类型的场景地址 public String getScenceAddress() { String a = ""; if (scenseCurrent != null) { if (scenseCurrent.getTownname() == null) { scenseCurrent.setTownname(""); } a = scenseCurrent.getCityname() + scenseCurrent.getDistrictname() + scenseCurrent.getTownname() + scenseCurrent.getLocation(); } return a; } //重命名文件 public Boolean renameFile(File oldFile, File newFile) { if (!oldFile.getAbsolutePath().equals(newFile.getAbsolutePath())) { if (!oldFile.exists()) { showToast("旧文件不存在"); return false; } else if (newFile.exists()) { showToast("新文件已存在"); return false; } else { oldFile.renameTo(newFile); return true; } } else { showToast("新文件和旧文件名名字相同"); return false; } } //复制文件 public static void copyfile(File oldfile, File newfile) throws IOException { FileInputStream ins = new FileInputStream(oldfile); FileOutputStream out = new FileOutputStream(newfile); //自定义缓冲对象 byte[] b = new byte[1024]; int n = 0; while ((n = ins.read(b)) != -1) { out.write(b, 0, b.length); } ins.close(); out.close(); System.out.println("copy success"); } public static byte intToByte(int x) { return (byte) x; } //显示toast public void showToast(String s) { Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show(); } // private void showLoadingDialog() { if (dialog == null) { dialog = DialogUtil.createLoadingDialog(getActivity(), ""); } if (!dialog.isShowing()) { dialog.show(); } } private void loadingOver(boolean b) { new Handler().postDelayed(new Runnable() { @Override public void run() { if (dialog.isShowing()) { dialog.dismiss(); } } }, 500); if (b) {//加载成功 // scrollView.setVisibility(View.VISIBLE); // no_data.setVisibility(View.GONE); } else {//加载失败 // scrollView.setVisibility(View.GONE); // no_data.setVisibility(View.VISIBLE); } } @Override public void onCalendarOutOfRange(Calendar calendar) { } @Override public void onCalendarSelect(Calendar calendar, boolean isClick) { } // }