package cn.flightfeather.thirdapp.activity; import android.app.AlertDialog; import android.app.DatePickerDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.graphics.Point; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; 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.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.DatePicker; 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.model.BitmapDescriptor; import com.amap.api.maps.model.BitmapDescriptorFactory; import com.amap.api.maps.model.CameraPosition; 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.PolylineOptions; import com.amap.api.maps.model.TextOptions; import com.amap.api.services.core.AMapException; import com.amap.api.services.core.LatLonPoint; import com.amap.api.services.district.DistrictItem; import com.amap.api.services.district.DistrictResult; import com.amap.api.services.district.DistrictSearch; import com.amap.api.services.district.DistrictSearchQuery; import com.ping.greendao.gen.ScenseDao; import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.Executors; import cn.flightfeather.thirdapp.CommonApplication; import cn.flightfeather.thirdapp.R; import cn.flightfeather.thirdapp.adapter.MOVListAdapter; import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener; import cn.flightfeather.thirdapp.bean.entity.Domainitem; import cn.flightfeather.thirdapp.bean.entity.Monitorobjectversion; import cn.flightfeather.thirdapp.bean.entity.Scense; import cn.flightfeather.thirdapp.bean.entity.Subtask; import cn.flightfeather.thirdapp.bean.entity.Task; import cn.flightfeather.thirdapp.bean.vo.TaskVo; import cn.flightfeather.thirdapp.httpservice.MonitorObjectVersionService; import cn.flightfeather.thirdapp.httpservice.SubTaskService; import cn.flightfeather.thirdapp.httpservice.TaskService; import cn.flightfeather.thirdapp.task.ObtainBoundaryRunnable; import cn.flightfeather.thirdapp.util.CommonUtils; import cn.flightfeather.thirdapp.util.Constant; import cn.flightfeather.thirdapp.util.DateFormatter; import cn.flightfeather.thirdapp.util.Domain; import cn.flightfeather.thirdapp.util.UUIDGenerator; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; public class MOVMapActivity extends AppCompatActivity implements View.OnClickListener , AdapterView.OnItemSelectedListener, RecyclerItemClickListener.OnItemClickListener , DistrictSearch.OnDistrictSearchListener { private static final String TAG = "MOVMapActivity"; public static final int OPERATION_FREE = 0; public static final int OPERATION_ADD = 1; public static final int OPERATION_REPLACE = 2; public static final int MODE_ADD_MOV = 1; public static final int MODE_REPLACE_MOV = 2; public static final int MODE_UPDATE_MOV = 3; public static final int MODE_ADD_SUBTASK = 4; private static final int MODE_TEMPORARY = 5; public static final int MODE_UNKNOWN = -1; private static final String REGEX_SELECTED_SCENSE_NUM = "#"; private boolean mSelectedAll; private boolean mHadDayTask; private boolean mHadPutMOVList; private boolean mHadPutTopClassTask; private boolean mIsCallingPutMovService; private boolean mIsCallingPutTaskService; private int mCurrentMode; private int mCurrentOperation; private int mDisableScenseNum; private int mCurrentPosition; private int mTopClassTaskPosition; private int mScenseTypeChoice; private int mCallGetMOVListByTGuidLoop, mCallGetMOVListByTGuidLeftLoop; private float mCurrentScalePerPixel; private String mScenseDescStr; private String districtSearchKeyWord; private Task mCurrentTopClassTask; private Task mTodayTask; private AMap mMap; private CommonApplication mApp; private Scense mBeReplacedScense; private BitmapDescriptor mBitmapDescriptor_Spare, mBitmapDescriptor_disable, mBitmapDescriptor_disableSel; private boolean[] mCheckedArray; private int[] markerIDS = {R.drawable.icon_mark_red, R.drawable.icon_mark_green, R.drawable.icon_mark_orange , R.drawable.icon_mark_purple, R.drawable.icon_mark_blue}; private int[] markerIDS_sel = {R.drawable.icon_mark_red_sel, R.drawable.icon_mark_green_sel, R.drawable.icon_mark_orange_sel, R.drawable.icon_mark_purple_sel, R.drawable.icon_mark_blue_sel }; private BitmapDescriptor[] mBitmapDescriptorArr; private BitmapDescriptor[] mBitmapDescriptorArr_sel; //2019.2.20 by Riku 所有场景列表 private ArrayList mScenseList = new ArrayList<>(); private ArrayList mSelectedScenseList = new ArrayList<>(); private ArrayList mSpareScenseList = new ArrayList<>(); // private ArrayList mMOVList = new ArrayList<>(); //2019.2.20 by Riku 当前数据库中所有的场景类型 private ArrayList mHadScenseTypeList = new ArrayList<>(); private ArrayList mTopClassTaskList = new ArrayList<>(); private ArrayList mMarkerList = new ArrayList<>(); private HashMap bdTypeMap = new HashMap<>(); //用于记录marker用的是哪一个颜色 private HashMap mScenseTypeMap; private HashMap mDataHolderMap = new HashMap<>(); private HashMap> mScenseByTypeMap = new HashMap<>(); private HashMap> mSpareScenseByTypeMap = new HashMap<>(); private TaskService mTaskService; private SubTaskService mSubTaskService; private MonitorObjectVersionService mMOVService; private DistrictSearch mDistrictSearch; private TextView tv_scenseDescBar_left; private TextView tv_scenseDesc; private TextView tv_exec_date; private TextView tv_task_executors; private View actionbar_waiting, view_waiting; private MapView mMapView; private View iBtn3; private Spinner mSpinner_topclass_task; private RecyclerView mRV_ScenseList; private PolylineOptions mDistrictBoundary; private MOVListAdapter mAdapter; private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { if (18 == msg.what) { mDistrictBoundary = (PolylineOptions) msg.obj; mMap.addPolyline(mDistrictBoundary); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_monitor_object_version_map); initBaseData(); initMap(savedInstanceState); initActionBar(); initServerData(); initScenseList(); view_waiting = findViewById(R.id.view_waiting); } private void initBaseData() { mApp = (CommonApplication) getApplication(); Retrofit retrofit = mApp.getRetrofit(); mTaskService = retrofit.create(TaskService.class); mSubTaskService = retrofit.create(SubTaskService.class); mMOVService = retrofit.create(MonitorObjectVersionService.class); mScenseTypeMap = CommonUtils.getDomainItemMapByCalalogGuid(mApp.getDaoSession(), Domain.DOMAINGUID_SCENSETYPE); Intent intent = getIntent(); mCurrentMode = intent.getIntExtra(Constant.KEY_INTENT_MODE, MODE_UNKNOWN); Serializable obj = intent.getSerializableExtra(Constant.KEY_INTENT_TOPCLASS_TASK); if (obj != null) { mCurrentTopClassTask = (Task) obj; if (mCurrentTopClassTask.getTypename().equals(Domain.TASK_DEADLINE_TYPE_TEMPORARY)) { mCurrentMode = MODE_TEMPORARY; } else { mCurrentMode = MODE_UNKNOWN; } } mBitmapDescriptorArr = new BitmapDescriptor[mScenseTypeMap.size()]; mBitmapDescriptorArr_sel = new BitmapDescriptor[mScenseTypeMap.size()]; for (int i = 0; i < mScenseTypeMap.size(); i++) { mBitmapDescriptorArr[i] = BitmapDescriptorFactory.fromResource(markerIDS[i % markerIDS.length]); mBitmapDescriptorArr_sel[i] = BitmapDescriptorFactory.fromResource(markerIDS_sel[i % markerIDS_sel.length]); } mBitmapDescriptor_Spare = BitmapDescriptorFactory.fromResource(R.drawable.icon_mark_blue); mBitmapDescriptor_disable = BitmapDescriptorFactory.fromResource(R.drawable.icon_mark_gray); mBitmapDescriptor_disableSel = BitmapDescriptorFactory.fromResource(R.drawable.icon_mark_black); } private void initMap(Bundle savedInstanceState) { mMapView = (MapView) findViewById(R.id.map); mMap = mMapView.getMap(); mMapView.onCreate(savedInstanceState); mMap.getUiSettings().setRotateGesturesEnabled(false); mMap.getUiSettings().setScaleControlsEnabled(true); mDistrictSearch = new DistrictSearch(this); mDistrictSearch.setOnDistrictSearchListener(this); mMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition cameraPosition) { } @Override public void onCameraChangeFinish(CameraPosition cameraPosition) { // tv_scenseDesc.setTitle(lngCurrent + "," + latCurrent); float scalePerPixel = mMap.getScalePerPixel(); if (scalePerPixel - mCurrentScalePerPixel > 0) { //缩小 if (mCurrentScalePerPixel / scalePerPixel < 0.85) { mCurrentScalePerPixel = scalePerPixel; Log.e(TAG, "onCameraChangeFinish()缩小"); invalidateMap(); } } else { //变大 if (scalePerPixel / mCurrentScalePerPixel < 0.75) { mCurrentScalePerPixel = mMap.getScalePerPixel(); Log.e(TAG, "onCameraChangeFinish()变大"); invalidateMap(); } } } }); mCurrentScalePerPixel = mMap.getScalePerPixel(); } private void initActionBar() { findViewById(R.id.img_right).setVisibility(View.GONE); findViewById(R.id.img_left).setOnClickListener(this); actionbar_waiting = findViewById(R.id.actionbar_waiting); actionbar_waiting.setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.actionbar_title)).setText("监管对象"); mSpinner_topclass_task = (Spinner) findViewById(R.id.spinner_topclass_task); if (mCurrentMode != MODE_ADD_SUBTASK && mCurrentMode != MODE_UPDATE_MOV) { mSpinner_topclass_task.setVisibility(View.GONE); actionbar_waiting.setVisibility(View.GONE); } mSpinner_topclass_task.setOnItemSelectedListener(this); mSpinner_topclass_task.setVisibility(View.GONE); } private void initServerData() { switch (mCurrentMode) { case MODE_UNKNOWN: // mCurrentMode = MODE_ADD_MOV; // getLocalScense(); getLastestTopClassTask(); break; case MODE_UPDATE_MOV: getMOVListByTGuid(mCurrentTopClassTask.getTguid()); break; case MODE_ADD_SUBTASK: getUnfinishedTopClassTaskList(); break; case MODE_TEMPORARY: getLocalScense(null); break; } } private void initScenseList() { mRV_ScenseList = (RecyclerView) findViewById(R.id.rv_scenselist); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); mRV_ScenseList.setLayoutManager(layoutManager); mAdapter = new MOVListAdapter(this, mScenseList); mRV_ScenseList.setAdapter(mAdapter); mRV_ScenseList.addOnItemTouchListener(new RecyclerItemClickListener(this, mRV_ScenseList, this)); } private void getUnfinishedTopClassTaskList() { Call> call = mTaskService.getTopClassTaskList(Constant.TOPCLASS_TASK_TYPE_UNFINISHED); call.enqueue(new Callback>() { @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { actionbar_waiting.setVisibility(View.GONE); if (response.body() != null) { mTopClassTaskList.clear(); ArrayList list = response.body(); ArrayList topClassTaskNameList = new ArrayList<>(); for (TaskVo taskVo : list) { mTopClassTaskList.add(taskVo); topClassTaskNameList.add(taskVo.getName()); } ArrayAdapter adapter = new ArrayAdapter<>(MOVMapActivity.this, android.R.layout.simple_spinner_dropdown_item, topClassTaskNameList); mSpinner_topclass_task.setVisibility(View.VISIBLE); mSpinner_topclass_task.setAdapter(adapter); } else if (response.errorBody() != null) { Toast.makeText(MOVMapActivity.this, "获取未完成顶层任务失败,请重试。", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { actionbar_waiting.setVisibility(View.GONE); Toast.makeText(MOVMapActivity.this, "获取未完成顶层任务接口调用失败。", Toast.LENGTH_SHORT).show(); } }); } private void getLastestTopClassTask() { Call call = mTaskService.getLastTopClassTask(mCurrentTopClassTask); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.body() != null) { Task lastTask = response.body(); if (lastTask.getTguid() == null) { //加载该区域所有场景信息 mCurrentMode = MODE_ADD_MOV; getLocalScense(null); } else { mCurrentMode = MODE_REPLACE_MOV; getMOVListByTGuid(lastTask.getTguid()); } } else if (response.errorBody() != null) { Log.e(TAG, "initData():onResponse()" + response.errorBody().toString()); Toast.makeText(MOVMapActivity.this, "获取任务信息失败,请重试。", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.e(TAG, "onFailure():t:" + t.getMessage()); } }); } private void getMOVListByTGuid(String tguid) { mCallGetMOVListByTGuidLoop++; Call> call = mMOVService.getMOVByTaskGuid(tguid); call.enqueue(new Callback>() { @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { if (response.body() != null) { ArrayList movList = response.body(); judgeMOVList(movList); } else if (response.errorBody() != null) { Log.e(TAG, "getMOVBytguid():onResponse():" + response.errorBody().toString()); } } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { Log.e(TAG, "getMOVBytguid():onFailure():" + t.getMessage()); } }); } /** * 获取对应顶层任务的所有子任务 * * @param tguid 顶层任务GUID */ private void getMOVListByTGuidLeft(String tguid) { mCallGetMOVListByTGuidLeftLoop++; Call> call = mMOVService.getMOVByTaskGuidLeft(tguid); call.enqueue(new Callback>() { @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { if (response.body() != null) { ArrayList movList = response.body(); judgeMOVList(movList); } else if (response.errorBody() != null) { Toast.makeText(MOVMapActivity.this, "获取失败,请重新获取数据。", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { } }); } /** * 判断监管对象版本,若数量为0,则根据权限判断此类问题。 */ private void judgeMOVList(ArrayList movList) { if (movList.size() == 0) { switch (mCurrentMode) { case MODE_REPLACE_MOV: case MODE_UPDATE_MOV: if (mCallGetMOVListByTGuidLoop < 2) { getMOVListByTGuid(mCurrentTopClassTask.getTguid()); } else { Toast.makeText(mApp, "获取监管对象版本失败,请与管理员联系。", Toast.LENGTH_SHORT).show(); } break; case MODE_ADD_SUBTASK: if (mCallGetMOVListByTGuidLeftLoop < 2) { getMOVListByTGuidLeft(mCurrentTopClassTask.getTguid()); } else { Toast.makeText(mApp, "获取监管对象版本失败,请与管理员联系。", Toast.LENGTH_SHORT).show(); } break; } } else { Log.e(TAG, "getMOVBytguid():onResponse() 有货"); getLocalScense(movList); } } private void initOtherView() { findViewById(R.id.iBtn1).setOnClickListener(this); findViewById(R.id.iBtn2).setOnClickListener(this); iBtn3 = findViewById(R.id.iBtn3); iBtn3.setOnClickListener(this); if (mCurrentMode != MODE_ADD_MOV) { iBtn3.setVisibility(View.VISIBLE); } findViewById(R.id.iBtn4).setVisibility(View.GONE); findViewById(R.id.iBtn5).setVisibility(View.GONE); } private void getLocalScense(ArrayList movList) { initOtherView(); mScenseList.clear(); mSpareScenseList.clear(); mScenseByTypeMap.clear(); mSpareScenseByTypeMap.clear(); mHadScenseTypeList.clear(); mDataHolderMap.clear(); ScenseDao scenseDao = mApp.getDaoSession().getScenseDao(); ArrayList movScenseList = new ArrayList<>(); if (mCurrentMode == MODE_REPLACE_MOV || mCurrentMode == MODE_ADD_SUBTASK || mCurrentMode == MODE_UPDATE_MOV) { for (Monitorobjectversion mov : movList) { Scense scense = scenseDao.queryBuilder().where(ScenseDao.Properties.Guid.eq(mov.getSguid())).unique(); if (scense != null ) { if (scense.getExtension1() != null && scense.getExtension1().equals(Domain.SCENSE_DISABLE)) { mDisableScenseNum++; } if (mCurrentMode == MODE_REPLACE_MOV) { scense.setSelected(true); } scense.setMonitorNum(mov.getMonitornum()); scense.setDisplayID(mov.getDisplayid()); if (mov.getExtension1() != null) { scense.setInspectedNum(Integer.parseInt(mov.getExtension1())); } Log.d(TAG, "getLocalDBScenseList()" + mov.getSguid() + "; SCENSEGUID:" + scense); Log.d(TAG, "getLocalDBScenseList()" + mov.getSguid() + "; SCENSEGUID:" + scense.getGuid()); movScenseList.add(scense); } } if (mDisableScenseNum > 0 && mSpareScenseList.size() > 0) { iBtn3.setVisibility(View.GONE); } } List list; //获取场景信息时,必须根据TypeID排序,确保在调用createMOV()方法时,scenselist中是按typeID排列避免多次重置j=0; if (mCurrentTopClassTask.getExtension1().equals(Domain.DOMAIN_SUITABLE_TOWN)) { list = scenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(mCurrentTopClassTask.getProvincecode()), ScenseDao.Properties.Citycode.eq(mCurrentTopClassTask.getCitycode()), ScenseDao.Properties.Districtcode.eq(mCurrentTopClassTask.getDistrictcode()), ScenseDao.Properties.Towncode.eq(mCurrentTopClassTask.getTowncode()), ScenseDao.Properties.Typeid.notEq(Domain.SCENSETYPE_UNFIXED_SCENSE)) .orderAsc(ScenseDao.Properties.Typeid, ScenseDao.Properties.Towncode).list(); } else { list = scenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(mCurrentTopClassTask.getProvincecode()), ScenseDao.Properties.Citycode.eq(mCurrentTopClassTask.getCitycode()), ScenseDao.Properties.Districtcode.eq(mCurrentTopClassTask.getDistrictcode()), ScenseDao.Properties.Typeid.notEq(Domain.SCENSETYPE_UNFIXED_SCENSE)) .orderAsc(ScenseDao.Properties.Typeid, ScenseDao.Properties.Towncode).list(); } DataHolder dholder = new DataHolder(); dholder.scenseType = "所有场景"; mDataHolderMap.put(Domain.SCENSETYPE_ALL, new DataHolder()); List scenseList; switch (mCurrentMode) { case MODE_ADD_MOV: case MODE_TEMPORARY: scenseList = list; break; case MODE_REPLACE_MOV: case MODE_ADD_SUBTASK: case MODE_UPDATE_MOV: scenseList = movScenseList; break; default: scenseList = list; } // for (Scense scense : scenseList) { DataHolder dataHolder = mDataHolderMap.get(Domain.SCENSETYPE_ALL); dataHolder.scenseTotalNum += 1; if (scense == null) continue; byte scenseTypeID = scense.getTypeid(); if (!mDataHolderMap.containsKey(scenseTypeID)) { ArrayList subList = new ArrayList<>(); subList.add(scense); mScenseByTypeMap.put(scenseTypeID, subList); DataHolder dHolder = new DataHolder(); dHolder.scenseTypeID = scenseTypeID; dHolder.scenseType = scense.getType(); dHolder.scenseTotalNum = 1; mDataHolderMap.put(scenseTypeID, dHolder); int k = 0; for (Domainitem item : mHadScenseTypeList) { if (Byte.parseByte(item.getValue()) < scenseTypeID) { k++; } } mHadScenseTypeList.add(k, mScenseTypeMap.get(scenseTypeID)); } else { mScenseByTypeMap.get(scenseTypeID).add(scense); DataHolder dHolder = mDataHolderMap.get(scenseTypeID); dHolder.scenseTotalNum += 1; } } // for (Domainitem item : mHadScenseTypeList) { ArrayList subList = mScenseByTypeMap.get(Byte.parseByte(item.getValue())); if (mCurrentMode == MODE_ADD_MOV) { int i=1; for (Scense scense : subList) { scense.setDisplayID(i); i++; } } mScenseList.addAll(subList); } list.removeAll(movScenseList); for (Scense scense : list) { if (mSpareScenseByTypeMap.containsKey(scense.getTypeid())) { mSpareScenseByTypeMap.get(scense.getTypeid()).add(scense); } else { ArrayList sublist = new ArrayList<>(); sublist.add(scense); mSpareScenseByTypeMap.put(scense.getTypeid(), sublist); } mSpareScenseList.add(scense); } initScenseDescBar(); searchDistrict(); invalidateMap(); } private void initScenseDescBar() { tv_scenseDescBar_left = (TextView) findViewById(R.id.tv_scenseDescBar_left); TextView tv_submit = (TextView) findViewById(R.id.tv_submit); tv_scenseDescBar_left.setOnClickListener(this); tv_submit.setOnClickListener(this); tv_scenseDesc = (TextView) findViewById(R.id.tv_scenseDesc); DataHolder dataHolder = mDataHolderMap.get(Domain.SCENSETYPE_ALL); StringBuilder sb = new StringBuilder(); switch (mCurrentMode) { case MODE_REPLACE_MOV: mSelectedAll = true; dataHolder.scenseSelectedNum = dataHolder.scenseTotalNum; case MODE_ADD_MOV: case MODE_TEMPORARY: break; case MODE_ADD_SUBTASK: tv_scenseDescBar_left.setText("详情"); break; } if (mHadScenseTypeList.size() > 1) { sb.append("所有场景:").append(REGEX_SELECTED_SCENSE_NUM) .append("/").append(dataHolder.scenseTotalNum).append(" "); } for (Domainitem item : mHadScenseTypeList) { dataHolder = mDataHolderMap.get(Byte.parseByte(item.getValue())); sb.append(dataHolder.scenseType).append(":"); sb.append(REGEX_SELECTED_SCENSE_NUM).append("/").append(dataHolder.scenseTotalNum).append(" "); if (mCurrentMode == MODE_REPLACE_MOV) { dataHolder.scenseSelectedNum = dataHolder.scenseTotalNum; } } mScenseDescStr = sb.toString(); updateScenseDesc(); } private void invalidateMap() { mMap.clear(); mMarkerList.clear(); if (mDistrictBoundary != null) { mMap.addPolyline(mDistrictBoundary); } final ArrayList list = new ArrayList<>(); list.addAll(mScenseList); if (mCurrentMode == MODE_REPLACE_MOV || mCurrentMode == MODE_UPDATE_MOV) { list.addAll(mSpareScenseList); } mAdapter.notifyDataSetChanged(); int length = list.size(); int movLength = mScenseList.size(); Log.e(TAG, "invalidate()LENGTH:" + length); for (int i = 0; i < length; i++) { Scense info = list.get(i); LatLng ll; if (info.getLatitude() == null || info.getLongitude() == null) { ll = new LatLng(31.230378, 121.473658); info.setLatitude(31.230378); info.setLongitude(121.473658); } else { ll = new LatLng(info.getLatitude(), info.getLongitude()); } BitmapDescriptor[] bitmapDesctiptorArr; BitmapDescriptor bitmapDescriptor = mBitmapDescriptorArr[0]; if (info.isSelected()) { bitmapDesctiptorArr = mBitmapDescriptorArr_sel; } else { bitmapDesctiptorArr = mBitmapDescriptorArr; } int j; for (j = 0; j < mHadScenseTypeList.size(); j++) { Domainitem domainitem = mHadScenseTypeList.get(j); if (info.getTypeid() == Integer.parseInt(domainitem.getValue())) { bitmapDescriptor = bitmapDesctiptorArr[j]; break; } } if (i >= movLength) { bitmapDescriptor = mBitmapDescriptor_Spare; } if (info.getExtension1() != null && info.getExtension1().equals(Domain.SCENSE_DISABLE)) { bitmapDescriptor = mBitmapDescriptor_disable; } bdTypeMap.put(i, j); Marker marker = mMap.addMarker(new MarkerOptions().icon(bitmapDescriptor).position(ll)); mMarkerList.add(marker); String displayId = ""; if (i < movLength) { displayId = String.valueOf(info.getDisplayID()); } mMap.addText(new TextOptions().zIndex(marker.getZIndex()).text(displayId) .backgroundColor(Color.TRANSPARENT).fontColor(Color.WHITE) .fontSize(33) .position(new LatLng(getLat(mMap.getScalePerPixel(), ll.latitude), ll.longitude))); // addMarkerInScreenCenter(); } // addMarkerInScreenCenter(); // 初始化搜索模块,注册事件监听 mMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() { public boolean onMarkerClick(final Marker marker) { mCurrentPosition = mMarkerList.indexOf(marker); Scense scense = list.get(mCurrentPosition); if (mCurrentMode == MODE_REPLACE_MOV) { if (scense.getExtension1() != null && scense.getExtension1().equals(Domain.SCENSE_DISABLE)) { pickupBeReplacedScense(scense); } else { if (mCurrentOperation == OPERATION_REPLACE) { Toast.makeText(MOVMapActivity.this, "OPERATION_REPLACE。", Toast.LENGTH_SHORT).show(); if (mBeReplacedScense == null) { Toast.makeText(MOVMapActivity.this, "请选择须替换的场景。", Toast.LENGTH_SHORT).show(); } else { if (mSpareScenseList.contains(scense)) { showUpdateScenseDialog(scense); } else { Toast.makeText(MOVMapActivity.this, "该场景不可用,请重新选择。", Toast.LENGTH_SHORT).show(); } } } else if (mCurrentOperation == OPERATION_ADD) { if (mSpareScenseList.contains(scense)) { showUpdateScenseDialog(scense); } else { Toast.makeText(MOVMapActivity.this, "该场景不可用,请重新选择。", Toast.LENGTH_SHORT).show(); } } else { updateMarkers(marker, scense); } } } else { if (mCurrentMode == MODE_ADD_SUBTASK) { mSelectedScenseList.add(scense); } updateMarkers(marker, scense); } return true; } }); } private double getLat(float scalePerPixel, double lat) { return 0.0004 * scalePerPixel + lat; } private void showUpdateScenseDialog(final Scense scense) { String message = "是否将场景:\n%s\n替换为:\n%s"; if (mCurrentOperation == OPERATION_ADD) { message = "是否新增场景:\n%s\n%s"; message = String.format(Locale.CHINA, message, scense.getName(), scense.getType()); } else { message = String.format(Locale.CHINA, message, mBeReplacedScense.getName(), scense.getName()); } new AlertDialog.Builder(MOVMapActivity.this).setTitle("监管对象版本变更") .setMessage(message) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mCurrentOperation = OPERATION_FREE; } }) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mCurrentOperation == OPERATION_REPLACE) { replaceScense(scense); } else if (mCurrentOperation == OPERATION_ADD) { addScense(scense); } mCurrentOperation = OPERATION_FREE; } }).show(); } public void updateMarkers(Marker marker, Scense scense) { boolean selected = scense.isSelected(); scense.setSelected(!selected); if (!selected) { mSelectedAll = false; } else { mSelectedAll = true; for (Scense scense1 : mScenseList) { if (scense1.isSelected()) { mSelectedAll = false; break; } } } BitmapDescriptor bd; int monitorNum; if (selected) { bd = mBitmapDescriptorArr[bdTypeMap.get(mCurrentPosition)]; monitorNum = 0; mDataHolderMap.get(Domain.SCENSETYPE_ALL).scenseSelectedNum -= 1; mDataHolderMap.get(scense.getTypeid()).scenseSelectedNum -= 1; } else { bd = mBitmapDescriptorArr_sel[bdTypeMap.get(mCurrentPosition)]; monitorNum = 1; mDataHolderMap.get(Domain.SCENSETYPE_ALL).scenseSelectedNum += 1; mDataHolderMap.get(scense.getTypeid()).scenseSelectedNum += 1; } marker.setIcon(bd); if (mCurrentMode != MODE_ADD_SUBTASK) { scense.setMonitorNum(monitorNum); } mAdapter.notifyDataSetChanged(); updateScenseDesc(); mRV_ScenseList.scrollToPosition(mCurrentPosition); } public void updateScenseDesc() { DataHolder dataHolder; if (mCurrentMode != MODE_ADD_SUBTASK) { tv_scenseDescBar_left.setText(mSelectedAll ? "取消" : "全选"); } String description = mScenseDescStr; if (mHadScenseTypeList.size() > 1) { dataHolder = mDataHolderMap.get(Domain.SCENSETYPE_ALL); description = description.replaceFirst(REGEX_SELECTED_SCENSE_NUM, String.valueOf(dataHolder.scenseSelectedNum)); } for (Domainitem item : mHadScenseTypeList) { dataHolder = mDataHolderMap.get(Byte.parseByte(item.getValue())); description = description.replaceFirst(REGEX_SELECTED_SCENSE_NUM, String.valueOf(dataHolder.scenseSelectedNum)); } tv_scenseDesc.setText(description); } /** * 更换监管对象版本中的场景 * * @param scense 新场景信息 */ private void replaceScense(Scense scense) { int index = mScenseList.indexOf(mBeReplacedScense); mScenseList.remove(mBeReplacedScense); mScenseList.add(index, scense); ArrayList list = mScenseByTypeMap.get(scense.getTypeid()); index = list.indexOf(mBeReplacedScense); list.remove(mBeReplacedScense); list.add(index, scense); mSpareScenseList.remove(scense); mSpareScenseByTypeMap.get(scense.getTypeid()).remove(scense); if (mBeReplacedScense.getExtension1() != null && mBeReplacedScense.getExtension1().equals(Domain.SCENSE_DISABLE)) { mDisableScenseNum--; if (mDisableScenseNum == 0) { iBtn3.setVisibility(View.VISIBLE); } } mBeReplacedScense = null; invalidateMap(); } /** * 新增监管对象版本中的场景 * * @param scense 新场景信息 */ private void addScense(Scense scense) { mScenseList.clear(); ArrayList list = mScenseByTypeMap.get(scense.getTypeid()); list.add(scense); for (Domainitem item : mHadScenseTypeList) { mScenseList.addAll(mScenseByTypeMap.get(Byte.parseByte(item.getValue()))); } mSpareScenseList.remove(scense); mSpareScenseByTypeMap.get(scense.getTypeid()).remove(scense); invalidateMap(); } //在屏幕中心添加一个固定的marker private void addMarkerInScreenCenter() { LatLng latLng = mMap.getCameraPosition().target; Point screenPosition = mMap.getProjection().toScreenLocation(latLng); Marker locationMarker = mMap.addMarker(new MarkerOptions() .anchor(0.5f, 0.5f) .icon(BitmapDescriptorFactory.fromResource(R.drawable.purple_pin))); //设置Marker在屏幕上,不跟随地图移动 locationMarker.setPositionByPixels(screenPosition.x, screenPosition.y); locationMarker.setZIndex(10); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.img_left: this.finish(); break; case R.id.tv_scenseDescBar_left: switch (mCurrentMode) { case MODE_ADD_MOV: case MODE_REPLACE_MOV: updateMOV(); break; case MODE_ADD_SUBTASK: break; case MODE_UPDATE_MOV: break; } break; case R.id.tv_submit: if (mCurrentMode == MODE_ADD_SUBTASK) { if (mSelectedScenseList.size() == 0) { Toast.makeText(this, "当前还未选择监管对象,请选择。", Toast.LENGTH_SHORT).show(); return; } showPlanSubtaskDialog(); } else { //先创建监管对象版本,然后验证信息,若信息不合规,弹出对话框,告知不合规地方, // 若合规,弹出对话框,提示是否提交监管对象版本信息。 checkMOVInfo(); } break; case R.id.ll_exec_date: Calendar cal = Calendar.getInstance(); cal.setTime(mTodayTask.getStarttime()); showDatePickerDialog(cal); break; case R.id.ll_task_executors: showExecutorsDialog(); break; case R.id.iBtn1: toggleView(mRV_ScenseList); break; case R.id.iBtn2: if (mHadScenseTypeList.size() == 1) { Toast.makeText(mApp, "单一场景,无需切换。", Toast.LENGTH_SHORT).show(); } else { showScenseTypeDialog(); } break; case R.id.iBtn3: if (mCurrentMode == MODE_ADD_SUBTASK) { clearSelectedScense(); } else { new AlertDialog.Builder(this).setTitle("新增监管对象") .setMessage("请在地图上选取蓝色图标的场景,作为新增加的监管对象。") .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mCurrentOperation = OPERATION_ADD; } }).show(); } break; } } private void clearSelectedScense() { for (int i = 0; i < mScenseList.size(); i++) { Scense scense = mScenseList.get(i); if (scense.isSelected()) { scense.setSelected(false); Marker marker = mMarkerList.get(i); marker.setIcon(mBitmapDescriptorArr[bdTypeMap.get(i)]); } } for (Map.Entry entity : mDataHolderMap.entrySet()) { entity.getValue().scenseSelectedNum = 0; } mSelectedScenseList.clear(); updateScenseDesc(); mAdapter.notifyDataSetChanged(); } private void updateMOV() { mSelectedAll = !mSelectedAll; BitmapDescriptor[] bitmapDescriptorArr; int monitorNum; if (mSelectedAll) { bitmapDescriptorArr = mBitmapDescriptorArr_sel; monitorNum = 1; } else { bitmapDescriptorArr = mBitmapDescriptorArr; monitorNum = 0; } for (int i = 0; i < mScenseList.size(); i++) { Scense scense = mScenseList.get(i); scense.setMonitorNum(monitorNum); scense.setSelected(mSelectedAll); Marker marker = mMarkerList.get(i); marker.setIcon(bitmapDescriptorArr[bdTypeMap.get(i)]); } for (Map.Entry entry : mDataHolderMap.entrySet()) { DataHolder dataHolder = entry.getValue(); if (mSelectedAll) { dataHolder.scenseSelectedNum = dataHolder.scenseTotalNum; } else { dataHolder.scenseSelectedNum = 0; } } updateScenseDesc(); mAdapter.notifyDataSetChanged(); } /** * 验证该监管对象版本信息是否合规,如监管频次不可为0等。 */ private void checkMOVInfo() { if (mDisableScenseNum > 0) { Toast.makeText(this, "该监管对象版本存在不可用场景,请替换该场景。", Toast.LENGTH_SHORT).show(); } else { showAlertDialog(); } } /** * 显示提交监管对象版本对话框 */ private void showAlertDialog() { String msg = "本次监管对象版本信息如下:\n" + tv_scenseDesc.getText() + "\n"; //若存在监管多次的工地,则添加以下语句:其中,部分场景需监管多次; msg += "总共需监管%d次。\n是否现在提交?"; int totalMonitorNum = 0; int j = 0; byte typeID = 0; final ArrayList movList = new ArrayList<>(); for (int i = 0; i < mScenseList.size(); i++) { Scense scense = mScenseList.get(i); if (scense.getTypeid() != typeID) { j = 0; typeID = mScenseList.get(i).getTypeid(); } if (scense.getMonitorNum() == 0) { mScenseList.remove(i); i--; } else { j++; totalMonitorNum += scense.getMonitorNum(); scense.setDisplayID(j); Monitorobjectversion mov = createMOV(scense, j); movList.add(mov); } } new AlertDialog.Builder(this).setTitle("提交监管对象版本") .setMessage(String.format(Locale.CHINA, msg, totalMonitorNum)) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!mHadPutTopClassTask) { callPutTopClassTask(mCurrentTopClassTask); } if (!mHadPutMOVList) { callPutMOV(movList); } } }).show(); } /** * @param cal 日任务开始日期 */ private void showDatePickerDialog(Calendar cal) { final int year, month, day; year = cal.get(Calendar.YEAR); month = cal.get(Calendar.MONTH); day = cal.get(Calendar.DAY_OF_MONTH); //日历控件 DatePickerDialog dp = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int iyear, int monthOfYear, int dayOfMonth) { Calendar cal_s = Calendar.getInstance(); cal_s.setTime(mTodayTask.getStarttime()); cal_s.set(Calendar.YEAR, iyear); cal_s.set(Calendar.MONTH, monthOfYear); cal_s.set(Calendar.DAY_OF_MONTH, dayOfMonth); cal_s.set(Calendar.HOUR_OF_DAY, 0); cal_s.set(Calendar.MINUTE, 0); cal_s.set(Calendar.SECOND, 0); mTodayTask.setStarttime(cal_s.getTime()); Calendar cal_e = Calendar.getInstance(); cal_e.set(Calendar.YEAR, iyear); cal_e.set(Calendar.MONTH, monthOfYear); cal_e.set(Calendar.DAY_OF_MONTH, dayOfMonth); cal_e.set(Calendar.HOUR_OF_DAY, 23); cal_e.set(Calendar.MINUTE, 59); cal_e.set(Calendar.SECOND, 59); mTodayTask.setEndtime(cal_e.getTime()); tv_exec_date.setText(DateFormatter.dateFormat.format(mTodayTask.getStarttime())); } }, year, month, day); DatePicker datePicker = dp.getDatePicker(); datePicker.setMinDate(mCurrentTopClassTask.getStarttime().getTime()); datePicker.setMaxDate(mCurrentTopClassTask.getEndtime().getTime()); dp.show(); } /** * 显示任务执行者多选对话框 */ private void showExecutorsDialog() { // 设置默认选中的选项,全为false默认均未选中 final String[] executorguids = mCurrentTopClassTask.getExecutorguids().split(Constant.CONNECTOR); final String[] executoruName = mCurrentTopClassTask.getExecutorusernames().split(Constant.CONNECTOR); final String[] executorrName = mCurrentTopClassTask.getExecutorrealnames().split(Constant.CONNECTOR); if (mCheckedArray == null) { mCheckedArray = new boolean[executorguids.length]; for (int i = 0; i < mCheckedArray.length; i++) { mCheckedArray[i] = true; } } AlertDialog.Builder multiChoiceDialog = new AlertDialog.Builder(this); multiChoiceDialog.setTitle("选择任务执行者"); multiChoiceDialog.setMultiChoiceItems(executorrName, mCheckedArray, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { mCheckedArray[which] = isChecked; } }); multiChoiceDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int i = 0; StringBuilder sb = new StringBuilder(); StringBuilder sb_un = new StringBuilder(); //用户名字符串 StringBuilder sb_rn = new StringBuilder(); //真实姓名字符串,用于界面显示 for (boolean isChecked : mCheckedArray) { if (isChecked) { sb.append(executorguids[i]).append(Constant.CONNECTOR); sb_un.append(executoruName[i]).append(Constant.CONNECTOR); sb_rn.append(executorrName[i]).append(Constant.CONNECTOR); } i++; } if (sb.length() > 0) { String executors = sb.deleteCharAt(sb.length() - 1).toString(); String executors_un = sb_un.deleteCharAt(sb_un.length() - 1).toString(); String executors_rn = sb_rn.deleteCharAt(sb_rn.length() - 1).toString(); mTodayTask.setExecutorguids(executors); mTodayTask.setExecutorusernames(executors_un); mTodayTask.setExecutorrealnames(executors_rn); String names = executors_rn.replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW); tv_task_executors.setText(names); } } }); multiChoiceDialog.show(); } /** * 显示子任务制定界面 */ private void showPlanSubtaskDialog() { ArrayList scenseNameList = new ArrayList<>(); final ArrayList selectedScenseList = new ArrayList<>(); mTodayTask = mCurrentTopClassTask.clone(); mTodayTask.setTguid(UUIDGenerator.generate16ShortUUID()); mTodayTask.setTsguid(mCurrentTopClassTask.getTguid()); mTodayTask.setLevelnum(null); Calendar cal = Calendar.getInstance(); cal.setTime(mCurrentTopClassTask.getStarttime()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); mTodayTask.setStarttime(cal.getTime()); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); mTodayTask.setEndtime(cal.getTime()); mTodayTask.setPlannerguid(mApp.getCurrentUser().getGuid()); mTodayTask.setPlannerusername(mApp.getCurrentUser().getAcountname()); mTodayTask.setPlannerrealname(mApp.getCurrentUser().getRealname()); for (Scense scense : mScenseList) { if (scense.isSelected()) { scenseNameList.add(scense.getName()); selectedScenseList.add(scense); } } View view = LayoutInflater.from(this).inflate(R.layout.dialog_plansubtask, null); Spinner spinner = (Spinner) view.findViewById(R.id.spinner_scenselist); tv_exec_date = (TextView) view.findViewById(R.id.tv_exec_date); tv_exec_date.setText(DateFormatter.dateFormat.format(mTodayTask.getStarttime())); tv_task_executors = (TextView) view.findViewById(R.id.tv_task_executors); String users = mTodayTask.getExecutorrealnames().replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW); tv_task_executors.setText(users); view.findViewById(R.id.ll_exec_date).setOnClickListener(this); view.findViewById(R.id.ll_task_executors).setOnClickListener(this); spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, scenseNameList)); new AlertDialog.Builder(this).setTitle("任务制定") .setView(view) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (selectedScenseList.size() == 0) { Toast.makeText(MOVMapActivity.this, "请选择监管对象。", Toast.LENGTH_SHORT).show(); } else { callPutSubTaskList(selectedScenseList); } } }).show(); } private void showScenseTypeDialog() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("场景类型"); final String[] items; if (mHadScenseTypeList.size() > 1) { items = new String[mHadScenseTypeList.size() + 1]; items[0] = "所有场景"; for (int i = 0; i < items.length; i++) { if (i > 0) { Domainitem item = mHadScenseTypeList.get(i - 1); items[i] = item.getText(); } } } else { items = new String[1]; Domainitem item = mHadScenseTypeList.get(0); items[0] = item.getText(); } builder.setSingleChoiceItems(items, mScenseTypeChoice, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mScenseTypeChoice = which; switchScenseType(); dialog.dismiss(); Toast.makeText(MOVMapActivity.this, items[which], Toast.LENGTH_SHORT).show(); } }); builder.show(); } private void switchScenseType() { mScenseList.clear(); mSpareScenseList.clear(); if (mScenseTypeChoice == 0) { for (Domainitem item : mHadScenseTypeList) { byte typeID = Byte.parseByte(item.getValue()); mScenseList.addAll(mScenseByTypeMap.get(typeID)); if (mSpareScenseByTypeMap.containsKey(typeID)) { mSpareScenseList.addAll(mSpareScenseByTypeMap.get(typeID)); } } } else { byte typeID = Byte.parseByte(mHadScenseTypeList.get(mScenseTypeChoice - 1).getValue()); mScenseList.addAll(mScenseByTypeMap.get(typeID)); if (mSpareScenseByTypeMap.containsKey(typeID)) { mSpareScenseList.addAll(mSpareScenseByTypeMap.get(typeID)); } } if (mCurrentOperation == OPERATION_FREE) { resetSelectedScenseMap(); } invalidateMap(); } private void toggleView(View view) { if (view.isShown()) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } } @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { mCurrentTopClassTask = mTopClassTaskList.get(position).taskVo2Task(); mTopClassTaskPosition = position; switch (mCurrentMode) { case MODE_ADD_SUBTASK: getMOVListByTGuidLeft(mCurrentTopClassTask.getTguid()); break; case MODE_UPDATE_MOV: getMOVListByTGuid(mCurrentTopClassTask.getTguid()); break; } } @Override public void onNothingSelected(AdapterView parent) { } @Override public void onItemClick(View view, int position) { Scense curScense = mScenseList.get(position); mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(curScense.getLatitude(), curScense.getLongitude()))); } @Override public void onItemLongClick(View view, int position) { if (mCurrentMode == MODE_REPLACE_MOV) { if (mSpareScenseList.size() == 0) { Toast.makeText(mApp, "当前无可替换场景,请添加场景。", Toast.LENGTH_SHORT).show(); return; } mCurrentPosition = position; Scense scense = mScenseList.get(mCurrentPosition); pickupBeReplacedScense(scense); } } private void pickupBeReplacedScense(Scense scense) { mBeReplacedScense = scense; if (mBeReplacedScense.getExtension1() != null && mBeReplacedScense.getExtension1().equals(Domain.SCENSE_DISABLE)) { aniToScense(mMarkerList.get(mCurrentPosition)); mCurrentOperation = OPERATION_REPLACE; } else { new AlertDialog.Builder(this).setTitle("提示") .setMessage("是否确定要变更该监管对象?") .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { aniToScense(mMarkerList.get(mCurrentPosition)); mCurrentOperation = OPERATION_REPLACE; } }).show(); } } /** * 选择场景 * * @param marker 场景marker */ public void aniToScense(Marker marker) { Scense curScense = mScenseList.get(mCurrentPosition); marker.setIcon(mBitmapDescriptor_disableSel); int i = 0; for (Domainitem item : mHadScenseTypeList) { if (Byte.parseByte(item.getValue()) == curScense.getTypeid()) { break; } i++; } mScenseTypeChoice = i + 1; switchScenseType(); mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(curScense.getLatitude(), curScense.getLongitude()))); } private void searchDistrict() { DistrictSearchQuery query = new DistrictSearchQuery(); String level = mCurrentTopClassTask.getExtension1(); switch (level) { case Domain.DOMAIN_SUITABLE_PROVINCE: districtSearchKeyWord = mCurrentTopClassTask.getProvincename(); break; case Domain.DOMAIN_SUITABLE_CITY: districtSearchKeyWord = mCurrentTopClassTask.getCityname(); break; case Domain.DOMAIN_SUITABLE_DISTRICT: case Domain.DOMAIN_SUITABLE_TOWN: districtSearchKeyWord = mCurrentTopClassTask.getDistrictname(); break; default: districtSearchKeyWord = mCurrentTopClassTask.getDistrictname(); } query.setKeywords(districtSearchKeyWord); Log.e(TAG, "searchDistrict()area:" + districtSearchKeyWord); query.setShowBoundary(true); mMap.clear(); mDistrictSearch.setQuery(query); mDistrictSearch.searchDistrictAsyn(); } /** * 创建单一监管对象版本信息 * * @param scense 场景信息 */ private Monitorobjectversion createMOV(Scense scense, int index) { Monitorobjectversion mov = new Monitorobjectversion(); mov.setMovid(UUIDGenerator.generate16ShortUUID()); mov.setTid(mCurrentTopClassTask.getTguid()); mov.setSensename(scense.getName()); mov.setSguid(scense.getGuid()); mov.setTasktypeid(mCurrentTopClassTask.getTypeno()); mov.setTasktype(mCurrentTopClassTask.getTypename()); mov.setMonitornum(scense.getMonitorNum()); mov.setDisplayid(index); return mov; } public void resetSelectedScenseMap() { boolean selected = false; if (mCurrentMode == MODE_REPLACE_MOV) { selected = true; } for (Scense scense : mScenseList) { scense.setSelected(selected); } } private void callPutTopClassTask(Task mCurTask) { mIsCallingPutTaskService = true; Call call = mTaskService.putTask(mCurTask); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.body() != null) { mHadPutTopClassTask = true; Toast.makeText(MOVMapActivity.this, "顶层任务上传成功。", Toast.LENGTH_SHORT).show(); mIsCallingPutTaskService = false; if (!mIsCallingPutMovService && !mIsCallingPutTaskService) { MOVMapActivity.this.finish(); } } else if (response.errorBody() != null) { Toast.makeText(MOVMapActivity.this, "顶层任务上传失败,请重试。", Toast.LENGTH_SHORT).show(); response.errorBody().contentType(); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { } }); } private void callPutMOV(ArrayList movList) { mIsCallingPutMovService = true; toggleView(view_waiting); Call call = mMOVService.putMOVList(movList); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { toggleView(view_waiting); if (response.body() != null) { mHadPutMOVList = true; Toast.makeText(MOVMapActivity.this, "监管对象版本上传成功。", Toast.LENGTH_SHORT).show(); mIsCallingPutMovService = false; if (!mIsCallingPutMovService && !mIsCallingPutTaskService) { MOVMapActivity.this.finish(); } } else if (response.errorBody() != null) { Toast.makeText(MOVMapActivity.this, "监管对象版本上传失败,请重试。", Toast.LENGTH_SHORT).show(); response.errorBody().contentType(); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { // Log.e(TAG, "callPutMOV():onFailure():" + t.getMessage()); } }); } private void callPutSubtaskList(final ArrayList list) { ArrayList subtaskList = new ArrayList<>(); for (Scense scense : list) { Subtask subtask = new Subtask(); subtask.setStguid(UUIDGenerator.generate16ShortUUID()); subtask.setTguid(mCurrentTopClassTask.getTguid()); if (mCurrentTopClassTask.getLevelnum() == Domain.TASK_LEVEL_2) { subtask.setTsguid(mTodayTask.getTguid()); } subtask.setProvincecode(mCurrentTopClassTask.getProvincecode()); subtask.setProvincename(mCurrentTopClassTask.getProvincename()); subtask.setCitycode(mCurrentTopClassTask.getCitycode()); subtask.setCityname(mCurrentTopClassTask.getCityname()); subtask.setDistrictcode(mCurrentTopClassTask.getDistrictcode()); subtask.setDistrictname(mCurrentTopClassTask.getDistrictname()); subtask.setTowncode(mCurrentTopClassTask.getTowncode()); subtask.setTownname(mCurrentTopClassTask.getTownname()); subtask.setTypeno(mCurrentTopClassTask.getTypeno()); subtask.setType(mCurrentTopClassTask.getTypename()); subtask.setScenseid(scense.getGuid()); subtask.setScensename(scense.getName()); subtask.setPlanstarttime(mTodayTask.getStarttime()); subtask.setPlanendtime(mTodayTask.getEndtime()); subtask.setScenseaddress(scense.getLocation()); subtask.setDeployerguid(mApp.getCurrentUser().getGuid()); subtask.setDeployerusername(mApp.getCurrentUser().getAcountname()); subtask.setDeployerrealname(mApp.getCurrentUser().getRealname()); subtask.setExecutorguids(mTodayTask.getExecutorguids()); subtask.setExecutorusernames(mTodayTask.getExecutorusernames()); subtask.setExecutorrealtimes(mTodayTask.getExecutorrealnames()); // String day = DateFormater.dateFormat.format(subtask.getPlanstarttime()); subtask.setName(/*day+*/scense.getName() + mCurrentTopClassTask.getTypename()); subtask.setStatus(Domain.TASK_STATUS_WAITING); subtaskList.add(subtask); } Call call = mSubTaskService.putSubTaskList(subtaskList); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (view_waiting.isShown()) { toggleView(view_waiting); } if (response.body() != null) { response.body(); callUpdateMOV(list); } else if (response.errorBody() != null) { Toast.makeText(MOVMapActivity.this, "子任务信息上传失败,请重试。", Toast.LENGTH_SHORT).show(); } mHadDayTask = false; } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { if (view_waiting.isShown()) { toggleView(view_waiting); } mHadDayTask = false; } }); } private void callPutSubTaskList(final ArrayList list) { toggleView(view_waiting); String day = DateFormatter.dateFormat.format(mTodayTask.getStarttime()); String area; if (mCurrentTopClassTask.getExtension1().equals(Domain.DOMAIN_SUITABLE_TOWN)) { area = mCurrentTopClassTask.getCityname() + mCurrentTopClassTask.getDistrictname() + mCurrentTopClassTask.getTownname(); } else { area = mCurrentTopClassTask.getCityname() + mCurrentTopClassTask.getDistrictname(); } Calendar cal = Calendar.getInstance(); cal.setTime(mTodayTask.getStarttime()); List dayList = mTopClassTaskList.get(mTopClassTaskPosition).getDaytaskList(); for (TaskVo taskVo : dayList) { Task task = taskVo.taskVo2Task(); Calendar calTemp = Calendar.getInstance(); calTemp.setTime(task.getStarttime()); if ((cal.get(Calendar.YEAR) == calTemp.get(Calendar.YEAR)) && (cal.get(Calendar.MONTH) == calTemp.get(Calendar.MONTH)) && (cal.get(Calendar.DAY_OF_MONTH) == calTemp.get(Calendar.DAY_OF_MONTH))) { mHadDayTask = true; mTodayTask = task.clone(); callPutSubtaskList(list); break; } } mTodayTask.setName(day + area + mCurrentTopClassTask.getTypename() + "任务"); mTodayTask.setSettime(Calendar.getInstance().getTime()); if (!mHadDayTask) { Call call = mTaskService.putTask(mTodayTask); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { mCheckedArray = null; if (response.body() != null) { callPutSubtaskList(list); } else if (response.errorBody() != null) { toggleView(view_waiting); Toast.makeText(MOVMapActivity.this, "日任务信息上传失败,请重试。", Toast.LENGTH_SHORT).show(); } mHadDayTask = false; } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { toggleView(view_waiting); mHadDayTask = false; } }); } } private void callUpdateMOV(final ArrayList list) { final ArrayList movList = new ArrayList<>(); for (Scense scense : list) { Monitorobjectversion mov = createMOV(scense, scense.getDisplayID()); String extension1 = mov.getExtension1(); if (extension1 == null) { mov.setExtension1(String.valueOf(1)); } else { int leftNum = Integer.parseInt(extension1); leftNum++; mov.setExtension1(String.valueOf(leftNum)); } movList.add(mov); } Call call = mMOVService.postMOVList(movList); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.body() != null) { Toast.makeText(MOVMapActivity.this, "监管对象版本更新成功。", Toast.LENGTH_SHORT).show(); mScenseList.removeAll(list); resetSelectedScenseMap(); mSelectedScenseList.clear(); invalidateMap(); new AlertDialog.Builder(MOVMapActivity.this).setTitle("提示") .setMessage("任务制作成功。是否返回任务列表?") .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MOVMapActivity.this.setResult(2, new Intent()); MOVMapActivity.this.finish(); } }).show(); } else if (response.errorBody() != null) { Toast.makeText(MOVMapActivity.this, "监管对象版本更新失败,请重新提交。", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Toast.makeText(MOVMapActivity.this, "监管对象版本更新失败,请重新提交。", Toast.LENGTH_SHORT).show(); } }); } public ArrayList getmMarkerList() { return mMarkerList; } public int getmCurrentMode() { return mCurrentMode; } public void setmCurrentPosition(int mCurrentPosition) { this.mCurrentPosition = mCurrentPosition; } @Override protected void onPause() { super.onPause(); mMapView.onPause(); } @Override protected void onResume() { super.onResume(); mMapView.onResume(); } @Override protected void onDestroy() { super.onDestroy(); mMapView.onDestroy(); } @Override public void onDistrictSearched(DistrictResult districtResult) { Log.e(TAG, "onDistrictSearched()"); if (districtResult == null || districtResult.getDistrict() == null) { Log.e(TAG, "onDistrictSearched()null"); return; } Log.e(TAG, "ErrorCode:" + districtResult.getAMapException().getErrorCode()); if (districtResult.getAMapException().getErrorCode() == AMapException.CODE_AMAP_SUCCESS) { List list = districtResult.getDistrict(); DistrictItem item = null; for (DistrictItem dItem : list) { Log.e(TAG, "cityCode:" + dItem.getCitycode()); if (dItem.getName().equals(districtSearchKeyWord) && dItem.getCitycode().equals(CommonUtils.getAmapCityCode(mCurrentTopClassTask.getCitycode()))) { item = dItem; break; } } if (item == null) { Log.e(TAG, "onDistrictSearched()item = null"); return; } Log.e(TAG, "onDistrictSearched()item" + item.getName()); LatLonPoint mCenterLatLng = item.getCenter(); if (mCenterLatLng != null) { //地图加载时就显示行政区域 int zoom = 9; int level = Integer.valueOf(mCurrentTopClassTask.getExtension1()); if (level == Domain.LEVEL_PROVINCE) { zoom = 8; } else if (level == Domain.LEVEL_CITY) { zoom = 9; } else if (level == Domain.LEVEL_DISTRICT) { zoom = 12; } mMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(mCenterLatLng.getLatitude(), mCenterLatLng.getLongitude()), zoom));//13为缩放级别 //创建划线子线程 ObtainBoundaryRunnable fromRunnable = new ObtainBoundaryRunnable(item, mHandler); //线程池执行 Executors.newSingleThreadExecutor().execute(fromRunnable); } } } private class DataHolder { byte scenseTypeID; String scenseType; int scenseTotalNum; int scenseSelectedNum; } }