riku
2025-10-31 1897c4ad5fa73b3f0a36e1aa0e1e9000302a6ace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
package cn.flightfeather.thirdappmodule.activity;
 
import static cn.flightfeather.thirdappmodule.util.CommonUtils.getDomainItemByCalalogGuid;
 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
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.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
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.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.DaoSession;
import com.ping.greendao.gen.ScenseDao;
 
import org.greenrobot.greendao.query.QueryBuilder;
 
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
 
import cn.flightfeather.thirdappmodule.CommonApplication;
import cn.flightfeather.thirdappmodule.R;
import cn.flightfeather.thirdappmodule.adapter.RecyclerItemClickListener;
import cn.flightfeather.thirdappmodule.adapter.ScenseListAdapter;
import cn.flightfeather.thirdappmodule.bean.entity.City;
import cn.flightfeather.thirdappmodule.bean.entity.District;
import cn.flightfeather.thirdappmodule.bean.entity.Domainitem;
import cn.flightfeather.thirdappmodule.bean.entity.Province;
import cn.flightfeather.thirdappmodule.bean.entity.Scense;
import cn.flightfeather.thirdappmodule.bean.entity.Subtask;
import cn.flightfeather.thirdappmodule.bean.entity.Town;
import cn.flightfeather.thirdappmodule.task.ObtainBoundaryRunnable;
import cn.flightfeather.thirdappmodule.util.Area;
import cn.flightfeather.thirdappmodule.util.CommonUtils;
import cn.flightfeather.thirdappmodule.util.Constant;
import cn.flightfeather.thirdappmodule.util.Domain;
import cn.flightfeather.thirdappmodule.util.NavigationHelper;
 
public class ScenseMapActivity extends AppCompatActivity implements View.OnClickListener,
        RecyclerItemClickListener.OnItemClickListener, DistrictSearch.OnDistrictSearchListener
        , AdapterView.OnItemSelectedListener {
 
    private static final String TAG = "ScenseMapActivity";
    private static final int SHOWMODE_SCENSE = 1;
    private static final int SHOWMODE_TASK_SCENSE = 2;
    private MapView mMapView;
    private AMap aMap;
    private float mCurrentScalePerPixel;                                                            //当前地图缩放的大小
    private CommonApplication application;
    private ScenseDao mScenseDao;
    private Area curArea;
    private ArrayList<Scense> mScenseList = new ArrayList<>();
    private ArrayList<Scense> mShownScenseList = new ArrayList<>();
    private ArrayList<Byte> mScenseTypeList = new ArrayList<>();
    private ScenseListAdapter mAdapter;
    private ArrayList<Marker> markerList = new ArrayList<>();
    private BitmapDescriptor[] bitmapDescriptorArr;
    private List<Domainitem> scenseTypeDomainItemList;
    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 int curPos;
    //    private HashMap<Integer, Integer> bdTypeMap = new HashMap<>(); //用于记录marker用的是哪一个颜色
    private List<Province> mProvinceList;
    private List<City> mCityList;
    private List<District> mDistrictList;
    private List<Town> mTownList;
    private List<City> mShowCityList = new ArrayList<>();
    private List<District> mShowDistrictList = new ArrayList<>();
    private List<Town> mShowTownList = new ArrayList<>();
    private RecyclerView mRecyclerView;
    private View rl_scenseinfo;
    private TextView tv_scenseName, tv_address, tv_lat, tv_lng, tv_contact, tv_tel;
    private Scense mSelectedScense;
    private int mLastPos = -1;
    private BitmapDescriptor mLastBitmapDesc;
    private BitmapDescriptor mSelectedBitmapDesc;
    private int mScenseTypeChoice;
    private ArrayList<Subtask> mSubTaskList;
    private int mCurrentShowMode = SHOWMODE_SCENSE;
    private View iBtn_data, iBtn_inspection;
    private DistrictSearch mDistrictSearch;
    private LatLonPoint mCenterLatLng;
    private PolylineOptions mDistrictBoundary;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (18 == msg.what) {
                mDistrictBoundary = (PolylineOptions) msg.obj;
                aMap.addPolyline(mDistrictBoundary);
            }
        }
    };
    private View iBtn2;
    private Spinner spinner_province;
    private Spinner spinner_city;
    private Spinner spinner_district;
    private Spinner spinner_town;
    private ArrayAdapter<String> mCityAdapter;
    private ArrayAdapter<String> mDistrictAdapter;
    private ArrayAdapter<String> mTownAdapter;
    private ArrayList<String> mProvinceNameList = new ArrayList<>();
    private ArrayList<String> mCityNameList = new ArrayList<>();
    private ArrayList<String> mDistrictNameList = new ArrayList<>();
    private ArrayList<String> mTownNameList = new ArrayList<>();
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scense_map);
        initUI(savedInstanceState);
        initData();
    }
 
    /**
     * 初始化UI
     *
     * @param savedInstanceState bundle
     */
    private void initUI(Bundle savedInstanceState) {
        findViewById(R.id.img_right).setOnClickListener(this);
        findViewById(R.id.spinner_topclass_task).setVisibility(View.GONE);
        findViewById(R.id.iBtn1).setOnClickListener(this);
        spinner_province = (Spinner)findViewById(R.id.spinner_province);
        spinner_city = (Spinner)findViewById(R.id.spinner_city);
        spinner_district = (Spinner)findViewById(R.id.spinner_district);
        spinner_town = (Spinner)findViewById(R.id.spinner_town);
        iBtn2 = findViewById(R.id.iBtn2);
        iBtn2.setOnClickListener(this);
        findViewById(R.id.iBtn3).setVisibility(View.GONE);
        findViewById(R.id.iBtn4).setVisibility(View.GONE);
        findViewById(R.id.iBtn5).setVisibility(View.GONE);
        findViewById(R.id.tv_level).setVisibility(View.GONE);
        findViewById(R.id.view_empty1).setOnClickListener(this);
        findViewById(R.id.iBtn_navi).setOnClickListener(this);
        findViewById(R.id.iBtn_call).setOnClickListener(this);
        iBtn_data = findViewById(R.id.iBtn_data);
        iBtn_inspection = findViewById(R.id.iBtn_inspection);
        iBtn_data.setVisibility(View.GONE);
        iBtn_inspection.setVisibility(View.GONE);
        iBtn_data.setOnClickListener(this);
        iBtn_inspection.setOnClickListener(this);
        rl_scenseinfo = findViewById(R.id.rl_scenseinfo);
        tv_scenseName = (TextView) findViewById(R.id.tv_scenseName);
        tv_address = (TextView) findViewById(R.id.tv_address);
        tv_lat = (TextView) findViewById(R.id.tv_lat);
        tv_lng = (TextView) findViewById(R.id.tv_lng);
        tv_contact = (TextView) findViewById(R.id.tv_contact);
        tv_tel = (TextView) findViewById(R.id.tv_tel);
        ((TextView) findViewById(R.id.actionbar_title)).setText("场景地图");
        findViewById(R.id.img_left).setOnClickListener(this);
        mRecyclerView = (RecyclerView) findViewById(R.id.rv_scenselist);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(manager);
        mAdapter = new ScenseListAdapter(this, mShownScenseList);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, mRecyclerView, this));
        initMap(savedInstanceState);
    }
 
    private void initMap(Bundle savedInstanceState) {
        mMapView = (MapView) findViewById(R.id.map);
        mMapView.onCreate(savedInstanceState);
        aMap = mMapView.getMap();
        //不合理,通过顶层任务所在区县初始化位置
        aMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(31.230378, 121.473658)));
        aMap.getUiSettings().setRotateGesturesEnabled(false);
        aMap.getUiSettings().setScaleControlsEnabled(true);
        mDistrictSearch = new DistrictSearch(this);
        mDistrictSearch.setOnDistrictSearchListener(this);
        aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition cameraPosition) {
            }
 
            @Override
            public void onCameraChangeFinish(CameraPosition cameraPosition) {
                //                tv_scenseDesc.setTitle(lngCurrent + "," + latCurrent);
                float scalePerPixel = aMap.getScalePerPixel();
                if (scalePerPixel - mCurrentScalePerPixel > 0) {
                    //缩小
                    if (mCurrentScalePerPixel / scalePerPixel < 0.85) {
                        mCurrentScalePerPixel = scalePerPixel;
                        Log.e(TAG, "onCameraChangeFinish()缩小");
                        invalidate();
                    }
                } else {
                    //变大
                    if (scalePerPixel / mCurrentScalePerPixel < 0.75) {
                        mCurrentScalePerPixel = aMap.getScalePerPixel();
                        Log.e(TAG, "onCameraChangeFinish()变大");
                        invalidate();
                    }
                }
            }
        });
        mCurrentScalePerPixel = aMap.getScalePerPixel();
    }
 
    /**
     * 获取数据
     */
    private void initData() {
        mSubTaskList = (ArrayList<Subtask>) getIntent().getSerializableExtra(Constant.KEY_INTENT_TODAY_TASKLIST);
        application = (CommonApplication) getApplication();
        DaoSession daoSession = application.getDaoSession();
        mScenseDao = application.getDaoSession().getScenseDao();
        initArea(daoSession);
        initBitmapDescriptor();
        getScenseLocal();
    }
 
    private void initBitmapDescriptor() {
        //注:***没有值域就会出问题
        DaoSession daoSession = application.getDaoSession();
        scenseTypeDomainItemList = getDomainItemByCalalogGuid(daoSession, Domain.DOMAINGUID_SCENSETYPE);
        bitmapDescriptorArr = new BitmapDescriptor[scenseTypeDomainItemList.size()];
//        bitmapDescriptorArr_sel = new BitmapDescriptor[scenseTypeDomainItemList.size()];
        for (int i = 0; i < scenseTypeDomainItemList.size(); i++) {
            bitmapDescriptorArr[i] = BitmapDescriptorFactory.fromResource(markerIDS[i % markerIDS.length]);
//            bitmapDescriptorArr_sel[i] = BitmapDescriptorFactory.fromResource(markerIDS_sel[i % markerIDS_sel.length]);
        }
        mSelectedBitmapDesc = BitmapDescriptorFactory.fromResource(R.drawable.icon_mark_blue);
    }
 
    private void initArea(DaoSession daoSession) {
        curArea = new Area();
        curArea.setLevel(Domain.LEVEL_CITY);
        mProvinceList = daoSession.getProvinceDao().loadAll();
        mProvinceNameList = new ArrayList<>();
        for (Province p : mProvinceList) {
            mProvinceNameList.add(p.getProvincename());
        }
        mCityList = daoSession.getCityDao().loadAll();
        mCityNameList = new ArrayList<>();
        if (!CommonUtils.isMDUCG(mProvinceNameList.get(0))) {
            mCityNameList.add(Constant.EMPTY_STRING);
        }
        for (City c : mCityList) {
            mCityNameList.add(c.getCityname());
        }
        mDistrictList = daoSession.getDistrictDao().loadAll();
        mDistrictNameList = new ArrayList<>();
        mDistrictNameList.add(Constant.EMPTY_STRING);
        for (District d : mDistrictList) {
            if (d.getCityid().equals(mCityList.get(0).getCityId())) {
                mDistrictNameList.add(d.getDistrictname());
            }
        }
        mTownList = daoSession.getTownDao().loadAll();
        mTownNameList = new ArrayList<>();
        mTownNameList.add(Constant.EMPTY_STRING);
        curArea.setProvinceCode(mProvinceList.get(0).getProvincecode());
        curArea.setProvinceName(mProvinceList.get(0).getProvincename());
        curArea.setCityCode(mCityList.get(0).getCitycode());
        curArea.setCityName(mCityList.get(0).getCityname());
        curArea.setDistrictCode(Constant.EMPTY_STRING);
        curArea.setDistrictName(Constant.EMPTY_STRING);
        curArea.setTownCode(Constant.EMPTY_STRING);
        curArea.setTownName(Constant.EMPTY_STRING);
        ArrayAdapter<String> mProvinceAdapter = new ArrayAdapter<>(this, R.layout.item_spinner_area, mProvinceNameList);
        spinner_province.setAdapter(mProvinceAdapter);
        mCityAdapter = new ArrayAdapter<>(this, R.layout.item_spinner_area, mCityNameList);
        spinner_city.setAdapter(mCityAdapter);
        mDistrictAdapter = new ArrayAdapter<>(this, R.layout.item_spinner_area, mDistrictNameList);
        spinner_district.setAdapter(mDistrictAdapter);
        mTownAdapter = new ArrayAdapter<>(this, R.layout.item_spinner_area, mTownNameList);
        spinner_town.setAdapter(mTownAdapter);
        spinner_province.setOnItemSelectedListener(this);
        spinner_city.setOnItemSelectedListener(this);
        spinner_district.setOnItemSelectedListener(this);
        spinner_town.setOnItemSelectedListener(this);
    }
 
    private void getScenseLocal() {
        mLastPos = -1;
        aMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(31.230378, 121.473658)));
        QueryBuilder<Scense> qb;
        Log.d(TAG, "getScenseLocal()" + curArea.getLevel() + "Province:" + curArea.getProvinceCode() + curArea.getProvinceName()
                + ";city:" + curArea.getCityCode() + curArea.getCityName() + ";district:" + curArea.getDistrictCode() + curArea.getDistrictName()
                + ";town:" + curArea.getTownCode() + curArea.getTownName());
        switch (curArea.getLevel()) {
            case Domain.LEVEL_PROVINCE:
                qb = mScenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(curArea.getProvinceCode()), ScenseDao.Properties.Extension1.notEq("0"))
                        .orderAsc(ScenseDao.Properties.Typeid);
                break;
            case Domain.LEVEL_CITY:
                qb = mScenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(curArea.getProvinceCode()),
                        ScenseDao.Properties.Citycode.eq(curArea.getCityCode()), ScenseDao.Properties.Extension1.notEq("0"))
                        .orderAsc(ScenseDao.Properties.Typeid);
                break;
            case Domain.LEVEL_DISTRICT:
                qb = mScenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(curArea.getProvinceCode()),
                        ScenseDao.Properties.Citycode.eq(curArea.getCityCode()),
                        ScenseDao.Properties.Districtcode.eq(curArea.getDistrictCode()), ScenseDao.Properties.Extension1.notEq("0"))
                        .orderAsc(ScenseDao.Properties.Typeid);
                break;
            case Domain.LEVEL_TOWN:
                qb = mScenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(curArea.getProvinceCode()),
                        ScenseDao.Properties.Citycode.eq(curArea.getCityCode()),
                        ScenseDao.Properties.Districtcode.eq(curArea.getDistrictCode()),
                        ScenseDao.Properties.Towncode.eq(curArea.getTownCode()), ScenseDao.Properties.Extension1.notEq("0"))
                        .orderAsc(ScenseDao.Properties.Typeid);
                break;
            default:
                qb = mScenseDao.queryBuilder().where(ScenseDao.Properties.Provincecode.eq(curArea.getProvinceCode()), ScenseDao.Properties.Extension1.notEq("0"))
                        .orderAsc(ScenseDao.Properties.Typeid);
                break;
        }
        List<Scense> list = qb.where(ScenseDao.Properties.Extension1.notEq(Domain.SCENSE_DISABLE))
                .orderAsc(ScenseDao.Properties.Districtcode, ScenseDao.Properties.Index).list();
        mScenseList.clear();
        mShownScenseList.clear();
        mScenseTypeList.clear();
        mScenseTypeList.add(Domain.SCENSETYPE_ALL);
        for (Scense scense : list) {
            if (!mScenseTypeList.contains(scense.getTypeid())) {
                mScenseTypeList.add(scense.getTypeid());
            }
            mScenseList.add(scense);
            mShownScenseList.add(scense);
        }
        Log.e(TAG, "size:"+mScenseList.size());
        if (mScenseTypeList.size() <= 2) {
            iBtn2.setVisibility(View.GONE);
        } else {
            iBtn2.setVisibility(View.VISIBLE);
        }
        invalidate();
    }
 
    /**
     *
     */
    private void invalidate() {
        mAdapter.notifyDataSetChanged();
        aMap.clear();
        markerList.clear();
        if (mDistrictBoundary != null) {
            aMap.addPolyline(mDistrictBoundary);
        }
        int length = mShownScenseList.size();
        for (int i = 0; i < length; i++) {
            Scense info = mShownScenseList.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());
            }
            int j;
            BitmapDescriptor bitmapDescriptor = bitmapDescriptorArr[0];
            for (j = 0; j < scenseTypeDomainItemList.size(); j++) {
                Domainitem domainitem = scenseTypeDomainItemList.get(j);
                if (info.getTypeid() == Integer.parseInt(domainitem.getValue())) {
                    bitmapDescriptor = bitmapDescriptorArr[j];
                    break;
                }
            }
            Marker marker = aMap.addMarker(new MarkerOptions().icon(bitmapDescriptor).position(ll));
            markerList.add(marker);
            //添加序号
            String displayId = String.valueOf(info.getIndex());
            aMap.addText(new TextOptions().zIndex(marker.getZIndex()).text(displayId)
                    .backgroundColor(Color.TRANSPARENT).fontColor(Color.WHITE)
                    .fontSize(33)
                    .position(new LatLng(getLat(aMap.getScalePerPixel(), ll.latitude), ll.longitude)));
        }
        // 初始化搜索模块,注册事件监听
        aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {
            public boolean onMarkerClick(final Marker marker) {
                // Log.e("Location", "markerList.size:" + markerList.size());
                curPos = markerList.indexOf(marker);
                selectScense(marker);
                return true;
            }
        });
    }
 
    private double getLat(float scalePerPixel, double lat) {
        return 0.0004 * scalePerPixel + lat;
    }
 
    private void selectScense(Marker marker) {
        mSelectedScense = mShownScenseList.get(curPos);
        if (mLastPos != -1 && mLastPos < markerList.size()) {
            markerList.get(mLastPos).setIcon(mLastBitmapDesc);
        }
        mLastBitmapDesc = marker.getIcons().get(0);
        marker.setIcon(mSelectedBitmapDesc);
        moveToSelectedScense();
        if (mRecyclerView.isShown()) {
            mRecyclerView.setVisibility(View.GONE);
        }
        showScenseInfo();
        mLastPos = curPos;
    }
 
    private void moveToSelectedScense() {
        aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mSelectedScense.getLatitude(), mSelectedScense.getLongitude()), 15));
    }
 
//    /**
//     * 获取场景:首次加载获取服务端全部场景数据,存入本地数据库;
//     * 当程序不退出,则获取本地数据即可。
//     */
//    private void getScense() {
//        ScenseService scenseService = application.getRetrofit().create(ScenseService.class);
//        Call<ArrayList<Scense>> call = scenseService.getAllScenses();
//        call.enqueue(new Callback<ArrayList<Scense>>() {
//            @Override
//            public void onResponse(Call<ArrayList<Scense>> call, Response<ArrayList<Scense>> response) {
//                if (response.body() != null) {
//
//                } else if (response.errorBody() != null) {
//
//                }
//            }
//
//            @Override
//            public void onFailure(Call<ArrayList<Scense>> call, Throwable t) {
//
//            }
//        });
//    }
 
    private void searchArea(String area) {
        DistrictSearchQuery query = new DistrictSearchQuery();
        query.setKeywords(area);//传入关键字
        query.setShowBoundary(true);//是否返回边界值
        mDistrictSearch.setQuery(query);
        mDistrictSearch.searchDistrictAsyn();
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }
 
    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }
 
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.img_left) {
            this.finish();
        } else if (id == R.id.img_right) {
            toggleView(mRecyclerView);
        } else if (id == R.id.iBtn2) {
            showScenseTypeDialog();
        } else if (id == R.id.iBtn1) {//今日任务地图
            if (mCurrentShowMode == SHOWMODE_SCENSE) {
                mCurrentShowMode = SHOWMODE_TASK_SCENSE;
                getSubTaskScense();
                iBtn_data.setVisibility(View.VISIBLE);
                iBtn_inspection.setVisibility(View.VISIBLE);
            } else {
                mCurrentShowMode = SHOWMODE_SCENSE;
                getScenseLocal();
                iBtn_data.setVisibility(View.GONE);
                iBtn_inspection.setVisibility(View.GONE);
            }
        } else if (id == R.id.view_empty1) {
            toggleView(rl_scenseinfo);
            if (mCurrentShowMode == SHOWMODE_SCENSE && mScenseTypeList.size() > 2) {
                iBtn2.setVisibility(View.VISIBLE);
            }
        } else if (id == R.id.iBtn_call) {
            String tel = mSelectedScense.getContactst();
            if (tel != null && CommonUtils.checkCellphone(tel)) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mSelectedScense.getContactst()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } else {
                Toast.makeText(this, "当前号码不可用,请重新确认号码。", Toast.LENGTH_SHORT).show();
            }
        } else if (id == R.id.iBtn_navi) {
            if (NavigationHelper.haveGaodeMap(getApplicationContext())) {
                NavigationHelper.openGaodeMapToGuide(this, mSelectedScense.getLatitude(), mSelectedScense.getLongitude(), mSelectedScense.getLocation());
            } else if (NavigationHelper.haveBaiduMap(getApplicationContext())) {
                NavigationHelper.openBaiduMapToGuide(this, mSelectedScense.getLocation(), mSelectedScense.getLatitude(), mSelectedScense.getLongitude());
            } else {
                NavigationHelper.openBrowserToGuide(this, mSelectedScense.getLocation(), mSelectedScense.getLatitude(), mSelectedScense.getLongitude());
            }
        } else if (id == R.id.iBtn_data) {//                Intent detailIntent = new Intent(this, TaskDetailActivity.class);
//                detailIntent.putExtra(Constant.KEY_INTENT_SUBTASK, mSubTaskList.get(curPos));
//                startActivity(detailIntent);
        } else if (id == R.id.iBtn_inspection) {//                Intent inspectionIntent = new Intent(this, MainActivity.class);
//                inspectionIntent.putExtra(Constant.KEY_INTENT_SUBTASK, mSubTaskList.get(curPos));
//                setResult(RESULT_OK, inspectionIntent);
//                this.finish();
        }
    }
 
    private void getSubTaskScense() {
        mLastPos = -1;
        aMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(31.230378, 121.473658)));
        mShownScenseList.clear();
        for (Subtask subtask : mSubTaskList) {
            Scense scense = mScenseDao.queryBuilder().where(ScenseDao.Properties.Guid.eq(subtask.getScenseid())).unique();
            if (scense != null) {
                mShownScenseList.add(scense);
            }
        }
        if (mShownScenseList.size() == 0) {
            Toast.makeText(this, "您今日暂无任务。", Toast.LENGTH_SHORT).show();
        } else {
            invalidate();
        }
        if (iBtn2.isShown()) {
            iBtn2.setVisibility(View.GONE);
        }
    }
 
    private void showScenseTypeDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final String[] items = new String[mScenseTypeList.size()];
        for (int i = 0; i < mScenseTypeList.size(); i++) {
            for (Domainitem domainitem : scenseTypeDomainItemList) {
                if (i == 0) {
                    items[i] = "所有类型";
                    break;
                } else {
                    if (domainitem.getValue().equals(String.valueOf(mScenseTypeList.get(i)))) {
                        items[i] = domainitem.getText();
                        break;
                    }
                }
            }
        }
        builder.setSingleChoiceItems(items, mScenseTypeChoice,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mScenseTypeChoice = which;
                        dialog.dismiss();
                        switchScenseType();
                    }
                });
        builder.create().show();
    }
 
    private void switchScenseType() {
        int curScenseType = mScenseTypeList.get(mScenseTypeChoice);
        mShownScenseList.clear();
        if (curScenseType == Domain.SCENSETYPE_ALL) {
            mShownScenseList.addAll(mScenseList);
        } else {
            for (Scense scense : mScenseList) {
                if (scense.getTypeid() == curScenseType) {
                    mShownScenseList.add(scense);
                }
            }
        }
        invalidate();
    }
 
    private void updateShowText(int level, int valueIndex, boolean isMDUCG) {
        long areaId;
        switch (level) {
            case Domain.LEVEL_PROVINCE:
                break;
            case Domain.LEVEL_CITY:
                mCityNameList.clear();
                mShowCityList.clear();
                areaId = mProvinceList.get(valueIndex).getProvinceid();
                if (!isMDUCG) {
                    mCityNameList.add(Constant.EMPTY_STRING);
                }
                for (City city : mCityList) {
                    if (city.getPronvinceid() == areaId) {
                        mCityNameList.add(city.getCityname());
                        mShowCityList.add(city);
                    }
                }
                mCityAdapter.notifyDataSetChanged();
                break;
            case Domain.LEVEL_DISTRICT:
                mDistrictNameList.clear();
                mShowDistrictList.clear();
                mDistrictNameList.add(Constant.EMPTY_STRING);
                areaId = mCityList.get(valueIndex).getCityId();
                for (District district : mDistrictList) {
                    if (district.getCityid() == areaId) {
                        mDistrictNameList.add(district.getDistrictname());
                        mShowDistrictList.add(district);
                    }
                }
                mDistrictAdapter.notifyDataSetChanged();
                break;
            case Domain.LEVEL_TOWN:
                mTownNameList.clear();
                mShowTownList.clear();
                mTownNameList.add(Constant.EMPTY_STRING);
                if (valueIndex > 0) {
                    areaId = mDistrictList.get(valueIndex - 1).getDistrictid();
                    for (Town town : mTownList) {
                        if (town.getDistrictid() == areaId) {
                            mTownNameList.add(town.getTownname());
                            mShowTownList.add(town);
                        }
                    }
                }
                mTownAdapter.notifyDataSetChanged();
                break;
        }
    }
 
    private String getLocationName() {
        String area = curArea.getCityName();
        switch (curArea.getLevel()) {
            case Domain.LEVEL_PROVINCE:
                area = curArea.getProvinceName();
                break;
            case Domain.LEVEL_CITY:
                area = curArea.getCityName();
                break;
            case Domain.LEVEL_DISTRICT:
                area = curArea.getDistrictName();
                break;
        }
        return area;
    }
 
    private void toggleView(View view) {
        if (view.isShown()) {
            view.setVisibility(View.GONE);
        } else {
            view.setVisibility(View.VISIBLE);
        }
    }
 
    @Override
    public void onItemClick(View view, int position) {
        curPos = position;
        selectScense(markerList.get(curPos));
        toggleView(mRecyclerView);
    }
 
    private void showScenseInfo() {
        iBtn2.setVisibility(View.GONE);
        rl_scenseinfo.setVisibility(View.VISIBLE);
        String scenseName = mSelectedScense.getName();
        if (scenseName == null) {
            scenseName = Constant.EMPTY_STRING;
        }
        tv_scenseName.setText(scenseName);
        String address = mSelectedScense.getLocation();
        if (address == null) {
            address = Constant.EMPTY_STRING;
        }
        tv_address.setText(address);
        tv_lat.setText(String.valueOf(mSelectedScense.getLatitude()));
        tv_lng.setText(String.valueOf(mSelectedScense.getLongitude()));
        String contact = mSelectedScense.getContacts();
        if (contact == null) {
            contact = Constant.EMPTY_STRING;
        }
        tv_contact.setText(contact);
        String tel = mSelectedScense.getContactst();
        if (tel == null) {
            tel = Constant.EMPTY_STRING;
        }
        tv_tel.setText(tel);
    }
 
    @Override
    public void onItemLongClick(View view, int position) {
//        Intent intent = new Intent(this, ScneseDetailActivity.class);
//        intent.putExtra(ScenseDao.Properties.Guid.name, mScenseList.get(position).getAdGuid());
//        startActivity(intent);
    }
 
    @Override
    public void onDistrictSearched(DistrictResult districtResult) {
        if (districtResult == null || districtResult.getDistrict() == null) {
            return;
        }
        final DistrictItem item = districtResult.getDistrict().get(0);
        if (item == null) {
            return;
        }
        mCenterLatLng = item.getCenter();//得到行政中心点坐标
        if (mCenterLatLng != null) {  //地图加载时就显示行政区域
            int zoom = 9;
            if (curArea.getLevel() == Domain.LEVEL_PROVINCE) {
                zoom = 8;
            } else if (curArea.getLevel() == Domain.LEVEL_CITY) {
                zoom = 9;
            } else if (curArea.getLevel() == Domain.LEVEL_DISTRICT) {
                zoom = 10;
            }
            aMap.animateCamera(
                    CameraUpdateFactory.newLatLngZoom(new LatLng(mCenterLatLng.getLatitude(), mCenterLatLng.getLongitude()), zoom));//13为缩放级别
            //创建划线子线程
            ObtainBoundaryRunnable fromRunnable = new ObtainBoundaryRunnable(item, mHandler);
            //线程池执行
            Executors.newSingleThreadExecutor().execute(fromRunnable);
        }
    }
 
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        boolean isMDUCG;
        int parentId = parent.getId();
        if (parentId == R.id.spinner_province) {
            curArea.setProvincePosition(position);
            isMDUCG = CommonUtils.isMDUCG(mProvinceNameList.get(position));
            if (isMDUCG) {
                curArea.setLevel(Domain.LEVEL_CITY);
            } else {
                curArea.setLevel(Domain.LEVEL_PROVINCE);
            }
            curArea.setProvinceCode(mProvinceList.get(position).getProvincecode());
            curArea.setProvinceName(mProvinceList.get(position).getProvincename());
            updateShowText(Domain.LEVEL_CITY, position, isMDUCG);
        } else if (parentId == R.id.spinner_city) {
            curArea.setCityPosition(position);
            isMDUCG = CommonUtils.isMDUCG(mProvinceNameList.get(position));
            if (position != 0 || (position == 0 && isMDUCG)) {
                curArea.setLevel(Domain.LEVEL_CITY);
                if (!isMDUCG) {
                    position -= 1;
                }
                curArea.setCityCode(mShowCityList.get(position).getCitycode());
                curArea.setCityName(mShowCityList.get(position).getCityname());
            } else {
                curArea.setLevel(Domain.LEVEL_PROVINCE);
                curArea.setCityCode(Constant.EMPTY_STRING);
                curArea.setCityName(Constant.EMPTY_STRING);
            }
            updateShowText(Domain.LEVEL_DISTRICT, position, isMDUCG);
        } else if (parentId == R.id.spinner_district) {
            curArea.setDistrictPosition(position);
            if (position != 0) {
                curArea.setLevel(Domain.LEVEL_DISTRICT);
                curArea.setDistrictCode(mShowDistrictList.get(position - 1).getDistrictcode());
                curArea.setDistrictName(mShowDistrictList.get(position - 1).getDistrictname());
            } else {
                curArea.setLevel(Domain.LEVEL_CITY);
                curArea.setDistrictCode(Constant.EMPTY_STRING);
                curArea.setDistrictName(Constant.EMPTY_STRING);
            }
            updateShowText(Domain.LEVEL_TOWN, position, false);
        } else if (parentId == R.id.spinner_town) {
            curArea.setLevel(position);
            if (position != 0) {
                curArea.setLevel(Domain.LEVEL_TOWN);
                curArea.setTownCode(mShowTownList.get(position - 1).getTowncode());
                curArea.setTownName(mShowTownList.get(position - 1).getTownname());
            } else {
                curArea.setLevel(Domain.LEVEL_DISTRICT);
                curArea.setTownCode(Constant.EMPTY_STRING);
                curArea.setTownName(Constant.EMPTY_STRING);
            }
        }
        if (curArea.getTownName() != null && !curArea.getTownName().equals(Constant.EMPTY_STRING)) {
            curArea.setLevel(Domain.LEVEL_TOWN);
        } else if (curArea.getDistrictName() != null && !curArea.getDistrictName().equals(Constant.EMPTY_STRING)) {
            curArea.setLevel(Domain.LEVEL_DISTRICT);
        } else if (curArea.getCityName() != null && !curArea.getCityName().equals(Constant.EMPTY_STRING)) {
            curArea.setLevel(Domain.LEVEL_CITY);
        } else {
            curArea.setLevel(Domain.LEVEL_PROVINCE);
        }
        if (curArea.getDistrictName() == null || curArea.getDistrictName().equals(Constant.EMPTY_STRING)) {
            searchArea(curArea.getCityName());
        } else {
            searchArea(curArea.getDistrictName());
        }
        getScenseLocal();
    }
 
    @Override
    public void onNothingSelected(AdapterView<?> parent) {
 
    }
}