Pu Zhibing
2025-12-11 ab0c19e49fabdb8cc6eea454ea455bce2efbb718
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
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
package com.igo.user.ui.trip
 
import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.sinata.rxnetty.NettyClient
import cn.sinata.xldutils.activity.BaseActivity
import cn.sinata.xldutils.callPhone
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.utils.SPUtils
import cn.sinata.xldutils.utils.SpanBuilder
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.parserTime
import cn.sinata.xldutils.view.TitleBar
import cn.sinata.xldutils.visible
import com.facebook.drawee.view.SimpleDraweeView
import com.github.zackratos.ultimatebar.UltimateBar
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.Polyline
import com.google.android.gms.maps.model.PolylineOptions
import com.google.android.libraries.mapsplatform.transportation.consumer.ConsumerApi
import com.google.android.libraries.mapsplatform.transportation.consumer.managers.TripModelCallback
import com.google.android.libraries.mapsplatform.transportation.consumer.managers.TripModelManager
import com.google.android.libraries.mapsplatform.transportation.consumer.model.MarkerType
import com.google.android.libraries.mapsplatform.transportation.consumer.model.TripInfo
import com.google.android.libraries.mapsplatform.transportation.consumer.model.TripInfo.TripStatus
import com.google.android.libraries.mapsplatform.transportation.consumer.model.TripModelOptions
import com.google.android.libraries.mapsplatform.transportation.consumer.model.VehicleLocation
import com.google.android.libraries.mapsplatform.transportation.consumer.sessions.JourneySharingSession
import com.google.android.libraries.mapsplatform.transportation.consumer.view.ConsumerController
import com.google.android.libraries.mapsplatform.transportation.consumer.view.ConsumerGoogleMap
import com.google.android.libraries.mapsplatform.transportation.consumer.view.ConsumerMapFragment
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.igo.user.IGoApplication
import com.igo.user.IGoApplication.Companion.address
import com.igo.user.IGoApplication.Companion.phone
import com.igo.user.R
import com.igo.user.dialog.ShareDialog
import com.igo.user.dialog.TipDialog
import com.igo.user.interfaces.OrderStateChangeListener
import com.igo.user.network.Apis
import com.igo.user.network.HttpManager
import com.igo.user.network.entity.Order
import com.igo.user.network.entity.Point
import com.igo.user.network.entity.RouteBean
import com.igo.user.network.entity.TrippingInfo
import com.igo.user.network.request
import com.igo.user.ui.mine.TripOrderFragment
import com.igo.user.ui.trip.adapter.ProgressAdapter
import com.igo.user.utils.Const
import com.igo.user.utils.Const.OrderType.TYPE_SPECIAL
import com.igo.user.utils.IGoShareUtils
import com.igo.user.utils.google.JsonAuthTokenFactory
import com.share.utils.ShareUtils
import com.tbruyelle.rxpermissions2.RxPermissions
import com.umeng.socialize.UMShareListener
import com.umeng.socialize.bean.SHARE_MEDIA
import com.umeng.socialize.media.UMImage
import io.reactivex.subscribers.DisposableSubscriber
import org.jetbrains.anko.dip
import org.jetbrains.anko.find
import org.jetbrains.anko.imageResource
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
 
class TripActivity : BaseActivity(), Handler.Callback, OrderStateChangeListener, UMShareListener {
    lateinit var aMap: ConsumerGoogleMap
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_trip)
        initView()
        initClick()
    }
 
    private val app by lazy {
        application as IGoApplication
    }
    private val handler by lazy {
        Handler(this)
    }
    private val gson by lazy { Gson() }
 
    //已行驶的路径,灰色
    private var newDrivedRouteOverlay: Polyline? = null
    private var oldDrivedRouteOverlay: Polyline? = null
 
    private var consumerController: ConsumerController? = null
    private var vehicleLocation: VehicleLocation? = null //车辆位置
 
    private val noResponseDialog by lazy { //无应答弹窗,不重复覆盖弹窗
        val tipDialog = TipDialog()
        tipDialog.arguments =
            bundleOf(
                "msg" to getString(R.string.附近暂无司机接单),
                "ok" to getString(R.string.继续等待),
                "cancel" to getString(R.string.取消订单)
            )
        tipDialog.setCallback(object : TipDialog.OnClickCallback {
            override fun onOk() {
            }
 
            override fun onCancel() {
                cancelOrder()
            }
        })
        tipDialog.setDismissCallback(object : TipDialog.OnDismiss {
            override fun onDismiss() {
                HttpManager.pushOrderTaxi(id, type).request(this@TripActivity) { _, _ ->
                }
            }
        })
        tipDialog
    }
    private var id = 0
    private var type: Int = 0
    private var order: Order? = null
 
    var phoneEmergency = "" //报警电话
    var phoneService = ""  //客服电话
 
 
    private val iv_shuaxing by lazy { find<View>(R.id.iv_shuaxing) }
    private val titleBar by lazy { find<TitleBar>(R.id.titleBar) }
    private val tv_action by lazy { find<View>(R.id.tv_action) }
    private val tv_complain by lazy { find<View>(R.id.tv_complain) }
    private val iv_call by lazy { find<View>(R.id.iv_call) }
    private val tv_110 by lazy { find<View>(R.id.tv_110) }
    private val tv_service by lazy { find<View>(R.id.tv_service) }
    private val iv_location by lazy { find<View>(R.id.iv_location) }
    private val tv_cancel by lazy { find<View>(R.id.tv_cancel) }
    private val tv_change_destination by lazy { find<View>(R.id.tv_change_destination) }
    private val fl_one_click by lazy { find<View>(R.id.fl_one_click) }
    private val iv_header_home by lazy { find<SimpleDraweeView>(R.id.iv_header_home) }
    private val tv_end by lazy { find<TextView>(R.id.tv_end) }
    private val tv_start by lazy { find<TextView>(R.id.tv_start) }
    private val tv_time by lazy { find<TextView>(R.id.tv_time) }
    private val tv_passenger_num by lazy { find<TextView>(R.id.tv_passenger_num) }
    private val tv_remark by lazy { find<TextView>(R.id.tv_remark) }
    private val tv_state by lazy { find<TextView>(R.id.tv_state) }
    private val cl_driver by lazy { find<View>(R.id.cl_driver) }
    private val tv_name by lazy { find<TextView>(R.id.tv_name) }
    private val tv_car by lazy { find<TextView>(R.id.tv_car) }
    private val tv_car_info by lazy { find<AppCompatTextView>(R.id.tv_car_info) }
    private val tv_score by lazy { find<TextView>(R.id.tv_score) }
    private val fl_reserve by lazy { find<View>(R.id.fl_reserve) }
    private val tv_count by lazy { find<TextView>(R.id.tv_count) }
    private val tv_progress by lazy { find<TextView>(R.id.tv_progress) }
    private val line by lazy { find<View>(R.id.line) }
    private val ll_progress by lazy { find<View>(R.id.ll_progress) }
    private val rv_progress by lazy { find<RecyclerView>(R.id.rv_progress) }
    private val view_bg by lazy { find<View>(R.id.view_bg) }
 
 
    private var consumerApi: ConsumerApi? = null //谷歌消费者sdk
    private var tripModelManager: TripModelManager? = null
    private var session: JourneySharingSession? = null
 
    private val progressList = arrayListOf<String>()
    private val progressAdapter = ProgressAdapter(progressList)
 
 
    fun initClick() {
        iv_shuaxing.onClick {
            Log.e("订单信息: ", id.toString())
            Log.e("订单信息: ", type.toString())
            HttpManager.getOrderDrivingData(id, type)
                .request(this@TripActivity, false, { _, _ ->
                }) { _, msg ->
 
                    var data = gson.fromJson(msg, TrippingInfo::class.java)
                    Log.e("订单信息: ", data.toString())
                    setTrippingUI(data)
                }
 
        }
        tv_complain.onClick {
            startActivity<ComplainActivity>("id" to order!!.driverId)
        }
 
        tv_action.setOnClickListener {
            if (order?.state == 1) {
                val tipDialog = TipDialog()
                tipDialog.arguments = bundleOf(
                    "msg" to getString(R.string.取消订单吗), "ok" to getString(
                        R.string.确定取消
                    ), "cancel" to getString(R.string.不取消)
                )
                tipDialog.setCallback(object : TipDialog.OnClickCallback {
                    override fun onOk() {
                        showDialog()
                        cancelOrder()
                    }
 
                    override fun onCancel() {
                    }
                })
                tipDialog.show(supportFragmentManager, "cancel")
            }
        }
 
        iv_call.setOnClickListener {
            callPhone(order?.driverPhone)
        }
 
        tv_110.setOnClickListener {
            callPhone(phoneEmergency)
        }
        tv_service.setOnClickListener {
            callPhone(phoneService)
        }
 
        /*tv_share.onClick {
            val shareDialog = ShareDialog()
            shareDialog.arguments = bundleOf("isTrip" to true)
            shareDialog.setCallback(object :ShareDialog.Callback{
                override fun onOk(way: Int) {
                    val language = SPUtils.instance().getString("language")
                    val languageP = if (language == "ch") 1 else if(language == "fr") 3 else 2
                    val url = String.format(Apis.TRIP_URL,languageP,id.toString(),type,languageP)
                    if (way == 3)
                        IGoShareUtils.shareWA(this@TripActivity,getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),url)
                    else
                    if (way == 4)
                        IGoShareUtils.shareFB(this@TripActivity,url,getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),null)
                    else if (way == 5)
                        IGoShareUtils.shareTweet(this@TripActivity,getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),url)
                    else if (way == 1)
                        ShareUtils.share(this@TripActivity,SHARE_MEDIA.WEIXIN_CIRCLE, getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),
                            getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),url, UMImage(this@TripActivity,R.mipmap.ic_share_trip),this@TripActivity,IGoApplication.emergency)
                    else
                        ShareUtils.share(this@TripActivity,if (way == 0) SHARE_MEDIA.WEIXIN else if (way == 1) SHARE_MEDIA.WEIXIN_CIRCLE else
                            SHARE_MEDIA.MORE, getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),
                            Const.Share.TITLE,url, UMImage(this@TripActivity,R.mipmap.ic_share_trip),this@TripActivity,IGoApplication.emergency)
                    shareDialog.dismiss()
                }
            })
            shareDialog.show(supportFragmentManager,"share")
        }*/
 
        iv_header_home.setOnClickListener {
            startActivity<DriverDetailActivity>("id" to order!!.driverId)
        }
 
        iv_location.setOnClickListener {
            if (order?.state == 5 && vehicleLocation != null) {
                aMap.animateCamera(
                    CameraUpdateFactory.newLatLngZoom(
                        LatLng(
                            vehicleLocation!!.latLng.latitude,
                            vehicleLocation!!.latLng.longitude
                        ), 18f
                    )
                )
            } else
                aMap.animateCamera(
                    CameraUpdateFactory.newLatLngZoom(
                        LatLng(
                            IGoApplication.lat,
                            IGoApplication.lon
                        ), 18f
                    )
                )
            handler.removeMessages(4)
            consumerController?.isAutoCameraEnabled = false
        }
        tv_change_destination.setOnClickListener {
            startActivityForResult<ChoosePositionActivity>(2, "isModify" to true)
        }
 
        tv_cancel.setOnClickListener {
            val tipDialog = TipDialog()
            tipDialog.arguments = bundleOf(
                "msg" to getString(R.string.未达取消),
                "ok" to getString(R.string.确认), "cancel" to getString(R.string.拒绝)
            )
            tipDialog.setCallback(object : TipDialog.OnClickCallback {
                override fun onOk() {
                    startActivityForResult<CancelOrderActivity>(
                        1, "id" to id, "type" to type, "timeOut" to order?.timeOutCancel,
                        "driverTimeOut" to order?.driverTimeOut, "state" to order?.state
                    )
                }
 
                override fun onCancel() {
                }
            })
            tipDialog.show(supportFragmentManager, "cancel")
        }
 
        tv_progress.setOnClickListener {
            showDialog()
            HttpManager.queryTimeInfo(id).request(this) { _, data ->
                data?.apply {
                    progressList.clear()
                    progressList.add(getString(R.string.接单时间) + snatchOrderTime)
                    progressList.add(getString(R.string.取件时间) + startServiceTime)
                    progressList.add(getString(R.string.目前用时) + usedTime)
                    progressList.add(getString(R.string.剩余时间) + remainingTime)
                    progressList.add(getString(R.string.送达时间) + endServiceTime)
                    progressList.add(getString(R.string.整体里程公里).format(allMileage))
                    progressList.add(getString(R.string.当前里程公里).format(mileage))
                    ll_progress.visible()
                }
            }
        }
        view_bg.setOnClickListener {
            ll_progress.gone()
        }
    }
 
    private fun cancelOrder() {
        var lat = 0.0
        var lon = 0.0
        if (vehicleLocation == null) {
            lat = IGoApplication.lat
            lon = IGoApplication.lon
        } else {
            lat = vehicleLocation!!.latLng.latitude
            lon = vehicleLocation!!.latLng.longitude
        }
        HttpManager.cancelOrder(lat, lon, id, type).request(this) { _, _ ->
            myToast(getString(R.string.取消成功))
            setResult(Activity.RESULT_OK)
            finish()
        }
    }
 
    fun initView() {
        UltimateBar.with(this)
            .statusDark(true)
            .create().immersionBar() //沉浸状态栏
        id = intent.getIntExtra("id", 0)
        type = intent.getIntExtra("type", Const.OrderType.TYPE_TAXI)
        titleBar.addRightButton(
            getString(R.string.取消订单),
            onClickListener = View.OnClickListener {
                if (titleBar.getRightButton(0)?.text == getString(R.string.取消订单))
                    startActivityForResult<CancelOrderActivity>(
                        1, "id" to id, "type" to type, "timeOut" to order?.timeOutCancel,
                        "driverTimeOut" to order?.driverTimeOut, "state" to order?.state
                    )
                else if (titleBar.getRightButton(0)?.text == getString(R.string.投诉司机))
                    tv_complain.callOnClick()
                else
                    startActivityForResult<ChoosePositionActivity>(2, "isModify" to true)
            })
        titleBar.getRightButton(0)?.gone()
        initConsumerSdk()
        initMap()
        app.addTripStateListener(this)
        getPhone()
        rv_progress.layoutManager = LinearLayoutManager(this)
        rv_progress.adapter = progressAdapter
    }
 
    private fun initConsumerSdk() {
        //谷歌乘客端api初始化
        val consumerApiTask = ConsumerApi.initialize(
            this, Const.google_provider_id,
            JsonAuthTokenFactory()
        )
        consumerApiTask?.addOnSuccessListener { consumerApi: ConsumerApi ->
            Log.e(Const.GoogleTag, "ConsumerApi初始化成功")
            this.consumerApi = consumerApi
            tripModelManager = consumerApi.tripModelManager
        }
    }
 
    private fun initMap() {
        val fragment = supportFragmentManager.findFragmentById(R.id.mMapView) as ConsumerMapFragment
        fragment.getConsumerGoogleMapAsync(object : ConsumerGoogleMap.ConsumerMapReadyCallback() {
            override fun onConsumerMapReady(consumerGoogleMap: ConsumerGoogleMap) {
                consumerController = consumerGoogleMap.consumerController!!
                val markerOptions = MarkerOptions()
                markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_car))
                consumerController?.consumerMapStyle?.setMarkerStyleOptions(
                    MarkerType.TRIP_VEHICLE,
                    markerOptions
                )
//                consumerController?.isAutoCameraEnabled = false
                aMap = consumerGoogleMap
                aMap.setPadding(0, dip(120), 0, dip(70))
                enableMyLocation()
                aMap.uiSettings.isMyLocationButtonEnabled = false
                aMap.moveCamera(
                    CameraUpdateFactory.newLatLng(
                        LatLng(
                            IGoApplication.lat,
                            IGoApplication.lon
                        )
                    )
                )
                aMap.setOnCameraMoveStartedListener {
                    if (it == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
                        handler.removeMessages(4)
                        consumerController?.isAutoCameraEnabled = false
                    }
                }
                //地图相机(视角)停止移动并变为空闲状态时触发回调
                aMap.setOnCameraIdleListener {
                    handler.sendEmptyMessageDelayed(4, 10000)
                }
            }
        })
    }
 
    /**
     * Enables the My Location layer if the fine location permission has been granted.
     */
    @SuppressLint("MissingPermission")
    private fun enableMyLocation() {
        // 1. Check if permissions are granted, if so, enable the my location layer
        if (ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_FINE_LOCATION
            ) == PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_COARSE_LOCATION
            ) == PackageManager.PERMISSION_GRANTED
        ) {
            aMap.isMyLocationEnabled = true
            return
        }
        // 2. If if a permission rationale dialog should be shown  //todo 权限说明弹窗
//        if (ActivityCompat.shouldShowRequestPermissionRationale(
//                this,
//                Manifest.permission.ACCESS_FINE_LOCATION
//            ) || ActivityCompat.shouldShowRequestPermissionRationale(
//                this,
//                Manifest.permission.ACCESS_COARSE_LOCATION
//            )
//        ) {
//            PermissionUtils.RationaleDialog.newInstance(
//                LOCATION_PERMISSION_REQUEST_CODE, true
//            ).show(supportFragmentManager, "dialog")
//            return
//        }
        val subscribe = RxPermissions(this).request(
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION
        ).subscribe {
            if (it)
                enableMyLocation()
            else {
                myToast(getString(R.string.没有权限))
            }
        }
    }
 
 
    private fun getPhone() {
        HttpManager.getPhone(IGoApplication.lat, IGoApplication.lon)
            .request(this, false) { _, data ->
                data?.let {
                    it.forEach {
                        if (it.type == 1)
                            phoneEmergency = it.phone
                        else if (it.type == 2)
                            phoneService = it.phone
                    }
                }
            }
    }
 
    /**
     * 获取订单基础数据:起终点,订单状态等
     */
    private var lastMin = 0 //剩余到达分钟
    private var lastDistance = 0 //剩余距离米
    private fun getData() {
        HttpManager.queryOrderInfo(id, type).request(this) { _, data ->
            order = data
            data?.let {
 
                if (session == null) {
                    try {
                        IGoApplication.tripId = it.tripId
                        val tripName = "providers/i-go-odrd-testing/trips/${it.tripId}"
                        val tripModelManager = consumerApi?.tripModelManager
                        val tripModel = tripModelManager?.getTripModel(tripName)
                        // Create a JourneySharingSession instance based on the TripModel.
                        session = JourneySharingSession.createInstance(tripModel!!)
                        // Add the JourneySharingSession instance on the map for updating the UI.
                        consumerController?.showSession(session!!)
                        tripModel.registerTripCallback(object : TripModelCallback() {
//                            override fun onTripETAToNextWaypointUpdated(
//                                tripInfo: TripInfo,
//                                timestampMillis: Long?,
//                            ) {
//                                // ...
//                            }
//
//                            override fun onTripActiveRouteRemainingDistanceUpdated(
//                                tripInfo: TripInfo,
//                                distanceMeters: Int?,
//                            ) {
//                                // ...
//                            }
 
                            override fun onTripStatusUpdate(p0: TripInfo, p1: Int) {
                                super.onTripStatusUpdate(p0, p1)
                                Log.e(Const.GoogleTag, "onTripStatusUpdate:${p1}")
                                if (p1 == TripStatus.CANCELED || p1 == TripStatus.COMPLETE) {
                                    Log.e(Const.GoogleTag, "重置tripId")
                                    IGoApplication.tripId = ""
                                }
                            }
 
                            override fun onTripUpdated(p0: TripInfo) {
                                super.onTripUpdated(p0)
                                lastMin = (((p0.dropoffTimeMillis
                                    ?: 0L) - System.currentTimeMillis()) / 1000 / 60).toInt()
                                lastDistance = p0.activeRouteRemainingDistanceMeters ?: 0
                                Log.e(
                                    Const.GoogleTag,
                                    "onTripUpdated:${lastMin}分钟,;;${p0.activeRouteRemainingDistanceMeters}米"
                                )
                                vehicleLocation = p0.vehicleLocation
                                vehicleLocation?.let {
                                    IGoApplication.lat = it.latLng.latitude
                                    IGoApplication.lon = it.latLng.longitude
                                }
                            }
 
 
                        })
                        // Set refresh interval to 2 seconds.
                        val tripOptions =
                            TripModelOptions.builder().setRefreshIntervalMillis(2000).build()
                        tripModel.tripModelOptions = tripOptions
                    } catch (e: Exception) {
                        Log.e(Const.GoogleTag, e.message ?: "用户sdk初始化异常")
                    }
                }
                if (type == Const.OrderType.TYPE_TAXI && it.endLat == 0.0) {
                    tv_end.text = "——"
                    fl_one_click.visible()
                } else
                    tv_end.text = it.endAddress
                tv_start.text = it.startAddress
                tv_time.text = it.travelTime
                if (type == Const.OrderType.TYPE_CROSS_CITY) {
                    tv_passenger_num.visible()
                    tv_passenger_num.text =
                        String.format("%d人   座位:%s号", it.peopleNumber, it.seatNumber)
                            .replace(",", "号,")
                    tv_remark.visibility = if (it.remark.isNotEmpty()) View.VISIBLE else View.GONE
                    tv_remark.text = it.remark
                }
                if (type == Const.OrderType.TYPE_SAME_CITY) {
                    tv_passenger_num.visible()
                    tv_passenger_num.text = if (it.remark.isNullOrEmpty()) "——" else it.remark
                    /* if (it.state in 2..6) {
 
                         tv_progress.visible()
 
                         line.visible()
                     }*/
                }
                if (it.state != 1) { //有司机
                    handler.removeMessages(0)
                    handler.removeMessages(1)
                    handler.removeMessages(2)
                    titleBar.getRightButton(0)?.visible()
                    tv_action.gone()
                    if (type == TYPE_SPECIAL)
                        tv_state.visible()
                    else
                        tv_state.gone()
                    cl_driver.visible()
                    order?.run {
                        iv_header_home.setImageURI(driverAvatar)
                        tv_name.text = driverName
                        tv_car.text = licensePlate
                        tv_car_info.text = "$brand·$carColor"
                        tv_score.text = String.format("%.1f", score)
                        tv_count.text = getString(R.string.单数, orderNum)
                    }
                }
                setStateUI()
            }
        }
    }
 
    /**
     * 订单状态变化后的UI渲染,主要是起终点,标题等数据
     */
    private fun setStateUI() {
        iv_shuaxing.gone()
        order?.let {
            when (it.state) {
                1 -> {
                    titleBar.getRightButton(0)?.visible()
                    titleBar.setTitle(getString(R.string.等待应答))
                    if (!handler.hasMessages(0))
                        handler.sendEmptyMessage(0)
                    tv_action.visible()
                    aMap.animateCamera(
                        CameraUpdateFactory.newLatLngZoom(
                            LatLng(
                                it.startLat,
                                it.startLon
                            ), 18f
                        )
                    )
                    queryEndPush()
                }
 
                2 -> {
                    if (type == TripOrderFragment.TYPE_LOGISTICS)
                        titleBar.getRightButton(0)?.gone()
                    titleBar.setTitle(
                        getString(
                            if (type == TripOrderFragment.TYPE_LOGISTICS) {
                                ll_progress.gone()
                                R.string.等待取件
                            } else R.string.等待接驾
                        )
                    )
                    fl_reserve.visibility =
                        if (it.travelTime1.isNotEmpty() && it.travelTime1.parserTime() - System.currentTimeMillis() > (30L * 60 * 1000)) View.VISIBLE else View.GONE
                    if (!handler.hasMessages(2))
                        handler.sendEmptyMessage(2)
                    setMarker(LatLng(it.startLat, it.startLon), it.startAddress)
                    getTrippingData()
                }
 
                3 -> {
                    titleBar.getRightButton(0)?.gone()
                    titleBar.setTitle(
                        getString(
                            if (type == TripOrderFragment.TYPE_LOGISTICS) {
                                ll_progress.gone()
                                R.string.等待取件
                            } else R.string.等待接驾
                        )
                    )
                    if (!handler.hasMessages(2))
                        handler.sendEmptyMessage(2)
                    setMarker(LatLng(it.startLat, it.startLon), it.startAddress)
                    getTrippingData()
                }
 
                4 -> {
                    titleBar.getRightButton(0)?.gone()
                    println("隐藏取消订单")
                    titleBar.setTitle(getString(R.string.司机已到达))
                    setMarker(LatLng(it.startLat, it.startLon), it.startAddress)
                    if (!handler.hasMessages(1))
                        handler.sendEmptyMessage(1)
                    getTrippingData()
                }
 
                5 -> {
                    if (type == TYPE_SPECIAL)
                        iv_shuaxing.visible() else iv_shuaxing.gone()
                    titleBar.setTitle(getString(R.string.serving))
                    if (!handler.hasMessages(2))
                        handler.sendEmptyMessage(2)
                    setMarker(LatLng(it.startLat, it.startLon))
                    setMarker(LatLng(it.endLat, it.endLon), isStart = false)
                    getTrippingData()
//                    tv_complain.visible()
                    titleBar.getRightButton(0)?.visible()
                    titleBar.getRightButton(0)?.text = getString(R.string.投诉司机)
//                    if (type == Const.OrderType.TYPE_CROSS_CITY) //跨城行程中无法取消  //todo 原型没有修改终点
//                        titleBar.getRightButton(0)?.gone()
//                    if (type == Const.OrderType.TYPE_CROSS_CITY||type == Const.OrderType.TYPE_SPECIAL) //专车行程中增加修改目的地
//                        titleBar.getRightButton(0)?.text = getString(R.string.修改终点)
                    if (type == TYPE_SPECIAL) tv_change_destination.visible() else tv_change_destination.gone()
                    if (type != Const.OrderType.TYPE_SAME_CITY) {
                        tv_cancel.gone()
                    } //客户反馈:快件单一旦司机开始行程后(取到快件送货途中)就不能再取消订单
                    titleBar.getRightButton(0)?.gone()
                    aMap.isMyLocationEnabled = false //行程中取消乘客定位
                }
 
                10 -> {
                    if (it.cancelUserType != 1) {
                        startActivity<OrderCancelDetailActivity>("id" to id, "type" to type)
                        finish()
                    }
                }
 
                else -> {
                    startActivity<OrderDetailActivity>("id" to id, "type" to type)
                    finish()
                }
            }
        }
    }
 
 
    /**
     * 获取行程中的数据:主要是司机位置,订单状态变化,距离、时间等预算信息
     */
    private fun getTrippingData() {
        IGoApplication.intervalCount = 0
        HttpManager.trippingInfo(id, type).request(this) { _, data ->
            data?.let {
                if (it.lat.isNotEmpty())
                    setDriverMarker(LatLng(it.lat.toDouble(), it.lon.toDouble()))
                if (it.state != order?.state) //订单状态发生变化,重新拉取数据
                    getData()
                else {
                    setTrippingUI(it)
                }
            }
        }
    }
 
    /**
     * 获取是否有司机接单
     */
    private fun queryEndPush() {
        IGoApplication.intervalCount = 0
        HttpManager.queryEndPush(id, type).request(this) { _, data ->
            data?.let {
                if (it.state == 2) { //无人接单
                    noResponse(id)
                }
            }
        }
    }
 
    /**
     * 超时无应答
     */
    fun noResponse(id: Int) {
        if (id == this@TripActivity.id && !noResponseDialog.isAdded) {
            noResponseDialog.show(supportFragmentManager, "noResponse")
        }
    }
 
    /**
     * 行程中的UI,展示不同状态下的动态数据
     * */
    private fun setTrippingUI(it: TrippingInfo) {
        when (order?.state) {
            2, 3 -> {
                if ((it.reservationMileage.isNullOrEmpty() || it.reservationMileage.toDouble() == 0.0)
                    && (it.reservationTime.isNullOrEmpty() || it.reservationTime.toInt() == 0)
                ) { //无数据
                    tv_state.text = getString(R.string.司机接驾途中)
                } else {
                    val time = getString(R.string.多少分钟, it.reservationTime)
                    val distance = "%.2f".format(it.reservationMileage.toDouble())
                    val s = getString(R.string.接驾中, distance, time)
                    tv_state.text = SpanBuilder(s).color(
                        this, s.indexOf(distance), s.indexOf(distance) + distance.length,
                        R.color.colorPrimary
                    ).color(
                        this,
                        s.indexOf(time),
                        s.indexOf(time) + it.reservationTime.length,
                        R.color.colorPrimary
                    ).build()
                }
 
                if (it.lat.isNotEmpty()) {
                    //todo 移动视角吗?不需要,因为查询路径后做了移动
//                    val builder = LatLngBounds.builder()
//                    builder.include(LatLng(order!!.startLat,order!!.startLon)).include(
//                        LatLng(it.lat.toDouble(),it.lon.toDouble()))
 
                    if (order?.state == 2) {
//                        aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(it.lat.toDouble(),it.lon.toDouble()),25f))
                    }
                    if (order?.state == 3)
                        setRoute(
                            it.lat.toDouble(), it.lon.toDouble(),
                            order!!.startLat, order!!.startLon
                        )
                }
            }
 
            4 -> {
//                aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(it.lat.toDouble(),it.lon.toDouble()), 15f))
//                oldDrivingRouteOverlay?.remove()
//                newDrivingRouteOverlay?.remove()
            }
 
            5, 6 -> {
//                val mile2 = "%.2f".format(it.servedMileage.toDouble())
//                val timeS = getString(R.string.多少分钟,it.laveTime)
//                val s = getString(R.string.已服务时间,it.servedTime, mile2,it.laveMileage,timeS)
//                tv_state.text = SpanBuilder(s).color(this,s.indexOf(it.servedTime),s.indexOf(it.servedTime)+it.servedTime.length,R.color.colorPrimary)
//                    .color(this,s.indexOf(mile2),s.indexOf(mile2)+mile2.length,R.color.colorPrimary)
//                    .color(this,s.indexOf(it.laveMileage),s.indexOf(it.laveMileage)+it.laveMileage.length,R.color.colorPrimary)
//                    .color(this,s.lastIndexOf(timeS),s.lastIndexOf(timeS)+it.laveTime.length,R.color.colorPrimary)
//                    .build()
                showStateStr(it.servedMileage, it.servedTime)
                if (it.lat.isNotEmpty())
                    setRoute(it.lat.toDouble(), it.lon.toDouble(), order!!.endLat, order!!.endLon)
                if (!it.orderPositionList.isNullOrEmpty()) {
                    val list = gson.fromJson<List<Point>>(
                        it.orderPositionList,
                        object : TypeToken<List<Point>>() {}.type
                    )
                    if (list.isNotEmpty()) {
                        oldDrivedRouteOverlay = newDrivedRouteOverlay
                        newDrivedRouteOverlay = drawLine(list.map { LatLng(it.lat, it.lon) })
                        oldDrivedRouteOverlay?.remove()
                    }
                }
            }
        }
    }
 
    private fun showStateStr(servedMileage: String, servedTime: String) {
        val mile2 = "%.2f".format(servedMileage.toDouble())
        val timeS = getString(R.string.多少分钟, lastMin.toString())
        val laveMileage = "%.2f".format(lastDistance.toDouble() / 1000)
 
        val s = getString(R.string.已服务时间, servedTime, mile2, laveMileage, timeS)
        tv_state.text = SpanBuilder(s).color(
            this,
            s.indexOf(servedTime),
            s.indexOf(servedTime) + servedTime.length,
            R.color.colorPrimary
        )
            .color(this, s.indexOf(mile2), s.indexOf(mile2) + mile2.length, R.color.colorPrimary)
            .color(
                this,
                s.indexOf(laveMileage),
                s.indexOf(laveMileage) + laveMileage.length,
                R.color.colorPrimary
            )
            .color(
                this,
                s.lastIndexOf(timeS),
                s.lastIndexOf(timeS) + lastMin.toString().length,
                R.color.colorPrimary
            )
            .build()
    }
 
    private var startMarker: Marker? = null
    private var endMarker: Marker? = null
 
    /**
     * @param isStart true:起点标记 false:终点标记
     */
    private fun setMarker(latLon: LatLng, content: CharSequence = "", isStart: Boolean = true) {
        val language = SPUtils.instance().getString("language", "en")
        if (isStart) {
            val ic = when (language) {
                "en" -> R.mipmap.starting_point_e
                "ch" -> R.mipmap.starting_point
                else -> R.mipmap.starting_point_f
            }
            val icon = if (content.isEmpty()) BitmapDescriptorFactory.fromResource(ic)
            else {
                val view = layoutInflater.inflate(R.layout.marker_with_text_2, null, false)
                view.find<TextView>(R.id.tv_content).text = content
                view.find<ImageView>(R.id.iv).imageResource =
                    if (order?.state == 1) R.mipmap.icon_location else ic
                BitmapDescriptorFactory.fromBitmap(convertViewToBitmap(view)!!)
            }
            if (startMarker != null) {
                startMarker!!.position = latLon
                startMarker!!.setIcon(icon)
            } else {
                val options = MarkerOptions()
                options.position(latLon).icon(icon)
                startMarker = aMap.addMarker(options)
            }
        } else {
            val ic = when (language) {
                "en" -> R.mipmap.end_point_e
                "ch" -> R.mipmap.end_point
                else -> R.mipmap.end_point_f
            }
            if (endMarker != null) {
                endMarker!!.position = latLon
            } else {
                val options = MarkerOptions()
                options.position(latLon).icon(BitmapDescriptorFactory.fromResource(ic))
                endMarker = aMap.addMarker(options)
            }
        }
    }
 
    private var driverMarker: Marker? = null //司机标记
    private fun setDriverMarker(latLng: LatLng) {  //现在使用谷歌套餐,不需要自己画司机位置
//        if (driverMarker == null) {
//            val b = BitmapDescriptorFactory.fromResource(R.mipmap.location_car)
//            val options = MarkerOptions()
//            options.position(latLng)
//            options.icon(b)
//            driverMarker = aMap.addMarker(options)
//        } else {
//            driverMarker?.position = latLng
//        }
    }
 
    private var oldDrivingRouteOverlay: Polyline? = null
    private var newDrivingRouteOverlay: Polyline? = null
    private var routeSearchDisposable: DisposableSubscriber<RouteBean>? = null
 
    private var lastMoveTime = 0L
 
    /**
     * 废弃
     * 现在使用谷歌乘客sdk,不再自己计算路径
     */
    private fun setRoute(startLat: Double, startLon: Double, endLat: Double, endLon: Double) {
        //如果上一次还没处理完,取消订阅
//        if (routeSearchDisposable != null && !routeSearchDisposable!!.isDisposed) {
//            routeSearchDisposable?.dispose()
//        }
//        routeSearchDisposable = object : DisposableSubscriber<RouteBean>() {
//            override fun onComplete() {
//            }
//
//            override fun onNext(t: RouteBean?) {
//                if (t?.status == "OK") {
//                    oldDrivingRouteOverlay = newDrivingRouteOverlay
//                    val geodesic = PolylineOptions()
//                        .add(LatLng(startLat, startLon))
//                        .width(20f)
//                        .color(Color.parseColor("#00C47A"))
//                        .geodesic(true)
//                    t.routes.firstOrNull()?.legs?.firstOrNull()?.steps?.forEach {
//                        geodesic.add(LatLng(it.end_location.lat, it.end_location.lng))
//                    }
//                    geodesic.add(LatLng(endLat,endLon))
//                    newDrivingRouteOverlay = aMap.addPolyline(geodesic)
//                    oldDrivingRouteOverlay?.remove()
//
//                    if (System.currentTimeMillis() - lastMoveTime > 10000L){
//                        lastMoveTime = System.currentTimeMillis()
//                        aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(
//                            LatLngBounds(LatLng(t.routes.firstOrNull()?.bounds?.southwest?.lat?:0.0,t.routes.firstOrNull()?.bounds?.southwest?.lng?:0.0),
//                                LatLng(t.routes.firstOrNull()?.bounds?.northeast?.lat?:0.0,t.routes.firstOrNull()?.bounds?.northeast?.lng?:0.0)),280))
//                    }
//                }
//            }
//
//            override fun onError(t: Throwable?) {
//                Log.e("Trip","路径规划失败")
//            }
//        }
//        HttpManager.directions(startLat, startLon, endLat, endLon).defaultScheduler().subscribe(routeSearchDisposable)
    }
 
    /**
     * 绘制已行驶灰色路径
     */
    private fun drawLine(latLngs: List<LatLng?>): Polyline? {
        val options = PolylineOptions().addAll(latLngs)
        if (driverMarker != null) {
            options.add(driverMarker!!.position)
        }
        options.width(20f)
            .color(Color.parseColor("#999999"))
        return aMap.addPolyline(options)
    }
 
    /**
     * handler定时器
     * #what:0:等待应答 1:司机等待 2:其他状态时,判断socket是否在线,如果不在线就调仿socket接口
     */
    override fun handleMessage(msg: Message): Boolean {
        if (order == null)
            return true
        when (msg?.what) {
            0 -> {
                if (order?.state == 1) {
                    val latLon = LatLng(order!!.startLat, order!!.startLon)
                    val waittime = order!!.insertTime.parserTime()
                    val s = System.currentTimeMillis()
                    val i = Math.max(s - waittime, 0L)
                    val c = getString(R.string.正在寻找车辆, i / 1000 / 60, i / 1000 % 60)
                    setMarker(
                        latLon, SpanBuilder(c)
                            .color(this, c.length - 6, c.length, R.color.colorRed).build()
                    )
                    IGoApplication.intervalCount++
                    if (IGoApplication.intervalCount > 7) {
                        queryEndPush()
                        getTrippingData()
                    }
                    Log.e("timer", "事件0:" + IGoApplication.intervalCount)
                    handler.sendEmptyMessageDelayed(0, 1000)
                }
            }
 
            1 -> {
                if (order?.state == 4) {
                    val waittime = order!!.arriveTime.parserTime()
                    val s = System.currentTimeMillis()
                    val i = Math.max(s - waittime, 0L)
                    val c = getString(R.string.司机到达预约地点等待, i / 1000 / 60, i / 1000 % 60)
                    tv_state.text =
                        SpanBuilder(c).color(this, c.length - 5, c.length, R.color.colorPrimary)
                            .build()
                    IGoApplication.intervalCount++
                    if (IGoApplication.intervalCount > 7) {
                        getTrippingData()
                    }
                    Log.e("timer", "事件1:" + IGoApplication.intervalCount)
                    handler.sendEmptyMessageDelayed(1, 1000)
                }
            }
 
            2 -> {
                IGoApplication.intervalCount++
                if (IGoApplication.intervalCount > 7) {
                    getTrippingData()
                }
                Log.e("timer", "事件2:" + IGoApplication.intervalCount)
                if (order?.state == 2)
                    fl_reserve.visibility =
                        if (order!!.travelTime1.isNotEmpty() && order!!.travelTime1.parserTime() - System.currentTimeMillis() > (30L * 60 * 1000)) View.VISIBLE else View.GONE
                handler.sendEmptyMessageDelayed(2, 1000)
            }
 
            4 -> {
                consumerController?.isAutoCameraEnabled = true
            }
        }
        return true
    }
 
    override fun onStateChanged(id: Int, state: Int) { //state
        if (id == order?.orderId) {
            setResult(Activity.RESULT_OK)
            if (order?.driverId == 0 || order?.arriveTime.isNullOrEmpty() || state == 15 || state == 10) { //司机接单和到达预约点需要掉接口去获取司机信息以及等待开始时间
                getData()
            } else {
                order?.state = state
                setStateUI()
            }
        }
    }
 
    override fun onTrippingChanged(info: TrippingInfo) {
        if (info.orderId == order?.orderId) {
            setTrippingUI(info)
        }
    }
 
    override fun onAddressChanged(info: TrippingInfo) {
        Log.e("地址变更: ", (info.status == 2).toString())
        if (info.orderId == order?.orderId) {
            if (info.status == 2) { //司机同意修改目的地
                getData()
            }
            if (info.status == 3) {//司机拒绝修改目的地
                val tipDialog = TipDialog()
                tipDialog.arguments = bundleOf(
                    "msg" to getString(R.string.拒绝变更),
                    "ok" to getString(R.string.确认), "isAlert" to true
                )
                tipDialog.setCallback(object : TipDialog.OnClickCallback {
                    override fun onOk() {
                    }
 
                    override fun onCancel() {
                    }
                })
                tipDialog.show(supportFragmentManager, "refuse")
            }
        }
    }
 
    override fun onShuttleConfirm(id: Int, type: Int) {
        if (this.type == Const.OrderType.TYPE_SPECIAL && order?.state == 1) {
            this.type = type
            this.id = id
            getData()
        }
    }
 
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK && data != null) {
            if (requestCode == 1) {
                setResult(Activity.RESULT_OK)
                finish()
                val money = data.getDoubleExtra("money", 0.0)
                if (money != 0.0)
                    startActivity<OrderDetailActivity>("id" to id, "type" to type)
            } else if (requestCode == 2) { //修改终点
                val lat = data.getDoubleExtra("lat", 0.0)
                val lon = data.getDoubleExtra("lon", 0.0)
                val address = data.getStringExtra("name") ?: ""
                val tipDialog = TipDialog()
                tipDialog.arguments = bundleOf(
                    "msg" to getString(R.string.变更目的地提示),
                    "ok" to getString(R.string.确认),
                    "cancel" to getString(R.string.拒绝)
                )
                tipDialog.setCallback(object : TipDialog.OnClickCallback {
                    override fun onOk() {
                        showDialog()
                        HttpManager.updateEndAddress(address, lat, lon, id, type)
                            .request(this@TripActivity) { _, _ ->
                            }
                    }
 
                    override fun onCancel() {
                    }
                })
                tipDialog.show(supportFragmentManager, "modify")
            }
        }
    }
 
    /**
     * 吧iew转化为bitmap
     *
     * @param view
     * @return
     */
    fun convertViewToBitmap(view: View): Bitmap? {
        view.isDrawingCacheEnabled = true
        view.measure(
            View.MeasureSpec.makeMeasureSpec(
                0,
                View.MeasureSpec.UNSPECIFIED
            ),
            View.MeasureSpec.makeMeasureSpec(
                0,
                View.MeasureSpec.UNSPECIFIED
            )
        )
        view.layout(0, 0, view.measuredWidth, view.measuredHeight)
        view.buildDrawingCache()
        val mCacheBitmap = view.drawingCache
        return Bitmap.createBitmap(mCacheBitmap)
    }
 
    override fun onResume() {
        super.onResume()
        getData()
        NettyClient.getInstance().checkNettyState()
    }
 
 
    override fun onDestroy() {
        handler.removeMessages(0)
        handler.removeMessages(1)
        handler.removeMessages(2)
        handler.removeMessages(3)
        app.removeTripStateListener(this)
        IGoApplication.tripId = ""
        session?.stop()
        super.onDestroy()
    }
 
    override fun onResult(p0: SHARE_MEDIA?) {
    }
 
    override fun onCancel(p0: SHARE_MEDIA?) {
    }
 
    override fun onError(p0: SHARE_MEDIA?, p1: Throwable?) {
    }
 
    override fun onStart(p0: SHARE_MEDIA?) {
    }
 
    override fun onBackPressed() {
        if (ll_progress.visibility == View.VISIBLE)
            ll_progress.gone()
        else
            super.onBackPressed()
    }
}