电子产业一站式赋能平台

PCB联盟网

搜索
查看: 284|回复: 0
收起左侧

基于Mobile SDK V4版固件开发大疆无人机手机端遥控器(3)

[复制链接]

1001

主题

1001

帖子

8807

积分

高级会员

Rank: 5Rank: 5

积分
8807
发表于 2023-6-15 12:00:00 | 显示全部楼层 |阅读模式

oex35tit1ci64011355440.gif

oex35tit1ci64011355440.gif
2 \" G/ z" P7 z/ i) h
点击上方蓝色字体,关注我们
; w( q7 O5 [  ?4 m
9 s! L& f$ K2 k- d3 }- o
3 [& J; |2 `( k4 h6 y第三篇文章准备单独拿出来写,因为在大疆为人机的所有功能中,航线规划的功能最为复杂,也相当的繁琐,这里需要说仔细一点,可能会将代码进行多步分解。
2 `# s; r0 n. z! ^0 Q, v) F1, {% e) `0 b2 Z9 b7 a. K4 u, n
航线规划
3 t! Q( P2 \; m% ]" Q% t+ a" y* h航线打点
) o0 d: P3 R% E- T+ P5 @. ^, L! G# w1 q& v* k( c! g- R. J
在地图中手动选择点位选择完成航线打点;若打点位置错了可进行点位删除。
! \. o5 r/ D" V2 }2 [. i- |3 |

kmvudl1k00u64011355540.png

kmvudl1k00u64011355540.png

! F3 L% a9 _' `% E. d: j1 q  }7 r+ o
航点设置
' U) f. T7 @1 b$ S1 s5 A, v$ |5 w' y- M, Q+ [5 P
可对航线点位进行设置,如飞行高度,速度(慢速:3m/s;中速: 7m/s;高速:10 m/s)、任务结束后操作及航向,点击[设置]按钮完成设置。0 l# S/ m( f' d

zfkndzh1sfz64011355640.png

zfkndzh1sfz64011355640.png

8 I* ^) i7 P5 }" w& p) d8 p设置完成后会显示总距离及飞行总时间。; ]* d) b5 c) X, T

x2zuyyvnnno64011355740.png

x2zuyyvnnno64011355740.png
! @  E1 Z: N$ z  ^5 r9 `
* o9 Z+ B1 n# M: m
航线上传
# _, t5 T) x) U/ a3 A# _
# h/ Q# v' b7 K% n4 L# x5 r; J" h点击[上传]按钮,进行航线上传。可以进入本地存储中选择航线文件进行上传,航线文件为 .kml结尾。2 S$ ^. H; c- I, R) F0 |0 m+ u

zixisey3u1d64011355840.png

zixisey3u1d64011355840.png

) |1 p: f1 H, t7 m% _- k" L, A5 l( b  S
航线执行 : o6 q" L; ~: [0 Z, g1 v
' s) e- p& ^$ E3 z+ ^
点击 [开始]按钮,则可对航线进行执行。若中途需要暂停也可点击[暂停]安装进行暂停操作。
/ g  I: V( b  [

lhmr0zgppoe64011355941.png

lhmr0zgppoe64011355941.png
5 e6 b' |8 s+ j  s

% U# j7 {- U7 H0 H7 _/ t9 _航线管理
! _. E3 }! S8 `2 S$ Q6 T- b6 `+ d3 X
按钮即可进入航线管理界面。
& {. I  E5 W' w1 t3 x* m
% G% R$ |7 i" N; i, R* ?8 ]7 r

ybznvwfnn2m64011356041.png

ybznvwfnn2m64011356041.png

8 R5 ]& {* z5 s& ~$ x2 `
$ k/ B/ ^: a7 b获取航线
0 X# [$ U1 [  B- u1 ]7 {1 G; y0 A9 E1 `$ w7 {( X$ _$ r) \, ?
点击[获取]按钮,即可将航线信息展示到地图界面中。
5 v+ n( G9 W; Y) W% U
: K! y! V7 J, _2 o4 [$ R* ~( _! s& t5 w/ S4 z* P" m
2
6 t! x- \! O9 h% ?; a主要功能代码
+ D6 z+ q3 G2 c* Q7 O# F创建activity_setting_route.xml及SettingRouteActivity文件。
* F$ h% I3 y; Q6 i" n- w, J1 L
7 F6 R$ T# i* A& A6 q& F, ^" Y
3 u1 v! c6 {' y+ q% `( a3 f1 k1 p2 f
activity_setting_route.xml3 q) o, j/ r! s* @

5 W0 ^& n7 D' u# c" HLinearlayout xmlns:android="http://schemas.android.com/apk/res/android"
* n* h% x8 d5 s9 c6 ?- [! I; I9 e$ m    xmlns:app="http://schemas.android.com/apk/res-auto"
2 f: n: S6 i, _. @    xmlns:tools="http://schemas.android.com/tools"' q( Z# l+ H1 o) W( Y+ z
    android:layout_width="match_parent". S- u  Z; c& V/ x! U- R. [
    android:layout_height="match_parent"
# X/ ?5 `; _$ |! o1 }. X    android:orientation="vertical"* N. \: _: ~4 g; n) h1 [8 R/ X4 v' N+ p0 J
    tools:context=".ui.SettingRouteActivity">
4 H! |& L) j) B3 l    include
# x1 m: P) ?8 `        android:id="@+id/layout_route"% |. W- H, }! D4 {. a
        layout="@layout/activity_toolbar">include># ^& u5 N% Q; z6 k5 f
    RelativeLayout0 \/ w+ G2 w/ C/ X! x9 h' X* n# y
        android:layout_width="match_parent"
, b! b2 n! ]% @" [* j* q8 F        android:layout_height="match_parent">
( k$ h8 o+ k8 U7 n! M        com.amap.api.maps.MapView
2 F. K; R& r$ W% T2 \1 E- ^* W            android:id="@+id/map"; m. _) u* G  {
            android:layout_width="match_parent"
7 j8 c+ \) Y% R0 `* \2 |            android:layout_height="match_parent" />
5 @, {4 e5 `7 e  D. H' t- a6 y        LinearLayout
! i- T+ t5 m, ?6 \            android:layout_width="wrap_content"
/ M: I0 f5 e5 V            android:layout_height="wrap_content"
3 }/ J+ R# }$ F            android:layout_alignParentTop="true"
6 ]  N2 Y# C6 P+ \' F            android:layout_centerInParent="true"
8 C( L- \: ^5 N5 ~            android:layout_marginTop="5dp">3 \# c  o! K# V1 o% p7 X' y% U0 z
            Button
0 [7 v0 F+ u7 Q0 M( g* W$ D( J                android:id="@+id/btn_delete"6 r7 T% k3 Z) @9 f# N$ M) m
                android:layout_width="60dp"
3 T4 X) i/ Y2 \                android:layout_height="30dp"
( P* G( L) R7 L! Z                android:visibility="gone"
. L2 k& k1 \3 H5 E                android:text="删除"5 X7 U. S5 ~3 \* S. {
                android:textColor="@color/white"3 s* o3 M6 @& X! H  x0 c
                android:background="@drawable/button_task_background">Button>8 f% A  G6 [/ N' H# Q& H/ |1 D
            Button
# C% _$ X/ F! n( g                android:id="@+id/btn_finish"
/ A9 G$ P4 m) d, {3 B% Q                android:layout_width="60dp", N. J7 p2 o4 k
                android:layout_height="30dp"
/ j* w7 f, ~6 r! \% x                android:visibility="gone"
/ p, V: @8 @! S                android:textColor="@color/white"  ]6 ~0 r, H7 `, e- E! a- ~  k  E
                android:background="@drawable/button_task_background"1 V; u5 k" j3 J  }5 \% }' @
                android:text="完成">Button>
( T3 R4 I& Z4 g7 _            Button2 @& M' E3 n( r* h+ @/ }" V
                android:id="@+id/btn_setting"
4 G4 C+ M9 N5 ^8 g: g$ n6 u                android:layout_width="60dp"& E  l- ?( l2 _* G9 A# b; d
                android:layout_height="30dp"9 R- _% I, Z7 f1 G
                android:visibility="gone"
8 U; s3 U8 B/ D) p( F' m& N6 N3 U  n                android:textColor="@color/white"5 t: x! n; S" r" H
                android:background="@drawable/button_task_background"5 |! W0 K9 I$ C+ o+ \1 _
                android:text="设置">Button>
9 O% \$ ~! Y1 u7 s! \8 v( u# q            Button
7 g2 `* g9 }' ~" q" s! e( U                android:id="@+id/btn_upload"
% M& h1 L* m, l1 s7 L                android:layout_width="60dp"
% S5 f- ^) c" j( O$ P                android:layout_height="30dp"' n. P( {- G: ~
                android:visibility="gone"4 k3 f$ {' V& ?% r
                android:textColor="@color/white", z% B% \0 V- J6 F0 b
                android:background="@drawable/button_task_background": {6 A( w6 V5 [; m7 I6 |
                android:text="上传">Button>
3 Y% L8 b5 o3 w8 C            Button
) H: n) r- w0 Y1 V0 D                android:id="@+id/btn_start"3 U8 j- b, _$ u. _- |: N9 V5 h
                android:layout_width="60dp"& B7 c9 h" e* T: _7 n% c
                android:layout_height="30dp"
2 F( t6 F* r& E9 _' E                android:visibility="gone"
. O) P7 v( C* G  b9 H+ l, y                android:textColor="@color/white"  i8 F/ N2 p$ V* a
                android:background="@drawable/button_task_background"
" t4 t3 y' d( r                android:text="开始">Button>
7 q: I2 [* f  W5 f  z. B' i            Button
2 U/ s: i7 S2 U4 ~                android:id="@+id/btn_stop"
" l1 ^& N$ L& a& X  X1 l6 D                android:layout_width="60dp"
% T- Y* f, s8 T9 F                android:layout_height="30dp"
3 s& W: k0 l5 {  G& i                android:visibility="gone"
6 J; \! `: }3 [. m/ [0 f                android:textColor="@color/white"% Y) l! b2 x6 p7 [1 C
                android:background="@drawable/button_task_background"
1 }: V, x7 A0 O: }4 X5 J2 G4 b; y                android:text="暂停">Button>2 h& r  i& [' h/ N; Q
        LinearLayout>
2 [) w* K3 Z6 k7 ]$ P: v        LinearLayout
! ?0 S" G& u  ]            android:id="@+id/ll_information"
8 @% W/ m* Q2 K            android:layout_width="wrap_content"
# T( N( V$ F6 N+ C6 L            android:layout_height="wrap_content"
, ]) {$ h4 w3 v! [0 G            android:layout_alignParentBottom="true"" t: ~  g$ @) h  z% N
            android:layout_centerInParent="true"
3 T$ F$ L" f2 v7 A% H7 u' t6 x            android:layout_marginBottom="5dp"
: q% ~  F% u) a$ Y7 X, `) [            android:padding="10dp"! k# o) e- D1 O- g
            android:visibility="gone"
+ F7 N! D3 T8 d* W2 \            android:background="@color/color_nav_Item_unselected">' @( u) |  {- t* W1 @! c
            TextView
( [6 r* S5 u0 p: }* _6 I5 T                android:id="@+id/tv_height"/ M* r7 r$ W5 H4 `
                android:layout_width="wrap_content"
; `, o3 S9 L0 I                android:layout_height="wrap_content"! k4 p: ~+ ]! T; b% R3 ?$ N
                android:text="高度:"  f0 J& o0 H* Q0 F6 C9 B& L9 v
                android:textColor="@color/white"
( J$ Q: a( [5 ~8 f9 |                >TextView>, }1 G9 ?+ Z5 R" Q: H# b5 P. b
            TextView8 F& c! s! w$ P9 R" P. P' h
                android:id="@+id/tv_speed"
" Z: @% E) C4 H' `! ]                android:layout_width="wrap_content"
4 A6 u  g/ J6 F                android:layout_height="wrap_content"
% v3 \! T: N# p" C0 `3 Y                android:text="速度:"
) N( [1 W% `9 O! ^- B. Y* ]! [3 i                android:textColor="@color/white"
$ ^  A3 H, W2 c0 U                android:layout_marginLeft="10dp"; L  Z4 {& D& K, D, @
                >TextView>
  F9 w. ^0 y/ L+ Q9 ]5 g            TextView
8 T9 b) p" L0 q- |0 V                android:id="@+id/tv_count"
+ \. U* {$ e$ X+ j+ E# e* P' |4 Q                android:layout_width="wrap_content"% U/ P. ?  |+ ^- @. D$ z6 U  e" A
                android:layout_height="wrap_content"" [2 a- H8 `! z+ ^* m  s: V
                android:text="航点数:"
) S% A& _4 E: e5 `5 L2 h' A8 ?                android:textColor="@color/white"# ?! u6 U8 u* K
                android:layout_marginLeft="10dp"
* Y- Y7 M0 t2 c3 y                >TextView>
+ U& `  n' r) z            TextView
" e2 H+ y" B: F, e* \/ d; u                android:id="@+id/tv_distance"! @  T3 {$ W' Q8 I/ H+ f
                android:layout_width="wrap_content"
" ?  s: z4 k; q) p+ Q, f" H                android:layout_height="wrap_content", X, \3 \0 a: i
                android:text="总距离:"
, @& }6 x& U4 a1 o                android:textColor="@color/white"
! n6 q: p0 z2 Y6 Q2 r                android:layout_marginLeft="10dp"2 l9 z4 C8 b" w& u
                >TextView>
' v5 q0 ^: ^/ l' Z            TextView
# a9 X2 Q, h7 X' ]6 L                android:id="@+id/tv_time"" \4 K5 I5 n& W
                android:layout_width="wrap_content"
5 o" h9 }) E) O6 g) c                android:layout_height="wrap_content", L- J  ^2 Z: K0 l$ v( F4 F
                android:text="总时间:"
7 D: ?. a4 F% V9 b) r                android:textColor="@color/white"
& B( e* h0 N  H( W9 a                android:layout_marginLeft="10dp"$ n, s0 a. Y) Z0 W, o9 A
                >TextView>
5 H3 L& A% F0 E4 I% m        LinearLayout>
  i& @4 f! @& k+ V    RelativeLayout>
) A" ?; v  ~0 a0 b2 eLinearLayout>
) N# V* G6 O9 H3 vSettingRouteActivity
  S9 @% E& ^5 w; i# j3 s/ ]6 ~3 j5 \9 }7 c" |, n" N
public class SettingRouteActivity extends BaseActivity implements AMap.OnMarkerClickListener, View.OnClickListener, AMap.OnMapClickListener, LocationSource, AMapLocationListener, AMap.InfoWindowAdapter {
6 M# @' b5 }) @3 I2 L- j: j    @BindView(R.id.layout_route)' q/ h. f* X! F/ ~3 W% d( V/ r. s
        View mViewLayoutToolbar;
. Z$ o$ e# y) a2 \        @BindView(R.id.ll_route)
. T% H( v, a: i# ~5 C        LinearLayout mLinearLayout;
5 L3 B$ ^& a  u8 y5 J2 |! {* R        @BindView(R.id.tv_toolbar_title)! ~" o. X0 N4 H! a
        TextView mTextViewToolbarTitle;
5 L# S6 s) [- ]' R7 ]/ Z    //    @BindView(R.id.map)
$ R0 e# k) g% Z( y# x6 z1 w0 o    //    MapView mMapView;0 ]) D$ a4 ]+ a, F2 h3 Q+ c! Y
        @BindView(R.id.btn_delete)
2 }- n. \/ T7 \6 e        Button mButtonDelete;
3 b& V; H7 h" ?        @BindView(R.id.btn_finish)2 Y# |2 P7 R5 x/ g" ?' b% h* R5 M
        Button mButtonFinish;( |* ]& _" \3 m9 _0 z. B
        @BindView(R.id.btn_setting)
3 D# y! E. J+ T! S/ H! D2 u        Button mButtonSetting;
# v4 \5 t, Z; g$ c# N. B& e        @BindView(R.id.btn_upload)
- W1 J$ w5 ]% ?, t; M& x        Button mButtonUpload;
! F( |$ g4 p7 @6 Y        @BindView(R.id.btn_start)
2 r# ]0 n" [5 E* w9 G        Button mButtonStart;' i/ I( C6 u2 ?9 N" _/ x1 e
        @BindView(R.id.btn_stop)8 I- f5 n) r  w. U; U2 H- n
        Button mButtonStop;% J5 H0 @; c; b) R6 D% m
        @BindView(R.id.ll_information)
$ y8 t) j9 o* T        LinearLayout mLinearLayoutInformation;+ r" P6 e  X2 m; h5 e
        @BindView(R.id.tv_height)7 ^3 W2 e$ K- ?" S. i3 ^
        TextView mTextViewHeight;: ~3 n. T. I4 w3 x2 d9 V
        @BindView(R.id.tv_speed)5 F. Y/ d1 i9 S" M( l
        TextView mTextViewSpeed;
  b5 m$ O2 P# {5 ~; J2 `5 n4 t1 S3 j        @BindView(R.id.tv_count)
2 N. |" A; s) f* P        TextView mTextViewCount;; j; P. B: k# }% d9 T: q# i
        @BindView(R.id.tv_distance)) x' O+ J5 e$ Q+ [2 h9 c6 U2 J" c
        TextView mTextViewDistance;
( \- I  n# s. n( L        @BindView(R.id.tv_time)
2 [' p( s0 C8 c0 G# m& k2 b        TextView mTextViewTime;4 b8 ?" [- S6 [6 E: m" w( n4 _
        private MapView mMapView;
" p& Z6 n( U' P        private OnLocationChangedListener mListener;
- m" q- j( y# V; R& G* w! _        private AMapLocationClient mlocationClient;3 K+ f4 ]" b1 B) q* W9 X+ Q
        private AMapLocationClientOption mLocationOption;* j( c9 C7 [# ]* n2 Z2 J' p
        private double D_latitude, D_longitude;
/ b" M. M% y  t  Y( m0 m, F        private UiSettings mUiSettings;; D$ g, D6 T6 j: E% J6 V
        private AMap aMap;& T) W( B3 S' A% v
        private Marker droneMarker = null;
2 q+ m3 p/ g( @; H        private float altitude = 100.0f;% I6 ~! ?( A4 }6 c9 }; A
        private float mSpeed = 10.0f;
1 b- P% X6 }/ m' W/ }1 H; p        private boolean isAdd = false;
; ?( c3 H, g9 P9 F        private final Map[I] mMarkers = new ConcurrentHashMap[I]();% U6 I( w# U) o+ ~! u
        private Marker mClickMarker;% G6 {4 P' P2 Q7 z8 o3 K) w& f
        private List waypointList = new ArrayList();
' y/ U* s+ W* B3 H        private List mLatLng = new ArrayList();# }" R: K/ s% E, S4 D
        private List mPointInfo = new ArrayList();
$ ?# r3 c1 c# o; H8 J        public static WaypointMission.Builder waypointMissionBuilder;8 Q1 s- o( z2 M" Z$ y0 {- z
        private FlightController mFlightController;
, p5 u- ^: G! ^0 J! W        private WaypointMissionOperator instance;
6 c2 d- ~( ~6 r9 j        private WaypointMissionFinishedAction mFinishedAction = WaypointMissionFinishedAction.NO_ACTION;
" {4 s3 A8 t8 M; L" x0 _9 L        private WaypointMissionHeadingMode mHeadingMode = WaypointMissionHeadingMode.AUTO;
( {# x5 t7 M* Y$ d9 i" d        private SQLiteHelper mSQLiteHelper;) B0 O7 @+ t  Z. w8 i$ h
        private String FinishedAction, HeadingMode;, d4 t' H) q/ h$ a# G2 X6 d
        //自定义窗体! O6 Q- C2 ?$ W! |9 Y0 A
        View infoWindow = null;! A3 s' }- [" E7 _0 q0 ]! Y0 B" Y
        int speed_RG_id = 0;
( L3 L7 ?' I7 }$ t8 X! n        int actionAfterFinished_RG_id = 0;" b. b6 q. c2 P1 @$ u, d0 M( b
        int heading_RG_id = 0;" r& \' ~7 \. ~  i4 c
        //kim
3 w0 `6 q0 h9 f8 `4 v        static ReadKml readKml = new ReadKml();+ \$ A0 k' [8 ^2 V: H; R1 ~4 S
        private static List sampleList = readKml.getCoordinateList();" j/ N( j, N$ t) a
        @Override2 W; Z5 l+ R6 r! ^6 I; j: K
        public void initViews() {; g0 c- T$ L. i6 J* T
            mLinearLayout.setVisibility(View.VISIBLE);' K$ q' g, x# L6 B% x. E
            mTextViewToolbarTitle.setText("航线规划");0 n( v3 m" Z; F8 \! e* g3 a
            IntentFilter filter = new IntentFilter();) D, f7 V3 T, I% C- B) r
            filter.addAction(ReceiverApplication.FLAG_CONNECTION_CHANGE);
& J  k2 e# o' c: N% M- t            registerReceiver(mReceiver, filter);6 B8 q" {7 ~) H- T
            mMapView = findViewById(R.id.map);
2 i0 q8 Y* g& w1 X5 {7 t            mMapView.onCreate(InstanceState);
9 [2 J4 r) |5 d' B2 F6 j5 \            initMapView();9 v6 D9 e7 ?. ?4 I
            addListener();
. T$ B- ]5 {% g* E, w5 x7 ~0 M% _            onProductConnectionChange();
" V$ ]+ Q; t  W- y' F) r        }
& i- Q' w& N, B0 m! i        @Override
9 T0 i, D1 M8 H2 P% }8 g- A        protected void onResume() {9 G+ H6 H  F' c, R7 J( x
            super.onResume();) c( M3 s' Z9 f- t9 v
            initFlightController();
* T" g1 M6 X6 A# P4 h            mMapView.onResume();9 t+ a) H2 b+ U. x" s
        }1 I( L9 K! J: {7 G/ I
        /**
" ^5 G, e3 @! i: E4 O         * 方法必须重写9 F7 W* X! h) \  f
         */2 N, G4 Z1 K4 V; e7 S3 a; g
        @Override
( S7 J3 `& T& g. i. v+ Y7 j        protected void onSaveInstanceState(Bundle outState) {% W( K$ ?8 w! i! c+ x/ l! c/ B
            super.onSaveInstanceState(outState);
% r: n+ i  p; s5 R3 [( F            mMapView.onSaveInstanceState(outState);! r% K1 V7 _4 S5 b- F4 ?
        }! L; }1 P/ u( ?# E
        @Override
; }( ?0 b9 }# G        protected void onPause() {. \. L0 ]0 {5 e' B' d; k
            super.onPause();' O9 w' P8 D. B/ e3 V) y
            mMapView.onPause();
) i* L. p+ T0 L6 s8 |6 a! K            deactivate();5 a7 R" g, \) e" k
        }
; x* S! M" s$ @: d- u% W2 T' Q        @Override
/ `& t+ c. Y/ n8 i) H' O: L        protected void onDestroy() {
2 n# A9 G. t8 q9 Q            super.onDestroy();
8 F4 ~7 t; S6 G' ]            unregisterReceiver(mReceiver);
' V* ~$ ?$ K" n" x, W            removeListener();% d% |$ y( M; k% h& ]& |. Q" F
            mMapView.onDestroy();8 G4 |) f* [% e' p! h
            if (null != mlocationClient) {
( w7 V1 R. ^. p- o. W- g                mlocationClient.onDestroy();1 \  f/ |& n. d
            }
0 H0 M* [' Y* m  T0 [        }
' k) B9 M6 C* w: B, U3 o$ N        @Override; k# [( U2 ~9 n7 I
        public void initDatas() {
! O; W) ~, M/ \& j0 W        }
' K( j" j5 Q' J4 [! E$ T# \        @Override
' c' U& I/ F% M1 L        protected void requestData() {
# k% T0 N& @3 E8 g5 k        }# |6 K9 h# V9 \5 E$ z3 T  x
        private void initMapView() {
3 R! ?+ u9 K5 d2 Z: e, Y            if (aMap == null) {7 Y5 n& B9 q6 J0 ^3 w
                aMap = mMapView.getMap();, s! x# e% n4 s3 e0 b
                mUiSettings = aMap.getUiSettings();4 g+ s8 C2 @1 U# l6 O
                mUiSettings.setMyLocationButtonEnabled(true);
  m0 ]# [9 ~$ a                mUiSettings.setScaleControlsEnabled(true);$ k# Y) J$ P& B
                aMap.setOnMapClickListener(this);// add the listener for click for amap object
( E2 r/ Z0 B/ w$ F  D6 o/ q! ^                aMap.setLocationSource(this);) a' i. l5 C. ?0 [
                aMap.setMyLocationEnabled(true);; S( @* F- p- _4 o7 S# z$ D
                aMap.setInfoWindowAdapter(this);  |& t; r8 E, u
                aMap.setOnMarkerClickListener(this);/ \+ u. P2 t9 o0 ~1 {1 V
                setupLocationStyle();! i7 Q5 Q. J; R5 f
            }
8 I. p' q( {3 i! o( j+ j" {2 `        }& V2 @, Y$ W5 N6 {( q: ?; k
        private void setupLocationStyle() {
! W% F/ G* e# g3 C0 v# P            // 自定义系统定位蓝点
3 m' Y% d$ _, q% y2 t( |" U& h            MyLocationStyle myLocationStyle = new MyLocationStyle();
# j( h2 ^- J2 ~$ @            // 自定义定位蓝点图标, l& E$ E$ k8 H! w* Y% V
            myLocationStyle.myLocationIcon(BitmapDescriptorFactory.
6 A! _7 M3 u# k5 t. Q/ j                    fromResource(R.mipmap.icv_gps_point_36dp));
" V2 |; d6 w" p$ B, Y4 w9 S2 W            // 自定义精度范围的圆形边框颜色
4 ^6 T# c; [6 S/ J$ W+ V            myLocationStyle.strokeColor(Color.parseColor("#00000000"));2 V, t# J* [% h* C  H
            //自定义精度范围的圆形边框宽度1 x" ^+ c+ b# \4 t( N- R. u
            myLocationStyle.strokeWidth(5);, {# o. M6 M) f  a% j- E
            // 设置圆形的填充颜色/ L9 v! a( f2 ^. i' X
            myLocationStyle.radiusFillColor(Color.parseColor("#00000000"));+ G+ R: K8 t" Z( v
            // 将自定义的 myLocationStyle 对象添加到地图上
* E5 L! l1 t4 E. E' P' j; e            aMap.setMyLocationStyle(myLocationStyle);3 Q( t6 Z  z5 [/ e8 M+ V- m$ V
        }# h# M" A2 Y0 ?+ E
        @OnClick({R.id.img_kml_input, R.id.img_setting_route, R.id.img_start_fly, R.id.btn_delete,
2 V) P( W9 d6 K, z3 v6 [7 d                R.id.img_setting_clear, R.id.btn_finish, R.id.btn_setting, R.id.btn_upload,
8 K: F' Y4 d+ F( ?) ~; K( u                R.id.btn_start, R.id.btn_stop, R.id.img_back})
' w9 d3 t/ d/ C. E" V- `3 H6 f& v  T        @Override- T; A4 m! _' z1 V5 N+ r! m
        public void onClick(View v) {8 p' E' R7 S% x+ s! D
            switch (v.getId()) {
) F! ?) n1 l! h5 P/ q5 k+ N* |2 [                case R.id.img_back:
, R! W( L6 U: p: C2 y                    SettingRouteActivity.this.finish();# e* o% P- ]0 x9 F
                    break;
4 N  R3 N( Y/ K( A4 [0 l; z                case R.id.img_kml_input:& X) L/ ]% i! `+ R; l8 i0 G5 J
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);1 |- X, ^' L$ o3 q
                    intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
4 O; U' }; B+ A1 g( s& M, I: I                    intent.addCategory(Intent.CATEGORY_OPENABLE);
6 T" m9 S* n) R: m  ]- [6 A! M, F                    startActivityForResult(intent, MyStatic.REQUEST_CODE_FILE);
& D% U) z$ o4 ^: b                    break;4 i, o8 Y: w$ d: u& E
                case R.id.img_setting_route:
3 t. ~, b) j8 J6 S2 c                    enableDisableAdd();2 H7 n. l" T0 f3 I, m( X3 ^* O
                    break;
) X3 v$ }. M; {                case R.id.img_setting_clear:  e  c# }/ ~) B0 u8 Z
                    runOnUiThread(new Runnable() {" j" D: W, q4 e" N5 {( j
                        @Override
2 W* e' C8 i: T* E3 t+ J% C* \                        public void run() {5 |7 a8 S9 g: Y* }; ^) P
                            aMap.clear();8 t: F( I( h  t, C. M
                            mMarkers.clear();
$ A& R( c1 L: j- e$ Z                            mPointInfo.clear();6 l$ z0 ^; c6 v$ I' ?
                            mLinearLayoutInformation.setVisibility(View.GONE);- O- G; }  c8 o7 |+ M0 B! e
                            mButtonFinish.setVisibility(View.GONE);2 n1 c/ z4 c5 Y( m5 S  ]' S
                            mButtonSetting.setVisibility(View.GONE);' b5 j) T/ g+ I, `" l
                            mButtonUpload.setVisibility(View.GONE);5 Y4 ^( }# @/ S$ d+ G5 u( O$ W2 @
                            mButtonStart.setVisibility(View.GONE);
8 b1 u; L: x% u: {1 J2 n' ]& K' P                            mButtonStop.setVisibility(View.GONE);
! t8 V5 O+ a1 o4 B                        }9 P3 T2 f* @& p, n
                    });
1 }) H2 n4 P/ }0 b/ x' ~                    waypointList.clear();4 ^# n; t9 A4 x  s! f
                    waypointMissionBuilder.waypointList(waypointList);6 `1 ?/ R9 A& z, y- e
                    break;
$ t% z: T0 ]) I) I                case R.id.img_start_fly:
3 d: L3 n5 [& D% j                    atyAction(WaypointActivity.class, MyStatic.REQUEST_CODE_ID);
2 L7 J* @% J0 I) a6 V- f, M' T                    break;8 t; S1 ~4 \3 S+ E) D
                case R.id.btn_delete:
5 Z9 D6 I1 `6 _7 `                    runOnUiThread(new Runnable() {
. d/ X, h3 U/ }" k. F3 s5 c, L                        @Override
  X7 e7 p4 Q3 Q) y0 Z                        public void run() {7 n7 ]3 d* x7 M' @( t4 D5 K
                            aMap.clear();
0 |! R3 g( S: S. X+ T  `$ g                        }
- U. u( w1 \5 o9 z/ y. ]                    });  @+ w0 b1 S6 v( s: l
                    for (int i = 0; i if (mMarkers.get(i).getTitle().equals(mClickMarker.getTitle())) {; y, L9 Z" l# }
                            for (int j = i; j 1; j++) {
! I- z% e& k# F$ D9 J                                mMarkers.put(j, mMarkers.get(j + 1));
5 v( J: [2 ^0 m! d. O6 Q9 b" D7 W                            }
0 D0 q( j& p! W0 E                            mMarkers.remove(mMarkers.size() - 1);3 m9 L- g; j/ T& y6 j6 Z) \9 i3 p
                        }9 i- s3 O7 k" g- I* w" Q
                    }, C5 b7 v9 s0 Z% Z/ c
                    for (int i = 0; i "航点" + (i + 1));0 y9 T1 u& h/ L6 M) _: t* \
                    }8 l( b7 v. N- M
                    updateMarkWaypoint();
7 j  Z  B: ^5 ~( O" v( u                    break;
7 ?1 C% f; e4 S4 j                case R.id.btn_finish:/ v( j  u* O" `/ n
                    MyLog.d("航点数:" + waypointMissionBuilder.getWaypointCount());% f3 D1 K7 W2 @! J/ T( }+ b: t9 B
                    MyLog.d("总距离:" + waypointMissionBuilder.calculateTotalDistance());& b4 ^6 M- n1 c; E. u$ @
                    MyLog.d("总时间:" + waypointMissionBuilder.calculateTotalTime());: `# \( w% B0 w, p
                    isAdd = false;- G" n6 s0 `" T
                    mButtonFinish.setVisibility(View.GONE);
' m, ?- X% d3 W6 u                    mButtonSetting.setVisibility(View.VISIBLE);! f) f% A, ^; U. j' o1 n. h
                    mButtonUpload.setVisibility(View.VISIBLE);
; I2 s( H* }( \4 f: W7 h                    showSettingDialog();
' M* c6 R- Z" Q+ r2 u; \- k% M                    break;
" N3 ?; a' a! N0 D                case R.id.btn_setting:
0 P2 C  V# f6 O! D                    showSettingDialog();
$ A0 _/ _# o- u# l: d                    break;2 _4 p2 p$ @$ }  s, R6 n
                case R.id.btn_upload:+ Z; h1 W% B1 `( w( ?& x! E
                    uploadWayPointMission();! ^$ B) X# g' h% i
                    break;
' G5 g6 L) O4 z                case R.id.btn_start:
& c2 h: U( l7 p% l                    startWaypointMission();! r7 O( `) O' d# ~
                    break;: x2 Y1 D) g' ?
                case R.id.btn_stop:+ @& S; ?% x/ a& o9 c3 u
                    stopWaypointMission();
8 |7 C: e' J# F' h                    break;$ h' {  Y+ T% p: @+ ]1 D! A$ e
            }
) H% L9 ~# I+ {5 p+ _        }6 p* N; P! S9 A
        private void enableDisableAdd() {
# ]9 q$ L0 L2 N% `  j            if (isAdd == false) {5 X+ e: k/ C, `/ ?; y9 f
                isAdd = true;' I8 K2 U7 V1 L( H
                mButtonFinish.setVisibility(View.VISIBLE);
3 u, [7 _0 j/ U# X9 s            } else {* O: N* x6 g3 k3 @2 ?# Q
                isAdd = false;
1 X4 z" X3 c+ h5 o            }
, E/ C7 Z: I6 A) H; b# ^$ Q  `        }/ P, [$ B/ Y1 F# H
        private void initFlightController() {, Y3 H! n: x; G4 q# y4 Q
            BaseProduct product = ReceiverApplication.getProductInstance();
: C9 c) |% O% Q& x9 O            if (product != null && product.isConnected()) {$ y9 E+ N8 v+ i  X7 n5 H
                if (product instanceof Aircraft) {! R8 Q# V+ b) j+ I
                    mFlightController = ((Aircraft) product).getFlightController();. p3 w* Z! [2 ?' R9 r
                }; K# \' K# x$ I: z+ Q3 K
            }
) O3 Y: ]% a; u8 o" d0 c( g+ {            if (mFlightController != null) {
# _- M. X# b+ P/ S0 G, o" u                mFlightController.setStateCallback(- K" `' c- D! L/ H8 h1 H, ^+ v
                        new FlightControllerState.Callback() {) K# m8 V9 ]& N
                            @Override
* ~. ]! G% [. H8 [$ |( Y7 i                            public void onUpdate(FlightControllerState( J; p2 ~. O4 B  w
                                                         djiFlightControllerCurrentState) {
2 Y% q* o- y" q7 g- o5 B                                if (djiFlightControllerCurrentState.getAircraftLocation().getLatitude() != 0.0 && djiFlightControllerCurrentState.getAircraftLocation().getLongitude() != 0.0) {0 [6 f" D9 ]8 k1 E8 @
                                    D_latitude = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();
2 ]9 i4 C7 R+ U- ^: m$ Q6 j                                    D_longitude = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();
' ?! y$ H- n; Q# J% q, n6 b                                }: m+ @' j4 E7 |' @) I1 C4 m
                                updateDroneLocation();
5 \, ?" S% o6 |! r) R: z4 b; V                            }8 a+ D- j& Y) |0 W
                        });
" X4 A9 b* }3 U& E/ R4 T+ b& N            }
' u! _9 h" D8 l! ^5 e        }
7 y$ A4 R7 m8 m/ z        private void updateDroneLocation() {& {5 S( Q& @, P+ U0 k' \9 V
            LatLng pos = new LatLng(D_latitude, D_longitude);
7 K+ `) w3 W! Y; G8 V" @            //Create MarkerOptions object6 e. N) J' G1 n0 l) K) ]+ h5 j
            final MarkerOptions markerOptions = new MarkerOptions();3 T- V  Q/ A) \2 U
            markerOptions.position(pos);/ I7 `3 u6 m& X
            markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_aircraft_write_36dp));
& b8 x& e$ s- B+ f$ F            runOnUiThread(new Runnable() {
4 Z9 @9 h0 c4 P& a5 H                @Override/ P/ ]& O$ |: D1 Q. F, g' Z% B) u
                public void run() {# v  ^6 r# F& f; Q
                    if (droneMarker != null) {7 R% J' V9 r3 k. W5 n
                        droneMarker.remove();
1 L! v& \3 S/ Y                    }/ [# G# Z$ Z6 T' z! j
                    if (checkGpsCoordination(D_latitude, D_longitude)) {9 @$ b4 Z0 e4 U& U1 Q- Y
                        droneMarker = aMap.addMarker(markerOptions);8 [9 l0 D! U7 ?  C6 |: m
                    }' `2 A7 ?/ |7 k4 k! v* \+ l" [) W7 p
                }' G! n- ^% i" G- [
            });
" y4 n1 p! u+ R8 C* @" _& A0 L6 P' h        }
7 Z7 W( _" J8 A  q' l1 z        public static boolean checkGpsCoordination(double latitude, double longitude) {
2 ?- G0 I6 g( b8 q5 `0 v* A            return (latitude > -90 && latitude 90 && longitude > -180 && longitude 180) && (latitude != 0f && longitude != 0f);8 D7 }/ ?- |7 \* Y% J# M
        }' o( _  q8 z  y- l. y
        protected BroadcastReceiver mReceiver = new BroadcastReceiver() {
& T7 q' N. l# \+ f            @Override
  S( G' W& S, e2 K; T            public void onReceive(Context context, Intent intent) {1 L9 \9 A- G: Y* F
                onProductConnectionChange();) C! b( y3 m) k4 {$ u
            }
0 \# ?/ V' {  g$ p( h0 F        };. V" M5 P. P0 r( q
        private void onProductConnectionChange() {
: d5 U( q. t) S+ f# @: e7 K# e) f2 {            initFlightController();
; g# M# v6 ~/ P4 j. Q  B! G        }
, h/ d7 r* G! a' q        private void addListener() {
# }& {: I2 o* I' f2 A& F. p            if (getWaypointMissionOperator() != null) {
6 m. L- ^- U" Y( A" q                getWaypointMissionOperator().addListener(eventNotificationListener);4 `8 Q9 H2 `$ F3 g3 E
            }
6 i& }* J6 Q  Z        }" t. C' z/ T& O. p, S
        private void removeListener() {  T6 l, y7 a" s# C% c* o' l. _. p
            if (getWaypointMissionOperator() != null) {& U$ N7 _# D) h4 x
                getWaypointMissionOperator().removeListener(eventNotificationListener);4 c9 ?' N  ?- [7 l3 X
            }
/ u9 x: g9 Q+ X& s" @& v        }
7 s: p# V' t+ D7 R) K6 R        private WaypointMissionOperatorListener eventNotificationListener = new WaypointMissionOperatorListener() {8 b/ B/ @" B- N9 c  ?/ {; M! y
            @Override/ j0 W. B% ]/ q5 F3 w1 C
            public void onDownloadUpdate(WaypointMissionDownloadEvent downloadEvent) {! V# ~" @. V; }7 M
            }
" ~! N& V+ g0 U; j& ]6 r* ~7 l            @Override8 G: V7 L, t8 h! Z. ?2 }; Z/ z% l
            public void onUploadUpdate(WaypointMissionUploadEvent uploadEvent) {
8 f* }+ ~2 L9 b4 X' B            }
4 s! l7 G9 K9 N9 M& u+ V2 p: t            @Override$ a" V: P# ?. Y0 D( H6 S
            public void onExecutionUpdate(WaypointMissionExecutionEvent executionEvent) {1 x1 ~5 I) \. h" B
            }& H# P5 Q7 a' B! f
            @Override& u1 _5 r' _9 ^  H- `/ z9 E2 e
            public void onExecutionStart() {+ l: T) [* r1 l
            }
; i5 [/ d, E0 U. F            @Override
0 d$ x: `; w+ f/ O: g) z. P( z            public void onExecutionFinish(@Nullable final DJIError error) {
) j9 g( I1 M. ~9 i) w                showToasts("Execution finished: " + (error == null ? "Success!" : error.getDescription()));* J7 m- s5 A$ O2 H* Q0 @
            }  B: C- W5 k& ^) f
        };
1 @1 d2 H# _  F# n        public WaypointMissionOperator getWaypointMissionOperator() {, }2 ~' Z2 c* @% s, z
            if (instance == null) {
  ]/ f9 ]$ G# Q& k" C: `                instance = DJISDKManager.getInstance().getMissionControl().getWaypointMissionOperator();" {8 ^, N) P, A% V+ m
            }. X. Q2 d. O* y& \/ Y
            return instance;/ q, a) Y) }0 e5 Y( ?
        }$ M0 T# p; N. L+ t
        @Override
/ K1 w# O7 _  D+ l! c" O        public void onMapClick(LatLng point) {( @" N% p+ D) g* Y
            if (isAdd == true) {
5 S/ N3 ~# V' y0 j9 ~! l, i                markWaypoint(point);$ T% Q0 d+ e8 b, Z4 d  ?
                Waypoint mWaypoint = new Waypoint(point.latitude, point.longitude, altitude);, E5 l& _5 R! P4 Z
                //Add Waypoints to Waypoint arraylist;. N, }8 n5 i0 `& Z# c
                if (waypointMissionBuilder != null) {
4 K" L' [  W7 F( G7 }" v                    waypointList.add(mWaypoint);
9 y4 L4 G. ~( N- k                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());8 }) d+ @' a* y
                } else {
; G. f  j7 j9 X- |# K- s7 _6 s                    waypointMissionBuilder = new WaypointMission.Builder();
" d" k! |3 y7 Z# h6 @                    waypointList.add(mWaypoint);' A# R( F! M  X  C' e2 l" s
                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());2 \2 ]: ^, `# u  O0 _# Y+ f0 H
                }
1 ?: h" U8 p8 ~3 f                mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());* E, ^+ m/ x0 q2 l
                mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");
: E. e/ x" C0 G                mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");
5 N2 t( p9 d; w/ A3 ^            } else {$ C- ~/ }+ G  {% f
                if (mClickMarker != null && mClickMarker.isInfoWindowShown()) {6 b! O5 i6 c2 p
                    mClickMarker.hideInfoWindow();: {" b5 s1 p, P; K% t, `) P: j
                    mButtonDelete.setVisibility(View.GONE);
* H$ j$ l* R9 W  b' ^" v                }
. ]3 z4 F  f- @4 g; b# v                //            showToasts("当前未开启增加点模式");
2 Q* B( _' I; V  l! o; f            }
4 L- }) |, i1 U) E/ t, V        }
  o: |* }1 B8 W1 r        private void markWaypoint(LatLng point) {
7 f$ M; |: {' J* G5 e            MarkerOptions markerOptions = new MarkerOptions();3 M. K7 ?5 X: V3 q# R1 R
            markerOptions.position(point);6 e0 F4 m, e- D4 T
            mPointInfo.add(new PointInfo(point.latitude, point.longitude));
8 ]  q) Q8 @0 W' E6 |            markerOptions.title("航点" + (mMarkers.size() + 1));
. p+ p& Y! Q3 c" Y            markerOptions.snippet("事件:");3 L* g! ~! v6 B& f3 T4 U/ U( E
            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));' ^2 ]  i( p2 |
            markerOptions.infoWindowEnable(true);. k/ N: o* g3 ~2 W
            Marker marker = aMap.addMarker(markerOptions);
- e, o% e6 t/ `- S            mMarkers.put(mMarkers.size(), marker);
& l) d( p! }2 A; R            marker.showInfoWindow();& z' \9 M3 c! r; T0 V; O3 C
            if (mMarkers.size() > 0) {8 G# X( i1 W( W+ m
                mLatLng.clear();' m4 M0 F: e2 q
                PolylineOptions PolylineOptions = new PolylineOptions();: R' q; _( S# V) W% m7 x* B
                for (int i = 0; i 10);0 V4 K" [) j7 V5 H1 F$ d
                PolylineOptions.color(Color.argb(255, 1, 1, 1));4 W  J  u2 t% n% z0 l% r! M0 c+ x
                aMap.addPolyline(PolylineOptions);0 A0 M+ V# B3 L. D# \
            }" n4 f2 Z2 C2 i1 u6 Z$ d6 h
        }( c2 @0 |5 f$ h  _/ }0 @
        private void updateMarkWaypoint() {
7 ?4 c, _; g* @3 w/ C: K5 _            mLatLng.clear();/ K9 v: m& Z5 F% e( X; M. z
            waypointList.clear();  O& y/ S7 {, n9 n& `' ~$ ]8 k
            mPointInfo.clear();. N3 I  M) p# w) Q( v9 m5 c! R
            waypointMissionBuilder.waypointList(waypointList);
7 I! v# ~6 i0 E* Y3 {- o8 C- P            for (int i = 0; i new PointInfo(mMarkers.get(i).getPosition().latitude, mMarkers.get(i).getPosition().longitude));
$ T; O; U  [1 j- J0 n1 j6 C                MarkerOptions markerOptions = new MarkerOptions();
+ O5 p8 y! G( U                Waypoint mWaypoint = new Waypoint(mMarkers.get(i).getPosition().latitude, mMarkers.get(i).getPosition().longitude, altitude);) S- q! ~0 B3 v* A( D
                waypointList.add(mWaypoint);/ H4 Q8 J  K* ?, t" w( L
                markerOptions.position(mMarkers.get(i).getPosition());0 U% S$ s, a' u
                markerOptions.title(mMarkers.get(i).getTitle());
: V8 j, ]% J* g3 ~3 `$ x. U( J                markerOptions.snippet(mMarkers.get(i).getSnippet());
0 M0 A. Z5 p* b                markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
3 v- z( L, h) z" ~5 \" p                aMap.addMarker(markerOptions);% t/ k* Q4 Y7 ]* P5 x
                mLatLng.add(mMarkers.get(i).getPosition());  A6 B0 m% G8 f6 H$ i* U$ k- h% o
            }$ C/ l3 Y7 ?1 G4 E4 t- o
            if (mMarkers.size() > 0) {
) \4 M0 `% y# v/ \                PolylineOptions PolylineOptions = new PolylineOptions();
- f; `  [8 c0 |: n8 m                PolylineOptions.addAll(mLatLng);
- [& S& q# ?- c# n2 t* _$ b/ a  `                PolylineOptions.width(10);: f# d3 x9 Z+ u8 o* H& j
                PolylineOptions.color(Color.argb(255, 1, 1, 1));
( o9 {, z# z5 c# ]) }                aMap.addPolyline(PolylineOptions);
# c6 v* ~2 O9 p            }1 P% w( p. i/ J6 k
            waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());. ?9 c, U; @- R: G: k' H
            mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());
! e- B; H. ^$ \- y. b% m! t$ u            mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");
' F! \) z4 t9 y& ?& [# A" l            mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");
/ E0 p  c, P8 H; q9 x; [            MyLog.d("航点数:" + waypointMissionBuilder.getWaypointCount());
! Q0 I" F9 g( b, G- C  u5 ~/ ?            MyLog.d("总距离:" + waypointMissionBuilder.calculateTotalDistance());; Z& f  ^3 y* g  R& N
            MyLog.d("总时间:" + waypointMissionBuilder.calculateTotalTime());5 T# K" F1 |$ Z  _% e
            mButtonDelete.setVisibility(View.GONE);
2 C7 M% m6 K) }) x) h+ \        }
6 W: }. b$ q+ k2 @0 _$ _8 h/ S. C1 K0 E) A
        /**
; Q1 n* D6 a8 A) y         * 定位成功后回调函数
. u* m  e5 w1 L3 f( q9 T' K         */- r$ A( Q+ }# i8 B. R
        @Override
1 @+ S! l, k% p' {/ X5 d        public void onLocationChanged(AMapLocation amapLocation) {
+ _* t3 s* W$ D& H            if (mListener != null && amapLocation != null) {
7 i7 A3 Z  [: J! C/ _                if (amapLocation != null
# _; ^2 Q7 }: o2 q( z: O1 I                        && amapLocation.getErrorCode() == 0) {6 }: C, I$ |2 B4 ^4 t9 q) s
                    D_latitude = amapLocation.getLatitude(); //获取纬度
: g; d7 i( L. R' n, y# F: |0 Y! D                    D_longitude = amapLocation.getLongitude(); //获取经度
0 `+ C. _8 c# H6 d) e                    mListener.onLocationChanged(amapLocation);// 显示系统小蓝点/ ], y1 y7 {: U- p; f% `
                    aMap.moveCamera(CameraUpdateFactory.zoomTo(18));
1 l: m: Z2 b; Y2 J3 {                } else {0 O0 y- p1 a% }% ]9 y' e% e) v
                    String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();2 j6 p* M* F! J. S! M& F. ~7 E
                    Log.e("AmapErr", errText);
: u3 i7 l* i* K7 `                }
/ Y+ L; r$ Y7 k- Z            }3 a5 e4 X0 h( v6 H
        }9 m! s! v, A2 V, O7 T5 B. D, m6 C
        @Override$ N5 q# r3 C& I: u
        public void activate(OnLocationChangedListener listener) {+ V3 e) {8 y% J
            mListener = listener;
* H( W( D( F% c2 A# N0 M* Q            if (mlocationClient == null) {
( @% N9 d: N8 v6 f                try {
, x. S4 H) z2 b+ M' \                    mlocationClient = new AMapLocationClient(this);2 F+ v# R1 j  ?/ \, E4 t
                } catch (Exception e) {; F% }% o$ r2 @  S2 k9 O) G
                    e.printStackTrace();
6 j9 v8 ~( L0 _/ W- [: _3 r+ X                }
$ X+ r9 b/ |2 J5 \                mLocationOption = new AMapLocationClientOption();6 w7 l: j5 s3 ]" x% X9 R
                //设置定位监听: U. f& D/ ~: R% @5 U+ u) T
                mlocationClient.setLocationListener(this);
) g: Q- F, L; B' x                //设置为高精度定位模式0 [6 j' L) R& }" M
                mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);/ U" w( P' u& x5 x2 F' e, E- j
                //设置定位参数
( W+ m( @' Z* |) m                mLocationOption.setOnceLocation(true);
) k' T: w8 |. e# r- r# B. V6 I                mlocationClient.setLocationOption(mLocationOption);5 V1 k' }) z. L
                // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,7 v9 V$ W- a8 X/ a) W/ a. k
                // 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求( d5 ^  K; V4 h9 r
                // 在定位结束后,在合适的生命周期调用onDestroy()方法
5 Q/ s6 J& L; s9 H                // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
8 z+ X5 A! m% D5 r                mlocationClient.startLocation();
% v, m, N3 S# N            }
2 j3 i! i" j5 y1 `        }7 b# E" T* @& }: J* Y- |' U
        @Override( F# N+ ^% j8 ]' w8 B
        public void deactivate() {
6 d8 ^  Q8 }# Y7 B+ l4 T            mListener = null;  z7 c  v8 g# H2 }" T% a. a" E
            if (mlocationClient != null) {4 e1 W7 Z; v3 {4 \  r
                mlocationClient.stopLocation();8 c7 i, O2 z6 K
                mlocationClient.onDestroy();2 R/ N' G0 W6 @1 f$ `
            }* K3 n2 \/ K, k! H' x
            mlocationClient = null;
! [  r$ \4 R2 b0 e4 v        }) i" {4 [5 x( }8 I6 L) c
        @Override% U6 H* o. d) g! ^" E
        public View getInfoWindow(Marker marker) {/ d. ?4 l/ `! Y5 a3 C% K
            if (infoWindow == null) {
( j: [! o8 a1 G' w) N! @$ ]( E                infoWindow = LayoutInflater.from(this).inflate(R.layout.amap_info_window, null);' p6 x6 T8 x) W
            }- g3 i3 J1 m3 Q9 \7 a6 C! Q
            render(marker, infoWindow);
! B0 e+ n, M3 O4 y1 V/ E7 e+ o            return infoWindow;
; C9 x. {* |* p& z; J        }% O8 O- y) g' j& d) y
        /**
! f5 Y4 l$ b- V4 p( M' K; b         * 自定义infoWindow窗口! H% ^9 ?  ~5 `! b- C. {; y
         */; c* _- ]$ Z4 Z1 J" |" }
        private void render(Marker marker, View infoWindow) {7 \9 x% Q: i" U0 X% x  @; d
            TextView title = infoWindow.findViewById(R.id.info_window_title);
$ k9 B! }! Y" F3 \2 |            TextView content = infoWindow.findViewById(R.id.info_window_content);
7 E2 L* ]1 G; U: A            title.setText(marker.getTitle());5 Q  \+ B* A9 I$ S7 f
            content.setText(marker.getSnippet());; X" o4 {% |: ^% y- Z8 G3 h& H4 T
        }
6 E& \) {% e' v7 i5 {( M
+ s, O/ v1 ^2 m! D: j% h        @Override
2 t" v1 N& G& H) q0 P' e$ |0 h5 p        public View getInfoContents(Marker marker) {8 X6 d4 X+ G! B9 {
            return null;9 _% k6 ?1 A9 p
        }6 A: m5 u" d2 n& p4 s
        @Override) K+ s+ R4 ^' _
        public boolean onMarkerClick(Marker marker) {
1 N2 _, m0 L$ D+ }0 M2 V7 Y            marker.showInfoWindow();! L4 D/ I; a8 Z$ N) @2 D; t/ R
            mClickMarker = marker;
7 k: y% k9 y+ H( e, L            mButtonDelete.setVisibility(View.VISIBLE);
3 ]$ Z& m4 f9 q) k( m: X            //        aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(marker.getPosition(),18,0,0)));7 R4 b! x, w6 Q+ ^$ ~/ z/ _
            return true;" T! j4 Y/ `) R# K  e+ J3 @
        }& D8 t- N# K+ H
        private void showSettingDialog() {2 N- k  u/ Y7 d; F. C
            LinearLayout wayPointSettings = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_waypointsetting, null);
; J* c9 k0 T6 v4 T            final TextView wpAltitude_TV = (TextView) wayPointSettings.findViewById(R.id.altitude);9 Y( E+ @  M9 `( K: W& i
            RadioGroup speed_RG = (RadioGroup) wayPointSettings.findViewById(R.id.speed);
+ L3 [8 l' B; V; \            RadioGroup actionAfterFinished_RG = (RadioGroup) wayPointSettings.findViewById(R.id.actionAfterFinished);
8 h1 p2 X  F9 x            RadioGroup heading_RG = (RadioGroup) wayPointSettings.findViewById(R.id.heading);
8 W5 a: \1 l: U, K1 D# o            wpAltitude_TV.setText(Math.round(altitude) + "");
- [( C6 z/ }6 t1 O; u) j( a0 {9 [            if (speed_RG_id != 0) {
# c8 K  K: D2 J3 R                RadioButton radioButton = (RadioButton) speed_RG.findViewById(speed_RG_id);4 u+ }8 R! q; B' u% M
                radioButton.setChecked(true);
6 m- I+ M; P3 w            }
5 t4 {# z* _0 ?            if (actionAfterFinished_RG_id != 0) {7 l" P6 w2 O1 A" |
                RadioButton radioButton = (RadioButton) actionAfterFinished_RG.findViewById(actionAfterFinished_RG_id);5 X5 t1 y' t6 f. _
                radioButton.setChecked(true);
1 _  K8 s* @. M7 p. x            }
" f9 x/ E  U! R. y' p" i# H            if (heading_RG_id != 0) {
" B, Z& m6 ]; I5 ]                RadioButton radioButton = (RadioButton) heading_RG.findViewById(heading_RG_id);5 v' D% ~  D6 X
                radioButton.setChecked(true);
( D/ C0 Q' _$ k( J' N            }
# F. v$ G" {: q% M8 r  [. W3 L. _            speed_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
0 p) Z/ z8 O, S8 K" H1 |                @Override) S3 W/ S+ z8 h, J* {
                public void onCheckedChanged(RadioGroup group, int checkedId) {8 Q5 X: \6 m& u  n
                    if (checkedId == R.id.lowSpeed) {4 _; F' j" G# z* D+ ~0 Z, n
                        mSpeed = 3.0f;  W0 e) E3 Z% W2 _0 [# l
                    } else if (checkedId == R.id.MidSpeed) {/ K. {4 ^4 }. u$ M1 W
                        mSpeed = 5.0f;2 m6 a0 ~' m7 Q0 ^5 H( w7 J
                    } else if (checkedId == R.id.HighSpeed) {7 l* U6 Q4 \% I7 v
                        mSpeed = 10.0f;4 M! }; t( c8 E
                    }. ^1 R, j& E$ z. `" p5 z
                    speed_RG_id = checkedId;+ k: X  @! `8 @% p3 q. d& U
                }9 F4 \$ p, s0 J2 v' \% K: J
            });
+ q, i: L2 r1 H. u3 b            actionAfterFinished_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {  \" i# M& u# C' _2 w+ l4 f  H% N
                @Override
/ p1 |, `, B: X! r                public void onCheckedChanged(RadioGroup group, int checkedId) {0 _, b7 ]) i3 J
                    MyLog.d("选择动作完成");5 h5 ~0 s! Z! j1 A
                    if (checkedId == R.id.finishNone) {
  I  d7 i* t, W5 n- s2 f5 K                        mFinishedAction = WaypointMissionFinishedAction.NO_ACTION;
( p" }! T0 A. X) t: ]8 Y                        FinishedAction = "0";
/ G) y8 v% `- L, t9 e                    } else if (checkedId == R.id.finishGoHome) {2 K" G2 v) ^# w# ~7 Y
                        mFinishedAction = WaypointMissionFinishedAction.GO_HOME;! ?- Z& P7 R: W$ k3 Q2 T2 U8 T
                        FinishedAction = "1";
3 T0 p9 G3 v. O" V  _4 `, X                    } else if (checkedId == R.id.finishAutoLanding) {
- c9 x5 W% e( J2 e                        mFinishedAction = WaypointMissionFinishedAction.AUTO_LAND;
/ [% Y: N% B, `3 S+ x2 }4 I( U' K                        FinishedAction = "2";2 r  c8 m, v4 u5 F
                    } else if (checkedId == R.id.finishToFirst) {9 r% w. ]* e* E
                        mFinishedAction = WaypointMissionFinishedAction.GO_FIRST_WAYPOINT;
2 h5 {9 M& Q/ t' B' ^: r7 c                        FinishedAction = "3";, c+ w: E& Z, t: p5 I' Y. c; j
                    }
! M: E: |& d" P9 m$ |                    actionAfterFinished_RG_id = checkedId;
8 H8 N, u- E8 F                }  j7 I  [; P3 Y
            });
8 _  ~" C- ?- P4 s            heading_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {; C7 m2 ^6 P1 X, k4 @
                @Override
3 U' q: i9 T: _* x, u. f5 i1 Z                public void onCheckedChanged(RadioGroup group, int checkedId) {
, ?6 i; j( @) J& p8 {                    MyLog.d("选择标题");$ t6 ~* u# }" N7 v. B3 _  z
                    if (checkedId == R.id.headingNext) {, j7 I2 O+ l! f# D% X
                        mHeadingMode = WaypointMissionHeadingMode.AUTO;  s- S1 i* u0 i4 [1 S6 G# u" Q
                        HeadingMode = "0";# r* O) D$ f: {- F- v( u1 s
                    } else if (checkedId == R.id.headingInitDirec) {
/ G8 h9 X7 E, A. J. K& h                        mHeadingMode = WaypointMissionHeadingMode.USING_INITIAL_DIRECTION;: M2 ]7 T6 U; b$ A( p, o6 v
                        HeadingMode = "1";4 e5 F( v* U7 j7 X; R- s( x4 {
                    } else if (checkedId == R.id.headingRC) {
$ k1 _" j2 [$ j' Y  ~                        mHeadingMode = WaypointMissionHeadingMode.CONTROL_BY_REMOTE_CONTROLLER;
! D4 c" m* ^5 ?5 Y                        HeadingMode = "2";
6 E, A# Q% G( j4 r                    } else if (checkedId == R.id.headingWP) {  s$ j8 |' G5 p9 n6 r% Q
                        mHeadingMode = WaypointMissionHeadingMode.USING_WAYPOINT_HEADING;, A! N9 T* c1 w$ S2 D1 ~: j/ g
                        HeadingMode = "3";
+ ^4 y1 x: M8 L" h3 B. p6 z6 e                    }7 A- L4 e- m; R! h, p1 o
                    heading_RG_id = checkedId;1 q1 M4 |# e6 d1 L. t8 U3 z2 y
                }5 k8 X1 \+ \8 M3 l
            });
- a" b& ]# N0 H: z+ _1 j            new AlertDialog.Builder(this)% r0 A0 R8 @, q6 Z. t4 i6 p
                    .setTitle("航点设置"): t' z( X# F7 B% E3 n
                    .setView(wayPointSettings); s0 h) C# H, s* Z; n% K. q' c3 l' n  X
                    .setNeutralButton("设置", new DialogInterface.OnClickListener() {% ~3 m* I" B3 {1 ]& T( e9 \! g
                        public void onClick(DialogInterface dialog, int id) {
9 `( K8 g. o: X, K. j- l2 k                            String altitudeString = wpAltitude_TV.getText().toString();
+ d* n9 i8 O) q5 t8 \4 ?                            altitude = Integer.parseInt(nulltoIntegerDefalt(altitudeString));; N& L, t9 W6 S# k1 {
                            MyLog.e("altitude " + altitude);; q+ r! P+ X' u+ B! s
                            MyLog.e("speed " + mSpeed);
( _+ _/ C. \  |7 K6 a, d                            MyLog.e("mFinishedAction " + mFinishedAction);: d! a0 g7 o9 m* [, i9 i9 R- I
                            MyLog.e("mHeadingMode " + mHeadingMode);' w# j5 _' ~7 r  a
                            configWayPointMission();7 l3 x: h" n' x3 h  j% C) N+ [3 [; v
                        }
# a2 ]& e1 c- P2 @* s3 l0 a! s) q+ c                    })+ ]' r" c/ A5 g8 s. X
                    .setCancelable(false)
% t0 C; T7 Q. V( H5 d                    .create()
9 N, [: V) V  |1 A+ ~9 R5 F8 K5 F                    .show();
8 B( A. T$ r7 X" U& i2 i        }
# n- @; x" I% K        String nulltoIntegerDefalt(String value) {) s2 I9 H- A$ J2 L+ f2 U: h: I
            if (!isIntValue(value))# {& L4 ]; a$ _0 W3 p6 `
                value = "0";$ Y& g! M. q. T& g$ ]0 Y4 q& v) p& D
            return value;
2 m4 w* O* ?. G% e- }        }: \& J( |, }2 R) z3 C( u2 N
        boolean isIntValue(String val) {
8 p8 d+ z2 j4 \+ f0 @" A            try {
5 S1 w5 _. h9 S0 u  n* x3 y5 [                val = val.replace(" ", "");$ `( ~4 C( P1 K
                Integer.parseInt(val);
9 n$ P0 F  }8 u9 F7 n            } catch (Exception e) {' @! h0 v' b' G
                return false;
) [) {( Q. |- Y( g7 N. }" ?1 \            }
+ L' G8 e1 k6 j7 {6 S- c2 A            return true;$ K8 q' n* o9 H3 e
        }
2 N) w5 o+ Y% ^( X        private void configWayPointMission() {
& e6 x, q: V  C            if (waypointMissionBuilder == null) {
6 a' G$ S6 n, v9 f: J% y6 R5 s8 B                waypointMissionBuilder = new WaypointMission.Builder().finishedAction(mFinishedAction)
/ j5 B/ @. o8 b                        .headingMode(mHeadingMode)
, U/ u) p: J+ y! `9 E0 d                        .autoFlightSpeed(mSpeed)& S# p1 i- v- ^7 J! c$ K
                        .maxFlightSpeed(mSpeed)
2 x  w% F8 K  c                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);$ x1 \! D# l( D: X
            } else {
( A' |6 `1 |3 M$ g8 z" {, r                waypointMissionBuilder.finishedAction(mFinishedAction)
) I' g% X& c& v9 X                        .headingMode(mHeadingMode)
- g( b0 X2 Q* N                        .autoFlightSpeed(mSpeed)
5 U+ i( A6 T% [2 e- ~                        .maxFlightSpeed(mSpeed)
2 G4 B$ Z6 a2 A2 D8 }+ r, r                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);
$ C% f% S) H5 u+ t! g            }
- j& G  p& s( S2 |* S/ O0 x/ Q            if (waypointMissionBuilder.getWaypointList().size() > 0) {
( F. W6 y  }5 Y7 \. q                for (int i = 0; i if (error == null) {) K" l% X9 }3 H9 n+ z) j, l5 H2 Q
                if (mLinearLayoutInformation.getVisibility() == View.GONE) {
( I. I7 H* h8 M- L                    mLinearLayoutInformation.setVisibility(View.VISIBLE);& v' \1 @- e5 \; N
                }' ]$ t; m& M1 r" ^
                mTextViewHeight.setText("高度:" + altitude + "m");
+ J. }: c! T7 V" T% r                mTextViewSpeed.setText("速度:" + mSpeed + "m/s");
3 x" j% N) \& e1 m# g                mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());0 y0 B6 L/ M8 A- h& ^( w  o
                mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");& F5 j+ C4 ]) ^
                mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");% E# o4 K5 `. T: r% U- H6 ?  }
                MyLog.d("航点数:" + waypointMissionBuilder.getWaypointCount());; d  I. s! z& G- O3 z5 m4 J
                MyLog.d("总距离:" + waypointMissionBuilder.calculateTotalDistance());$ N& W9 y! b. z" ^6 z$ U3 ?$ @) J
                MyLog.d("总时间:" + waypointMissionBuilder.calculateTotalTime());' G) o7 z+ H$ u; q( ~
                showToasts("航路点配置成功");6 b- v  q+ P+ y0 e- p0 o
            } else {
5 e  S9 ]0 M* P- H9 x5 d, R/ @                showToasts("航路点配置失败 " + error.getDescription());
  |8 R+ B% s" l/ N            }3 R. P7 I" b3 d, W) d0 {6 Z
        }
2 c3 K( t3 }# N- d8 K- F$ x9 w9 n8 v/ f        private void uploadWayPointMission() {0 R& y5 ^6 c7 E7 v
            getWaypointMissionOperator().uploadMission(new CommonCallbacks.CompletionCallback() {5 R, h  G) z( p
                @Override' h! P' p: c6 U( F* Z; a8 Y
                public void onResult(DJIError error) {* p" s7 p+ _% B4 I. q8 Z& _
                    if (error == null) {0 S9 \) J3 q: o1 U( [+ @
                        runOnUiThread(new Runnable() {
4 M- l: w  W: R                            @Override  l, A9 L* P, L% X& _3 s
                            public void run() {5 m1 c2 V, {9 _- e. D! r
                                mButtonSetting.setVisibility(View.GONE);4 t5 ~* @( `( D* J+ q/ @  E' m  t
                                mButtonUpload.setVisibility(View.GONE);
& o& W5 X# g+ c                                mButtonStart.setVisibility(View.VISIBLE);
7 S2 c. @  R; ^' _: a. Y, \% W                                mButtonStop.setVisibility(View.VISIBLE);$ ]$ j* d& H. {7 j+ Q( n, l$ F9 O
                            }
- M- [8 @+ \& {; D1 w  L/ A) [& U1 a                        });" d6 G- ?% ?5 W+ e( A5 W: z
                        showToasts("任务上传成功!");
  m& Q) A: G& {- {* K5 e7 C( y                        mSQLiteHelper = new SQLiteHelper(SettingRouteActivity.this);
5 c+ P# G: ]5 M! y                        MyLog.d("航点值:" + GsonUtil.GsonString(mPointInfo));
) X, r$ i+ f# H- g) k0 X* p! W/ p; v                        mSQLiteHelper.doInsert(GsonUtil.GsonString(mPointInfo), altitude, mSpeed, HeadingMode, FinishedAction,& Z3 v1 M; f+ a$ ?2 ]( r
                                waypointMissionBuilder.getWaypointCount(), Math.round(waypointMissionBuilder.calculateTotalDistance()),- K6 G8 E; M( U6 o0 H
                                Math.round(waypointMissionBuilder.calculateTotalTime()), DateUtils.getCurrentDate());
' H, o; }" L# z7 f                        mSQLiteHelper.close();! J7 m5 Q! A' W7 [
                    } else {8 `" m& s4 \8 }/ P
                        showToasts("任务上传失败, error: " + error.getDescription() + " retrying...");0 F1 T5 p, F0 t
                        getWaypointMissionOperator().retryUploadMission(null);
  z, i( V  g& B' }( N% E5 p                    }
' a' {5 _$ |+ ^- j0 L9 U0 U                }
9 ^; Y* }( @# T            });) Y% e$ e, i9 u; w! m8 M; h2 x. j
        }5 ?3 J. M+ v# ]& ]" U# |+ O! G
        private void startWaypointMission() {$ [, D* X6 t8 k0 J, |0 `+ P5 {: O
            getWaypointMissionOperator().startMission(new CommonCallbacks.CompletionCallback() {4 |# B' I) J, {8 ~' ?  ^( c* J
                @Override+ b; {, l( |' n; ~0 R
                public void onResult(DJIError error) {
5 P1 i2 x8 U/ U2 n1 K, T7 c: y  j" n$ f                    showToasts("任务开始: " + (error == null ? "成功" : "失败:" + error.getDescription()));
. h% N' u; t2 p                }
# \  s9 s3 s) q$ W8 ^            });
; G) w7 U& k, Y0 M! l' C0 X        }/ G" j: ^" a4 v# ~. i5 V9 |& y7 k
        private void stopWaypointMission() {, [# w) B" d, i" T1 T3 j
            getWaypointMissionOperator().stopMission(new CommonCallbacks.CompletionCallback() {8 q, k; H5 N% n$ b3 x2 X  p9 j
                @Override
4 R; a* o7 j4 Z                public void onResult(DJIError error) {. A. F, j  H& R. b9 i! o' |# ^& C, K
                    showToasts("任务暂停: " + (error == null ? "成功" : "失败" + error.getDescription()));
5 c  ?& Z* r5 x, V$ v9 u2 e                }
! I: g4 w4 u1 N! X" |' X' r            });- t8 V2 O1 g3 S5 U' L
        }
4 H' @5 u+ u; r1 F4 ^/ r3 t        @Override
, q; A1 t" L8 Z* {        protected void onActivityResult(int requestCode, int resultCode, Intent data) {" x+ ?! O$ V& D
            switch (requestCode) {
9 D* K' G' S# }7 C( E                case 101:) v" |8 K  g* p& A0 R+ t3 ?1 S* `, [
                    int Id = data.getExtras().getInt("id");! ~+ C9 s, o7 X9 a- Q' C
                    MyLog.d("返回的ID:" + Id);( ~3 ~* q2 r3 X; ?4 z7 A
                    if (Id > -1) {8 H* r) n, N; V8 E' x+ ~
                        refreshMapPoint(Id);' y7 B# X* D' X2 u8 d. j' Q
                    }
6 v2 c4 k/ t% t3 K  ~3 q                    break;4 \7 l/ H1 F3 l8 U5 L
                case 102:
& Q4 ]% @; Z6 D) T                    if (data.getData() != null) {8 a3 c; T& ?, A% @
                        Uri uri = data.getData();//得到uri,后面就是将uri转化成file的过程。
9 ?( w0 y) v. g- R3 [9 x                        String img_path = uri.getPath();. u/ [" H. w# y% S8 b0 K! {
                        try {
& w+ S6 z$ N5 E1 M1 Y                            if (!TextUtils.isEmpty(img_path)) {4 G& b# @' s9 ^% m0 |0 m
                                readKml.parseKml(img_path);
/ e7 \" ?  T1 i                                addSampleMarker();9 Y- B/ Q$ l; V% |- R' f
                            }: e& O3 c9 K$ g$ u$ M  E/ U; H
                        } catch (Exception e) {: D: h' w1 d# |
                            e.printStackTrace();
8 A0 f( t$ n: j# w" G                        }, m9 O2 O; i2 K5 w
                    }4 }, ]7 Z" M. ?& W. o
                    break;8 Y# [6 t' o) [  h/ `4 N1 Z1 Y" }
                default:" ~7 ]6 |# R& ?
                    break;
  j, r5 m/ m7 Z1 u8 u/ S. I! s% a            }
4 m! }* x2 r- r+ t" ^        }
3 |6 ~0 H# ^/ ~# F* ?        private void refreshMapPoint(int id) {. o' C, W, l% W- Z0 K8 B+ ^
            aMap.clear();
# o0 p! F7 I9 h1 Z8 U            mMarkers.clear();8 x$ U. M6 x+ x8 t3 m$ W
            mPointInfo.clear();
2 S: d0 q. p" h. m            mLinearLayoutInformation.setVisibility(View.GONE);
* v6 _. L+ N! J6 \" ^            mButtonFinish.setVisibility(View.GONE);. c8 \( I1 X" F, Y0 l6 C
            mButtonSetting.setVisibility(View.GONE);7 F& G0 T; T, A% c( J6 s% ^
            mButtonUpload.setVisibility(View.GONE);
% S& t( n; i, j  a, d            mButtonStart.setVisibility(View.GONE);* D; a% I) L2 R4 o
            mButtonStop.setVisibility(View.GONE);
$ B, ]% D8 ]" X: c            waypointList.clear();. E+ S' K$ G: R  _& x. f
            mSQLiteHelper = new SQLiteHelper(SettingRouteActivity.this);: o% P  s+ A+ L5 X9 l$ x
            Cursor c = mSQLiteHelper.doSelectWaypoint(id);
! M% M! h* g$ @* M! V9 \; N/ V7 d            if (c != null) {
8 V% i2 }) a+ ?! `- k, _                if (c.moveToNext()) {3 Q, [% C. h) {. V. N% o4 U
                    MyLog.d("航点:" + "{'pointInfo':" + c.getString(1) + "}");
, M, g! ]) E: Z7 V& G                    mPointInfo.addAll(GsonUtil.GsonToBean("{'pointInfo':" + c.getString(1) + "}", Root.class).getPointInfo());" C& A7 ^) R$ |
                    altitude = c.getFloat(2);
  ^7 a* ~8 ]/ A7 E- }& G$ r' Z                    mSpeed = c.getFloat(3);$ \9 b# ?3 K+ H
                    switch (c.getString(4)) {# v# ]1 e/ y3 }! ]5 @
                        case "0":
+ e. R* M+ p1 ^( j4 W2 g( z0 p                            mHeadingMode = WaypointMissionHeadingMode.AUTO;8 k0 `0 e6 B; |" J' a
                            break;0 m: C5 i( y! C+ X/ v1 s1 i' K
                        case "1":
- r6 }7 [# ~, X, Y9 q6 h                            mHeadingMode = WaypointMissionHeadingMode.USING_INITIAL_DIRECTION;
3 R1 y( l9 j& l% p, |- M/ G3 I                            break;
; g5 K' m' v& g! f8 e/ K0 G                        case "2":! [% Q, U( W* d+ S
                            mHeadingMode = WaypointMissionHeadingMode.CONTROL_BY_REMOTE_CONTROLLER;/ {0 w$ `$ b* Z1 N4 G2 T
                            break;: ?2 o4 ~- T6 \+ d1 R3 s% e* l
                        case "3":9 w% r2 h0 _! {2 }3 R6 n2 m
                            mHeadingMode = WaypointMissionHeadingMode.USING_WAYPOINT_HEADING;
( j! e# e3 j. l" O0 m/ R                            break;; t& L9 d/ M' O  ?* A* w
                        case "4":
  _$ R" n( N7 ^" h0 P                            mHeadingMode = WaypointMissionHeadingMode.TOWARD_POINT_OF_INTEREST;
! n3 @9 m2 A1 w4 n2 H6 e                            break;
2 e. x) l7 w. V# a  s2 c) ?                    }# l2 T2 L, E4 b0 i8 Z5 H" I# l/ P4 }
                    switch (c.getString(5)) {4 y% ]4 c! ]  }7 m, x8 R0 P; N
                        case "0":
" b2 B1 S: W, O+ _                            mFinishedAction = WaypointMissionFinishedAction.NO_ACTION;0 f7 ], w  I, d" C- a
                            break;1 O) M2 o; ]/ z$ ?1 V1 d6 N
                        case "1":  F0 J7 n! s: ]1 y+ }3 ?
                            mFinishedAction = WaypointMissionFinishedAction.GO_HOME;' L) n4 z& p( j0 ]& l
                            break;
: ^/ e% ]# `0 h/ F+ a+ K% W* P, }$ c                        case "2":, V2 p  A( V4 X  F# _# f- D# u4 v
                            mFinishedAction = WaypointMissionFinishedAction.AUTO_LAND;) w0 E' H3 s5 l( q
                            break;# }+ B% L/ T3 [. e; r5 X1 @
                        case "3":
( `4 z* S! Z% _: v% L) ?                            mFinishedAction = WaypointMissionFinishedAction.GO_FIRST_WAYPOINT;
  i( _( H4 o, x6 n% a# C9 F* f                            break;
& D' t! ?9 N7 v( ]                        case "4":
' ~+ Y& }( D! R1 o$ S( ?4 `7 L) l2 i                            mFinishedAction = WaypointMissionFinishedAction.CONTINUE_UNTIL_END;
; g  r' i% \! \/ u- t' {* I( `7 m                            break;- Z. Y: i1 X5 w6 T
                    }2 W" L- D8 _  L0 x9 h
                }
4 b$ {) [' I9 M. p1 f            }! W. E. \, x9 ^: {0 [
            for (int i = 0; i new LatLng(mPointInfo.get(i).getLatitude(), mPointInfo.get(i).getLongitude()));" r4 K  _! K: I' q: ]5 f
                Waypoint mWaypoint = new Waypoint(mPointInfo.get(i).getLatitude(), mPointInfo.get(i).getLongitude(), altitude);
( ^- z& |/ c* t7 c0 u% N                if (waypointMissionBuilder != null) {
. v' b. E6 I2 n& z, u7 m5 m4 V                    waypointList.add(mWaypoint);
  @8 w- U# g  M4 u9 J                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
( a8 Q: g, \5 h$ ^                } else {1 E; y) ^0 I1 t
                    waypointMissionBuilder = new WaypointMission.Builder();
& ~9 x0 x# a0 e' f5 o5 c9 ]: m                    waypointList.add(mWaypoint);
) z1 d: U9 H2 u( l                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
  D* W  h. n5 h6 p* ^& p                }
3 k; u3 J6 v- ~8 H' K  ^0 Z            }
7 Y7 D; N6 \8 W( A: G1 n  D            aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(mPointInfo.get(0).getLatitude(), mPointInfo.get(0).getLongitude()), 18, 0, 0)));7 O( f$ G4 g/ j- I
            ResultconfigWayPointMission();5 |  r& ?0 T" i- F) A" A
            getWaypointMissionOperator().uploadMission(new CommonCallbacks.CompletionCallback() {6 @& ]% |, @/ C1 U( ]4 B' ]
                @Override  z+ f- b2 Y: k$ Y7 h8 [- s. J
                public void onResult(DJIError djiError) {
. ~6 g4 U2 m, w. s' _                    if (djiError == null) {
7 a! |0 Q, d! K                        showToasts("获取任务成功!");
, @) P5 q$ {9 k, e4 T                    }. {3 T/ b1 P) B) F6 m
                }( g% x5 _; O5 Y
            });
  U4 I& C6 g' i0 H4 T0 b2 r        }
  W- P; E/ q( L( S        private void showWaypoint(LatLng point) {  {; M, k: }# Y8 U$ m
            MarkerOptions markerOptions = new MarkerOptions();
& a5 u% w0 g' `' O            markerOptions.position(point);6 k& p% I) u! U
            markerOptions.title("航点" + (mMarkers.size() + 1));
) m$ [$ e8 G: o2 w; A; X            markerOptions.snippet("事件:");% z* q+ t7 ]: \# G2 J. i, X) G
            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
4 w6 a) t. L7 F6 G2 e3 {            markerOptions.infoWindowEnable(true);1 Q' V4 b! M+ r: p/ N
            Marker marker = aMap.addMarker(markerOptions);
. l, O! d" C+ `9 S            mMarkers.put(mMarkers.size(), marker);% b4 g$ l! Y  h
            marker.showInfoWindow();  A8 b' [( u: [4 Z$ a, a
            if (mMarkers.size() > 0) {( p* d$ h1 v( k* \( M7 C$ I
                mLatLng.clear();
# V5 b2 R1 e# R) {1 }) q                PolylineOptions PolylineOptions = new PolylineOptions();, g) \7 [% ?; |; B: u2 m5 c
                for (int i = 0; i 10);/ j) e( V# K8 U- Z# `
                PolylineOptions.color(Color.argb(255, 1, 1, 1));
" l1 }# L" N! t- f6 C( K: [                aMap.addPolyline(PolylineOptions);
8 Q# t# [0 G7 P& E+ ^- K, k' _            }
1 u7 y, M2 v" S8 P, p* N2 w" e' y5 a        }
& s5 n8 J* S0 m. W, ?# }        private void ResultconfigWayPointMission() {, }; x" B0 E3 }, ?% @& P3 M; C
            if (waypointMissionBuilder == null) {2 T) g6 D8 j/ o6 j
                waypointMissionBuilder = new WaypointMission.Builder().finishedAction(mFinishedAction)
2 ]' Y2 f) d  y7 m# |0 Z, S5 V  R                        .headingMode(mHeadingMode)
2 V# ~, \& n% B                        .autoFlightSpeed(mSpeed)) x! O) e2 K8 d, [: [$ B+ ]
                        .maxFlightSpeed(mSpeed)+ Y* N7 t0 w  U  G- b
                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);
. m) b5 f1 U' c3 Z" j% e            } else {
! D' y7 l1 u0 K4 I! A3 B                waypointMissionBuilder.finishedAction(mFinishedAction)" S, P) ?; @# w" D3 U- Z# M
                        .headingMode(mHeadingMode)+ R9 k3 u  P6 ?4 x* M# Y
                        .autoFlightSpeed(mSpeed)
) q$ M4 |% Z. P                        .maxFlightSpeed(mSpeed)3 h# H: n' n$ p* V& x7 q$ r
                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);( Q/ k5 Q" Z( p" `! Q  {4 ^
            }# A1 m( C, }" j  z, N) |4 X
            if (waypointMissionBuilder.getWaypointList().size() > 0) {
; _+ l1 `0 H# v: g5 W                for (int i = 0; i if (error == null) {
' b. c7 u  D% \( X                if (mLinearLayoutInformation.getVisibility() == View.GONE) {  C1 g* j/ L- h/ ^; w$ c
                    mLinearLayoutInformation.setVisibility(View.VISIBLE);) L) K7 @& V" V8 N
                }
2 S* A2 a' ?1 Z2 M* E7 c6 g                mButtonStart.setVisibility(View.VISIBLE);
3 x9 m: x) c- A; Y' J                mButtonStop.setVisibility(View.VISIBLE);
/ B$ ^# U: K2 ]/ }                mTextViewHeight.setText("高度:" + altitude + "m");) ~: g$ a8 C& m: l' @4 e
                mTextViewSpeed.setText("速度:" + mSpeed + "m/s");9 V% c, U" @4 I# p; I- o# J$ F9 u
                mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());
1 h" v1 B  n* z# I  C" ]) u                mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");
3 L8 S, i1 u# ]5 o* u$ B1 E! P                mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");7 ^. T% l6 O6 d6 _9 E5 W
            }
. M# v. v6 r3 I, `5 I0 Y        }& @+ W, X6 ^, \" K9 {  G
        private void addSampleMarker() {
+ R2 j7 B4 y, b2 b            if (ReadKml.addSampleSuccess) {
. ?6 B% ^8 Y0 g) z6 p4 X0 I                aMap.clear();  A- x8 X# W& f
                mMarkers.clear();4 V% W8 r3 W$ h4 S* O  c1 H+ m
                mPointInfo.clear();
1 v" L8 t- M& ^( [) L                waypointList.clear();
; g6 n; n2 R, g+ v$ _! }) s- B6 g                if (mLinearLayoutInformation.getVisibility() == View.VISIBLE) {
3 _2 f& K' G0 t3 Q                    mLinearLayoutInformation.setVisibility(View.GONE);
, W% |% }/ L* e                }4 {; E. j- M  k5 z# y
                mButtonFinish.setVisibility(View.GONE);
8 o6 S" w; n9 m                mButtonSetting.setVisibility(View.GONE);
' f& G! S2 j# p( X7 C2 J4 r, C1 f                mButtonUpload.setVisibility(View.GONE);' _( e4 c4 m; |7 h$ X: c
                mButtonStart.setVisibility(View.GONE);1 z( x9 \0 o) w
                mButtonStop.setVisibility(View.GONE);
! f+ {. [( D' v- K1 m  L& b4 u! J                for (int i = 0; i new LatLng(sampleList.get(i).getX(), sampleList.get(i).getY()));
* G# D5 d' u. q                    Waypoint mWaypoint = new Waypoint(sampleList.get(i).getX(), sampleList.get(i).getY(), altitude);
- b0 n: T* Z' u) G8 d. Q                    //Add Waypoints to Waypoint arraylist;
7 ~+ [; J! t. c4 n% t3 x* M                    if (waypointMissionBuilder != null) {
9 u, R7 W: F3 F                        waypointList.add(mWaypoint);
8 R2 q# ]0 _$ n* R/ @  R3 o                        waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
8 V* U+ _% e2 E" N                    } else {& |* F: }% ?( e+ V) g
                        waypointMissionBuilder = new WaypointMission.Builder();
) J- w: I' G0 K* W- N  `0 F                        waypointList.add(mWaypoint);3 l: m4 B$ V$ x. T
                        waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
% I+ I( _/ J2 G- I$ y" _                    }
1 W$ u% [% p* j! j( b7 |& z                }
5 K/ k! A' E) D                aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(sampleList.get(0).getX(), sampleList.get(0).getY()), 18, 0, 0)));
5 W1 h7 C1 `5 F, |3 h                showSettingDialog();$ |% @- C! ?1 {
                mButtonSetting.setVisibility(View.VISIBLE);0 K6 [: v8 S4 p
                mButtonUpload.setVisibility(View.VISIBLE);; T9 c/ T+ m4 [
            } else {, i  V" O. L" h
                Log.d("MainActivity", "addSampleSuccess is false or aMap is null");
. G# d' q  a' i/ i* e6 y( B8 r4 a: d            }% j7 K) u5 x! ?4 R& c4 {
        }
1 [/ H7 A1 D0 ?3 H: C- |7 a% I4 t
* o; S( K$ E; C  O3
+ l+ T8 x7 H/ h% f3 j3 I1 Q航线管理
! ~9 {9 I( F. G9 P, J; @  M: I, N创建activity_waypoint.xml和WaypointActivity文件。* m  B0 z" v3 L0 ^8 A! R+ H
% D8 u9 ]$ A7 n9 j2 ^( e
activity_waypoint.xml
0 p. \$ _  k" U5 W; Z1 O8 y
: E) E) Y. g9 x7 F2 M7 HLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"4 u4 k: c. [. `! R8 ?- m/ H+ B+ e
    xmlns:app="http://schemas.android.com/apk/res-auto"  M. o. k( @$ S
    xmlns:tools="http://schemas.android.com/tools"
) |9 t& Q3 a( A6 }/ i    android:layout_width="match_parent"
) B( S% X" S+ l    android:layout_height="match_parent"! ]( S9 z) [" m
    tools:context=".ui.WaypointActivity"
" D2 {6 C4 ?  q( I' _& S0 d" D    android:orientation="vertical"( S3 o4 a6 _! e% F) c
    android:background="@drawable/shape_corner_eight">
! `$ G4 h4 `+ ^* z1 v: t    include
! p" u* S/ x5 Y+ H        android:id="@+id/layout_waypoint"$ H* j! J* D- c+ u/ n; S2 j
        layout="@layout/activity_toolbar">include>7 W+ u/ Y) {4 D/ T7 I" [
    View0 {1 B3 L4 p9 W: h
        android:layout_width="match_parent"
1 d6 v3 j+ P3 x: A/ k: v        android:layout_height="1dp"4 [: W% Z# D: Z; a  O4 r/ ~9 p
        android:background="#5B6782"+ w+ e7 e: t0 P; X/ Z& g3 o
        android:layout_marginTop="1dp"! a; i' p* \* f
        android:layout_marginRight="20dp"" }, s5 c9 ?- f" B0 H* W  A
        android:layout_marginLeft="20dp"
0 f: u* Q+ @* _, {        >View>
5 Q# G$ T9 o0 Z0 y/ x' B% e5 z    androidx.recyclerview.widget.RecyclerView
* [9 t/ E" l, b+ z        android:id="@+id/rv_waypoint"
6 ^- h7 ^: K0 I# v& K1 C/ t4 Q        android:layout_width="match_parent"$ M7 ?7 @3 o5 g3 I, p: `6 e
        android:layout_height="match_parent"
  x' j+ G7 `5 ^  y8 j        android:layout_marginRight="20dp"4 X1 ?2 {1 v1 b3 a, ^
        android:layout_marginLeft="20dp">androidx.recyclerview.widget.RecyclerView>9 ~$ h7 D% f1 f$ d4 U! _
LinearLayout>
; }# s4 k1 `" x+ Y9 H* }WaypointActivity
: b1 I; v% A, [2 q
, q6 C- E8 W9 M) N% I$ ]@Layout(R.layout.activity_waypoint)4 I  K+ s, Z: d
public class WaypointActivity extends BaseActivity implements View.OnClickListener {+ p( h; p8 i5 t
    @BindView(R.id.layout_waypoint)- L( G: C" h  ], |" I
    View mViewLayoutToolbar;
9 L9 e1 k( k+ i& W! B# B, n# c    @BindView(R.id.ll_waypoint)
8 c6 ?$ t% @4 _7 i+ y    LinearLayout mLinearLayout;8 j# I) A. u  e3 J! F
    @BindView(R.id.tv_toolbar_title)
0 \: a  L$ \: D3 J5 `+ Z    TextView mTextViewToolbarTitle;
5 X- R+ p8 i. u) k# y  H, e    @BindView(R.id.rv_waypoint)
1 _: P1 r0 T, O& T) N8 d; O    RecyclerView mRecyclerView;
2 z& ?8 ~( \3 K    private SQLiteHelper mSQLiteHelper;
& N; t+ n/ E0 P# z7 {1 b    private List mWaypointInfo = new ArrayList();
6 B/ f! @  Z. I    private WaypointAdapter mWaypointAdapter;9 |( t9 r( O) {: p" l
    private List[I] mWaypointId = new ArrayList();
: {8 F2 X; n; X$ @6 E1 O% B    private String StrId = "";3 ?9 k. h5 K0 z) J7 [# O
    @Override: X6 r) X; q: U  Q, g: u. _% P
    public void initViews() {
) g% F2 l7 D0 J. u$ Y( C8 G+ y        mLinearLayout.setVisibility(View.VISIBLE);) V; @' C- H" o' W
        mTextViewToolbarTitle.setText("航线管理");( M( l- }0 b1 i' }7 O& {0 `3 f
        MyStatic.isChoose = false;" ]) z, S9 i; V
    }
) s. `# m6 Z8 ?# x7 ]& k    @Override5 J8 ]2 a2 y6 ?6 F$ ^
    public void initDatas() {
3 l! Q* I( f4 p9 W- V# {, }$ f$ P        mSQLiteHelper = new SQLiteHelper(WaypointActivity.this);
" w( G0 G6 y: O( s2 _4 G8 r8 q        Cursor c = mSQLiteHelper.doSelect();
# g: o* g: l4 U! V: B& F0 T        if (c!=null){
3 K7 [/ i( C) o  ?7 O4 |5 ^  a            while (c.moveToNext()){
$ s+ P  R7 l, O3 m                mWaypointInfo.add(new WaypointInfo(c.getInt(0),c.getString(1),c.getFloat(2),c.getFloat(3),
5 d* J5 X) T  @+ e' }                        c.getString(4),c.getString(5),c.getString(6),c.getInt(7),c.getInt(8),4 S5 I! ^. c* }. g: M' m
                        c.getInt(9),c.getString(10)));
; \* a6 J, J3 S: {. i, K            }: C/ B  x$ T- E) R, L. N+ W# p7 }: I
        }
5 e; z8 U7 |* n$ P        c.close();
0 g6 c* I' c1 n; U3 f' O        mSQLiteHelper.close();
/ X7 P' ?0 g+ t  V( V        mWaypointAdapter = new WaypointAdapter(R.layout.item_waypoint);
) a9 T: m8 `3 g6 D1 L  ^) G        mWaypointAdapter.setNewData(mWaypointInfo);
$ K% v% r3 F/ q" u' L        initRv(mRecyclerView,mWaypointAdapter);
4 V( z1 Y: A2 @( D! p* }. @        mWaypointAdapter.setOnItemchildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
" Z! H# y7 c& ~" y2 P/ Z            @Override
) k! y/ Z, ]7 m( {# @% y& ~7 y: f            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
- `+ _  _$ O  S$ h6 {) Q/ r, u1 m2 b8 a                Intent intent = new Intent();
6 m4 ^  G9 O# Y1 |/ e                intent.putExtra("id", mWaypointInfo.get(position).getId());
' O4 {- p0 G2 ~$ E, |5 e( G3 F                setResult(RESULT_OK, intent);
1 e' g: w' v; `: f+ d0 m7 b5 B                finish();4 ^' g6 @0 a+ j4 R4 u
            }
& k0 s+ Y; g- _8 P, x! C2 `  U        });! C" j- J" |" j' G( i
        mWaypointAdapter.setOnCheckboxCheckedListener(new WaypointAdapter.OnCheckboxCheckedListener() {
5 i1 {- O# B2 C4 Q- O  @, D! }0 y# ?            @Override
. Y) _& |# [  |  h; J( ^            public void OnCheckboxChecked(boolean isCheck, int position) {
% ?7 m7 @  K; v- A% V/ P$ r( k9 A                if (isCheck){" z) j* {9 z- q
                    mWaypointId.add(position);. `6 D' N5 C2 ]1 I! R+ O$ z1 M
                }else {
! Q6 n6 |  _% o. m! Q! x2 v' f                    if (mWaypointId.contains(position)){" Z1 S3 V2 _2 [. k  q
                        mWaypointId.remove(position);6 j1 W& G) j) H1 T/ z  Q
                    }
1 R0 n, q& r' h: {* n5 \* t+ ~8 ?                }$ y: I/ _" N. [/ E* F
            }
. p- E8 P. e5 E0 P$ R6 h+ C        });6 W# }, x1 p3 f) B9 l( p! {
    }3 q$ L. x% ~0 o" t
    @Override
/ R! i: N/ C6 z  F5 z    protected void requestData() {/ ]( e; ]8 O* a5 M
    }$ e4 X2 q: ]: Q7 i# Y6 V
    @OnClick({R.id.img_way_choose,R.id.img_way_delete,R.id.img_back})
6 C5 H6 C) y! C3 R6 D* v; z    @Override
% F5 _& m4 e4 d$ z: A; Z    public void onClick(View v) {
7 j( S9 ^% z1 x( a. J' p) o8 _. Y        switch (v.getId()){
2 L- D# G! U$ h( n' I            case R.id.img_way_choose:4 y- ^4 S% K3 m
                if (MyStatic.isChoose){
: |7 p0 ~! b. v) X7 K                    MyStatic.isChoose = false;
- x# g5 L! F+ N0 z8 r                }else {
2 Z1 p. V* c3 L6 `3 U+ W                    MyStatic.isChoose = true;3 L$ u& B/ o. d- C; e1 B
                }0 W8 m' i3 {  v! p2 v8 g! L/ f
                if (mWaypointAdapter!=null){
: \( E# y9 m8 ]7 b                    mWaypointAdapter.notifyDataSetChanged();
- N' z. `3 f' g2 Y0 V+ E6 K: V                }
. W8 @0 T' e- J" E7 U5 n                break;
- l- I1 `) x% o            case R.id.img_way_delete:
" ]. N$ |+ Q: b) B- N& o4 a                if (mWaypointId.size() > 0){8 X0 ^  y, S3 w! t1 R" {" `& @1 ?
                    for (int i = 0; i ",";. w3 a1 u* K: [; p, ]
                    }
" }7 y) F6 [5 X0 N8 {                    if (!TextUtils.isEmpty(StrId)){7 y0 K1 F3 M+ `- }/ p8 y
                        StrId = StrId.substring(0,StrId.length()-1);3 }1 L* ^+ r+ h4 y
                        mSQLiteHelper = new SQLiteHelper(WaypointActivity.this);- Z6 }* A7 I9 ?2 c, S6 a4 B+ i8 z
                        mSQLiteHelper.doDelete(StrId);, D( E0 U/ k0 a
                        mSQLiteHelper.close();7 {% l( U7 W- _. U! p
                        for (int j = 0; j if (mWaypointAdapter!=null){
, o' A6 g. a# v                            mWaypointId.clear();' d- @: b2 y( l( h' e) `
                            MyStatic.isChoose = false;
& ^" d. a& V1 S- V/ a7 f+ B& W                            mWaypointAdapter.setNewData(mWaypointInfo);
% e3 W: D2 h1 K( F# C. f3 C8 A% p5 K                        }
6 L8 u* n3 d4 ?) g  Y; G                    }
! w* N! e7 {, W; R( n                }else {+ R  d/ f( ^! A# \( d& ]7 i  l
                    showToasts("请先选择删除的航线!");% o# V0 c/ b1 x( J, @4 Q
                }
% D/ m2 T% D( f( P                break;
& d6 S* p- j2 A" r$ n            case R.id.img_back:4 u% @9 ?/ V4 L7 z. A
                Intent intent = new Intent();
4 Y$ }. i/ K0 h% X1 `% {                intent.putExtra("id", -1);; E$ ]' M% f- C5 y, t6 Y3 h
                setResult(RESULT_OK, intent);
1 `7 w. W2 @: p% t/ G0 a4 A. h& v                finish();( B! i8 g. i' Q: D' ~& M
                break;/ d1 o# i9 o% m! e; T6 ^
        }' m# O( i6 z! t8 L  D
    }
6 B1 y! f2 Q" L, K+ w) `0 u以上代码仅供参考,如果想了解更多的大疆无人机二次开发过程可以私信我,源代码因为涉及到商业使用不能给大家共享,有什么问题我可以帮你解决。
6 t$ x: Q( i/ J  ]

tjuhowhxgm564011356141.png

tjuhowhxgm564011356141.png
9 t1 h0 L$ b4 y2 @* v3 b
往期推荐毕业设计So Easy:基于C++实现网络扫描器
9 d9 r- L5 ?9 y  ?, C) E# [详解CAN总线:CAN节点硬件构成方案
/ U5 N, e. v- p: O* CLabVIEW串口通信: S9 t8 A6 g: B9 `3 p/ {: M
LabVIEW感兴趣区域分析(实战篇—1)
. r+ w4 O/ U( k, o; X& rPython Qt GUI设计:信号与槽的使用方法(基础篇—7)
/ q; C9 M% S6 o3 @8 C7 U和12岁小同志搞创客开发:如何使用继电器?- `0 [5 J( i; e
PCB天线无线模组如何布局摆放?" b# m( A1 A4 v* I9 p; M5 s
芯片内部长啥样?牛人用1500张照片,一层一层放给你看!( X. M/ b* w  U. f: D
移柯L620模组使用MQTT协议连接移动OneNet云平台: J" p) ^  }: u- d) y6 d( ?

2 y% u; W( P" X% {% q& @% ]+ H

gh5suynspnx64011356241.jpg

gh5suynspnx64011356241.jpg

3 |. ^5 A* z5 ?/ U. D7 ~. a

dbh445dsx0y64011356341.gif

dbh445dsx0y64011356341.gif

8 E4 @0 l4 O. w& ^点击阅读原文,更精彩~
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


联系客服 关注微信 下载APP 返回顶部 返回列表