电子产业一站式赋能平台

PCB联盟网

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

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

[复制链接]

853

主题

853

帖子

8351

积分

高级会员

Rank: 5Rank: 5

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

0sd5zjq5jor64015967840.gif

0sd5zjq5jor64015967840.gif
8 @, t9 w8 Y. N' y6 g& Q$ L
点击上方蓝色字体,关注我们/ ~$ e  f/ j+ O+ d& u6 t
" i1 [% U& D! ]3 M; A

. z& S% s! P8 w2 q; e* ^/ u第三篇文章准备单独拿出来写,因为在大疆为人机的所有功能中,航线规划的功能最为复杂,也相当的繁琐,这里需要说仔细一点,可能会将代码进行多步分解。) l$ E! T5 N2 G8 T- C
1
% _  S" `6 z% p* s0 g航线规划
' K" u1 H: X' a$ H- D# H# ~) M" q( R* H航线打点
7 u, o9 a, J0 b
: |+ v4 g2 L8 `& [* N! r在地图中手动选择点位选择完成航线打点;若打点位置错了可进行点位删除。9 \# |6 f6 U6 {$ `3 }: }

1dbrfdy01x464015967940.png

1dbrfdy01x464015967940.png

# ]5 F4 Q* D5 T: F# v; s% @7 G5 Q9 P8 `6 _+ Y, e
航点设置 / a2 v# }+ @; V& ]$ w( v

) Z/ c  |$ |5 [$ T" \8 }* j% x可对航线点位进行设置,如飞行高度,速度(慢速:3m/s;中速: 7m/s;高速:10 m/s)、任务结束后操作及航向,点击[设置]按钮完成设置。" a6 }9 N2 ^( o7 b* ]

4vtltfcvumt64015968040.png

4vtltfcvumt64015968040.png

2 K' b( `! T& ^% f+ G设置完成后会显示总距离及飞行总时间。
# u4 f1 l5 {& N! s1 t* e

f3krgusspmh64015968140.png

f3krgusspmh64015968140.png

% ^" A( a& a/ b
! V8 F. v) t/ ~" P航线上传  B* n! I- u/ R1 \

( `( z0 J3 \) w% V点击[上传]按钮,进行航线上传。可以进入本地存储中选择航线文件进行上传,航线文件为 .kml结尾。/ n1 \5 _& F' z. _6 }; [

rlyvd4blqgu64015968240.png

rlyvd4blqgu64015968240.png

7 X$ n1 {6 j; D0 }3 ~  P$ T9 j7 M+ c, u' K
航线执行 ' A$ ^( {. s, Q! b2 w6 ^. e* q
+ [% ?& z8 p* I4 }1 F9 N6 m; ]$ k
点击 [开始]按钮,则可对航线进行执行。若中途需要暂停也可点击[暂停]安装进行暂停操作。8 V7 R5 {7 k# Z# _+ q9 C5 n+ j

0ovzxhr4rc364015968340.png

0ovzxhr4rc364015968340.png
" `7 z( t: `# M  m. R' w! K
0 L$ g" x0 l& ^0 c
航线管理
! G8 E5 x- p7 |& i, Y2 ?
  g; A: j( w9 S% S0 G0 E+ [* H8 U7 ?按钮即可进入航线管理界面。, u; T# P0 c/ q5 ]( e3 C
! }- J$ q7 p* D+ b6 W

2iutnkohtpj64015968441.png

2iutnkohtpj64015968441.png
* @! r. Z- A' m" Y! _3 r$ {

; _: L4 w- A! g& T获取航线
8 z& ^0 M6 z7 w- T2 }1 T
% b& _# F/ [& [- \9 }点击[获取]按钮,即可将航线信息展示到地图界面中。
0 g& d9 |5 Z2 ?
+ \6 {) G2 L! P9 m0 |, ~! R
! k& t6 n% H: R4 k' E2
6 K* s' a/ U  S. a: L主要功能代码
& o0 o: c8 r; u* }1 y( U7 I; H创建activity_setting_route.xml及SettingRouteActivity文件。3 W- ?$ w# ?. E

: ]0 }; @' e1 a) o( c/ c& V4 g
. c) T! F3 x9 k. c* Z' aactivity_setting_route.xml! ~$ N( K" E& M' Y% [, e: K. N

5 f# |$ C) b1 ]5 ~9 Q4 H1 Y; NLinearlayout xmlns:android="http://schemas.android.com/apk/res/android"
! w0 k" i  g0 o2 G) v* J$ d0 d7 t    xmlns:app="http://schemas.android.com/apk/res-auto"( K) x3 P1 ]3 D+ H" E
    xmlns:tools="http://schemas.android.com/tools"6 y/ n& Y) K- n; w# O# u
    android:layout_width="match_parent"
& j0 E6 y5 V% \    android:layout_height="match_parent"8 O7 k& g+ S. e& \4 ^
    android:orientation="vertical"3 e5 L* [4 Q$ p
    tools:context=".ui.SettingRouteActivity">
; l( O' J6 N! `+ ?+ A    include
* X0 N9 w; p. M2 P9 V7 G8 _        android:id="@+id/layout_route"; k6 I  _/ j$ x- b- G0 B
        layout="@layout/activity_toolbar">include>
# j% ^4 o, i9 {0 g    RelativeLayout# e* O# J, k$ V# h! l4 G3 S
        android:layout_width="match_parent"
9 o/ s* \4 b5 L* O6 ~        android:layout_height="match_parent">4 r" E$ z5 A) n) q+ X) Z
        com.amap.api.maps.MapView
& B/ b5 q9 ~8 T+ N" j7 J            android:id="@+id/map"; W0 J% k8 y/ O! }4 G+ O
            android:layout_width="match_parent"
4 Y7 r/ S% w% k, n4 M5 n* n            android:layout_height="match_parent" />  H$ S. S7 c/ h: R8 q: Y
        LinearLayout
4 v3 s3 H1 S0 r- R# D. n            android:layout_width="wrap_content"& b; k0 t! |  G6 ~: T6 ?$ L
            android:layout_height="wrap_content"7 }4 \7 p$ O% j* w5 l& l& n4 Q
            android:layout_alignParentTop="true"! `3 K$ z% X1 P  |. G
            android:layout_centerInParent="true"
) s. F: s6 Q1 _2 l: @            android:layout_marginTop="5dp">8 O; C" u6 r  ]$ [# I
            Button
4 _5 ~+ C. E; d" `' f                android:id="@+id/btn_delete"8 t6 j# Z" t) p$ l2 {
                android:layout_width="60dp"
: l2 c/ z* r3 i- Q                android:layout_height="30dp"
8 _9 z  u: P9 x                android:visibility="gone"" x. R8 S, B! F2 w) i5 [
                android:text="删除"
! x" S: D* J) J8 P2 ^9 _" v- {+ x                android:textColor="@color/white"
8 G  l( S5 Z. `8 x; a7 q                android:background="@drawable/button_task_background">Button>% c2 g  {+ a0 T4 ^8 Y
            Button) D9 [0 v* |( A$ i9 A2 @# _% |' E
                android:id="@+id/btn_finish"- E. \1 z# g4 t8 u& u5 K; W
                android:layout_width="60dp"
4 R" S4 f7 N4 p1 O4 [                android:layout_height="30dp"
0 }* K( T9 h8 n" m                android:visibility="gone"
7 ]& r, w+ H0 s  L( y5 i- y7 ~                android:textColor="@color/white"
) q& m# z6 @; I& |2 _- i                android:background="@drawable/button_task_background", u4 o0 Q! z  I" k3 u' r4 z
                android:text="完成">Button>
5 X6 S% B/ X& {            Button
* D$ s8 q$ f# l& u# [                android:id="@+id/btn_setting"
0 M- M3 U+ `. M( i" b) R9 X7 x                android:layout_width="60dp"
; ^0 q6 O) ^# K$ `# m                android:layout_height="30dp"
! o1 j/ j6 c2 [* d                android:visibility="gone"# _+ `+ _( @: Z
                android:textColor="@color/white"; s/ i1 v( q' H$ m1 `$ p( G
                android:background="@drawable/button_task_background"- w- E" k: {0 m2 u+ C$ t
                android:text="设置">Button>
8 a$ |& g) A1 ~. M( w            Button
- [0 `3 V1 U' H2 d. H                android:id="@+id/btn_upload"
  B, w4 e. X9 i" F  b* W2 Y- J                android:layout_width="60dp") k$ Y/ ^5 E( U6 K
                android:layout_height="30dp"
9 {8 T" W% x6 p( |% }                android:visibility="gone"
* d! J7 k4 O; p, P7 `  c! C                android:textColor="@color/white"
) k3 d0 k$ V; |1 f% d8 A, b$ z5 X                android:background="@drawable/button_task_background"
) M$ W( S# _; g0 e  S0 M) F2 p; M                android:text="上传">Button>
+ K) _( l% G6 n7 d' c. O) m+ }            Button  \8 e! n) @* L1 f6 E8 f
                android:id="@+id/btn_start"
8 B# @2 s. t8 @, e                android:layout_width="60dp"
0 X5 p. g4 F1 Y5 v1 |2 V                android:layout_height="30dp"( h4 ?% L) Q) J9 N
                android:visibility="gone"- _/ ~# q& V' g! H$ r0 A5 Y9 b
                android:textColor="@color/white"
% U5 N) U& f% w- {                android:background="@drawable/button_task_background"' Q* j5 U# V1 Z
                android:text="开始">Button>2 Z$ W4 Z, G0 x* u' }/ m
            Button, D. z* M/ B, C( F+ v# @9 Q( l
                android:id="@+id/btn_stop"
- R8 K3 v0 D; Q- O                android:layout_width="60dp") I/ q3 Z: T: ?1 t0 L7 c2 Y* T
                android:layout_height="30dp"' Z* l% T$ m7 ~2 }0 c  F: p6 V/ @
                android:visibility="gone"
) O' @' L" F2 V! r/ ~5 B( a# p                android:textColor="@color/white"; n/ d# u$ f- v+ L  u* @
                android:background="@drawable/button_task_background"% K7 I4 q, E3 H
                android:text="暂停">Button>, g% \% |: B4 o2 v: r
        LinearLayout>
7 A3 Q; o3 m4 N$ l" D# C: ?5 J' E        LinearLayout
. }1 D, Z/ r7 q/ t6 o            android:id="@+id/ll_information"9 e% J! k7 L2 `1 D/ o; l& a" E7 U( j# r
            android:layout_width="wrap_content"
6 p: |2 [$ a, n% p) b            android:layout_height="wrap_content"* v, Y* O! H2 M7 w3 a0 W
            android:layout_alignParentBottom="true"+ J: A1 \) j1 z
            android:layout_centerInParent="true"
$ Z& Q8 e+ I1 b            android:layout_marginBottom="5dp"9 G3 E. k* ], [7 b& `6 A/ e2 `
            android:padding="10dp"
. o$ r( O2 g& i" D            android:visibility="gone"6 `9 E/ q& c0 F' G' d
            android:background="@color/color_nav_Item_unselected">9 Q* L) ?8 A2 I) _
            TextView
3 r+ n/ _6 c8 X% K                android:id="@+id/tv_height"# D) r' b; `5 g  U& u0 H
                android:layout_width="wrap_content"! b$ g- _+ I2 L
                android:layout_height="wrap_content"
2 B! f- R. Q( ^% m                android:text="高度:"% M6 |4 r1 O5 H! N4 z) H+ x
                android:textColor="@color/white", r9 |- D+ a! f3 S& j. R
                >TextView>
3 N& x; u# b( @& g* G% c            TextView+ s; ]2 [, S' _# g2 b3 F
                android:id="@+id/tv_speed"
; s% G% b9 p& |6 J" u( ^1 d                android:layout_width="wrap_content"
2 e; E/ \1 D- G( f! p                android:layout_height="wrap_content"
/ _( Z' Y2 x" j' f* ?5 b4 f* ?                android:text="速度:"
4 w$ m  J9 B8 r# c4 I, X                android:textColor="@color/white"
! y; O5 q" _* B                android:layout_marginLeft="10dp"/ a: G3 i  @+ \) L7 @8 G+ D
                >TextView>8 o5 }+ Y! w$ y  Q; j/ ]
            TextView( N3 C# d8 A5 ^: g2 u
                android:id="@+id/tv_count". O0 }0 K4 C1 o7 i. x
                android:layout_width="wrap_content"% l3 I2 |0 u1 `
                android:layout_height="wrap_content"
' k& B: R! B. q! C% {                android:text="航点数:"
# z, {1 m* H7 l* o                android:textColor="@color/white": N; r5 c) a5 s" Y5 \. B
                android:layout_marginLeft="10dp"
+ s$ M" n4 C! r                >TextView>
0 {: u* w9 d8 k            TextView( H/ o5 r! B# Q
                android:id="@+id/tv_distance"
" m" O) o  _3 b$ i7 j. A; ], n                android:layout_width="wrap_content"% }, e4 y: a2 W) [, r
                android:layout_height="wrap_content"  [) b. v$ b. ?- J4 y
                android:text="总距离:"7 {" e2 C9 X/ z5 A
                android:textColor="@color/white"
. R4 Z) `" S" x7 C5 `. T5 j/ c                android:layout_marginLeft="10dp"% g; J9 f$ @) i2 e2 ~" B  d
                >TextView>
8 |+ Z7 q! k; l1 j2 z6 g; f            TextView1 j8 u$ t! t, K- z5 i
                android:id="@+id/tv_time"3 n: |  m9 P4 t' _$ Q4 K
                android:layout_width="wrap_content"
! y8 p( i6 Y, v, l- L2 a                android:layout_height="wrap_content"% `$ d+ D" Y5 ~  H! t" S' H
                android:text="总时间:"1 C# p  B: `) U( f  y* V/ w4 ?6 ~
                android:textColor="@color/white"/ b5 n! K; A  F6 |
                android:layout_marginLeft="10dp", q2 p+ P) P0 G7 ]. E
                >TextView>) g# t6 l% L+ l
        LinearLayout>) v9 a% g; u' D" v8 A6 a; T. h
    RelativeLayout>+ H, m" E4 N; o
LinearLayout>
$ f6 _- U, I0 }3 C3 fSettingRouteActivity. z% H. z$ A  ?
* n! g( m1 V/ r/ t9 q( f
public class SettingRouteActivity extends BaseActivity implements AMap.OnMarkerClickListener, View.OnClickListener, AMap.OnMapClickListener, LocationSource, AMapLocationListener, AMap.InfoWindowAdapter {  r, D2 f- f3 X% c* i% j6 h4 P
    @BindView(R.id.layout_route)3 p' y8 v2 V6 N( [$ }
        View mViewLayoutToolbar;- U! @/ y) o! g& o. O, n
        @BindView(R.id.ll_route)
) [5 ~' |" n0 F+ X7 L        LinearLayout mLinearLayout;# G3 z- f2 |( a) _. u9 S+ w
        @BindView(R.id.tv_toolbar_title)
6 L8 x2 `9 ?6 i        TextView mTextViewToolbarTitle;, `: I0 u4 C7 J" I# v$ t( F0 @$ P. w
    //    @BindView(R.id.map)
& S9 d( Z- e* R7 G    //    MapView mMapView;, e6 ]. C" b6 D
        @BindView(R.id.btn_delete). z) L% O$ |/ T1 f6 p( U+ b
        Button mButtonDelete;4 `* f& s, Q% L( Q" p# R4 L
        @BindView(R.id.btn_finish), r3 r! f8 i3 H/ R2 ]
        Button mButtonFinish;
7 `9 \6 p$ _! V9 W% u4 k& m8 z        @BindView(R.id.btn_setting)& t+ ]2 E8 _3 i
        Button mButtonSetting;
: B  ?7 e2 p4 k- b# k) |        @BindView(R.id.btn_upload)$ `: N; E& U; q! b/ O+ P
        Button mButtonUpload;: f5 \" p! Y2 A3 e1 ]
        @BindView(R.id.btn_start)# }2 ]2 V# L1 g; ~$ A3 Q( C
        Button mButtonStart;
7 q; z6 B6 t" ^" O: N  a' Z- I& i        @BindView(R.id.btn_stop)3 S$ M! j- R6 E' G; W. p
        Button mButtonStop;/ k! A! V. e4 T8 i& E$ k4 C
        @BindView(R.id.ll_information), [. q3 I3 B6 g) q# l, Y/ ^9 |4 L# K& O
        LinearLayout mLinearLayoutInformation;% C$ d, H2 u8 S. N* P4 W
        @BindView(R.id.tv_height)! L4 [: F7 L3 Y/ f
        TextView mTextViewHeight;
. g& P- C5 J. Q4 K: B& Y  v5 V* Q8 n! Q        @BindView(R.id.tv_speed)
. d5 ^0 z7 L  ~        TextView mTextViewSpeed;* ?7 Z$ ?% w5 G
        @BindView(R.id.tv_count)# e6 `( R8 E2 u# K  V: P/ l) O5 n
        TextView mTextViewCount;
1 B9 y$ \; m# v        @BindView(R.id.tv_distance)" M5 s7 W' j7 e: T8 ~) Q7 B8 e
        TextView mTextViewDistance;
, a6 V0 I: i2 h6 q. v* R5 P7 T        @BindView(R.id.tv_time)
, A* F* [1 k' @: y8 i, L+ o        TextView mTextViewTime;% O' y8 A$ ~' t0 f" o: P
        private MapView mMapView;3 N4 i9 F# q8 J* L% Y8 k% [9 O
        private OnLocationChangedListener mListener;
% {2 `# @" l+ V: L: l        private AMapLocationClient mlocationClient;
  f: O" _6 p$ V        private AMapLocationClientOption mLocationOption;! s+ C  [9 ]6 Z  `1 p1 _3 E
        private double D_latitude, D_longitude;
/ L# A6 U- G: Z8 y* p8 B        private UiSettings mUiSettings;
- {3 i  g! F/ ^! Q5 g) b4 V        private AMap aMap;5 c7 D: Z0 W& a1 C
        private Marker droneMarker = null;0 |5 H& N( S9 A/ w6 a- E6 q
        private float altitude = 100.0f;% ^8 O8 z* L2 u6 X1 T% B( u
        private float mSpeed = 10.0f;! a: i3 f( p* z6 e! j
        private boolean isAdd = false;
& u) o* o0 n' Y. X9 T. E7 {        private final Map[I] mMarkers = new ConcurrentHashMap[I]();, [) X5 Q0 m8 v8 v! x; |
        private Marker mClickMarker;
3 ^9 |: M3 Y# ?        private List waypointList = new ArrayList();; v5 `$ {+ p9 H3 S
        private List mLatLng = new ArrayList();
' U& P" _" d( ^2 P        private List mPointInfo = new ArrayList();6 W0 I# Z7 x; \6 m
        public static WaypointMission.Builder waypointMissionBuilder;5 {5 G3 z  w. Z7 o( C; p$ s/ q
        private FlightController mFlightController;! b+ }7 ]0 L0 C6 h: L
        private WaypointMissionOperator instance;( ?! ]; Q6 i( O. q# `
        private WaypointMissionFinishedAction mFinishedAction = WaypointMissionFinishedAction.NO_ACTION;
6 i+ P7 U1 O% ?        private WaypointMissionHeadingMode mHeadingMode = WaypointMissionHeadingMode.AUTO;0 P2 A' l. w* m& [7 k' |6 k2 v5 R
        private SQLiteHelper mSQLiteHelper;, w5 `% b, H) S9 Q9 h- V  ^& L
        private String FinishedAction, HeadingMode;3 n# ?& k% b' v' m; J! B; b
        //自定义窗体5 b4 l+ H6 N7 f1 c! S" T; Z
        View infoWindow = null;6 ^& y  p; a' X  o2 z
        int speed_RG_id = 0;
( M3 m9 o& |! [        int actionAfterFinished_RG_id = 0;
# M1 W/ [' ]. E        int heading_RG_id = 0;
. b  Z2 o, l8 o6 s        //kim
* s5 Q. h8 j2 D, t* m5 O$ ?, B        static ReadKml readKml = new ReadKml();) l0 g) X" Z: c7 ]
        private static List sampleList = readKml.getCoordinateList();
& p/ E% J8 |- c. Y9 Q        @Override
8 Q2 j# Z" i1 {* p7 l. S8 G        public void initViews() {' o. T. j3 P1 ]8 @7 e- A
            mLinearLayout.setVisibility(View.VISIBLE);: `2 e. |# F$ l' E6 G+ a5 O; u
            mTextViewToolbarTitle.setText("航线规划");
4 j9 G( b/ q5 t( x* A            IntentFilter filter = new IntentFilter();
2 B# `+ M7 ^7 J& L* G# [% c            filter.addAction(ReceiverApplication.FLAG_CONNECTION_CHANGE);/ ~: d: F, N4 x1 h8 D( ?. W
            registerReceiver(mReceiver, filter);
; o1 H& W/ ~5 G( B# S' u# M9 C            mMapView = findViewById(R.id.map);
) S1 y6 Q6 z* @  V% n            mMapView.onCreate(InstanceState);
! D& x3 m" a7 s+ y            initMapView();; D) G8 g$ \# I/ o) P6 E; w" S. D( p
            addListener();
4 \" s- }3 G3 _* c* S' k            onProductConnectionChange();$ d$ ^0 J$ ?* g  ]
        }6 [9 l" s5 g4 o; U, X6 T$ Y
        @Override
# d( m9 l, f7 s$ Y) y        protected void onResume() {, X" V' n. b' E: j
            super.onResume();3 L* s& x& Y4 @
            initFlightController();
, U4 u) D; e3 M& l            mMapView.onResume();
3 c  D  Q( B2 T, A9 N        }
7 R; k8 f% x+ q3 b# O1 r5 s        /**  j4 ]! t$ Q( Z4 N% |- ^+ C
         * 方法必须重写
: E. ^/ x. f3 Y) A. Y0 ^         */
8 }% F# @; l! U0 S8 P9 S2 t9 w        @Override
0 E$ r, q7 ^. f: u& }) p7 {        protected void onSaveInstanceState(Bundle outState) {
- O7 M( O3 n0 u- K! E            super.onSaveInstanceState(outState);& Y9 a( d+ v  d2 Y# T; z
            mMapView.onSaveInstanceState(outState);$ f! M; m: f4 j+ b
        }
" ]; X! ?2 N( Y1 r' x4 a3 C) t& R4 _        @Override( l" @7 \1 |! [" C
        protected void onPause() {
" y" g0 [; H" \4 T            super.onPause();
) r5 C9 i4 e: ?: T& {9 V6 j5 x            mMapView.onPause();
( ~$ q. b" e$ V7 u2 {# d+ {* k/ B8 w            deactivate();3 h$ P+ L! D7 j4 b" v6 K' _. E  }2 `
        }
' \9 Q/ U( k" j0 L# `! v. i/ ^        @Override! e, o& @7 E' C( w
        protected void onDestroy() {
& Y$ a0 Y& f: q+ K+ Y8 S            super.onDestroy();6 Y* v  r% s% S4 l/ y! N
            unregisterReceiver(mReceiver);
4 Y0 D  A; p: w& ]* r4 B            removeListener();
* z% o8 e( x6 J! [# K! u3 S, Z            mMapView.onDestroy();: E4 y$ S  ]1 g, G" L8 l: {9 N
            if (null != mlocationClient) {8 h+ c6 k# x4 g' h
                mlocationClient.onDestroy();5 n4 L4 r0 N3 p6 d5 t
            }
: `5 E1 \8 e1 k6 l- {        }9 Z( ~( `4 E) P5 W6 d& K
        @Override  Y4 a& U1 k( H: D
        public void initDatas() {, ~$ M  W) G; u; v' Y
        }7 E5 G1 m* T6 C1 b
        @Override
0 g# e* ?! m1 d' S8 O7 w8 v5 P        protected void requestData() {
: n/ E1 U4 H3 [$ C6 W  g. m! M. m$ m        }) Y! c4 }# J5 d8 t
        private void initMapView() {
) p! G6 A2 g' s5 q7 ], n7 I            if (aMap == null) {
3 Z2 ^1 Z1 B9 a. a                aMap = mMapView.getMap();/ N+ H0 M4 A# w: i4 r: Y( t* p
                mUiSettings = aMap.getUiSettings();9 X* c. M8 C9 O, P5 g
                mUiSettings.setMyLocationButtonEnabled(true);
# m2 J9 z+ I( G" S# |& [  F                mUiSettings.setScaleControlsEnabled(true);* A, }# C6 R1 h5 u0 q3 m
                aMap.setOnMapClickListener(this);// add the listener for click for amap object
' Z9 A: t4 R5 m4 c2 G7 k, m                aMap.setLocationSource(this);, }% D1 ]1 I" e3 @  ~$ y& O) w& r- v
                aMap.setMyLocationEnabled(true);* o8 \/ R- ]( f/ E9 v: B7 i+ g
                aMap.setInfoWindowAdapter(this);- E6 u* Q" r0 h! ?2 A6 c
                aMap.setOnMarkerClickListener(this);
2 ~! V$ U3 i) [- X0 g2 o                setupLocationStyle();
. R% \7 @5 K' n% n; w* V; |) D            }
1 P$ R" G$ _9 V9 d, T# r6 }5 h        }
$ L$ s2 `3 u& ~0 E4 W        private void setupLocationStyle() {8 I! Z0 q! ^$ c' X
            // 自定义系统定位蓝点
+ z; J6 E& |( D  S' z" U            MyLocationStyle myLocationStyle = new MyLocationStyle();
0 ~$ T% C4 K) m$ r            // 自定义定位蓝点图标$ \1 v4 E2 e4 C& d- q/ a
            myLocationStyle.myLocationIcon(BitmapDescriptorFactory.
; o3 r1 P0 m2 ]6 G! }, r                    fromResource(R.mipmap.icv_gps_point_36dp));/ x; M9 e! z0 P1 u  v; V* u
            // 自定义精度范围的圆形边框颜色
# o4 {) T3 h) ^* |7 @            myLocationStyle.strokeColor(Color.parseColor("#00000000"));2 A. i' s2 N9 L& W! `; h
            //自定义精度范围的圆形边框宽度& B+ r2 f- ]- g1 J' }# B: P
            myLocationStyle.strokeWidth(5);( [* m  {* H' R) X, r
            // 设置圆形的填充颜色' r" C3 |- O+ P1 X7 c
            myLocationStyle.radiusFillColor(Color.parseColor("#00000000"));
% t4 m2 R) d1 L            // 将自定义的 myLocationStyle 对象添加到地图上
, x0 r& c. r' F& v  T) S& [2 p9 M# v            aMap.setMyLocationStyle(myLocationStyle);
3 t8 x. z8 T+ {- u+ {3 E        }: X( z/ m, |: o2 i7 ]! K! s, x
        @OnClick({R.id.img_kml_input, R.id.img_setting_route, R.id.img_start_fly, R.id.btn_delete,, u1 w2 ?( t6 Z8 d* u
                R.id.img_setting_clear, R.id.btn_finish, R.id.btn_setting, R.id.btn_upload,% U/ \; G+ Y% {& g2 p9 v. D
                R.id.btn_start, R.id.btn_stop, R.id.img_back})# g% S4 J7 ?9 O2 p8 g
        @Override
" F2 `' a! i5 z, ?. R) J        public void onClick(View v) {
" l; P" e+ O1 H! m' f            switch (v.getId()) {
8 H3 C+ p5 c! x* F0 K3 ]4 A                case R.id.img_back:
7 T3 O2 Y3 Z5 d, i  @                    SettingRouteActivity.this.finish();8 v5 e  T% F: f$ u+ F6 t) e
                    break;
& c% o9 k8 r( u" D) K' H4 d$ h; T                case R.id.img_kml_input:
4 P3 V: f, G* ^, U                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);- ?9 A' x2 f7 C
                    intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
6 k4 G- R* |7 r% _                    intent.addCategory(Intent.CATEGORY_OPENABLE);
. r; T/ v" T6 m3 ]# m8 f                    startActivityForResult(intent, MyStatic.REQUEST_CODE_FILE);
5 D# m" k# S4 S9 c& l4 D7 {                    break;
) d  S9 A  U3 l                case R.id.img_setting_route:* f+ Z: r8 |+ G9 j
                    enableDisableAdd();
, V8 ~( M2 S  m  \+ t" v8 q                    break;1 i# ]: n; ~! |2 W* ~/ _
                case R.id.img_setting_clear:
# W( u7 e$ E! `3 B* E                    runOnUiThread(new Runnable() {
+ M& a$ B0 \' X& K& O                        @Override
2 X: i0 e, @/ v5 ^8 O% @1 d                        public void run() {! A$ G# a( a0 J# d
                            aMap.clear();
9 U4 T: D: A8 |$ \                            mMarkers.clear();9 \* s3 E0 w# V& |
                            mPointInfo.clear();; ?+ D; L+ ~+ l' B
                            mLinearLayoutInformation.setVisibility(View.GONE);" l( t! N- u4 [0 r0 ~
                            mButtonFinish.setVisibility(View.GONE);8 i1 g  Z2 ]5 O& L) Y& e9 v
                            mButtonSetting.setVisibility(View.GONE);3 x: j3 }& t! B
                            mButtonUpload.setVisibility(View.GONE);
- R& d8 L0 W1 f2 f2 S                            mButtonStart.setVisibility(View.GONE);
$ B! s2 h" o% T. u+ W                            mButtonStop.setVisibility(View.GONE);0 W" g- `6 n6 l: ?# l5 w
                        }% Q# X4 b4 x; k; t5 U
                    });5 D" u7 \: A: S2 D5 K3 _
                    waypointList.clear();
3 e- {2 ~2 }2 r                    waypointMissionBuilder.waypointList(waypointList);1 z; m6 y! A' G5 C9 s  L) o
                    break;4 m: [  W- f- A, l" H/ @! z
                case R.id.img_start_fly:
4 a* a% _; X, V                    atyAction(WaypointActivity.class, MyStatic.REQUEST_CODE_ID);
0 w7 s& T# H" l                    break;
3 \% U$ H4 l( l( J: a* a! d5 q                case R.id.btn_delete:) V1 }8 r( P2 G( n" Q2 I6 b
                    runOnUiThread(new Runnable() {
7 Q6 m: ]% }4 j                        @Override8 P8 ?: V# j3 O
                        public void run() {1 O! ?) k0 H) U; a' `9 s8 E+ u
                            aMap.clear();' A8 u9 B) E7 W( V7 [- l4 B
                        }
5 N9 Y# K5 Z  k. _9 w5 E                    });3 f# i! B* s/ |& |* g
                    for (int i = 0; i if (mMarkers.get(i).getTitle().equals(mClickMarker.getTitle())) {
1 }$ Z9 R$ G- L9 W& `# [. b                            for (int j = i; j 1; j++) {
! l) U1 F. ]+ D                                mMarkers.put(j, mMarkers.get(j + 1));7 T" f0 J8 Q1 ?1 [
                            }+ s! x; {1 `9 x3 R0 ^5 L- O( B
                            mMarkers.remove(mMarkers.size() - 1);
1 a, u/ [  v1 k* p" x  h                        }
& k0 p2 B7 z, Y6 q                    }
3 T% e* A# e% V- \9 j                    for (int i = 0; i "航点" + (i + 1));
! h6 `5 c; ?3 o. ]7 o- p% p                    }
/ p7 C4 m0 {$ N4 r                    updateMarkWaypoint();
( Z2 T1 p! J0 B' G1 V3 j                    break;
3 i' p8 u: ~; l% W+ E4 z                case R.id.btn_finish:) N/ F/ O& V  b; H( g- h& u. b
                    MyLog.d("航点数:" + waypointMissionBuilder.getWaypointCount());
$ s) l6 X' |9 p# v. P                    MyLog.d("总距离:" + waypointMissionBuilder.calculateTotalDistance());3 r! r% E; D% F7 w/ t+ K
                    MyLog.d("总时间:" + waypointMissionBuilder.calculateTotalTime());6 z- s  p, r# B; T! {
                    isAdd = false;
' S/ `4 N- Q; [; h                    mButtonFinish.setVisibility(View.GONE);
  |* W. e6 I; v% u$ j. S                    mButtonSetting.setVisibility(View.VISIBLE);
: v. S* f  S( ~! r4 l5 Q4 t                    mButtonUpload.setVisibility(View.VISIBLE);
4 ^6 _+ L, S0 a$ J/ L( i; c; C                    showSettingDialog();
$ v% A: `* {8 ]5 b+ q1 ^                    break;
& G* K8 l* u5 C1 r5 x                case R.id.btn_setting:: N! n+ l, N" e* A; A3 T
                    showSettingDialog();4 Y* E2 `  N+ q9 F7 h1 u3 S
                    break;
4 Y" G( [  L, f6 z  E& L$ N9 B                case R.id.btn_upload:/ g3 h) |0 V: [; Z. [% t7 r" k
                    uploadWayPointMission();3 K* x9 D4 z% E! A8 G  _
                    break;
5 |* H) Q8 G4 I% g                case R.id.btn_start:: y9 S) r# k, S" }" m
                    startWaypointMission();( ?5 g/ v& u1 I5 |1 q1 L% S1 @$ ^
                    break;: E: D; \; C, F, z; E$ ^
                case R.id.btn_stop:$ j! d& Y& }" w
                    stopWaypointMission();
0 T5 U- q  g1 r8 L  O6 @                    break;
5 o7 y# _5 ~3 _) f# y% c; b7 V            }3 F  w0 ]6 S3 ?& Q1 [9 e
        }
$ c6 m+ y5 s' w. c! n        private void enableDisableAdd() {
" _* Q! k, e! o, b4 x+ S( w            if (isAdd == false) {
. @' d4 m/ ?$ z, T( [                isAdd = true;
2 H5 x+ ^6 p3 F4 ]                mButtonFinish.setVisibility(View.VISIBLE);
$ x! ?' x/ W' Q( b; W; f6 D6 j% C            } else {- z8 w1 |) `) l4 D( [- |- f% C. M
                isAdd = false;
7 G* b' v  R" L& a9 j8 b3 P            }
' K. V" |1 G) w5 t) }        }4 c) R- u- c+ X# ~+ w' P
        private void initFlightController() {8 n; b4 {7 {2 P! i/ L- |
            BaseProduct product = ReceiverApplication.getProductInstance();
8 P: G% u. n4 r- x( k9 a: W/ j            if (product != null && product.isConnected()) {
& p6 m+ C% B# z4 i2 N                if (product instanceof Aircraft) {1 z! `( b) V, o" B" K
                    mFlightController = ((Aircraft) product).getFlightController();6 ?/ |% z/ ~9 L5 E1 N3 T1 i, S
                }2 s9 m0 c6 i. b, o; y$ H" m( z9 ]
            }$ y9 f  }+ M3 ~% I3 R
            if (mFlightController != null) {% M: C4 w8 ~7 Z) D3 W
                mFlightController.setStateCallback(1 y) N7 D" H# t, Z/ }
                        new FlightControllerState.Callback() {5 R  B1 O3 @7 _) s  d6 K" `
                            @Override
7 L' m% d3 g; i: W                            public void onUpdate(FlightControllerState
$ }% S* i7 a" g' D) F3 `                                                         djiFlightControllerCurrentState) {
5 }7 ~* {( h7 A( _$ D8 c. f6 t                                if (djiFlightControllerCurrentState.getAircraftLocation().getLatitude() != 0.0 && djiFlightControllerCurrentState.getAircraftLocation().getLongitude() != 0.0) {2 K; L. @9 C' L% @
                                    D_latitude = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();
" f9 m' H; l+ B/ c* D- L3 g                                    D_longitude = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();
" F8 {- V: m+ ~8 G                                }8 f% _( I1 S2 N  c1 g) A- j
                                updateDroneLocation();
8 U" m& r( z' T                            }* D9 C1 K* I: f  D. g
                        });
/ p/ }4 V" s- Y/ k3 H  |6 v4 u" A            }, T% F9 N6 V4 m9 {% O3 N
        }# P5 \2 e' Q1 [; y4 v# |
        private void updateDroneLocation() {% r& r3 e: x5 J
            LatLng pos = new LatLng(D_latitude, D_longitude);
1 f9 D9 |6 {* K! I. r9 o            //Create MarkerOptions object( d3 w! Q0 z3 h$ d; F& p
            final MarkerOptions markerOptions = new MarkerOptions();
- }7 v" t- m3 P. B; E- ~+ X            markerOptions.position(pos);
$ A* M2 U" t3 g, k            markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_aircraft_write_36dp));' y! w- \9 G& v( _! A( _3 A. e
            runOnUiThread(new Runnable() {. E, i, M) E. S. }
                @Override; q) y3 ~0 d6 w" i% e
                public void run() {5 K8 T, _$ M8 c( a* p) j
                    if (droneMarker != null) {* V+ g5 o2 Y0 }* {# P- M' s
                        droneMarker.remove();
( y6 b0 n) [) ]  B" F% M( `                    }
! B  r# G& e  e3 L8 |                    if (checkGpsCoordination(D_latitude, D_longitude)) {
* [9 ~5 d4 E) j4 @                        droneMarker = aMap.addMarker(markerOptions);
$ }9 g8 _. t0 k- ?* |' ]                    }9 Z5 W: }0 Z3 x: D
                }
  h6 ^# I# m/ T& E2 N* f3 i            });' G6 z0 G" F8 r9 k
        }
7 k* _- Y! Z* g5 s9 J3 v" O        public static boolean checkGpsCoordination(double latitude, double longitude) {
, M9 c, {( X  Q2 L* G" j) p            return (latitude > -90 && latitude 90 && longitude > -180 && longitude 180) && (latitude != 0f && longitude != 0f);+ `8 i+ {. ~) W7 P4 N
        }1 g5 e( G5 w6 R# |* u( z/ J
        protected BroadcastReceiver mReceiver = new BroadcastReceiver() {! [( P. l! d- V' B" Z: X
            @Override
2 K5 H: u& J& n, v' V& T. _0 b            public void onReceive(Context context, Intent intent) {+ q# }- M" `9 A  g3 Q0 X
                onProductConnectionChange();
) n, n, N) u1 H$ G5 ~* U1 H) B: q  U            }2 K$ K* u) w  ~7 L; g. F4 G! P
        };
" ^1 j* \. m4 h/ I        private void onProductConnectionChange() {, }7 |4 b) k* X) K0 j0 l1 X
            initFlightController();# i- n: Z- D) y  M
        }7 P/ J  J9 `6 W4 K/ n
        private void addListener() {
3 X5 i3 H. X3 r; _- {            if (getWaypointMissionOperator() != null) {9 |4 f8 y( s( a, [3 e8 @6 q
                getWaypointMissionOperator().addListener(eventNotificationListener);
1 {. N8 A" ?: b/ r! w            }
/ h* a: ?) N: ^& v9 X4 o        }
/ R4 m2 }# O+ z" D8 M9 S& m        private void removeListener() {. H, @6 c- e* H7 |* R. V+ @
            if (getWaypointMissionOperator() != null) {
" ?! x  Q# ?7 D                getWaypointMissionOperator().removeListener(eventNotificationListener);
* }1 y8 _7 D# s) q9 N% G* W. p3 Z            }
* S0 i/ G# p; n/ F/ \        }& w; H1 |& `* m3 i; X, @
        private WaypointMissionOperatorListener eventNotificationListener = new WaypointMissionOperatorListener() {7 j- {3 f- T2 p) x- ?/ j# _: M5 `
            @Override, o+ W7 ]1 P1 [9 a6 \9 C) f% W' k6 N
            public void onDownloadUpdate(WaypointMissionDownloadEvent downloadEvent) {0 g$ z3 i$ l0 u* U6 |5 |3 l" N
            }
8 s* X8 F6 n8 d0 d- X& G+ x            @Override
3 ?+ N- x9 C" ?; ]2 u, E6 F. j- D            public void onUploadUpdate(WaypointMissionUploadEvent uploadEvent) {+ r4 q; `2 s" t' D7 I) X
            }4 A  c4 z+ {* @
            @Override* T+ E0 R8 x. {2 B
            public void onExecutionUpdate(WaypointMissionExecutionEvent executionEvent) {
; E3 P; l9 q9 I$ w            }, `3 i/ ]5 s, s3 f& w# r
            @Override
4 t. J" g$ \: r6 r  F2 N. y. a            public void onExecutionStart() {6 S# g) L+ _" \% K1 ^' a. ^
            }
: `& K& D. A* r! C            @Override
6 N3 z# ~& V, M! E9 v6 }            public void onExecutionFinish(@Nullable final DJIError error) {3 V, J) H/ G2 I
                showToasts("Execution finished: " + (error == null ? "Success!" : error.getDescription()));
6 F# J7 D; }9 N8 y            }
+ Z: z# N- c' n        };% j' s, H! Y; a& J- O* z3 N: F: j2 w
        public WaypointMissionOperator getWaypointMissionOperator() {* Y& o) [, I9 H8 F4 ?% `1 n
            if (instance == null) {" h+ M, c1 Z) y
                instance = DJISDKManager.getInstance().getMissionControl().getWaypointMissionOperator();# ^8 V# q7 P; W# d; z4 {9 \6 l
            }$ @- G# K- `! c3 B) N% q* |: U, C6 R
            return instance;
  b8 T+ G' C8 [/ [/ z( X: n        }
- Y  j5 H4 E' A1 x( y        @Override  f7 Y2 X5 n9 L7 }- g* M
        public void onMapClick(LatLng point) {- i+ u  a# _' F6 c0 u8 H6 O" g+ C
            if (isAdd == true) {: f5 e) ^( K9 C, Y3 T- x% r+ a
                markWaypoint(point);
+ _& [! }3 I7 ?  D1 |( e7 y& G! T                Waypoint mWaypoint = new Waypoint(point.latitude, point.longitude, altitude);' R+ b  N2 G# [, J9 O. h8 o
                //Add Waypoints to Waypoint arraylist;
3 u- N: n2 ^9 [4 {8 u                if (waypointMissionBuilder != null) {7 H9 I0 \3 s3 s- c
                    waypointList.add(mWaypoint);7 P: y& t+ e* p# Z+ D
                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
9 Q3 \4 d" l2 N' z                } else {* ^- v5 S* n5 H3 H6 W8 D$ e
                    waypointMissionBuilder = new WaypointMission.Builder();
+ L5 \. j  `0 {& j6 \; [                    waypointList.add(mWaypoint);0 _& ?+ R% I- v  w2 N% `
                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
, T5 ~- [& P3 r3 H                }2 b: E2 W2 e/ M! k3 \5 ^9 S
                mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());
$ v9 N2 b/ E9 O( h/ G                mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");4 w' n3 S) f8 X, X5 f
                mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");/ W/ ]: |5 G9 t% j$ m# |! H
            } else {
  g# h! c3 \; V) Y  l. H' M                if (mClickMarker != null && mClickMarker.isInfoWindowShown()) {
8 v' r- j; `1 m! |                    mClickMarker.hideInfoWindow();
3 A) f4 U$ Q! y/ x' _, }: i                    mButtonDelete.setVisibility(View.GONE);% M: m  C" i" z, X/ f3 d, G# S. S5 Y
                }
1 W$ G/ d5 w; O) O1 ~                //            showToasts("当前未开启增加点模式");
: b; i) f( F& O# ?# x            }
% W8 s* U( \0 l3 R, a        }# K$ U! u5 c' y, ?
        private void markWaypoint(LatLng point) {" b3 E2 F2 Z8 {3 a
            MarkerOptions markerOptions = new MarkerOptions();9 ~, H% t* k" [( R; J) l; V" C
            markerOptions.position(point);
, l& {8 {5 C7 u# r1 ^' U. v* V            mPointInfo.add(new PointInfo(point.latitude, point.longitude));
- b  }' J, ?9 i  W& f$ c+ o* c- @& w. M            markerOptions.title("航点" + (mMarkers.size() + 1));; J% Q7 _/ s0 a
            markerOptions.snippet("事件:");
& L$ E$ D# p+ c            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));5 b/ D3 N9 ~# V6 T, q
            markerOptions.infoWindowEnable(true);6 e8 @7 Y, B$ j  t( A$ Y/ w
            Marker marker = aMap.addMarker(markerOptions);
' U$ ~* d% P( J3 G            mMarkers.put(mMarkers.size(), marker);: R; q- ^# Z1 w' [; Q
            marker.showInfoWindow();
4 p2 H$ A9 A6 i8 Q2 _            if (mMarkers.size() > 0) {
1 e8 C* D4 o: e- L/ W9 @8 n- `2 i                mLatLng.clear();( ]  d6 _3 e# i; r) _: e
                PolylineOptions PolylineOptions = new PolylineOptions();
; n, {% Y$ e* h                for (int i = 0; i 10);1 x) Z% K+ P" g* @; {9 ?/ g
                PolylineOptions.color(Color.argb(255, 1, 1, 1));6 v6 f' B1 P  Y$ \
                aMap.addPolyline(PolylineOptions);
4 C0 \$ \  b  f. A3 o- `            }7 W% U) x4 A% T* T: c( }1 k- t7 a
        }
: O$ c8 _4 j' ]& k        private void updateMarkWaypoint() {. r4 x- l! w! y  w* l7 A  i
            mLatLng.clear();) p$ p. I% k+ Q! H, _: Q/ [
            waypointList.clear();
+ z' i! ]  {* B0 ]            mPointInfo.clear();* F% d; D$ E/ b6 B4 ?
            waypointMissionBuilder.waypointList(waypointList);$ C9 z# h' ^2 n# [
            for (int i = 0; i new PointInfo(mMarkers.get(i).getPosition().latitude, mMarkers.get(i).getPosition().longitude));
  _# D$ d+ Q: t) W6 l! P8 b5 k                MarkerOptions markerOptions = new MarkerOptions();6 T2 q0 q% P" M5 u9 A* |
                Waypoint mWaypoint = new Waypoint(mMarkers.get(i).getPosition().latitude, mMarkers.get(i).getPosition().longitude, altitude);
" D, k4 Y: ], ~( s; H$ Y# V& t                waypointList.add(mWaypoint);" m$ ~5 D. @& n# M8 q& S
                markerOptions.position(mMarkers.get(i).getPosition());9 j6 F( K7 I& S% x* d; u, g
                markerOptions.title(mMarkers.get(i).getTitle());
  B2 l5 y- b* ]5 O$ Z5 Q! f2 q                markerOptions.snippet(mMarkers.get(i).getSnippet());0 D6 s& q1 O6 m! Y" U' Z: g
                markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
- E; \( g3 _  \& s6 c+ S                aMap.addMarker(markerOptions);# L# A  ^  p$ e6 S
                mLatLng.add(mMarkers.get(i).getPosition());
+ g# O( i% R3 H+ H% E8 o# P            }) `% |. s& O9 _5 k- O# E
            if (mMarkers.size() > 0) {5 v5 {& {+ E3 j3 h/ T
                PolylineOptions PolylineOptions = new PolylineOptions();
" p5 H3 g$ @) Z1 P                PolylineOptions.addAll(mLatLng);0 H: ~; c4 R( N8 o0 N
                PolylineOptions.width(10);
- H9 J# _( c- o( {0 A: v; l% N# v                PolylineOptions.color(Color.argb(255, 1, 1, 1));
  V7 H- q3 a% O: }5 N! |% Z                aMap.addPolyline(PolylineOptions);! N5 u2 j. X0 L+ Z5 [
            }( H+ t# ~1 @* |" B5 ?
            waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
" o) y# }) L8 O6 {- B( l* L& [' d            mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());
  p5 F5 P! W6 N. n: K            mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");
4 ~5 x, E; E9 V            mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");
3 h8 y) H" A* ]/ T            MyLog.d("航点数:" + waypointMissionBuilder.getWaypointCount());
1 W7 y/ C# `6 y; E7 @) L            MyLog.d("总距离:" + waypointMissionBuilder.calculateTotalDistance());
1 |# }4 s/ n& [            MyLog.d("总时间:" + waypointMissionBuilder.calculateTotalTime());8 `: V6 C+ U! m  J( x: K" r
            mButtonDelete.setVisibility(View.GONE);
1 u$ E/ f. N1 V' m3 N4 R0 d0 S! A        }  P4 V# e& V+ q% Y9 E

' w- S  E+ W! k% h        /**4 P% G. p, f  ]0 S  h. ^( f7 E6 C% ]  }
         * 定位成功后回调函数
  R0 b, |) ^, P3 Y% E         */
' P  f5 M! r- g  x8 D& {        @Override7 F, u& E: }5 C# q# ~- Z
        public void onLocationChanged(AMapLocation amapLocation) {
( a4 P+ p7 z' c            if (mListener != null && amapLocation != null) {, S2 b6 j) v% q. c! V
                if (amapLocation != null
% ?) k/ x1 O0 G                        && amapLocation.getErrorCode() == 0) {
6 ^' l" E9 y" p& O                    D_latitude = amapLocation.getLatitude(); //获取纬度3 d6 n5 Z$ j( m0 A
                    D_longitude = amapLocation.getLongitude(); //获取经度
4 Y  N4 k+ r* T5 E                    mListener.onLocationChanged(amapLocation);// 显示系统小蓝点: ^6 [% Q& j2 ~* n+ U
                    aMap.moveCamera(CameraUpdateFactory.zoomTo(18));) v4 N- g% Y% w! M) M/ @: j; m
                } else {# \# D; X+ m* G: z3 ^
                    String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();; z2 d3 Y) P; B* b
                    Log.e("AmapErr", errText);# M' d3 h% c% Z
                }
1 M# T4 L; Z/ ?2 N            }. B2 q$ l$ t/ ?9 i7 @4 N. m- L
        }6 ~9 h3 z" T# ]. _2 J4 S
        @Override) _* X8 K6 }! j& C; j* Q0 Z# s
        public void activate(OnLocationChangedListener listener) {, q7 j1 {, T7 {6 t" ^) g4 A
            mListener = listener;
4 ?* j8 v5 L  A& N# W6 M            if (mlocationClient == null) {
) C% m8 [0 b! v% u: o$ z( o                try {1 P' `9 U* x% v3 I; H8 B9 o/ w
                    mlocationClient = new AMapLocationClient(this);  U% m8 L% f9 I! Y; ?7 O" J) {
                } catch (Exception e) {
% K/ z+ J; ~; o: @                    e.printStackTrace();; v, a6 H, n# r9 y; L4 c
                }
5 O& x9 l+ }7 X                mLocationOption = new AMapLocationClientOption();
# I- ?) G  j4 a                //设置定位监听: {6 @$ _3 @* x& i
                mlocationClient.setLocationListener(this);* A+ `9 |- G1 X8 C) @, C
                //设置为高精度定位模式) ]" E) b0 l% Z& |% Z
                mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
8 L2 i! B: B1 ?( y8 |                //设置定位参数- u  T& l' C- @# h  z# X
                mLocationOption.setOnceLocation(true);
8 d+ y( w! m+ Z: `# O                mlocationClient.setLocationOption(mLocationOption);7 s6 t! P- w) P( J7 \: ?3 R
                // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,3 @9 d$ X1 |5 L' A3 e+ n+ R* h& C
                // 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求5 E2 J# H5 g2 M
                // 在定位结束后,在合适的生命周期调用onDestroy()方法
+ h% Y- t' D0 W+ y8 U. J- T                // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
7 l3 o/ I$ o: [: z3 u6 L                mlocationClient.startLocation();, m" M9 ?4 ^, z  n1 ]( W1 D
            }  l- z7 N- d7 i+ Y$ ?  {9 P
        }
2 L4 ~2 E# g8 B- o3 c7 i        @Override
4 y1 G$ o: j: T3 w        public void deactivate() {
3 v+ h& B" f) x& L, D            mListener = null;
. x- r! c* K1 r5 J! q- y& G. n            if (mlocationClient != null) {& V" @& {, W% A1 U! b
                mlocationClient.stopLocation();
. q) a; _+ S/ k1 k                mlocationClient.onDestroy();
/ w$ g% S, ]" v            }/ _) S5 W2 H' g: a2 i' q' ~8 _  T
            mlocationClient = null;
; t. |4 e! B  z2 H# l8 _        }0 v( ~$ K( v7 R- W5 H$ d2 }* F
        @Override
6 i8 U, r, f4 e$ X8 ?: E        public View getInfoWindow(Marker marker) {
4 G$ b* ~$ O9 P) }; V) g! A            if (infoWindow == null) {
/ b9 ^0 v9 q: ?                infoWindow = LayoutInflater.from(this).inflate(R.layout.amap_info_window, null);# @3 |6 a# W, e$ q
            }# ]0 h4 z/ u/ U. Z) k; o
            render(marker, infoWindow);
* x) q' U3 y5 k9 Y9 O            return infoWindow;: |3 [1 W9 G- \) g6 J4 G* T* n
        }
& W2 P# D2 t7 _' p. T5 b1 S        /**
$ y* _% y0 p, E$ g. G         * 自定义infoWindow窗口( d1 K7 k' B6 ?& E
         */
: f0 s4 r8 [+ l2 v4 a/ A        private void render(Marker marker, View infoWindow) {" B# W( o0 G" ^
            TextView title = infoWindow.findViewById(R.id.info_window_title);
! }$ O8 w7 |# c2 F1 ~: Q            TextView content = infoWindow.findViewById(R.id.info_window_content);
" P! l- _# Q5 A* u& \8 \            title.setText(marker.getTitle());7 t# Y: b" Z! [, n  F( a: l
            content.setText(marker.getSnippet());! b$ ?: |# R' J+ A! f
        }
/ ^; J$ q1 ~5 n8 \; B8 e  F9 ~1 j" E" a( f3 ]* T
        @Override
3 u; B7 Z5 C. X( Q3 {5 B1 D9 Y        public View getInfoContents(Marker marker) {8 g/ y2 ]  }3 t! \6 V3 h
            return null;! A. |" @: b$ ~1 x* e, u
        }6 H5 r" W' A0 X
        @Override
& r/ Y5 ~9 N+ s+ e& p        public boolean onMarkerClick(Marker marker) {8 q2 \# [1 L/ A9 ^/ v' O
            marker.showInfoWindow();
, c1 d( M' [- _% L6 F) p' C            mClickMarker = marker;
' Z+ Z7 }9 d9 @2 @9 c* q            mButtonDelete.setVisibility(View.VISIBLE);' g! ^7 j- V* f. i; L* D1 R4 b, v, Z) {) t
            //        aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(marker.getPosition(),18,0,0)));1 J8 e: Z( ^8 J7 w  j" N
            return true;) ^! M) w0 [& a  K' |1 \8 i6 W
        }& |" m# ?9 ?8 F
        private void showSettingDialog() {- e1 m3 O$ c1 J* B* X
            LinearLayout wayPointSettings = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_waypointsetting, null);
5 t3 C1 u6 u) T" t8 [; G$ U) p1 J+ Y            final TextView wpAltitude_TV = (TextView) wayPointSettings.findViewById(R.id.altitude);
1 R+ Z, N. c) Q5 t! X9 T            RadioGroup speed_RG = (RadioGroup) wayPointSettings.findViewById(R.id.speed);
" ~6 X+ f9 ]% p* M" r            RadioGroup actionAfterFinished_RG = (RadioGroup) wayPointSettings.findViewById(R.id.actionAfterFinished);( r7 K% u  g+ [
            RadioGroup heading_RG = (RadioGroup) wayPointSettings.findViewById(R.id.heading);
) G5 @  X: ]! H: L# j            wpAltitude_TV.setText(Math.round(altitude) + "");# M/ z; i# m" L* t
            if (speed_RG_id != 0) {; q3 b5 O3 X' ]- \! i: q
                RadioButton radioButton = (RadioButton) speed_RG.findViewById(speed_RG_id);
* a* ^. A5 S; T: V8 A                radioButton.setChecked(true);4 Z6 _) y' a( }5 ]
            }, m  `; Q- J3 C0 m& K
            if (actionAfterFinished_RG_id != 0) {" P4 L) a  M( R, I
                RadioButton radioButton = (RadioButton) actionAfterFinished_RG.findViewById(actionAfterFinished_RG_id);
: z* h0 S. E) P2 {1 q7 s1 @                radioButton.setChecked(true);+ X  C1 Y1 F! t0 K, \5 ~. w' i2 W# I( H
            }1 y/ o  ]9 N+ q8 d& k- w" Y
            if (heading_RG_id != 0) {5 d8 P3 y, m" x/ s
                RadioButton radioButton = (RadioButton) heading_RG.findViewById(heading_RG_id);
2 f9 h- `' [* I- a                radioButton.setChecked(true);
: U, @$ o: ~8 t1 W& D4 M            }
- G8 }) a( k" Z" f: h& M  v( n            speed_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- \  a- Q, E, a                @Override
' k1 x% B6 k% ?' f# c; ]                public void onCheckedChanged(RadioGroup group, int checkedId) {
0 a; O0 t( z1 d                    if (checkedId == R.id.lowSpeed) {
6 y, k$ F: y& b" c/ w8 I                        mSpeed = 3.0f;2 x- _: v7 ~3 ]1 G6 ], w
                    } else if (checkedId == R.id.MidSpeed) {9 d- c, Q) D/ e8 N2 R: ~; C
                        mSpeed = 5.0f;
6 b! c4 T5 P% y" U( Z4 q                    } else if (checkedId == R.id.HighSpeed) {4 K% n9 N' \& \( P
                        mSpeed = 10.0f;. E5 {2 S/ q1 J# t* E
                    }5 Z$ m- N1 z) i0 ^
                    speed_RG_id = checkedId;
3 [( e8 s- ~- b3 t- ]) b5 X1 v+ Y                }
) F  F+ ]! Y9 P8 @! E* E3 v* P            });
5 Y3 F/ o, B3 J            actionAfterFinished_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {, d0 l/ {0 Q  K& U
                @Override( @' Z- v  {0 `+ K4 z6 p5 i' p
                public void onCheckedChanged(RadioGroup group, int checkedId) {
& M/ _$ N8 G7 z7 r, s                    MyLog.d("选择动作完成");
6 P8 B7 s0 g# I" W                    if (checkedId == R.id.finishNone) {
7 o$ N+ c0 K& b0 n& G& j                        mFinishedAction = WaypointMissionFinishedAction.NO_ACTION;! i% m* [9 H2 a  U* g. \
                        FinishedAction = "0";7 R2 l3 u6 w) J3 {; Y1 o) F
                    } else if (checkedId == R.id.finishGoHome) {
& A- }+ G% E+ A: n/ V& z' t! Z* ~                        mFinishedAction = WaypointMissionFinishedAction.GO_HOME;
- {% p1 @7 m! Z' X# ~                        FinishedAction = "1";2 P  ]9 T3 ]: ]3 Q/ q; `  O
                    } else if (checkedId == R.id.finishAutoLanding) {# j, N) X) E; n4 S# n5 |
                        mFinishedAction = WaypointMissionFinishedAction.AUTO_LAND;
3 F; o$ m, X2 |- |& j$ C/ f( _                        FinishedAction = "2";
# H- R# G* x! t9 j3 M7 K                    } else if (checkedId == R.id.finishToFirst) {
" D( [& f# d3 f& [) ~2 E                        mFinishedAction = WaypointMissionFinishedAction.GO_FIRST_WAYPOINT;5 `, x6 f  S8 J, `% C
                        FinishedAction = "3";. s9 N2 S% ~9 m/ ~( N
                    }
2 \% E9 V0 E8 t  G/ N& r                    actionAfterFinished_RG_id = checkedId;
' G' Z$ d; H* W0 s( }9 _0 Z) `                }
6 a6 Z' M, _8 Y2 E/ ]            });9 U) l* c4 b) {5 }! e' N
            heading_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {7 ?) N" O+ Q2 p$ G
                @Override
1 P! m" p  D+ |1 Q$ |                public void onCheckedChanged(RadioGroup group, int checkedId) {
& o" Z% B* z0 j5 r1 f                    MyLog.d("选择标题");# o$ s* v; D7 ?' L
                    if (checkedId == R.id.headingNext) {
: K$ O/ W* q; ~( r  e$ O& E                        mHeadingMode = WaypointMissionHeadingMode.AUTO;
/ K. h6 V( u+ L* `; `                        HeadingMode = "0";
; e) X- g# N: ?                    } else if (checkedId == R.id.headingInitDirec) {
7 X9 H0 u/ x0 @; N                        mHeadingMode = WaypointMissionHeadingMode.USING_INITIAL_DIRECTION;
" z+ S; O+ s) l/ Z                        HeadingMode = "1";0 ^2 ^7 }3 N! A: U( w
                    } else if (checkedId == R.id.headingRC) {
& j+ [$ z1 o' e                        mHeadingMode = WaypointMissionHeadingMode.CONTROL_BY_REMOTE_CONTROLLER;
# q5 m0 K" G3 I) ~" \                        HeadingMode = "2";+ d7 b; H2 G. K7 H1 k
                    } else if (checkedId == R.id.headingWP) {
, D& S. e' z4 l( i" i" L                        mHeadingMode = WaypointMissionHeadingMode.USING_WAYPOINT_HEADING;" N- V6 ~3 c2 E' F5 x4 b# O
                        HeadingMode = "3";  z- F" f# }2 m1 M, d, ?
                    }
' Y) Q4 a4 L, e9 ^6 o4 w                    heading_RG_id = checkedId;
2 L4 j& {- B- m! P8 H7 o+ y) m6 [0 V                }# X: C( |7 Y" I- C- S0 i: `
            });4 x2 k; n# G) [* M2 p$ E" R, }2 @1 n1 _
            new AlertDialog.Builder(this)& M1 ]( h. O: ~( [! B/ A
                    .setTitle("航点设置")2 O1 P/ j' O; m
                    .setView(wayPointSettings)
% N9 r+ t2 ]+ x5 b/ A$ W( Z6 |                    .setNeutralButton("设置", new DialogInterface.OnClickListener() {4 a" l7 ?0 h  _! E
                        public void onClick(DialogInterface dialog, int id) {
# s' P) n$ t0 ?& R4 L/ x3 W                            String altitudeString = wpAltitude_TV.getText().toString();
# u0 \6 Q2 p( T* B* a                            altitude = Integer.parseInt(nulltoIntegerDefalt(altitudeString));
3 I7 J6 ?# u) s% v5 y, l2 Y# z                            MyLog.e("altitude " + altitude);7 t2 S; o+ c+ Q
                            MyLog.e("speed " + mSpeed);; h% M) H. C% n  ~
                            MyLog.e("mFinishedAction " + mFinishedAction);
* H  g) E( k  O# F                            MyLog.e("mHeadingMode " + mHeadingMode);
+ x( D5 |2 Q7 w                            configWayPointMission();( I% V& t% p( Q9 X& M
                        }7 M' b9 M6 q8 ^2 A! J3 P
                    })' `' l% ^) z1 I6 M3 Y1 `
                    .setCancelable(false)6 F) x* }  L6 ^" \' {+ [# h
                    .create()- y9 x* h% f, z% X! h  j# ?
                    .show();
7 _. a- |# z& Z( c# C, i7 g        }. \3 M% A# P/ l5 O2 i0 L$ U
        String nulltoIntegerDefalt(String value) {
5 }! K4 I- R# G$ `6 @$ n. f            if (!isIntValue(value))' ^: X# p9 ?9 c) r* d; A
                value = "0";; [; R7 S6 q0 z; T' w5 j9 i
            return value;! [6 x7 T* X/ L8 }/ s$ \3 @* F5 |/ h
        }" Q2 }; X' Z7 a8 Z# S! a
        boolean isIntValue(String val) {
) ]. }' j  g7 x# r- e: i1 q) K# o            try {! w( H1 ]" g$ P# k2 k
                val = val.replace(" ", "");) w$ [& n# K  |' I5 m
                Integer.parseInt(val);$ U( q8 }8 ?* `# Y! X5 Y
            } catch (Exception e) {
# i7 |; @1 J5 t9 m- n  a                return false;/ P) d1 G9 K" N# `( K' ]
            }
3 q( L+ R7 y1 p# z: F3 z            return true;
9 m3 d" e4 |6 I9 c, `) |        }
* ~6 o5 {4 b) p9 |        private void configWayPointMission() {
) G" w( b. k8 L! @, S( t            if (waypointMissionBuilder == null) {& j# D$ O/ _; ?  d% U4 I6 K7 P
                waypointMissionBuilder = new WaypointMission.Builder().finishedAction(mFinishedAction)' i5 {' }4 S7 D$ U' s: O3 |
                        .headingMode(mHeadingMode)  s5 q3 T, a. ?' D4 p' P; [
                        .autoFlightSpeed(mSpeed)
# |0 O6 P1 e+ @8 l1 H$ }3 f                        .maxFlightSpeed(mSpeed), X( A# C" n6 n3 q7 b
                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);  v7 q) D  i+ ^0 k3 k5 \
            } else {/ K* z( [1 \" O- g: v" N: N- g2 k; T
                waypointMissionBuilder.finishedAction(mFinishedAction)) L1 M& W, Q) [# Y6 ^0 N$ v
                        .headingMode(mHeadingMode)- M2 H+ T! o- n
                        .autoFlightSpeed(mSpeed)2 e; o0 {) q/ o" [2 Y; }
                        .maxFlightSpeed(mSpeed)
. }8 f3 i$ t0 @& u% A                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);
; t3 z: i1 q, z# P$ Y- ]8 A            }
2 Y# L" e( p5 N* E            if (waypointMissionBuilder.getWaypointList().size() > 0) {& U7 a0 F! J: ^+ D4 r
                for (int i = 0; i if (error == null) {! o8 A% a0 G! S+ r/ D" y" S" {
                if (mLinearLayoutInformation.getVisibility() == View.GONE) {
- z9 _4 p+ W/ D6 {                    mLinearLayoutInformation.setVisibility(View.VISIBLE);  ~7 D( Q5 s1 h) [! s9 h- R  z! ]
                }+ M2 ~* }7 p3 w. Y/ G
                mTextViewHeight.setText("高度:" + altitude + "m");
( I: `, i7 |3 B6 p  k/ m                mTextViewSpeed.setText("速度:" + mSpeed + "m/s");
( r: |$ I, u9 Y" f                mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());
! m  u& N9 e- k5 \7 K8 A! R* v: v                mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");9 g1 U7 X0 G' b9 V4 K6 X
                mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");
, n  m+ A' ^5 W/ ^" n5 e+ Z1 }                MyLog.d("航点数:" + waypointMissionBuilder.getWaypointCount());, b3 s' M0 _7 A. t7 G- y
                MyLog.d("总距离:" + waypointMissionBuilder.calculateTotalDistance());
/ i9 K. N& r* p  f2 p# O3 B                MyLog.d("总时间:" + waypointMissionBuilder.calculateTotalTime());
! ^2 \% d  s# a7 u! x9 H' _                showToasts("航路点配置成功");, M: q+ p' C& D- Z; |) f2 a- c5 G
            } else {" ?4 A1 |  F$ z7 c+ R% x5 d3 }' q
                showToasts("航路点配置失败 " + error.getDescription());$ j- s% k% y# A% n: @$ W8 A; l
            }
. U1 L  S' w& t1 z' o" G+ x        }
6 j8 i9 L7 G8 G" K/ ]        private void uploadWayPointMission() {3 R$ a2 W9 k* G8 [& [% O" X2 O
            getWaypointMissionOperator().uploadMission(new CommonCallbacks.CompletionCallback() {
1 k2 T7 m4 L; |7 K, A: C                @Override' w$ r3 o( k4 @* J3 ]; M
                public void onResult(DJIError error) {
3 ^. V" F8 n- t; B, q8 K" x- a7 q                    if (error == null) {, a* I2 e/ z4 [
                        runOnUiThread(new Runnable() {# w: a$ e! G- b4 P' c( d. z- X3 ?
                            @Override  n% t% o# E" l: Q. i+ Q7 ~; N& l
                            public void run() {
- l$ b8 g7 ~8 A. w! B  }/ `                                mButtonSetting.setVisibility(View.GONE);
% \/ g7 n- j: ?/ u0 w3 K0 B                                mButtonUpload.setVisibility(View.GONE);
8 Q- b8 H3 P' s1 F! n                                mButtonStart.setVisibility(View.VISIBLE);1 {. X% y/ h3 O* g  O! ]* @
                                mButtonStop.setVisibility(View.VISIBLE);1 P, Q& n6 [+ A" D" U  ]: }8 w
                            }
' ]" E! \' Q% B: [; \- w: q                        });
3 {7 Y/ {5 E$ c( ?; y! P: i                        showToasts("任务上传成功!");$ J1 R' j/ }/ z' @" u% q9 Y# X
                        mSQLiteHelper = new SQLiteHelper(SettingRouteActivity.this);
5 P" s  J( D/ r/ W& }& ?                        MyLog.d("航点值:" + GsonUtil.GsonString(mPointInfo));2 W4 Z: M5 L4 I9 y5 s
                        mSQLiteHelper.doInsert(GsonUtil.GsonString(mPointInfo), altitude, mSpeed, HeadingMode, FinishedAction,2 Z! Y$ c3 g$ ~7 M  ~  P7 o3 J; ^
                                waypointMissionBuilder.getWaypointCount(), Math.round(waypointMissionBuilder.calculateTotalDistance()),
& O8 x% J$ y. y  R, G# [; t                                Math.round(waypointMissionBuilder.calculateTotalTime()), DateUtils.getCurrentDate());
7 E9 ^% b' j& o) c                        mSQLiteHelper.close();
( P: }4 E$ j* b5 w- m$ Y& H( d& H: w                    } else {
3 Q" t6 o: w* Q; N% ]                        showToasts("任务上传失败, error: " + error.getDescription() + " retrying...");7 }' d$ \* }0 f0 x% `
                        getWaypointMissionOperator().retryUploadMission(null);
+ I. F+ r7 V: M  _                    }
0 n& L! {( m4 P                }
9 U( ], L6 s" f! y- ?+ W9 D            });, o6 s8 x. A& @4 F" n" z
        }
4 E$ \6 |# z! u; C& h5 d% ?        private void startWaypointMission() {' X4 j# A4 ]1 }/ N- F
            getWaypointMissionOperator().startMission(new CommonCallbacks.CompletionCallback() {
6 l* K3 }  R6 Z3 K3 l; L8 c0 L$ ]                @Override
) ]$ u% n! d7 j7 ~5 p                public void onResult(DJIError error) {
' |# x# d2 s) ]1 j$ j  ^                    showToasts("任务开始: " + (error == null ? "成功" : "失败:" + error.getDescription()));3 Z) J7 S7 c; q) g; R3 }
                }
/ O; e& [& Q  D+ v: T            });% n. r( w" y. {' U( E
        }3 C; T6 w" ], H7 r$ d5 T2 o/ p+ @' b
        private void stopWaypointMission() {
: l! D" V' z2 d* Z            getWaypointMissionOperator().stopMission(new CommonCallbacks.CompletionCallback() {. {  j9 {8 v/ o* [' c* v
                @Override" L6 u: z/ r' p: ]; M, `
                public void onResult(DJIError error) {
" P6 l& T5 |2 @& f$ g# |                    showToasts("任务暂停: " + (error == null ? "成功" : "失败" + error.getDescription()));
6 G& H5 x( g  V4 a  K) p3 }                }9 [2 l8 a( o+ Q5 _
            });5 F. R2 \6 J: `) z, D' ~
        }
1 F4 r7 ^. i" T' ~1 n7 z  x0 t        @Override7 c# t. }7 L4 W- X) k( O. w  r( @
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
* p3 @* n; X- B# r2 F6 M/ L# q            switch (requestCode) {3 X' @/ n/ ]) F. ]0 a
                case 101:( [; K. R% d7 I, [, y. c7 `6 j
                    int Id = data.getExtras().getInt("id");: k2 G7 H, q" n; N
                    MyLog.d("返回的ID:" + Id);3 t! u2 l0 l  ~! x
                    if (Id > -1) {
  f! V0 H! Z6 G* `                        refreshMapPoint(Id);, M( ~. L' d( ^% m; w& X& h  j
                    }8 c" K1 A6 T! ^- Y" L# d
                    break;7 C' g5 Y. Z( t8 G- L8 a
                case 102:9 t) ^% U) P' V$ y8 l$ D: u
                    if (data.getData() != null) {& w! Y" V/ x2 K. _' D
                        Uri uri = data.getData();//得到uri,后面就是将uri转化成file的过程。. m# O9 G0 _! y# L6 ]
                        String img_path = uri.getPath();; t1 o' [1 [: a$ `: O7 E
                        try {: Z* P; I; z+ o" h* G
                            if (!TextUtils.isEmpty(img_path)) {+ ~+ [) v9 E; b  {7 o+ H: F" d) `
                                readKml.parseKml(img_path);
: [$ ^; o; m. r. |0 D                                addSampleMarker();7 R, @4 C( Z6 A7 Y- `9 Q1 e
                            }9 K# Q; R! r4 y+ l
                        } catch (Exception e) {; {/ @! O+ m5 t( t
                            e.printStackTrace();3 n$ s6 D2 I( y$ j# G- e) R. C
                        }6 v3 i3 U6 s% o( }2 ?- v% D' x
                    }
0 s7 l; A8 f  m2 {" m* Y; \3 {% n                    break;
+ T: I6 E) b/ h! G0 d5 S                default:
1 x' G: R/ ~4 P                    break;2 R; N# N* Y9 ^. d. H* T
            }, v" v# Y$ l& ~: U( O( h" B9 B
        }. d( q0 a8 v+ C- G' ?5 j# ^9 Z
        private void refreshMapPoint(int id) {
7 P; T" w9 \. }3 i/ i            aMap.clear();
( F6 V( O2 X* x6 G! R            mMarkers.clear();
& d2 c% @- Y& |7 I. j! L            mPointInfo.clear();: E; d  S. Y7 i. D8 q2 C
            mLinearLayoutInformation.setVisibility(View.GONE);
0 y6 E: V  u, @( i            mButtonFinish.setVisibility(View.GONE);3 \% A. _3 U* ]4 V( w- W0 x
            mButtonSetting.setVisibility(View.GONE);
3 L9 {$ S# {' G; u# e            mButtonUpload.setVisibility(View.GONE);
" j5 Y! i  S: u% F- H) j            mButtonStart.setVisibility(View.GONE);! I6 w2 Q+ s6 a
            mButtonStop.setVisibility(View.GONE);/ h7 Q0 s9 z0 p1 i
            waypointList.clear();/ m, a* g# H6 A& I6 H9 D! i, H
            mSQLiteHelper = new SQLiteHelper(SettingRouteActivity.this);! Y- M7 Z! X, J7 H, h
            Cursor c = mSQLiteHelper.doSelectWaypoint(id);
3 b: n, l1 s  L# I/ z" i            if (c != null) {, ?& j' N" M1 l8 Z$ l, R
                if (c.moveToNext()) {% a9 `9 A# s" q6 ?- n0 u
                    MyLog.d("航点:" + "{'pointInfo':" + c.getString(1) + "}");) t" U* C2 e5 ?
                    mPointInfo.addAll(GsonUtil.GsonToBean("{'pointInfo':" + c.getString(1) + "}", Root.class).getPointInfo());, z( J1 f9 e- w& a; t; V& k0 D
                    altitude = c.getFloat(2);
' t8 R* {: L# a                    mSpeed = c.getFloat(3);0 _6 ~+ S( u( y5 Y$ N! {. G7 |
                    switch (c.getString(4)) {
2 A" I$ V* i: b" J  m0 J) R; e; z7 ?                        case "0":; u+ y* i3 p' H2 _( s
                            mHeadingMode = WaypointMissionHeadingMode.AUTO;
' P8 S4 |, J% I" ]) T& w, W& O                            break;
& N& v% n3 {9 {' R7 u$ N4 \- e' [                        case "1":/ x, o3 @' ^7 b' X+ {) v
                            mHeadingMode = WaypointMissionHeadingMode.USING_INITIAL_DIRECTION;1 _) M' E: L6 P! {/ }6 g
                            break;6 b% T: A0 \7 Z/ N1 e! T5 B9 b, {8 j
                        case "2":4 \  Q7 K; q+ ~8 I1 |
                            mHeadingMode = WaypointMissionHeadingMode.CONTROL_BY_REMOTE_CONTROLLER;
+ h3 M" J% F/ l  ~' s+ }3 k                            break;" k) f) M, W4 j" |1 p. f0 K
                        case "3":
7 d/ H4 M: }3 v7 k                            mHeadingMode = WaypointMissionHeadingMode.USING_WAYPOINT_HEADING;
4 j4 m# _, x8 h. H; n                            break;
4 T. @, m* p. q) \                        case "4":$ E9 e% F. l; u7 [
                            mHeadingMode = WaypointMissionHeadingMode.TOWARD_POINT_OF_INTEREST;$ ?  A. n! h2 d' \, T2 v
                            break;% W. c- i* S- \! l! A! _
                    }
. C/ _( f$ y0 j1 J                    switch (c.getString(5)) {1 j7 G/ o- r2 z4 X6 g# z% A  |
                        case "0":4 K; J9 S3 T; H) g. S0 {0 J
                            mFinishedAction = WaypointMissionFinishedAction.NO_ACTION;8 a6 V7 ]; }; C9 O
                            break;
$ @0 @4 i2 |% r5 P1 v  y* }                        case "1":: C+ k5 W; T6 t  v: @8 d
                            mFinishedAction = WaypointMissionFinishedAction.GO_HOME;
9 G, P5 g- a. k6 ?) _2 L6 I0 R                            break;# K- K3 e' g( s. P9 e. a
                        case "2":
: N" y3 K% r8 b4 A, l7 s                            mFinishedAction = WaypointMissionFinishedAction.AUTO_LAND;
2 Y, }, U4 C. J                            break;3 V( S, c) Y5 P: W5 z) C
                        case "3":
& m+ j& n! f( S9 V5 N' ?                            mFinishedAction = WaypointMissionFinishedAction.GO_FIRST_WAYPOINT;
2 c5 \( w& y  V" `1 u" T/ l7 |) G5 ~                            break;9 H! o: b. G, C( ]# P
                        case "4":8 T, ^! C5 o7 J' I, |% A" c4 O
                            mFinishedAction = WaypointMissionFinishedAction.CONTINUE_UNTIL_END;
) F' M( y3 \1 b2 @6 u4 n! O                            break;
7 g! V# [; a/ z; g( `( I                    }+ X/ j0 E) w. ~! u) q, l* y
                }: c3 S  l& l: B
            }
; u/ k% l; B! F* d            for (int i = 0; i new LatLng(mPointInfo.get(i).getLatitude(), mPointInfo.get(i).getLongitude()));2 F. Y6 `% U, v! O
                Waypoint mWaypoint = new Waypoint(mPointInfo.get(i).getLatitude(), mPointInfo.get(i).getLongitude(), altitude);2 \! t4 @$ w4 Z7 W, u9 _9 o; P
                if (waypointMissionBuilder != null) {8 ?& q9 F# p5 J2 q
                    waypointList.add(mWaypoint);
4 n3 v" t4 X: t4 |                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());8 u- G1 c( U! H4 j
                } else {. X. C3 g8 N' w# t7 c" J- e. g
                    waypointMissionBuilder = new WaypointMission.Builder();
0 P2 M) V5 {/ z# I                    waypointList.add(mWaypoint);
0 i1 n! \6 K8 y$ ]                    waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
& r1 {6 B; ~4 G/ w                }
3 T$ i1 r9 ?. Z            }. E0 f6 w3 C' ~# S
            aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(mPointInfo.get(0).getLatitude(), mPointInfo.get(0).getLongitude()), 18, 0, 0)));
& d7 f, z0 |8 G, t$ U5 L, @            ResultconfigWayPointMission();
4 S: f6 ]9 \8 x: x8 l            getWaypointMissionOperator().uploadMission(new CommonCallbacks.CompletionCallback() {
' l" z: `" d: J1 k: Y7 H                @Override2 R4 q$ E% s8 w- O5 v! I/ b
                public void onResult(DJIError djiError) {
, j& `9 |# d. Q. A                    if (djiError == null) {
4 T6 |5 d, j( m8 I$ e, n                        showToasts("获取任务成功!");7 ~0 K; U7 j5 ?" n0 r0 g
                    }# L6 J+ m# b$ H0 ?) o" W' s3 y" @* k
                }
- }- g# J+ K  ?9 K            });& r! Q. D& \. n3 }
        }( ?6 @% V" H" z& h7 J8 \. K6 X
        private void showWaypoint(LatLng point) {" I* T, \/ F8 E6 K
            MarkerOptions markerOptions = new MarkerOptions();
+ [' {6 v2 r$ X            markerOptions.position(point);9 b$ ?1 V) ?- B( k& q; y6 A* z
            markerOptions.title("航点" + (mMarkers.size() + 1));8 ]  K: A# O* @7 [( A4 Q
            markerOptions.snippet("事件:");
$ ?0 ]/ K; c8 n+ j            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));, q- e" f2 ]* v6 @
            markerOptions.infoWindowEnable(true);5 |: I' O6 e$ m- g# X8 ~
            Marker marker = aMap.addMarker(markerOptions);7 \% }5 r8 n; y: R' J
            mMarkers.put(mMarkers.size(), marker);7 M5 o9 @3 W2 |: ?! C: @
            marker.showInfoWindow();; N' @) x  t' F- {* f; N0 s: E4 U
            if (mMarkers.size() > 0) {
+ S4 Z: P6 p5 _6 U; \- [0 K8 r                mLatLng.clear();6 O; G* \' z" A! F" \
                PolylineOptions PolylineOptions = new PolylineOptions();
: @# b# W, l" C) t, c                for (int i = 0; i 10);
' H* G0 M! G+ C& t2 B                PolylineOptions.color(Color.argb(255, 1, 1, 1));: {7 U- I4 x- C9 H# a
                aMap.addPolyline(PolylineOptions);* u; D0 {8 b7 l+ @
            }1 E& }# i- @. N- c  J
        }
* w9 T- l8 g" \4 c4 y7 @* l1 z        private void ResultconfigWayPointMission() {
5 L7 F8 F4 T9 ]% Y- q  i7 z) v            if (waypointMissionBuilder == null) {
! d! s& e) j+ H7 _, e2 `                waypointMissionBuilder = new WaypointMission.Builder().finishedAction(mFinishedAction)
& j2 k- [0 o  _( r9 V9 ]! |3 E                        .headingMode(mHeadingMode)* v1 G# L' Z( x0 ]  d% Y" }
                        .autoFlightSpeed(mSpeed)% {9 @' W/ b+ L* C
                        .maxFlightSpeed(mSpeed). r' e0 q' C4 W, w
                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);) l9 c$ r, w6 a2 |
            } else {! q% J2 z7 T  x
                waypointMissionBuilder.finishedAction(mFinishedAction)2 m9 V/ U* I' n1 C
                        .headingMode(mHeadingMode)
' k& d1 a. d0 ?& c                        .autoFlightSpeed(mSpeed)% m3 j$ ]: O) u
                        .maxFlightSpeed(mSpeed)  R$ {  s+ h) I: S
                        .flightPathMode(WaypointMissionFlightPathMode.NORMAL);# x% e& q# E) l0 v% E
            }
* X7 ~5 {- T" e# P' D1 L8 t            if (waypointMissionBuilder.getWaypointList().size() > 0) {- I6 u; V* ?1 M8 ]7 q5 r6 V
                for (int i = 0; i if (error == null) {5 G3 d8 g4 u  Z8 t* A
                if (mLinearLayoutInformation.getVisibility() == View.GONE) {
% V$ R/ P% T6 C; l, E                    mLinearLayoutInformation.setVisibility(View.VISIBLE);
" K, J4 q7 k* i* \# G                }
% N: z# d4 M9 t- B. Z! [                mButtonStart.setVisibility(View.VISIBLE);* Z& y% A* Z& v4 Q
                mButtonStop.setVisibility(View.VISIBLE);
/ y' I3 \% E* u8 b                mTextViewHeight.setText("高度:" + altitude + "m");6 T0 j1 `; m7 L0 x4 E$ y/ v
                mTextViewSpeed.setText("速度:" + mSpeed + "m/s");
. V) y! ?) e4 ^/ |& L                mTextViewCount.setText("航点数:" + waypointMissionBuilder.getWaypointCount());
4 n7 B# _( u5 j4 k+ Y1 q, ~                mTextViewDistance.setText("总距离:" + Math.round(waypointMissionBuilder.calculateTotalDistance()) + "m");
% j: H1 ^; g- \, L5 J: u% e                mTextViewTime.setText("总时间:" + Math.round(waypointMissionBuilder.calculateTotalTime()) + "min");4 U& O& u9 F  P0 l
            }
3 {6 O4 C1 S( v3 q* D  E        }9 x3 v4 y1 {; j9 K
        private void addSampleMarker() {
, T- A, i  f1 J$ S  P            if (ReadKml.addSampleSuccess) {9 {3 i, q. w* x, s% h
                aMap.clear();
$ t' y" k# l8 @0 `5 q                mMarkers.clear();9 b3 @0 Q8 H' V. P7 Z* a) y2 C$ B
                mPointInfo.clear();. U2 E$ V4 [5 A, p8 {
                waypointList.clear();+ ?6 J8 H6 }( B0 v0 M
                if (mLinearLayoutInformation.getVisibility() == View.VISIBLE) {
# U. e4 u- J7 c% P4 [                    mLinearLayoutInformation.setVisibility(View.GONE);
' m, m; F! l. x7 {) x                }9 J/ @9 B( r# t0 T' T
                mButtonFinish.setVisibility(View.GONE);
6 Z- V/ a, W1 _* K* G                mButtonSetting.setVisibility(View.GONE);
0 z; U* q* v3 ^( A7 N' Z; _3 d6 ]% T                mButtonUpload.setVisibility(View.GONE);$ q, p. P) Q4 N" X1 v* |
                mButtonStart.setVisibility(View.GONE);5 [% @% q0 f9 y; ~
                mButtonStop.setVisibility(View.GONE);% r8 u6 T1 B" {$ K; F8 W
                for (int i = 0; i new LatLng(sampleList.get(i).getX(), sampleList.get(i).getY()));  _) A  n2 V+ s" @/ k7 F/ C
                    Waypoint mWaypoint = new Waypoint(sampleList.get(i).getX(), sampleList.get(i).getY(), altitude);
& O( K, z' q0 Y+ z                    //Add Waypoints to Waypoint arraylist;
5 i. `' M5 g, Q3 _7 {                    if (waypointMissionBuilder != null) {5 ]$ I0 x% S7 [4 R# p2 S
                        waypointList.add(mWaypoint);5 C2 z$ @& x& |  C
                        waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());4 H) G: E; h8 ?" G
                    } else {5 }9 \9 K9 y  r/ w5 ^3 @% L
                        waypointMissionBuilder = new WaypointMission.Builder();' v% D$ }  p; I# H* }0 U$ f
                        waypointList.add(mWaypoint);6 `& B" w1 r% x
                        waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size());
; f% \* x' T# I6 z                    }1 @" |4 }6 V4 t' H2 n& N
                }
; V/ d" {/ F% @7 E                aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(sampleList.get(0).getX(), sampleList.get(0).getY()), 18, 0, 0)));
( P0 N" I) C. ?                showSettingDialog();
0 v2 i  {+ w6 P# s/ h8 l; C                mButtonSetting.setVisibility(View.VISIBLE);: U! I8 m) u9 s2 t& K% K* S1 e
                mButtonUpload.setVisibility(View.VISIBLE);3 G8 x; R$ i# L5 `/ p
            } else {
8 y, E" G' [' J( K3 ?5 t4 |                Log.d("MainActivity", "addSampleSuccess is false or aMap is null");+ }! I  K& z0 }
            }
3 y) X4 U; d) C) {6 f5 t& a        }- P( A; v! |3 K. z4 R; R+ X1 l  y

) o: U, ^) G) p- R( S/ E6 E* D3
! ^+ [$ ]- _5 Z+ a7 s# a航线管理
5 l. z: ~$ s$ v$ _6 h9 w创建activity_waypoint.xml和WaypointActivity文件。7 }7 C3 }( ?6 s- S$ z+ A
8 ]+ y' U( ]' p& J7 _! J
activity_waypoint.xml
- Y9 R& x, L- B2 {4 R/ |, @
; t) M/ O7 f; O8 l% _LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
. s( v$ N7 |3 X7 X7 w6 Q  W    xmlns:app="http://schemas.android.com/apk/res-auto"7 l- b! W+ x* d9 V) K, z
    xmlns:tools="http://schemas.android.com/tools"2 ?( z  ]( t  x; k
    android:layout_width="match_parent"
$ w7 ]8 a6 z8 h$ ~4 t; Z    android:layout_height="match_parent"
- a' w/ x' R* J8 ~5 |' N    tools:context=".ui.WaypointActivity"
5 v3 O4 c% {/ q6 r    android:orientation="vertical"* j: s+ R  J7 O6 m- B
    android:background="@drawable/shape_corner_eight">
( [' g* E/ `( H9 z    include' A3 q4 s- f, a6 \7 K! n
        android:id="@+id/layout_waypoint"
1 j$ R2 v2 h; E; ]* r* o        layout="@layout/activity_toolbar">include>6 \; B  G. u7 k( p- t5 T
    View0 ~- d7 ?& P( {9 u
        android:layout_width="match_parent"
* Z: m1 W9 \0 O2 R/ ^1 e1 V. S        android:layout_height="1dp"
1 J" f! G* j% @        android:background="#5B6782"
$ Z: C4 c  X3 J  S2 t  @9 P        android:layout_marginTop="1dp"
5 m  z3 \8 S8 l3 j3 o4 O5 m        android:layout_marginRight="20dp"$ U$ S  q, `- T) [! X  o7 {* g
        android:layout_marginLeft="20dp"
  q2 l( v) S6 r% s4 a: K- M' v1 [* h        >View>
. d# n0 B& l& O( [    androidx.recyclerview.widget.RecyclerView
8 Y7 x. `, E9 u: o" H' m+ ~3 a$ u, b& k/ X        android:id="@+id/rv_waypoint"/ @: U/ T, \* J8 I
        android:layout_width="match_parent"
$ c: i; r9 `8 y5 J: r" D        android:layout_height="match_parent"7 w0 y$ Z4 ]4 ]4 M! x9 x" D2 L
        android:layout_marginRight="20dp"
! c* m0 R3 W$ K& f: @        android:layout_marginLeft="20dp">androidx.recyclerview.widget.RecyclerView>
) \& V9 k5 t7 a  FLinearLayout>5 ^& S$ X* }# ^2 b9 R! N8 f
WaypointActivity
: n$ o; p' T" |( i7 b
2 V: f4 e' I4 ^5 |9 c@Layout(R.layout.activity_waypoint)! ]: H/ N& p" F- l2 z# T$ m
public class WaypointActivity extends BaseActivity implements View.OnClickListener {
; R+ q8 g2 q. h9 ~* [  H    @BindView(R.id.layout_waypoint)
! N; J" Q6 k' t    View mViewLayoutToolbar;
9 G) z5 ~# _  Y( b9 H6 L2 A' X    @BindView(R.id.ll_waypoint)7 S" ]8 Y: Q8 u" P" d/ b$ P
    LinearLayout mLinearLayout;9 p1 B' Q# y' m* ^
    @BindView(R.id.tv_toolbar_title)
1 V3 \! k6 T& x* }    TextView mTextViewToolbarTitle;
7 E2 \& L/ |- H# g    @BindView(R.id.rv_waypoint)
7 N- r0 y3 U; Z4 z% V/ s* |, e    RecyclerView mRecyclerView;* E$ T- O8 F" Y
    private SQLiteHelper mSQLiteHelper;
, L9 h& |4 U6 z  y( A  E2 i; U    private List mWaypointInfo = new ArrayList();7 ]4 ?/ ~2 [* u$ v1 x, j
    private WaypointAdapter mWaypointAdapter;1 P+ s! x9 A+ P; a0 f/ D. k/ E
    private List[I] mWaypointId = new ArrayList();0 W5 G! V0 B" F( K+ \+ O! f
    private String StrId = "";
0 ^0 F# M. O: T$ I) \    @Override$ o' l# S" `6 ?# W
    public void initViews() {
0 K, C, @) A3 O        mLinearLayout.setVisibility(View.VISIBLE);; e6 T+ c6 ~) E  [+ m
        mTextViewToolbarTitle.setText("航线管理");# W5 [4 v) p9 R/ k1 L
        MyStatic.isChoose = false;& F; o/ G+ ]. e/ O0 e( g/ c3 w
    }  {$ D; D3 h0 z& \
    @Override
( }% M- `9 K/ e8 F+ E/ A    public void initDatas() {
5 z' \3 |& B4 r2 |6 Z5 u        mSQLiteHelper = new SQLiteHelper(WaypointActivity.this);
. f: H' H3 z4 e6 x        Cursor c = mSQLiteHelper.doSelect();8 U0 Y( B, ~% m! ^1 l( P
        if (c!=null){
+ ], G# [2 F- w" A8 o4 b* w) [. x% ?, W            while (c.moveToNext()){
# G( l( l* m, \                mWaypointInfo.add(new WaypointInfo(c.getInt(0),c.getString(1),c.getFloat(2),c.getFloat(3),
/ G( o4 h+ |2 X( Q1 e/ c                        c.getString(4),c.getString(5),c.getString(6),c.getInt(7),c.getInt(8),
/ s5 L8 Y% y: e+ G# Y                        c.getInt(9),c.getString(10)));: X/ N, \4 x6 g  X! ~! V" p- q
            }) V0 O; f0 a" U8 V% l
        }+ v  A7 }. H9 g, d1 p6 e, ?0 Q
        c.close();5 ^1 q* W( u! C* `
        mSQLiteHelper.close();
, d8 ]! A4 C, D5 y& P0 D7 z% ^* L        mWaypointAdapter = new WaypointAdapter(R.layout.item_waypoint);
5 [& ^& c1 O6 t. U7 @% B) J9 Q. V        mWaypointAdapter.setNewData(mWaypointInfo);
  x( R$ h7 ~6 J5 @/ z        initRv(mRecyclerView,mWaypointAdapter);3 B2 ^8 C( r/ Z* f- V, a) y% H' C
        mWaypointAdapter.setOnItemchildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
$ O3 ~8 \7 ]8 x/ L8 R8 }! I            @Override& V0 p2 i, B8 R; E
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {# |6 y+ E$ B# y) ]$ f/ Y
                Intent intent = new Intent();/ _: n9 v8 m9 C( c7 O6 D! a/ A
                intent.putExtra("id", mWaypointInfo.get(position).getId());5 e8 K/ L2 J; b- A
                setResult(RESULT_OK, intent);6 y0 ~( g# c+ K3 n
                finish();
9 K4 {6 \/ F8 q2 J- i            }
' e3 F+ e: A& F& l        });
6 H7 F. n; z7 A3 F5 y7 M        mWaypointAdapter.setOnCheckboxCheckedListener(new WaypointAdapter.OnCheckboxCheckedListener() {
5 V1 Q) I& s0 g4 b0 b. ^0 l5 @            @Override
1 i+ P( y/ _8 j8 Q            public void OnCheckboxChecked(boolean isCheck, int position) {' [+ ?3 m* G2 X% y* ~$ N5 I: \
                if (isCheck){
4 Y' h/ G$ I9 Z& t! D                    mWaypointId.add(position);: C3 k1 Z7 \+ Q/ _: [2 e& R2 {8 P  _
                }else {
) a  x3 a! G/ s$ O. G) u                    if (mWaypointId.contains(position)){6 t7 u4 |. J4 F( \7 a% b
                        mWaypointId.remove(position);
& ?6 G6 s2 P- `. x! R                    }8 p1 ?. g  x6 B3 ~4 K! k
                }
' k$ m6 D" a# i& ^5 B" s9 W            }9 V6 n& @" x2 B0 P7 P1 r/ S
        });
5 }9 A: {# ]& v0 H  j! B" s    }4 n% I* s# m# \/ I1 r1 P9 X
    @Override
, W+ v5 K" c- E/ E: D' X% |, B    protected void requestData() {
; n6 F- f( l1 U/ E% K6 k$ W6 w7 O    }, ^0 ]! b0 k% P$ W! s5 x7 _0 ]
    @OnClick({R.id.img_way_choose,R.id.img_way_delete,R.id.img_back})
% A+ A, b. S6 g* L    @Override! ]9 M3 M; Z) Y* ^3 f" P( m
    public void onClick(View v) {
$ a' w$ Y' |: S  V        switch (v.getId()){2 b9 C$ X& ?+ l4 Z3 z2 k
            case R.id.img_way_choose:. p. r  p- G7 v+ [% H. p; N5 `
                if (MyStatic.isChoose){, F3 G3 f3 V- ~5 j/ L
                    MyStatic.isChoose = false;
3 j9 `0 ~+ R& j* I# N2 g                }else {5 ~3 ~$ `. |5 b& r/ O& L1 F
                    MyStatic.isChoose = true;
# b4 ^4 _: P" B                }
+ a) s0 }' U6 z! t0 F                if (mWaypointAdapter!=null){
5 k0 _& S; a& z1 S                    mWaypointAdapter.notifyDataSetChanged();" x0 @/ L2 l+ `1 \
                }% w0 |+ E& t/ J
                break;$ E4 j/ ^- G1 o+ h
            case R.id.img_way_delete:/ T, ~/ w; a! t, z/ T) x
                if (mWaypointId.size() > 0){
/ K9 l: F. @% v" B# ]                    for (int i = 0; i ",";, r6 H( f1 G5 y! D
                    }8 F6 I8 X* ?( r
                    if (!TextUtils.isEmpty(StrId)){3 Q6 s$ n( g) D; D2 S3 N  Z( i
                        StrId = StrId.substring(0,StrId.length()-1);0 g' w3 G; B+ h5 y
                        mSQLiteHelper = new SQLiteHelper(WaypointActivity.this);
, l. Z* q9 I% v+ P                        mSQLiteHelper.doDelete(StrId);
- k6 v# y% y* R6 B0 [0 M7 D1 J                        mSQLiteHelper.close();2 z9 M+ |- y9 R. K- a
                        for (int j = 0; j if (mWaypointAdapter!=null){+ ^2 |3 [2 e5 l% Z% p
                            mWaypointId.clear();
6 M+ W# i4 C& G4 F1 L! V3 @+ N; j. ^                            MyStatic.isChoose = false;+ V: I* X4 c7 j. H1 {1 B$ ~8 [
                            mWaypointAdapter.setNewData(mWaypointInfo);
- j, S8 J! ?. U2 Z5 ]3 r                        }
- M' L6 j; r/ f% }                    }
2 [2 |1 [/ `; g- d# `                }else {8 n* y* L' R% I5 X" Q# u9 f+ [
                    showToasts("请先选择删除的航线!");
7 c; U/ ^) ^8 d  w) d8 W* X6 }% C5 O2 }                }3 m4 T0 J2 l4 k- ~
                break;6 Q2 Z, u+ |2 C8 O& ?8 a
            case R.id.img_back:  k6 u2 H! t: j% r8 o9 g
                Intent intent = new Intent();7 e1 v4 d, }  g: B8 E
                intent.putExtra("id", -1);1 g3 D6 F3 M3 ~1 X  z: @- p9 m
                setResult(RESULT_OK, intent);- r1 F5 d  J" t$ e
                finish();
" z/ A) |9 E8 K" m8 I7 F5 S                break;
5 q9 M0 z$ Y% T4 w3 }$ Z        }" J. a7 r5 ?+ ^; S2 B" C' ]; g
    }. f. M6 p( p* B, V0 p6 B8 N
以上代码仅供参考,如果想了解更多的大疆无人机二次开发过程可以私信我,源代码因为涉及到商业使用不能给大家共享,有什么问题我可以帮你解决。% U- |% |% X8 C! j- x$ h

foy31fawguz64015968541.png

foy31fawguz64015968541.png
3 T+ B8 a0 F8 B4 j2 c
往期推荐毕业设计So Easy:基于C++实现网络扫描器
- W6 M" `5 ?5 |% {" i. A0 g7 {/ @详解CAN总线:CAN节点硬件构成方案
/ m* Q7 D2 @7 x9 _LabVIEW串口通信
( s/ f! j. q3 t& h3 iLabVIEW感兴趣区域分析(实战篇—1)
% W5 p, j0 K$ EPython Qt GUI设计:信号与槽的使用方法(基础篇—7): P4 K3 R. U' g6 o
和12岁小同志搞创客开发:如何使用继电器?
! k: D* p8 @- S1 G) \PCB天线无线模组如何布局摆放?9 p+ V8 m) m* ?8 I9 J! @$ z! z
芯片内部长啥样?牛人用1500张照片,一层一层放给你看!* S. B/ h2 _" s! r5 ~; v* a* [
移柯L620模组使用MQTT协议连接移动OneNet云平台5 J# r' \* @3 Q1 y
+ p' V+ q- H: E+ v5 N# q

iid1wykcqwi64015968641.jpg

iid1wykcqwi64015968641.jpg
  `& A/ r( b0 P

hbtx5q2lqbl64015968741.gif

hbtx5q2lqbl64015968741.gif
* Q" U% z/ {& I2 n6 d
点击阅读原文,更精彩~
回复

使用道具 举报

发表回复

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

本版积分规则


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