第三篇文章準(zhǔn)備單獨(dú)拿出來(lái)寫,因?yàn)樵?a target="_blank">大疆為人機(jī)的所有功能中,航線規(guī)劃的功能最為復(fù)雜,也相當(dāng)?shù)姆爆?,這里需要說(shuō)仔細(xì)一點(diǎn),可能會(huì)將代碼進(jìn)行多步分解。
1航線規(guī)劃
航線打點(diǎn)
在地圖中手動(dòng)選擇點(diǎn)位選擇完成航線打點(diǎn);若打點(diǎn)位置錯(cuò)了可進(jìn)行點(diǎn)位刪除。
航點(diǎn)設(shè)置
可對(duì)航線點(diǎn)位進(jìn)行設(shè)置,如飛行高度,速度(慢速:3m/s;中速: 7m/s;高速:10 m/s)、任務(wù)結(jié)束后操作及航向,點(diǎn)擊[設(shè)置]按鈕完成設(shè)置。
設(shè)置完成后會(huì)顯示總距離及飛行總時(shí)間。
航線上傳
點(diǎn)擊[上傳]按鈕,進(jìn)行航線上傳??梢赃M(jìn)入本地存儲(chǔ)中選擇航線文件進(jìn)行上傳,航線文件為 .kml結(jié)尾。
航線執(zhí)行
點(diǎn)擊 [開始]按鈕,則可對(duì)航線進(jìn)行執(zhí)行。若中途需要暫停也可點(diǎn)擊[暫停]安裝進(jìn)行暫停操作。
航線管理
按鈕即可進(jìn)入航線管理界面。
獲取航線
點(diǎn)擊[獲取]按鈕,即可將航線信息展示到地圖界面中。
2主要功能代碼
創(chuàng)建activity_setting_route.xml及SettingRouteActivity文件。
activity_setting_route.xml
SettingRouteActivity
publicclassSettingRouteActivityextendsBaseActivityimplementsAMap.OnMarkerClickListener,View.OnClickListener,AMap.OnMapClickListener,LocationSource,AMapLocationListener,AMap.InfoWindowAdapter{ @BindView(R.id.layout_route) ViewmViewLayoutToolbar; @BindView(R.id.ll_route) LinearLayoutmLinearLayout; @BindView(R.id.tv_toolbar_title) TextViewmTextViewToolbarTitle; //@BindView(R.id.map) //MapViewmMapView; @BindView(R.id.btn_delete) ButtonmButtonDelete; @BindView(R.id.btn_finish) ButtonmButtonFinish; @BindView(R.id.btn_setting) ButtonmButtonSetting; @BindView(R.id.btn_upload) ButtonmButtonUpload; @BindView(R.id.btn_start) ButtonmButtonStart; @BindView(R.id.btn_stop) ButtonmButtonStop; @BindView(R.id.ll_information) LinearLayoutmLinearLayoutInformation; @BindView(R.id.tv_height) TextViewmTextViewHeight; @BindView(R.id.tv_speed) TextViewmTextViewSpeed; @BindView(R.id.tv_count) TextViewmTextViewCount; @BindView(R.id.tv_distance) TextViewmTextViewDistance; @BindView(R.id.tv_time) TextViewmTextViewTime; privateMapViewmMapView; privateOnLocationChangedListenermListener; privateAMapLocationClientmlocationClient; privateAMapLocationClientOptionmLocationOption; privatedoubleD_latitude,D_longitude; privateUiSettingsmUiSettings; privateAMapaMap; privateMarkerdroneMarker=null; privatefloataltitude=100.0f; privatefloatmSpeed=10.0f; privatebooleanisAdd=false; privatefinalMapmMarkers=newConcurrentHashMap (); privateMarkermClickMarker; privateList waypointList=newArrayList<>(); privateList mLatLng=newArrayList<>(); privateList mPointInfo=newArrayList<>(); publicstaticWaypointMission.BuilderwaypointMissionBuilder; privateFlightControllermFlightController; privateWaypointMissionOperatorinstance; privateWaypointMissionFinishedActionmFinishedAction=WaypointMissionFinishedAction.NO_ACTION; privateWaypointMissionHeadingModemHeadingMode=WaypointMissionHeadingMode.AUTO; privateSQLiteHelpermSQLiteHelper; privateStringFinishedAction,HeadingMode; //自定義窗體 ViewinfoWindow=null; intspeed_RG_id=0; intactionAfterFinished_RG_id=0; intheading_RG_id=0; //kim staticReadKmlreadKml=newReadKml(); privatestaticList sampleList=readKml.getCoordinateList(); @Override publicvoidinitViews(){ mLinearLayout.setVisibility(View.VISIBLE); mTextViewToolbarTitle.setText("航線規(guī)劃"); IntentFilterfilter=newIntentFilter(); filter.addAction(ReceiverApplication.FLAG_CONNECTION_CHANGE); registerReceiver(mReceiver,filter); mMapView=findViewById(R.id.map); mMapView.onCreate(InstanceState); initMapView(); addListener(); onProductConnectionChange(); } @Override protectedvoidonResume(){ super.onResume(); initFlightController(); mMapView.onResume(); } /** *方法必須重寫 */ @Override protectedvoidonSaveInstanceState(BundleoutState){ super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } @Override protectedvoidonPause(){ super.onPause(); mMapView.onPause(); deactivate(); } @Override protectedvoidonDestroy(){ super.onDestroy(); unregisterReceiver(mReceiver); removeListener(); mMapView.onDestroy(); if(null!=mlocationClient){ mlocationClient.onDestroy(); } } @Override publicvoidinitDatas(){ } @Override protectedvoidrequestData(){ } privatevoidinitMapView(){ if(aMap==null){ aMap=mMapView.getMap(); mUiSettings=aMap.getUiSettings(); mUiSettings.setMyLocationButtonEnabled(true); mUiSettings.setScaleControlsEnabled(true); aMap.setOnMapClickListener(this);//addthelistenerforclickforamapobject aMap.setLocationSource(this); aMap.setMyLocationEnabled(true); aMap.setInfoWindowAdapter(this); aMap.setOnMarkerClickListener(this); setupLocationStyle(); } } privatevoidsetupLocationStyle(){ //自定義系統(tǒng)定位藍(lán)點(diǎn) MyLocationStylemyLocationStyle=newMyLocationStyle(); //自定義定位藍(lán)點(diǎn)圖標(biāo) myLocationStyle.myLocationIcon(BitmapDescriptorFactory. fromResource(R.mipmap.icv_gps_point_36dp)); //自定義精度范圍的圓形邊框顏色 myLocationStyle.strokeColor(Color.parseColor("#00000000")); //自定義精度范圍的圓形邊框?qū)挾?myLocationStyle.strokeWidth(5); //設(shè)置圓形的填充顏色 myLocationStyle.radiusFillColor(Color.parseColor("#00000000")); //將自定義的myLocationStyle對(duì)象添加到地圖上 aMap.setMyLocationStyle(myLocationStyle); } @OnClick({R.id.img_kml_input,R.id.img_setting_route,R.id.img_start_fly,R.id.btn_delete, R.id.img_setting_clear,R.id.btn_finish,R.id.btn_setting,R.id.btn_upload, R.id.btn_start,R.id.btn_stop,R.id.img_back}) @Override publicvoidonClick(Viewv){ switch(v.getId()){ caseR.id.img_back: SettingRouteActivity.this.finish(); break; caseR.id.img_kml_input: Intentintent=newIntent(Intent.ACTION_GET_CONTENT); intent.setType("*/*");//設(shè)置類型,我這里是任意類型,任意后綴的可以這樣寫。 intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent,MyStatic.REQUEST_CODE_FILE); break; caseR.id.img_setting_route: enableDisableAdd(); break; caseR.id.img_setting_clear: runOnUiThread(newRunnable(){ @Override publicvoidrun(){ aMap.clear(); mMarkers.clear(); mPointInfo.clear(); mLinearLayoutInformation.setVisibility(View.GONE); mButtonFinish.setVisibility(View.GONE); mButtonSetting.setVisibility(View.GONE); mButtonUpload.setVisibility(View.GONE); mButtonStart.setVisibility(View.GONE); mButtonStop.setVisibility(View.GONE); } }); waypointList.clear(); waypointMissionBuilder.waypointList(waypointList); break; caseR.id.img_start_fly: atyAction(WaypointActivity.class,MyStatic.REQUEST_CODE_ID); break; caseR.id.btn_delete: runOnUiThread(newRunnable(){ @Override publicvoidrun(){ aMap.clear(); } }); for(inti=0;i-90&&latitude90?&&?longitude?>-180&&longitude180)?&&?(latitude?!=?0f?&&?longitude?!=?0f); ????????} ????????protected?BroadcastReceiver?mReceiver?=?new?BroadcastReceiver()?{ ????????????@Override ????????????public?void?onReceive(Context?context,?Intent?intent)?{ ????????????????onProductConnectionChange(); ????????????} ????????}; ????????private?void?onProductConnectionChange()?{ ????????????initFlightController(); ????????} ????????private?void?addListener()?{ ????????????if?(getWaypointMissionOperator()?!=?null)?{ ????????????????getWaypointMissionOperator().addListener(eventNotificationListener); ????????????} ????????} ????????private?void?removeListener()?{ ????????????if?(getWaypointMissionOperator()?!=?null)?{ ????????????????getWaypointMissionOperator().removeListener(eventNotificationListener); ????????????} ????????} ????????private?WaypointMissionOperatorListener?eventNotificationListener?=?new?WaypointMissionOperatorListener()?{ ????????????@Override ????????????public?void?onDownloadUpdate(WaypointMissionDownloadEvent?downloadEvent)?{ ????????????} ????????????@Override ????????????public?void?onUploadUpdate(WaypointMissionUploadEvent?uploadEvent)?{ ????????????} ????????????@Override ????????????public?void?onExecutionUpdate(WaypointMissionExecutionEvent?executionEvent)?{ ????????????} ????????????@Override ????????????public?void?onExecutionStart()?{ ????????????} ????????????@Override ????????????public?void?onExecutionFinish(@Nullable?final?DJIError?error)?{ ????????????????showToasts("Execution?finished:?"?+?(error?==?null???"Success!"?:?error.getDescription())); ????????????} ????????}; ????????public?WaypointMissionOperator?getWaypointMissionOperator()?{ ????????????if?(instance?==?null)?{ ????????????????instance?=?DJISDKManager.getInstance().getMissionControl().getWaypointMissionOperator(); ????????????} ????????????return?instance; ????????} ????????@Override ????????public?void?onMapClick(LatLng?point)?{ ????????????if?(isAdd?==?true)?{ ????????????????markWaypoint(point); ????????????????Waypoint?mWaypoint?=?new?Waypoint(point.latitude,?point.longitude,?altitude); ????????????????//Add?Waypoints?to?Waypoint?arraylist; ????????????????if?(waypointMissionBuilder?!=?null)?{ ????????????????????waypointList.add(mWaypoint); ????????????????????waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size()); ????????????????}?else?{ ????????????????????waypointMissionBuilder?=?new?WaypointMission.Builder(); ????????????????????waypointList.add(mWaypoint); ????????????????????waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size()); ????????????????} ????????????????mTextViewCount.setText("航點(diǎn)數(shù):"?+?waypointMissionBuilder.getWaypointCount()); ????????????????mTextViewDistance.setText("總距離:"?+?Math.round(waypointMissionBuilder.calculateTotalDistance())?+?"m"); ????????????????mTextViewTime.setText("總時(shí)間:"?+?Math.round(waypointMissionBuilder.calculateTotalTime())?+?"min"); ????????????}?else?{ ????????????????if?(mClickMarker?!=?null?&&?mClickMarker.isInfoWindowShown())?{ ????????????????????mClickMarker.hideInfoWindow(); ????????????????????mButtonDelete.setVisibility(View.GONE); ????????????????} ????????????????//????????????showToasts("當(dāng)前未開啟增加點(diǎn)模式"); ????????????} ????????} ????????private?void?markWaypoint(LatLng?point)?{ ????????????MarkerOptions?markerOptions?=?new?MarkerOptions(); ????????????markerOptions.position(point); ????????????mPointInfo.add(new?PointInfo(point.latitude,?point.longitude)); ????????????markerOptions.title("航點(diǎn)"?+?(mMarkers.size()?+?1)); ????????????markerOptions.snippet("事件:"); ????????????markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); ????????????markerOptions.infoWindowEnable(true); ????????????Marker?marker?=?aMap.addMarker(markerOptions); ????????????mMarkers.put(mMarkers.size(),?marker); ????????????marker.showInfoWindow(); ????????????if?(mMarkers.size()?>0){ mLatLng.clear(); PolylineOptionsPolylineOptions=newPolylineOptions(); for(inti=0;i0){ PolylineOptionsPolylineOptions=newPolylineOptions(); PolylineOptions.addAll(mLatLng); PolylineOptions.width(10); PolylineOptions.color(Color.argb(255,1,1,1)); aMap.addPolyline(PolylineOptions); } waypointMissionBuilder.waypointList(waypointList).waypointCount(waypointList.size()); mTextViewCount.setText("航點(diǎn)數(shù):"+waypointMissionBuilder.getWaypointCount()); mTextViewDistance.setText("總距離:"+Math.round(waypointMissionBuilder.calculateTotalDistance())+"m"); mTextViewTime.setText("總時(shí)間:"+Math.round(waypointMissionBuilder.calculateTotalTime())+"min"); MyLog.d("航點(diǎn)數(shù):"+waypointMissionBuilder.getWaypointCount()); MyLog.d("總距離:"+waypointMissionBuilder.calculateTotalDistance()); MyLog.d("總時(shí)間:"+waypointMissionBuilder.calculateTotalTime()); mButtonDelete.setVisibility(View.GONE); } /** *定位成功后回調(diào)函數(shù) */ @Override publicvoidonLocationChanged(AMapLocationamapLocation){ if(mListener!=null&&amapLocation!=null){ if(amapLocation!=null &&amapLocation.getErrorCode()==0){ D_latitude=amapLocation.getLatitude();//獲取緯度 D_longitude=amapLocation.getLongitude();//獲取經(jīng)度 mListener.onLocationChanged(amapLocation);//顯示系統(tǒng)小藍(lán)點(diǎn) aMap.moveCamera(CameraUpdateFactory.zoomTo(18)); }else{ StringerrText="定位失敗,"+amapLocation.getErrorCode()+":"+amapLocation.getErrorInfo(); Log.e("AmapErr",errText); } } } @Override publicvoidactivate(OnLocationChangedListenerlistener){ mListener=listener; if(mlocationClient==null){ try{ mlocationClient=newAMapLocationClient(this); }catch(Exceptione){ e.printStackTrace(); } mLocationOption=newAMapLocationClientOption(); //設(shè)置定位監(jiān)聽 mlocationClient.setLocationListener(this); //設(shè)置為高精度定位模式 mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); //設(shè)置定位參數(shù) mLocationOption.setOnceLocation(true); mlocationClient.setLocationOption(mLocationOption); //此方法為每隔固定時(shí)間會(huì)發(fā)起一次定位請(qǐng)求,為了減少電量消耗或網(wǎng)絡(luò)流量消耗, //注意設(shè)置合適的定位時(shí)間的間隔(最小間隔支持為2000ms),并且在合適時(shí)間調(diào)用stopLocation()方法來(lái)取消定位請(qǐng)求 //在定位結(jié)束后,在合適的生命周期調(diào)用onDestroy()方法 //在單次定位情況下,定位無(wú)論成功與否,都無(wú)需調(diào)用stopLocation()方法移除請(qǐng)求,定位sdk內(nèi)部會(huì)移除 mlocationClient.startLocation(); } } @Override publicvoiddeactivate(){ mListener=null; if(mlocationClient!=null){ mlocationClient.stopLocation(); mlocationClient.onDestroy(); } mlocationClient=null; } @Override publicViewgetInfoWindow(Markermarker){ if(infoWindow==null){ infoWindow=LayoutInflater.from(this).inflate(R.layout.amap_info_window,null); } render(marker,infoWindow); returninfoWindow; } /** *自定義infoWindow窗口 */ privatevoidrender(Markermarker,ViewinfoWindow){ TextViewtitle=infoWindow.findViewById(R.id.info_window_title); TextViewcontent=infoWindow.findViewById(R.id.info_window_content); title.setText(marker.getTitle()); content.setText(marker.getSnippet()); } @Override publicViewgetInfoContents(Markermarker){ returnnull; } @Override publicbooleanonMarkerClick(Markermarker){ marker.showInfoWindow(); mClickMarker=marker; mButtonDelete.setVisibility(View.VISIBLE); //aMap.moveCamera(CameraUpdateFactory.newCameraPosition(newCameraPosition(marker.getPosition(),18,0,0))); returntrue; } privatevoidshowSettingDialog(){ LinearLayoutwayPointSettings=(LinearLayout)getLayoutInflater().inflate(R.layout.dialog_waypointsetting,null); finalTextViewwpAltitude_TV=(TextView)wayPointSettings.findViewById(R.id.altitude); RadioGroupspeed_RG=(RadioGroup)wayPointSettings.findViewById(R.id.speed); RadioGroupactionAfterFinished_RG=(RadioGroup)wayPointSettings.findViewById(R.id.actionAfterFinished); RadioGroupheading_RG=(RadioGroup)wayPointSettings.findViewById(R.id.heading); wpAltitude_TV.setText(Math.round(altitude)+""); if(speed_RG_id!=0){ RadioButtonradioButton=(RadioButton)speed_RG.findViewById(speed_RG_id); radioButton.setChecked(true); } if(actionAfterFinished_RG_id!=0){ RadioButtonradioButton=(RadioButton)actionAfterFinished_RG.findViewById(actionAfterFinished_RG_id); radioButton.setChecked(true); } if(heading_RG_id!=0){ RadioButtonradioButton=(RadioButton)heading_RG.findViewById(heading_RG_id); radioButton.setChecked(true); } speed_RG.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Override publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){ if(checkedId==R.id.lowSpeed){ mSpeed=3.0f; }elseif(checkedId==R.id.MidSpeed){ mSpeed=5.0f; }elseif(checkedId==R.id.HighSpeed){ mSpeed=10.0f; } speed_RG_id=checkedId; } }); actionAfterFinished_RG.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Override publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){ MyLog.d("選擇動(dòng)作完成"); if(checkedId==R.id.finishNone){ mFinishedAction=WaypointMissionFinishedAction.NO_ACTION; FinishedAction="0"; }elseif(checkedId==R.id.finishGoHome){ mFinishedAction=WaypointMissionFinishedAction.GO_HOME; FinishedAction="1"; }elseif(checkedId==R.id.finishAutoLanding){ mFinishedAction=WaypointMissionFinishedAction.AUTO_LAND; FinishedAction="2"; }elseif(checkedId==R.id.finishToFirst){ mFinishedAction=WaypointMissionFinishedAction.GO_FIRST_WAYPOINT; FinishedAction="3"; } actionAfterFinished_RG_id=checkedId; } }); heading_RG.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Override publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){ MyLog.d("選擇標(biāo)題"); if(checkedId==R.id.headingNext){ mHeadingMode=WaypointMissionHeadingMode.AUTO; HeadingMode="0"; }elseif(checkedId==R.id.headingInitDirec){ mHeadingMode=WaypointMissionHeadingMode.USING_INITIAL_DIRECTION; HeadingMode="1"; }elseif(checkedId==R.id.headingRC){ mHeadingMode=WaypointMissionHeadingMode.CONTROL_BY_REMOTE_CONTROLLER; HeadingMode="2"; }elseif(checkedId==R.id.headingWP){ mHeadingMode=WaypointMissionHeadingMode.USING_WAYPOINT_HEADING; HeadingMode="3"; } heading_RG_id=checkedId; } }); newAlertDialog.Builder(this) .setTitle("航點(diǎn)設(shè)置") .setView(wayPointSettings) .setNeutralButton("設(shè)置",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ StringaltitudeString=wpAltitude_TV.getText().toString(); altitude=Integer.parseInt(nulltoIntegerDefalt(altitudeString)); MyLog.e("altitude"+altitude); MyLog.e("speed"+mSpeed); MyLog.e("mFinishedAction"+mFinishedAction); MyLog.e("mHeadingMode"+mHeadingMode); configWayPointMission(); } }) .setCancelable(false) .create() .show(); } StringnulltoIntegerDefalt(Stringvalue){ if(!isIntValue(value)) value="0"; returnvalue; } booleanisIntValue(Stringval){ try{ val=val.replace("",""); Integer.parseInt(val); }catch(Exceptione){ returnfalse; } returntrue; } privatevoidconfigWayPointMission(){ if(waypointMissionBuilder==null){ waypointMissionBuilder=newWaypointMission.Builder().finishedAction(mFinishedAction) .headingMode(mHeadingMode) .autoFlightSpeed(mSpeed) .maxFlightSpeed(mSpeed) .flightPathMode(WaypointMissionFlightPathMode.NORMAL); }else{ waypointMissionBuilder.finishedAction(mFinishedAction) .headingMode(mHeadingMode) .autoFlightSpeed(mSpeed) .maxFlightSpeed(mSpeed) .flightPathMode(WaypointMissionFlightPathMode.NORMAL); } if(waypointMissionBuilder.getWaypointList().size()>0){ for(inti=0;i-1){ refreshMapPoint(Id); } break; case102: if(data.getData()!=null){ Uriuri=data.getData();//得到uri,后面就是將uri轉(zhuǎn)化成file的過(guò)程。 Stringimg_path=uri.getPath(); try{ if(!TextUtils.isEmpty(img_path)){ readKml.parseKml(img_path); addSampleMarker(); } }catch(Exceptione){ e.printStackTrace(); } } break; default: break; } } privatevoidrefreshMapPoint(intid){ aMap.clear(); mMarkers.clear(); mPointInfo.clear(); mLinearLayoutInformation.setVisibility(View.GONE); mButtonFinish.setVisibility(View.GONE); mButtonSetting.setVisibility(View.GONE); mButtonUpload.setVisibility(View.GONE); mButtonStart.setVisibility(View.GONE); mButtonStop.setVisibility(View.GONE); waypointList.clear(); mSQLiteHelper=newSQLiteHelper(SettingRouteActivity.this); Cursorc=mSQLiteHelper.doSelectWaypoint(id); if(c!=null){ if(c.moveToNext()){ MyLog.d("航點(diǎn):"+"{'pointInfo':"+c.getString(1)+"}"); mPointInfo.addAll(GsonUtil.GsonToBean("{'pointInfo':"+c.getString(1)+"}",Root.class).getPointInfo()); altitude=c.getFloat(2); mSpeed=c.getFloat(3); switch(c.getString(4)){ case"0": mHeadingMode=WaypointMissionHeadingMode.AUTO; break; case"1": mHeadingMode=WaypointMissionHeadingMode.USING_INITIAL_DIRECTION; break; case"2": mHeadingMode=WaypointMissionHeadingMode.CONTROL_BY_REMOTE_CONTROLLER; break; case"3": mHeadingMode=WaypointMissionHeadingMode.USING_WAYPOINT_HEADING; break; case"4": mHeadingMode=WaypointMissionHeadingMode.TOWARD_POINT_OF_INTEREST; break; } switch(c.getString(5)){ case"0": mFinishedAction=WaypointMissionFinishedAction.NO_ACTION; break; case"1": mFinishedAction=WaypointMissionFinishedAction.GO_HOME; break; case"2": mFinishedAction=WaypointMissionFinishedAction.AUTO_LAND; break; case"3": mFinishedAction=WaypointMissionFinishedAction.GO_FIRST_WAYPOINT; break; case"4": mFinishedAction=WaypointMissionFinishedAction.CONTINUE_UNTIL_END; break; } } } for(inti=0;i0){ mLatLng.clear(); PolylineOptionsPolylineOptions=newPolylineOptions(); for(inti=0;i0){ for(inti=0;i
3
航線管理
創(chuàng)建activity_waypoint.xml和WaypointActivity文件。
activity_waypoint.xml
WaypointActivity
@Layout(R.layout.activity_waypoint) publicclassWaypointActivityextendsBaseActivityimplementsView.OnClickListener{ @BindView(R.id.layout_waypoint) ViewmViewLayoutToolbar; @BindView(R.id.ll_waypoint) LinearLayoutmLinearLayout; @BindView(R.id.tv_toolbar_title) TextViewmTextViewToolbarTitle; @BindView(R.id.rv_waypoint) RecyclerViewmRecyclerView; privateSQLiteHelpermSQLiteHelper; privateListmWaypointInfo=newArrayList<>(); privateWaypointAdaptermWaypointAdapter; privateList mWaypointId=newArrayList<>(); privateStringStrId=""; @Override publicvoidinitViews(){ mLinearLayout.setVisibility(View.VISIBLE); mTextViewToolbarTitle.setText("航線管理"); MyStatic.isChoose=false; } @Override publicvoidinitDatas(){ mSQLiteHelper=newSQLiteHelper(WaypointActivity.this); Cursorc=mSQLiteHelper.doSelect(); if(c!=null){ while(c.moveToNext()){ mWaypointInfo.add(newWaypointInfo(c.getInt(0),c.getString(1),c.getFloat(2),c.getFloat(3), c.getString(4),c.getString(5),c.getString(6),c.getInt(7),c.getInt(8), c.getInt(9),c.getString(10))); } } c.close(); mSQLiteHelper.close(); mWaypointAdapter=newWaypointAdapter(R.layout.item_waypoint); mWaypointAdapter.setNewData(mWaypointInfo); initRv(mRecyclerView,mWaypointAdapter); mWaypointAdapter.setOnItemChildClickListener(newBaseQuickAdapter.OnItemChildClickListener(){ @Override publicvoidonItemChildClick(BaseQuickAdapteradapter,Viewview,intposition){ Intentintent=newIntent(); intent.putExtra("id",mWaypointInfo.get(position).getId()); setResult(RESULT_OK,intent); finish(); } }); mWaypointAdapter.setOnCheckboxCheckedListener(newWaypointAdapter.OnCheckboxCheckedListener(){ @Override publicvoidOnCheckboxChecked(booleanisCheck,intposition){ if(isCheck){ mWaypointId.add(position); }else{ if(mWaypointId.contains(position)){ mWaypointId.remove(position); } } } }); } @Override protectedvoidrequestData(){ } @OnClick({R.id.img_way_choose,R.id.img_way_delete,R.id.img_back}) @Override publicvoidonClick(Viewv){ switch(v.getId()){ caseR.id.img_way_choose: if(MyStatic.isChoose){ MyStatic.isChoose=false; }else{ MyStatic.isChoose=true; } if(mWaypointAdapter!=null){ mWaypointAdapter.notifyDataSetChanged(); } break; caseR.id.img_way_delete: if(mWaypointId.size()>0){ for(inti=0;i
以上代碼僅供參考,如果想了解更多的大疆無(wú)人機(jī)二次開發(fā)過(guò)程可以私信我,源代碼因?yàn)樯婕暗缴虡I(yè)使用不能給大家共享,有什么問(wèn)題我可以幫你解決。
審核編輯:湯梓紅
-
Mobile
+關(guān)注
關(guān)注
0文章
518瀏覽量
26483 -
遙控器
+關(guān)注
關(guān)注
18文章
836瀏覽量
66053 -
無(wú)人機(jī)
+關(guān)注
關(guān)注
229文章
10420瀏覽量
180109 -
SDK
+關(guān)注
關(guān)注
3文章
1035瀏覽量
45897 -
大疆無(wú)人機(jī)
+關(guān)注
關(guān)注
13文章
111瀏覽量
30207
原文標(biāo)題:基于Mobile SDK V4版固件開發(fā)大疆無(wú)人機(jī)手機(jī)端遙控器(3)
文章出處:【微信號(hào):美男子玩編程,微信公眾號(hào):美男子玩編程】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論