From c73220e415774cee3d4baececaa7305a984a28b0 Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Fri, 19 Dec 2014 00:33:46 -0800 Subject: [PATCH 1/7] renamed CardWheelHorizontalView.OnChangedListener to CardWheelHorizontalView.OnScrollListener. added more functionality to the updated CardWheelHorizontalView.OnScrollListener interface. updated MissionSurveyFragment to get rid of the jerkiness of the cardwheelhorizontalview scroll. updated the ui for the SetServo mission item. --- Android/build.gradle | 4 +- .../fragment_editor_detail_set_servo.xml | 24 +- Android/res/values-zh-rCN/strings.xml | 3 - Android/res/values/strings.xml | 2 +- .../fragments/mode/ModeFollowFragment.java | 6 +- .../fragments/mode/ModeGuidedFragment.java | 20 +- .../MissionCameraTriggerFragment.java | 20 +- .../fragments/MissionChangeSpeedFragment.java | 20 +- .../item/fragments/MissionCircleFragment.java | 28 +- .../MissionConditionYawFragment.java | 21 +- .../MissionRegionOfInterestFragment.java | 20 +- .../MissionSplineWaypointFragment.java | 24 +- .../MissionStructureScannerFragment.java | 32 +- .../item/fragments/MissionSurveyFragment.java | 310 ++++++++++-------- .../fragments/MissionTakeoffFragment.java | 20 +- .../fragments/MissionWaypointFragment.java | 24 +- .../item/fragments/SetServoFragment.java | 71 ++-- .../spinnerWheel/CardWheelHorizontalView.java | 35 +- 18 files changed, 403 insertions(+), 281 deletions(-) diff --git a/Android/build.gradle b/Android/build.gradle index 4d7b680dd8..e99602be93 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -11,7 +11,7 @@ dependencies { compile 'com.android.support:cardview-v7:21.0.2' compile 'com.android.support:recyclerview-v7:21.0.2' - compile 'com.o3dr:3dr-services-lib:2.1.14' + compile 'com.o3dr:3dr-services-lib:2.1.17' compile files('libs/droneapi-java.jar') compile files('libs/j2xx.jar') @@ -29,7 +29,7 @@ android { applicationId 'org.droidplanner.android' minSdkVersion 14 targetSdkVersion 21 - versionCode 30010 + versionCode 30011 versionName getGitVersion() } diff --git a/Android/res/layout/fragment_editor_detail_set_servo.xml b/Android/res/layout/fragment_editor_detail_set_servo.xml index b88b44af06..6127dfc60f 100644 --- a/Android/res/layout/fragment_editor_detail_set_servo.xml +++ b/Android/res/layout/fragment_editor_detail_set_servo.xml @@ -93,25 +93,15 @@ android:layout_height="wrap_content" android:orientation="vertical" android:text="@string/channel_label" /> - - - - - + android:orientation="vertical" + android:text="@string/pwm"/> + \ No newline at end of file diff --git a/Android/res/values-zh-rCN/strings.xml b/Android/res/values-zh-rCN/strings.xml index ab334ea3fe..b3cb619d50 100644 --- a/Android/res/values-zh-rCN/strings.xml +++ b/Android/res/values-zh-rCN/strings.xml @@ -211,9 +211,6 @@ 设置一个位置和高度来设定飞行器指向,瞄准可选的相机。 重复航点 - - PWM: - 在LAND或RTL后无法添加新的航点 距离:200m,飞行时间:3:30s diff --git a/Android/res/values/strings.xml b/Android/res/values/strings.xml index 00f7eaf80f..a4ba4968c6 100644 --- a/Android/res/values/strings.xml +++ b/Android/res/values/strings.xml @@ -212,7 +212,7 @@ Repeat waypoint - PWM: + PWM One cannot add new waypoints after LAND or RTL diff --git a/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java b/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java index 5ba3a43921..6f5cce1c20 100644 --- a/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java +++ b/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java @@ -61,7 +61,7 @@ public void onViewCreated(View parentView, Bundle savedInstanceState) { mRadiusWheel = (CardWheelHorizontalView) parentView.findViewById(R.id.radius_spinner); mRadiusWheel.setViewAdapter(radiusAdapter); updateCurrentRadius(); - mRadiusWheel.addChangingListener(this); + mRadiusWheel.addScrollListener(this); spinner = (Spinner) parentView.findViewById(R.id.follow_type_spinner); adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item); @@ -93,7 +93,7 @@ public void onApiDisconnected() { } @Override - public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + public void onScrollingEnded(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { switch (cardWheel.getId()) { case R.id.radius_spinner: final Drone drone = getDrone(); @@ -102,7 +102,7 @@ public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newVa break; default: - super.onChanged(cardWheel, oldValue, newValue); + super.onScrollingEnded(cardWheel, oldValue, newValue); break; } } diff --git a/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java b/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java index a8d9554630..7fa9bd12ec 100644 --- a/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java +++ b/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java @@ -14,7 +14,7 @@ import org.droidplanner.android.widgets.spinnerWheel.adapters.NumericWheelAdapter; public class ModeGuidedFragment extends ApiListenerFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { private static final float DEFAULT_ALTITUDE = 2f; @@ -35,7 +35,7 @@ public void onViewCreated(View parentView, Bundle savedInstanceState) { mAltitudeWheel = (CardWheelHorizontalView) parentView.findViewById(R.id.altitude_spinner); mAltitudeWheel.setViewAdapter(altitudeAdapter); - mAltitudeWheel.addChangingListener(this); + mAltitudeWheel.addScrollListener(this); } @Override @@ -46,13 +46,23 @@ public void onDestroyView() { } } - @Override - public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, int endValue) { switch (cardWheel.getId()) { case R.id.altitude_spinner: final Drone drone = getDrone(); if (drone.isConnected()) - drone.setGuidedAltitude(newValue); + drone.setGuidedAltitude(endValue); break; } } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCameraTriggerFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCameraTriggerFragment.java index 993789ca10..d081279705 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCameraTriggerFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCameraTriggerFragment.java @@ -11,7 +11,7 @@ import com.o3dr.services.android.lib.drone.mission.item.command.CameraTrigger; public class MissionCameraTriggerFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -33,17 +33,27 @@ public void onApiConnected() { final CardWheelHorizontalView cardAltitudePicker = (CardWheelHorizontalView) view .findViewById(R.id.picker1); cardAltitudePicker.setViewAdapter(adapter); - cardAltitudePicker.addChangingListener(this); + cardAltitudePicker.addScrollListener(this); cardAltitudePicker.setCurrentValue((int) item.getTriggerDistance()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.picker1: for(MissionItem missionItem : getMissionItems()) { CameraTrigger item = (CameraTrigger) missionItem; - item.setTriggerDistance(newValue); + item.setTriggerDistance(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionChangeSpeedFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionChangeSpeedFragment.java index 025453d460..9c0aa811ba 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionChangeSpeedFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionChangeSpeedFragment.java @@ -11,7 +11,7 @@ import com.o3dr.services.android.lib.drone.mission.item.command.ChangeSpeed; public class MissionChangeSpeedFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -31,19 +31,29 @@ public void onApiConnected(){ CardWheelHorizontalView cardAltitudePicker = (CardWheelHorizontalView) view.findViewById (R.id.picker1); cardAltitudePicker.setViewAdapter(adapter); - cardAltitudePicker.addChangingListener(this); + cardAltitudePicker.addScrollListener(this); ChangeSpeed item = (ChangeSpeed) getMissionItems().get(0); cardAltitudePicker.setCurrentValue((int) item.getSpeed()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.picker1: for(MissionItem missionItem : getMissionItems()) { ChangeSpeed item = (ChangeSpeed) missionItem; - item.setSpeed(newValue); + item.setSpeed(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCircleFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCircleFragment.java index a9cb0cce13..8604304fcb 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCircleFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionCircleFragment.java @@ -14,7 +14,7 @@ import java.util.List; public class MissionCircleFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -36,14 +36,14 @@ public void onApiConnected() { CardWheelHorizontalView altitudePicker = (CardWheelHorizontalView) view .findViewById(R.id.altitudePicker); altitudePicker.setViewAdapter(altitudeAdapter); - altitudePicker.addChangingListener(this); + altitudePicker.addScrollListener(this); final NumericWheelAdapter loiterTurnAdapter = new NumericWheelAdapter(context, R.layout.wheel_text_centered, 0, 10, "%d"); CardWheelHorizontalView loiterTurnPicker = (CardWheelHorizontalView) view .findViewById(R.id.loiterTurnPicker); loiterTurnPicker.setViewAdapter(loiterTurnAdapter); - loiterTurnPicker.addChangingListener(this); + loiterTurnPicker.addScrollListener(this); final NumericWheelAdapter loiterRadiusAdapter = new NumericWheelAdapter(context, 0, 50, "%d m"); @@ -51,7 +51,7 @@ public void onApiConnected() { CardWheelHorizontalView loiterRadiusPicker = (CardWheelHorizontalView) view .findViewById(R.id.loiterRadiusPicker); loiterRadiusPicker.setViewAdapter(loiterRadiusAdapter); - loiterRadiusPicker.addChangingListener(this); + loiterRadiusPicker.addScrollListener(this); // Use the first one as reference. final Circle firstItem = getMissionItems().get(0); @@ -60,18 +60,28 @@ public void onApiConnected() { loiterRadiusPicker.setCurrentValue((int) firstItem.getRadius()); } - @Override - public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, int endValue) { switch (cardWheel.getId()) { case R.id.altitudePicker: for (Circle item : getMissionItems()) { - item.getCoordinate().setAltitude(newValue); + item.getCoordinate().setAltitude(endValue); } break; case R.id.loiterRadiusPicker: for (Circle item : getMissionItems()) { - item.setRadius(newValue); + item.setRadius(endValue); } MissionProxy missionProxy = getMissionProxy(); @@ -81,7 +91,7 @@ public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newVa case R.id.loiterTurnPicker: for (Circle item : getMissionItems()) { - item.setTurns(newValue); + item.setTurns(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionConditionYawFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionConditionYawFragment.java index 8a40c2d3ba..95a0fe5dba 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionConditionYawFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionConditionYawFragment.java @@ -4,7 +4,6 @@ import org.droidplanner.android.widgets.spinnerWheel.CardWheelHorizontalView; import org.droidplanner.android.widgets.spinnerWheel.adapters.NumericWheelAdapter; -import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -15,7 +14,7 @@ import com.o3dr.services.android.lib.drone.mission.item.command.YawCondition; public class MissionConditionYawFragment extends MissionDetailFragment - implements CardWheelHorizontalView.OnCardWheelChangedListener, + implements CardWheelHorizontalView.OnCardWheelScrollListener, OnCheckedChangeListener { @Override @@ -38,7 +37,7 @@ public void onApiConnected() { final CardWheelHorizontalView cardAltitudePicker = (CardWheelHorizontalView) view .findViewById(R.id.picker1); cardAltitudePicker.setViewAdapter(adapter); - cardAltitudePicker.addChangingListener(this); + cardAltitudePicker.addScrollListener(this); cardAltitudePicker.setCurrentValue((int) item.getAngle()); CheckBox checkBoxRelative = (CheckBox) view.findViewById(R.id.checkBox1); @@ -46,13 +45,23 @@ public void onApiConnected() { checkBoxRelative.setChecked(item.isRelative()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.picker1: for (MissionItem missionItem : getMissionItems()) { YawCondition item = (YawCondition) missionItem; - item.setAngle(newValue); + item.setAngle(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionRegionOfInterestFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionRegionOfInterestFragment.java index 76220b729c..98eb34b8b6 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionRegionOfInterestFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionRegionOfInterestFragment.java @@ -11,7 +11,7 @@ import org.droidplanner.android.widgets.spinnerWheel.adapters.NumericWheelAdapter; public class MissionRegionOfInterestFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -31,18 +31,28 @@ public void onApiConnected() { CardWheelHorizontalView altitudePicker = (CardWheelHorizontalView) view .findViewById(R.id.altitudePicker); altitudePicker.setViewAdapter(altitudeAdapter); - altitudePicker.addChangingListener(this); + altitudePicker.addScrollListener(this); altitudePicker.setCurrentValue((int) ((RegionOfInterest) getMissionItems().get(0)) .getCoordinate().getAltitude()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.altitudePicker: for (MissionItem missionItem : getMissionItems()) { - ((RegionOfInterest) missionItem).getCoordinate().setAltitude(newValue); + ((RegionOfInterest) missionItem).getCoordinate().setAltitude(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSplineWaypointFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSplineWaypointFragment.java index 04b2177cd3..e32b260b62 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSplineWaypointFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSplineWaypointFragment.java @@ -15,7 +15,7 @@ * This class renders the detail view for a spline waypoint mission item. */ public class MissionSplineWaypointFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -36,32 +36,42 @@ public void onApiConnected(){ CardWheelHorizontalView delayPicker = (CardWheelHorizontalView) view.findViewById(R.id .waypointDelayPicker); delayPicker.setViewAdapter(delayAdapter); - delayPicker.addChangingListener(this); + delayPicker.addScrollListener(this); final NumericWheelAdapter altitudeAdapter = new NumericWheelAdapter(context, R.layout.wheel_text_centered, MIN_ALTITUDE, MAX_ALTITUDE, "%d m"); CardWheelHorizontalView altitudePicker = (CardWheelHorizontalView) view.findViewById(R.id .altitudePicker); altitudePicker.setViewAdapter(altitudeAdapter); - altitudePicker.addChangingListener(this); + altitudePicker.addScrollListener(this); SplineWaypoint item = (SplineWaypoint) getMissionItems().get(0); delayPicker.setCurrentValue((int) item.getDelay()); altitudePicker.setCurrentValue((int) item.getCoordinate().getAltitude()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.altitudePicker: for(MissionItem item: getMissionItems()) { - ((SplineWaypoint)item).getCoordinate().setAltitude(newValue); + ((SplineWaypoint)item).getCoordinate().setAltitude(endValue); } break; case R.id.waypointDelayPicker: for(MissionItem item: getMissionItems()) { - ((SplineWaypoint)item).setDelay(newValue); + ((SplineWaypoint)item).setDelay(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java index e0db3374ff..151aec1826 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java @@ -25,7 +25,7 @@ import java.util.List; public class MissionStructureScannerFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener, CompoundButton.OnCheckedChangeListener { + CardWheelHorizontalView.OnCardWheelScrollListener, CompoundButton.OnCheckedChangeListener { private CamerasAdapter cameraAdapter; @@ -57,25 +57,25 @@ public void onApiConnected() { .findViewById(R.id.radiusPicker); radiusPicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, 2, 100, "%d m")); - radiusPicker.addChangingListener(this); + radiusPicker.addScrollListener(this); CardWheelHorizontalView startAltitudeStepPicker = (CardWheelHorizontalView) view .findViewById(R.id.startAltitudePicker); startAltitudeStepPicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, MIN_ALTITUDE, MAX_ALTITUDE, "%d m")); - startAltitudeStepPicker.addChangingListener(this); + startAltitudeStepPicker.addScrollListener(this); CardWheelHorizontalView endAltitudeStepPicker = (CardWheelHorizontalView) view .findViewById(R.id.heightStepPicker); endAltitudeStepPicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, 1, MAX_ALTITUDE, "%d m")); - endAltitudeStepPicker.addChangingListener(this); + endAltitudeStepPicker.addScrollListener(this); CardWheelHorizontalView mNumberStepsPicker = (CardWheelHorizontalView) view .findViewById(R.id.stepsPicker); mNumberStepsPicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, 1, 10, "%d")); - mNumberStepsPicker.addChangingListener(this); + mNumberStepsPicker.addScrollListener(this); CheckBox checkBoxAdvanced = (CheckBox) view.findViewById(R.id.checkBoxSurveyCrossHatch); checkBoxAdvanced.setOnCheckedChangeListener(this); @@ -106,14 +106,24 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { missionProxy.notifyMissionUpdate(); } - @Override - public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, int endValue) { Drone drone = getDrone(); switch (cardWheel.getId()) { case R.id.radiusPicker: { for (StructureScanner item : getMissionItems()) { - item.setRadius(newValue); + item.setRadius(endValue); drone.buildComplexMissionItem(item); } break; @@ -121,7 +131,7 @@ public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newVa case R.id.startAltitudePicker: { for (StructureScanner item : getMissionItems()) { - item.getCoordinate().setAltitude(newValue); + item.getCoordinate().setAltitude(endValue); drone.buildComplexMissionItem(item); } break; @@ -129,14 +139,14 @@ public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newVa case R.id.heightStepPicker: for (StructureScanner item : getMissionItems()) { - item.setHeightStep(newValue); + item.setHeightStep(endValue); drone.buildComplexMissionItem(item); } break; case R.id.stepsPicker: for (StructureScanner item : getMissionItems()) { - item.setStepsCount(newValue); + item.setStepsCount(endValue); drone.buildComplexMissionItem(item); } break; diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java index c67236551e..b7707d261b 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java @@ -12,6 +12,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.mission.MissionItemType; +import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.mission.item.complex.CameraDetail; import com.o3dr.services.android.lib.drone.mission.item.complex.Survey; import com.o3dr.services.android.lib.drone.mission.item.complex.SurveyDetail; @@ -31,53 +32,63 @@ import java.util.List; public class MissionSurveyFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener, - SpinnerSelfSelect.OnSpinnerItemSelectedListener{ + CardWheelHorizontalView.OnCardWheelScrollListener, + SpinnerSelfSelect.OnSpinnerItemSelectedListener { - private static final String TAG = MissionSurveyFragment.class.getSimpleName(); + private static final String TAG = MissionSurveyFragment.class.getSimpleName(); - private static final IntentFilter eventFilter = new IntentFilter(MissionProxy - .ACTION_MISSION_PROXY_UPDATE); + private static final IntentFilter eventFilter = new IntentFilter(MissionProxy.ACTION_MISSION_PROXY_UPDATE); private final BroadcastReceiver eventReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - if(MissionProxy.ACTION_MISSION_PROXY_UPDATE.equals(action)){ + if (MissionProxy.ACTION_MISSION_PROXY_UPDATE.equals(action)) { updateViews(); } } }; - private CardWheelHorizontalView mOverlapPicker; - private CardWheelHorizontalView mAnglePicker; - private CardWheelHorizontalView mAltitudePicker; - private CardWheelHorizontalView mSidelapPicker; - - public TextView distanceBetweenLinesTextView; - public TextView areaTextView; - public TextView distanceTextView; - public TextView footprintTextView; - public TextView groundResolutionTextView; - public TextView numberOfPicturesView; - public TextView numberOfStripsView; - public TextView lengthView; - private CamerasAdapter cameraAdapter; + private final Drone.OnMissionItemsBuiltCallback missionItemsBuiltListener = new Drone.OnMissionItemsBuiltCallback() { + @Override + public void onMissionItemsBuilt(MissionItem.ComplexItem[] complexItems) { + for (MissionItem.ComplexItem item : complexItems) { + checkIfValid((Survey) item); + } + + getMissionProxy().notifyMissionUpdate(); + } + }; + + private CardWheelHorizontalView mOverlapPicker; + private CardWheelHorizontalView mAnglePicker; + private CardWheelHorizontalView mAltitudePicker; + private CardWheelHorizontalView mSidelapPicker; + + public TextView distanceBetweenLinesTextView; + public TextView areaTextView; + public TextView distanceTextView; + public TextView footprintTextView; + public TextView groundResolutionTextView; + public TextView numberOfPicturesView; + public TextView numberOfStripsView; + public TextView lengthView; + private CamerasAdapter cameraAdapter; private SpinnerSelfSelect cameraSpinner; - @Override - protected int getResource() { - return R.layout.fragment_editor_detail_survey; - } + @Override + protected int getResource() { + return R.layout.fragment_editor_detail_survey; + } - @Override - protected List getMissionItems() { - return (List) super.getMissionItems(); - } + @Override + protected List getMissionItems() { + return (List) super.getMissionItems(); + } - @Override - public void onApiConnected() { - super.onApiConnected(); + @Override + public void onApiConnected() { + super.onApiConnected(); final View view = getView(); final Context context = getActivity().getApplicationContext(); @@ -85,17 +96,17 @@ public void onApiConnected() { CameraProxy camera = getDrone().getCamera(); List cameraDetails = camera == null ? Collections.emptyList() - : camera.getAvailableCameraInfos(); + : camera.getAvailableCameraInfos(); cameraAdapter = new CamerasAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item, cameraDetails); cameraSpinner = (SpinnerSelfSelect) view.findViewById(id.cameraFileSpinner); cameraSpinner.setAdapter(cameraAdapter); - cameraSpinner.setOnSpinnerItemSelectedListener(this); + cameraSpinner.setOnSpinnerItemSelectedListener(this); - mAnglePicker = (CardWheelHorizontalView) view.findViewById(id.anglePicker); - mAnglePicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, - 0, 180, "%dº")); + mAnglePicker = (CardWheelHorizontalView) view.findViewById(id.anglePicker); + mAnglePicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, + 0, 180, "%dº")); mOverlapPicker = (CardWheelHorizontalView) view.findViewById(id.overlapPicker); mOverlapPicker.setViewAdapter(new NumericWheelAdapter(context, @@ -109,92 +120,105 @@ public void onApiConnected() { mAltitudePicker.setViewAdapter(new NumericWheelAdapter(context, R.layout.wheel_text_centered, 0, 200, "%d m")); - areaTextView = (TextView) view.findViewById(id.areaTextView); - distanceBetweenLinesTextView = (TextView) view - .findViewById(id.distanceBetweenLinesTextView); - footprintTextView = (TextView) view.findViewById(id.footprintTextView); - groundResolutionTextView = (TextView) view.findViewById(id.groundResolutionTextView); - distanceTextView = (TextView) view.findViewById(id.distanceTextView); - numberOfPicturesView = (TextView) view.findViewById(id.numberOfPicturesTextView); - numberOfStripsView = (TextView) view.findViewById(id.numberOfStripsTextView); - lengthView = (TextView) view.findViewById(id.lengthTextView); + areaTextView = (TextView) view.findViewById(id.areaTextView); + distanceBetweenLinesTextView = (TextView) view + .findViewById(id.distanceBetweenLinesTextView); + footprintTextView = (TextView) view.findViewById(id.footprintTextView); + groundResolutionTextView = (TextView) view.findViewById(id.groundResolutionTextView); + distanceTextView = (TextView) view.findViewById(id.distanceTextView); + numberOfPicturesView = (TextView) view.findViewById(id.numberOfPicturesTextView); + numberOfStripsView = (TextView) view.findViewById(id.numberOfStripsTextView); + lengthView = (TextView) view.findViewById(id.lengthTextView); updateCamera(); - updateViews(); - - mAnglePicker.addChangingListener(this); - mOverlapPicker.addChangingListener(this); - mSidelapPicker.addChangingListener(this); - mAltitudePicker.addChangingListener(this); + updateViews(); + + mAnglePicker.addScrollListener(this); + mOverlapPicker.addScrollListener(this); + mSidelapPicker.addScrollListener(this); + mAltitudePicker.addScrollListener(this); typeSpinner.setSelection(commandAdapter.getPosition(MissionItemType.SURVEY)); - getBroadcastManager().registerReceiver(eventReceiver, eventFilter); - } - - @Override - public void onApiDisconnected() { - super.onApiDisconnected(); - getBroadcastManager().unregisterReceiver(eventReceiver); - } - - @Override - public void onSpinnerItemSelected(Spinner spinner, int position) { - if (spinner.getId() == id.cameraFileSpinner) { - CameraDetail cameraInfo = cameraAdapter.getItem(position); - for (Survey survey : getMissionItems()) { - survey.getSurveyDetail().setCameraDetail(cameraInfo); - } - - onChanged(mAnglePicker, 0, 0); - } - } - - @Override - public void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { - switch (cardWheel.getId()) { - case R.id.anglePicker: - case R.id.altitudePicker: - case R.id.overlapPicker: - case R.id.sidelapPicker: - Drone drone = getDrone(); - try { - for (Survey survey : getMissionItems()) { - SurveyDetail surveyDetail = survey.getSurveyDetail(); - surveyDetail.setAltitude(mAltitudePicker.getCurrentValue()); - surveyDetail.setAngle(mAnglePicker.getCurrentValue()); - surveyDetail.setOverlap(mOverlapPicker.getCurrentValue()); - surveyDetail.setSidelap(mSidelapPicker.getCurrentValue()); - - drone.buildComplexMissionItem(survey); - checkIfValid(survey); - } - } catch (Exception e) { - Log.e(TAG, "Error while building the survey.", e); - } + getBroadcastManager().registerReceiver(eventReceiver, eventFilter); + } - getMissionProxy().notifyMissionUpdate(); - break; - } - } + @Override + public void onApiDisconnected() { + super.onApiDisconnected(); + getBroadcastManager().unregisterReceiver(eventReceiver); + } + + @Override + public void onSpinnerItemSelected(Spinner spinner, int position) { + if (spinner.getId() == id.cameraFileSpinner) { + CameraDetail cameraInfo = cameraAdapter.getItem(position); + for (Survey survey : getMissionItems()) { + survey.getSurveyDetail().setCameraDetail(cameraInfo); + } + + onScrollingEnded(mAnglePicker, 0, 0); + } + } + + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, int endValue) { + switch (cardWheel.getId()) { + case R.id.anglePicker: + case R.id.altitudePicker: + case R.id.overlapPicker: + case R.id.sidelapPicker: + final Drone drone = getDrone(); + try { + final List surveyList = getMissionItems(); + if (!surveyList.isEmpty()) { + for (final Survey survey : surveyList) { + SurveyDetail surveyDetail = survey.getSurveyDetail(); + surveyDetail.setAltitude(mAltitudePicker.getCurrentValue()); + surveyDetail.setAngle(mAnglePicker.getCurrentValue()); + surveyDetail.setOverlap(mOverlapPicker.getCurrentValue()); + surveyDetail.setSidelap(mSidelapPicker.getCurrentValue()); + } + + final MissionItem.ComplexItem[] surveys = surveyList + .toArray(new MissionItem.ComplexItem[surveyList.size()]); + + drone.buildMissionItemsAsync(missionItemsBuiltListener, surveys); + } + } catch (Exception e) { + Log.e(TAG, "Error while building the survey.", e); + } + break; + } + } private void checkIfValid(Survey survey) { - if(mAltitudePicker == null) + if (mAltitudePicker == null) return; - if(survey.isValid()) + if (survey.isValid()) mAltitudePicker.setBackgroundResource(R.drawable.bg_cell_white); else mAltitudePicker.setBackgroundColor(Color.RED); } private void updateViews() { - if(isDetached()) + if (isDetached()) return; - updateTextViews(); - updateSeekBars(); - } + updateTextViews(); + updateSeekBars(); + } private void updateCamera() { List surveyList = getMissionItems(); @@ -207,11 +231,11 @@ private void updateCamera() { } private void updateSeekBars() { - List surveyList = getMissionItems(); - if (!surveyList.isEmpty()) { + List surveyList = getMissionItems(); + if (!surveyList.isEmpty()) { Survey survey = surveyList.get(0); - SurveyDetail surveyDetail = survey.getSurveyDetail(); - if(surveyDetail != null) { + SurveyDetail surveyDetail = survey.getSurveyDetail(); + if (surveyDetail != null) { mAnglePicker.setCurrentValue((int) surveyDetail.getAngle()); mOverlapPicker.setCurrentValue((int) surveyDetail.getOverlap()); mSidelapPicker.setCurrentValue((int) surveyDetail.getSidelap()); @@ -219,67 +243,67 @@ private void updateSeekBars() { } checkIfValid(survey); - } - } - - private void updateTextViews() { - boolean setDefault = true; - List surveyList = getMissionItems(); - if (!surveyList.isEmpty()) { + } + } + + private void updateTextViews() { + boolean setDefault = true; + List surveyList = getMissionItems(); + if (!surveyList.isEmpty()) { Survey survey = surveyList.get(0); - SurveyDetail surveyDetail = survey.getSurveyDetail(); - try { + SurveyDetail surveyDetail = survey.getSurveyDetail(); + try { UnitProvider unitProvider = UnitManager.getUnitProvider(); - footprintTextView.setText(String.format("%s: %s x %s", + footprintTextView.setText(String.format("%s: %s x %s", getString(R.string.footprint), unitProvider.distanceToString(surveyDetail.getLateralFootPrint()), unitProvider.distanceToString(surveyDetail .getLongitudinalFootPrint()))); - groundResolutionTextView.setText(String.format("%s: %s /px", + groundResolutionTextView.setText(String.format("%s: %s /px", getString(R.string.ground_resolution), unitProvider.areaToString(surveyDetail.getGroundResolution()))); - distanceTextView.setText(String.format("%s: %s", + distanceTextView.setText(String.format("%s: %s", getString(R.string.distance_between_pictures), unitProvider.distanceToString(surveyDetail .getLongitudinalPictureDistance()))); - distanceBetweenLinesTextView.setText(String.format("%s: %s", + distanceBetweenLinesTextView.setText(String.format("%s: %s", getString(R.string.distance_between_lines), unitProvider.distanceToString(surveyDetail .getLateralPictureDistance()))); - areaTextView.setText(String.format("%s: %s", getString(R.string.area), + areaTextView.setText(String.format("%s: %s", getString(R.string.area), unitProvider.areaToString(survey.getPolygonArea()))); - lengthView.setText(String.format("%s: %s", getString(R.string.mission_length), + lengthView.setText(String.format("%s: %s", getString(R.string.mission_length), unitProvider.distanceToString(survey.getGridLength()))); - numberOfPicturesView.setText(String.format("%s: %d", getString(R.string.pictures), + numberOfPicturesView.setText(String.format("%s: %d", getString(R.string.pictures), survey.getCameraCount())); - numberOfStripsView.setText(String.format("%s: %d", getString(R.string.number_of_strips), + numberOfStripsView.setText(String.format("%s: %d", getString(R.string.number_of_strips), survey.getNumberOfLines())); - setDefault = false; - } catch (Exception e) { - setDefault = true; - } - } - - if (setDefault) { - footprintTextView.setText(getString(R.string.footprint) + ": ???"); - groundResolutionTextView.setText(getString(R.string.ground_resolution) + ": ???"); - distanceTextView.setText(getString(R.string.distance_between_pictures) + ": ???"); - distanceBetweenLinesTextView.setText(getString(R.string.distance_between_lines) - + ": ???"); - areaTextView.setText(getString(R.string.area) + ": ???"); - lengthView.setText(getString(R.string.mission_length) + ": ???"); - numberOfPicturesView.setText(getString(R.string.pictures) + "???"); - numberOfStripsView.setText(getString(R.string.number_of_strips) + "???"); - } - } + setDefault = false; + } catch (Exception e) { + setDefault = true; + } + } + + if (setDefault) { + footprintTextView.setText(getString(R.string.footprint) + ": ???"); + groundResolutionTextView.setText(getString(R.string.ground_resolution) + ": ???"); + distanceTextView.setText(getString(R.string.distance_between_pictures) + ": ???"); + distanceBetweenLinesTextView.setText(getString(R.string.distance_between_lines) + + ": ???"); + areaTextView.setText(getString(R.string.area) + ": ???"); + lengthView.setText(getString(R.string.mission_length) + ": ???"); + numberOfPicturesView.setText(getString(R.string.pictures) + "???"); + numberOfStripsView.setText(getString(R.string.number_of_strips) + "???"); + } + } } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionTakeoffFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionTakeoffFragment.java index 4e63e6e5f1..991331d774 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionTakeoffFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionTakeoffFragment.java @@ -9,7 +9,7 @@ import org.droidplanner.android.widgets.spinnerWheel.adapters.NumericWheelAdapter; public class MissionTakeoffFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -27,19 +27,29 @@ public void onApiConnected() { CardWheelHorizontalView cardAltitudePicker = (CardWheelHorizontalView) getView() .findViewById(R.id.altitudePicker); cardAltitudePicker.setViewAdapter(altitudeAdapter); - cardAltitudePicker.addChangingListener(this); + cardAltitudePicker.addScrollListener(this); Takeoff item = (Takeoff) getMissionItems().get(0); cardAltitudePicker.setCurrentValue((int) item.getTakeoffAltitude()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.altitudePicker: for (MissionItem missionItem : getMissionItems()) { Takeoff item = (Takeoff) missionItem; - item.setTakeoffAltitude(newValue); + item.setTakeoffAltitude(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionWaypointFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionWaypointFragment.java index 9d43606a1e..88376ffa4d 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionWaypointFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionWaypointFragment.java @@ -12,7 +12,7 @@ import com.o3dr.services.android.lib.drone.mission.item.spatial.Waypoint; public class MissionWaypointFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener { + CardWheelHorizontalView.OnCardWheelScrollListener { @Override protected int getResource() { @@ -33,7 +33,7 @@ public void onApiConnected(){ CardWheelHorizontalView delayPicker = (CardWheelHorizontalView) view.findViewById(R.id .waypointDelayPicker); delayPicker.setViewAdapter(delayAdapter); - delayPicker.addChangingListener(this); + delayPicker.addScrollListener(this); final NumericWheelAdapter altitudeAdapter = new NumericWheelAdapter(context, @@ -41,25 +41,35 @@ public void onApiConnected(){ CardWheelHorizontalView altitudePicker = (CardWheelHorizontalView) view.findViewById(R.id .altitudePicker); altitudePicker.setViewAdapter(altitudeAdapter); - altitudePicker.addChangingListener(this); + altitudePicker.addScrollListener(this); final Waypoint item = (Waypoint) getMissionItems().get(0); delayPicker.setCurrentValue((int) item.getDelay()); altitudePicker.setCurrentValue((int) item.getCoordinate().getAltitude()); } - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, int newValue) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { + + } + + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { + + } + + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { switch (wheel.getId()) { case R.id.altitudePicker: for(MissionItem item: getMissionItems()) { - ((Waypoint)item).getCoordinate().setAltitude(newValue); + ((Waypoint)item).getCoordinate().setAltitude(endValue); } break; case R.id.waypointDelayPicker: for(MissionItem item: getMissionItems()) { - ((Waypoint)item).setDelay(newValue); + ((Waypoint)item).setDelay(endValue); } break; } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java index bc4f53ed31..58f602a8ba 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java @@ -4,6 +4,7 @@ import org.droidplanner.android.widgets.spinnerWheel.CardWheelHorizontalView; import org.droidplanner.android.widgets.spinnerWheel.adapters.NumericWheelAdapter; +import android.content.Context; import android.text.Editable; import android.text.TextWatcher; import android.view.View; @@ -13,8 +14,8 @@ import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.mission.item.command.SetServo; -public class SetServoFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelChangedListener, TextWatcher { +public class SetServoFragment extends MissionDetailFragment implements CardWheelHorizontalView + .OnCardWheelScrollListener { @Override protected int getResource() { @@ -28,55 +29,49 @@ public void onApiConnected() { final View view = getView(); typeSpinner.setSelection(commandAdapter.getPosition(MissionItemType.SET_SERVO)); - SetServo item = (SetServo) getMissionItems().get(0); - - final NumericWheelAdapter adapter = new NumericWheelAdapter( - getActivity().getApplicationContext(), R.layout.wheel_text_centered, 1, 8, "%d"); - final CardWheelHorizontalView cardChannelPicker = (CardWheelHorizontalView) view - .findViewById(R.id.picker1); - final EditText pwmEditText = (EditText) view.findViewById(R.id.PwmEditText); + final SetServo item = (SetServo) getMissionItems().get(0); + final Context context = getActivity().getApplicationContext(); + final NumericWheelAdapter adapter = new NumericWheelAdapter(context, R.layout.wheel_text_centered, 1, 8, "%d"); + final CardWheelHorizontalView cardChannelPicker = (CardWheelHorizontalView) view.findViewById(R.id.picker1); cardChannelPicker.setViewAdapter(adapter); - cardChannelPicker.addChangingListener(this); + cardChannelPicker.addScrollListener(this); cardChannelPicker.setCurrentValue(item.getChannel()); - pwmEditText.setText(Integer.toString(item.getPwm())); - pwmEditText.addTextChangedListener(this); - - } - - @Override - public void onChanged(CardWheelHorizontalView wheel, int oldValue, - int newValue) { - switch (wheel.getId()) { - case R.id.picker1: - for (MissionItem missionItem : getMissionItems()) { - SetServo item = (SetServo) missionItem; - item.setChannel(newValue); - } - break; - } + final NumericWheelAdapter pwmAdapter = new NumericWheelAdapter(context, R.layout.wheel_text_centered, 0, + 2000, "%d"); + final CardWheelHorizontalView pwmPicker = (CardWheelHorizontalView) view.findViewById(R.id.pwmPicker); + pwmPicker.setViewAdapter(pwmAdapter); + pwmPicker.addScrollListener(this); + pwmPicker.setCurrentValue(item.getPwm()); } - @Override - public void afterTextChanged(Editable editable) { + @Override + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { - } + } - @Override - public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, - int arg3) { + @Override + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { - } + } - @Override - public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) { - if (!s.toString().isEmpty()) { + @Override + public void onScrollingEnded(CardWheelHorizontalView wheel, int startValue, int endValue) { + switch (wheel.getId()) { + case R.id.picker1: for (MissionItem missionItem : getMissionItems()) { SetServo item = (SetServo) missionItem; - item.setPwm(Integer.valueOf(s.toString())); + item.setChannel(endValue); } - } + break; + case R.id.pwmPicker: + for(MissionItem missionItem: getMissionItems()){ + SetServo item = (SetServo) missionItem; + item.setPwm(endValue); + } + break; + } } } diff --git a/Android/src/org/droidplanner/android/widgets/spinnerWheel/CardWheelHorizontalView.java b/Android/src/org/droidplanner/android/widgets/spinnerWheel/CardWheelHorizontalView.java index 94bceebdb8..3deaad18da 100644 --- a/Android/src/org/droidplanner/android/widgets/spinnerWheel/CardWheelHorizontalView.java +++ b/Android/src/org/droidplanner/android/widgets/spinnerWheel/CardWheelHorizontalView.java @@ -25,11 +25,17 @@ public class CardWheelHorizontalView extends LinearLayout implements OnWheelChangedListener, OnWheelClickedListener, OnWheelScrollListener { - public interface OnCardWheelChangedListener { - void onChanged(CardWheelHorizontalView cardWheel, int oldValue, int newValue); + private final static String TAG = CardWheelHorizontalView.class.getSimpleName(); + + public interface OnCardWheelScrollListener { + void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue); + + void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue); + + void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, int endValue); } - private final List mChangingListeners = new LinkedList(); + private final List mScrollingListeners = new LinkedList(); private View mVerticalDivider; private View mHorizontalDivider; @@ -38,6 +44,8 @@ public interface OnCardWheelChangedListener { private EditText mNumberInputText; private WheelHorizontalView mSpinnerWheel; + private int scrollingStartValue; + public CardWheelHorizontalView(Context context) { this(context, null); } @@ -203,12 +211,12 @@ public CharSequence getText() { return mTitleView.getText(); } - public void addChangingListener(OnCardWheelChangedListener listener) { - mChangingListeners.add(listener); + public void addScrollListener(OnCardWheelScrollListener listener) { + mScrollingListeners.add(listener); } - public void removeChangingListener(OnCardWheelChangedListener listener) { - mChangingListeners.remove(listener); + public void removeChangingListener(OnCardWheelScrollListener listener) { + mScrollingListeners.remove(listener); } @Override @@ -216,8 +224,8 @@ public void onChanged(AbstractWheel wheel, int oldIndex, int newIndex) { final int oldValue = getValue(oldIndex); final int newValue = getValue(newIndex); - for (OnCardWheelChangedListener listener : mChangingListeners) { - listener.onChanged(this, oldValue, newValue); + for (OnCardWheelScrollListener listener : mScrollingListeners) { + listener.onScrollingUpdate(this, oldValue, newValue); } } @@ -236,10 +244,19 @@ public void onItemClicked(AbstractWheel wheel, int itemIndex, boolean isCurrentI @Override public void onScrollingStarted(AbstractWheel wheel) { hideSoftInput(); + scrollingStartValue = getCurrentValue(); + for(OnCardWheelScrollListener listener: mScrollingListeners){ + listener.onScrollingStarted(this, scrollingStartValue); + } } + @Override public void onScrollingFinished(AbstractWheel wheel) { + final int endValue = getCurrentValue(); + for (OnCardWheelScrollListener listener : mScrollingListeners) { + listener.onScrollingEnded(this, scrollingStartValue, endValue); + } } private void showSoftInput(String currentValue) { From c9ca4097c8a92c52b9385c913804ffc5d0d6aacb Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Fri, 19 Dec 2014 00:48:25 -0800 Subject: [PATCH 2/7] updated MissionStructureScannerFragment with the new buildMissionItemAsync method. --- .../MissionStructureScannerFragment.java | 46 +++++++++---------- .../item/fragments/MissionSurveyFragment.java | 25 +++++----- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java index 151aec1826..042ea64f10 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java @@ -7,7 +7,9 @@ import android.widget.Spinner; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.mission.Mission; import com.o3dr.services.android.lib.drone.mission.MissionItemType; +import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.mission.item.complex.CameraDetail; import com.o3dr.services.android.lib.drone.mission.item.complex.StructureScanner; import com.o3dr.services.android.lib.drone.mission.item.complex.SurveyDetail; @@ -25,7 +27,7 @@ import java.util.List; public class MissionStructureScannerFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelScrollListener, CompoundButton.OnCheckedChangeListener { + CardWheelHorizontalView.OnCardWheelScrollListener, CompoundButton.OnCheckedChangeListener, Drone.OnMissionItemsBuiltCallback { private CamerasAdapter cameraAdapter; @@ -93,38 +95,34 @@ public void onApiConnected() { checkBoxAdvanced.setChecked(firstItem.isCrossHatch()); } + private void submitForBuilding(){ + final List scannerList = getMissionItems(); + if(scannerList.isEmpty()) return; + + getDrone().buildMissionItemsAsync(this, scannerList.toArray(new MissionItem.ComplexItem[scannerList.size()])); + } + @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - Drone drone = getDrone(); for (StructureScanner item : getMissionItems()) { item.setCrossHatch(isChecked); - drone.buildComplexMissionItem(item); } - MissionProxy missionProxy = getMissionProxy(); - if (missionProxy != null) - missionProxy.notifyMissionUpdate(); + submitForBuilding(); } @Override - public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) { - - } + public void onScrollingStarted(CardWheelHorizontalView cardWheel, int startValue) {} @Override - public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) { - - } + public void onScrollingUpdate(CardWheelHorizontalView cardWheel, int oldValue, int newValue) {} @Override public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, int endValue) { - Drone drone = getDrone(); - switch (cardWheel.getId()) { case R.id.radiusPicker: { for (StructureScanner item : getMissionItems()) { item.setRadius(endValue); - drone.buildComplexMissionItem(item); } break; } @@ -132,7 +130,6 @@ public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, case R.id.startAltitudePicker: { for (StructureScanner item : getMissionItems()) { item.getCoordinate().setAltitude(endValue); - drone.buildComplexMissionItem(item); } break; } @@ -140,36 +137,30 @@ public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, case R.id.heightStepPicker: for (StructureScanner item : getMissionItems()) { item.setHeightStep(endValue); - drone.buildComplexMissionItem(item); } break; case R.id.stepsPicker: for (StructureScanner item : getMissionItems()) { item.setStepsCount(endValue); - drone.buildComplexMissionItem(item); } break; } - MissionProxy missionProxy = getMissionProxy(); - if (missionProxy != null) - missionProxy.notifyMissionUpdate(); + submitForBuilding(); } @Override public void onSpinnerItemSelected(Spinner spinner, int position) { if (spinner.getId() == id.cameraFileSpinner) { - Drone drone = getDrone(); CameraDetail cameraInfo = cameraAdapter.getItem(position); for (StructureScanner scan : getMissionItems()) { SurveyDetail surveyDetail = scan.getSurveyDetail(); surveyDetail.setCameraDetail(cameraInfo); - drone.buildComplexMissionItem(scan); } - getMissionProxy().notifyMissionUpdate(); + submitForBuilding(); } } @@ -177,5 +168,12 @@ public void onSpinnerItemSelected(Spinner spinner, int position) { protected List getMissionItems() { return (List) super.getMissionItems(); } + + @Override + public void onMissionItemsBuilt(MissionItem.ComplexItem[] complexItems) { + MissionProxy missionProxy = getMissionProxy(); + if (missionProxy != null) + missionProxy.notifyMissionUpdate(); + } } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java index b7707d261b..1b5defbb5f 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java @@ -32,8 +32,8 @@ import java.util.List; public class MissionSurveyFragment extends MissionDetailFragment implements - CardWheelHorizontalView.OnCardWheelScrollListener, - SpinnerSelfSelect.OnSpinnerItemSelectedListener { + CardWheelHorizontalView.OnCardWheelScrollListener, SpinnerSelfSelect.OnSpinnerItemSelectedListener, + Drone.OnMissionItemsBuiltCallback { private static final String TAG = MissionSurveyFragment.class.getSimpleName(); @@ -49,17 +49,6 @@ public void onReceive(Context context, Intent intent) { } }; - private final Drone.OnMissionItemsBuiltCallback missionItemsBuiltListener = new Drone.OnMissionItemsBuiltCallback() { - @Override - public void onMissionItemsBuilt(MissionItem.ComplexItem[] complexItems) { - for (MissionItem.ComplexItem item : complexItems) { - checkIfValid((Survey) item); - } - - getMissionProxy().notifyMissionUpdate(); - } - }; - private CardWheelHorizontalView mOverlapPicker; private CardWheelHorizontalView mAnglePicker; private CardWheelHorizontalView mAltitudePicker; @@ -193,7 +182,7 @@ public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, final MissionItem.ComplexItem[] surveys = surveyList .toArray(new MissionItem.ComplexItem[surveyList.size()]); - drone.buildMissionItemsAsync(missionItemsBuiltListener, surveys); + drone.buildMissionItemsAsync(this, surveys); } } catch (Exception e) { Log.e(TAG, "Error while building the survey.", e); @@ -306,4 +295,12 @@ private void updateTextViews() { } } + @Override + public void onMissionItemsBuilt(MissionItem.ComplexItem[] complexItems) { + for (MissionItem.ComplexItem item : complexItems) { + checkIfValid((Survey) item); + } + + getMissionProxy().notifyMissionUpdate(); + } } From 39c685c624c9f8f6be2921fef740e5d105659a3e Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Mon, 22 Dec 2014 00:14:23 -0800 Subject: [PATCH 3/7] completed code refactoring based on the 3dr services client lib api update. --- Android/build.gradle | 7 +- .../CopterFlightActionsFragment.java | 42 ++- .../android/fragments/DroneMap.java | 80 ++-- .../android/fragments/EditorMapFragment.java | 5 +- .../fragments/FlightActionsFragment.java | 11 +- .../android/fragments/FlightMapFragment.java | 12 +- .../fragments/GenericActionsFragment.java | 2 +- .../android/fragments/ParamsFragment.java | 354 +++++++++--------- .../fragments/PlaneFlightActionsFragment.java | 147 ++++---- .../android/fragments/SettingsFragment.java | 8 +- .../android/fragments/TelemetryFragment.java | 27 +- .../calibration/imu/FragmentSetupIMU.java | 3 +- .../calibration/mag/FragmentSetupMAG.java | 5 +- .../fragments/mode/FlightModePanel.java | 16 +- .../fragments/mode/ModeFollowFragment.java | 6 +- .../fragments/mode/ModeGuidedFragment.java | 3 +- .../android/graphic/map/GraphicDrone.java | 8 +- .../android/graphic/map/GraphicGuided.java | 9 +- .../android/graphic/map/GraphicHome.java | 7 +- .../google_map/GoogleMapFragment.java | 5 +- .../notifications/NotificationHandler.java | 5 +- .../PebbleNotificationProvider.java | 29 +- .../StatusBarNotificationProvider.java | 13 +- .../TTSNotificationProvider.java | 34 +- .../android/proxy/mission/MissionProxy.java | 35 +- .../proxy/mission/item/MissionItemProxy.java | 14 +- .../MissionStructureScannerFragment.java | 3 +- .../item/fragments/MissionSurveyFragment.java | 3 +- .../org/droidplanner/android/utils/Utils.java | 2 + .../widgets/actionProviders/InfoBarItem.java | 46 ++- .../widgets/checklist/CheckListSysLink.java | 12 +- .../widgets/checklist/row/ListRow.java | 29 +- 32 files changed, 565 insertions(+), 417 deletions(-) diff --git a/Android/build.gradle b/Android/build.gradle index e99602be93..1f6ba539b8 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -11,7 +11,7 @@ dependencies { compile 'com.android.support:cardview-v7:21.0.2' compile 'com.android.support:recyclerview-v7:21.0.2' - compile 'com.o3dr:3dr-services-lib:2.1.17' + compile 'com.o3dr:3dr-services-lib:2.1.22' compile files('libs/droneapi-java.jar') compile files('libs/j2xx.jar') @@ -33,6 +33,11 @@ android { versionName getGitVersion() } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + sourceSets { main { manifest.srcFile 'AndroidManifest.xml' diff --git a/Android/src/org/droidplanner/android/fragments/CopterFlightActionsFragment.java b/Android/src/org/droidplanner/android/fragments/CopterFlightActionsFragment.java index 34922e620b..ad7c575889 100644 --- a/Android/src/org/droidplanner/android/fragments/CopterFlightActionsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/CopterFlightActionsFragment.java @@ -17,6 +17,8 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.GuidedState; import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.VehicleMode; import com.o3dr.services.android.lib.gcs.follow.FollowState; @@ -75,7 +77,7 @@ else if(AttributeEvent.FOLLOW_START.equals(action) if((AttributeEvent.FOLLOW_START.equals(action) || AttributeEvent.FOLLOW_STOP.equals(action))) { - final FollowState followState = getDrone().getFollowState(); + final FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE); if (followState != null) { String eventLabel = null; switch (followState.getState()) { @@ -211,6 +213,7 @@ public void onClick(View v) { HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder() .setCategory(GAUtils.Category.FLIGHT); + final Drone drone = getDrone(); switch (v.getId()) { case R.id.mc_connectBtn: ((SuperUI) getActivity()).toggleDroneConnection(); @@ -243,14 +246,16 @@ public void onClick(View v) { .getLabel()); break; - case R.id.mc_pause: - if (getDrone().getFollowState().isEnabled()) { - getDrone().disableFollowMe(); + case R.id.mc_pause: { + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + if (followState.isEnabled()){ + drone.disableFollowMe(); } - getDrone().pauseAtCurrentLocation(); + drone.pauseAtCurrentLocation(); eventBuilder.setAction(ACTION_FLIGHT_ACTION_BUTTON).setLabel("Pause"); break; + } case R.id.mc_autoBtn: getDrone().changeVehicleMode(VehicleMode.COPTER_AUTO); @@ -265,8 +270,7 @@ public void onClick(View v) { break; case R.id.mc_follow: - Drone drone = getDrone(); - FollowState followState = drone.getFollowState(); + FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); if(followState != null) { if (followState.isEnabled()) drone.disableFollowMe(); @@ -354,11 +358,11 @@ public void onNo() {} private void updateFlightModeButtons() { resetFlightModeButtons(); - State droneState = getDrone().getState(); + State droneState = getDrone().getAttribute(AttributeType.STATE); if(droneState == null) return; - final VehicleMode flightMode = getDrone().getState().getVehicleMode(); + final VehicleMode flightMode = droneState.getVehicleMode(); if(flightMode == null) return; @@ -369,8 +373,9 @@ private void updateFlightModeButtons() { case COPTER_GUIDED: final Drone drone = getDrone(); - if (drone.getGuidedState().isInitialized() - && !drone.getFollowState().isEnabled()) { + final GuidedState guidedState = drone.getAttribute(AttributeType.GUIDED_STATE); + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + if (guidedState.isInitialized() && !followState.isEnabled()) { pauseBtn.setActivated(true); } break; @@ -395,7 +400,7 @@ private void resetFlightModeButtons() { } private void updateFollowButton() { - FollowState followState = getDrone().getFollowState(); + FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE); if(followState == null) return; @@ -424,9 +429,10 @@ private void resetButtonsContainerVisibility() { } private void setupButtonsByFlightState() { - if (getDrone().isConnected()) { - if (getDrone().getState().isArmed()) { - if (getDrone().getState().isFlying()) { + final State droneState = getDrone().getAttribute(AttributeType.STATE); + if (droneState.isConnected()) { + if (droneState.isArmed()) { + if (droneState.isFlying()) { setupButtonsForFlying(); } else { setupButtonsForArmed(); @@ -460,11 +466,11 @@ private void setupButtonsForFlying() { } @Override - public boolean isSlidingUpPanelEnabled(Drone api) { - if(!api.isConnected()) + public boolean isSlidingUpPanelEnabled(Drone drone) { + if(!drone.isConnected()) return false; - final State droneState = api.getState(); + final State droneState = drone.getAttribute(AttributeType.STATE); return droneState.isArmed() && droneState.isFlying(); } } diff --git a/Android/src/org/droidplanner/android/fragments/DroneMap.java b/Android/src/org/droidplanner/android/fragments/DroneMap.java index f77544dd5a..5632a1d242 100644 --- a/Android/src/org/droidplanner/android/fragments/DroneMap.java +++ b/Android/src/org/droidplanner/android/fragments/DroneMap.java @@ -16,6 +16,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.CameraProxy; import com.o3dr.services.android.lib.drone.property.Gps; @@ -59,38 +60,53 @@ public void onReceive(Context context, Intent intent) { return; final String action = intent.getAction(); - if (MissionProxy.ACTION_MISSION_PROXY_UPDATE.equals(action)) { - postUpdate(); - } else if (AttributeEvent.GPS_POSITION.equals(action)) { - mMapFragment.updateMarker(graphicDrone); - mMapFragment.updateDroneLeashPath(guided); - final Gps droneGps = drone.getGps(); - if (droneGps != null && droneGps.isValid()) { - mMapFragment.addFlightPathPoint(droneGps.getPosition()); - } - } else if (AttributeEvent.GUIDED_POINT_UPDATED.equals(action)) { - mMapFragment.updateMarker(guided); - mMapFragment.updateDroneLeashPath(guided); - } else if (AttributeEvent.HEARTBEAT_FIRST.equals(action) - || AttributeEvent.HEARTBEAT_RESTORED.equals(action)) { - mMapFragment.updateMarker(graphicDrone); - } else if (AttributeEvent.STATE_DISCONNECTED.equals(action) - || AttributeEvent.HEARTBEAT_TIMEOUT.equals(action)) { - mMapFragment.updateMarker(graphicDrone); - } else if (AttributeEvent.CAMERA_FOOTPRINTS_UPDATED.equals(action)) { - CameraProxy camera = drone.getCamera(); - if(camera != null && camera.getLastFootPrint() != null) - mMapFragment.addCameraFootprint(camera.getLastFootPrint()); - } else if (AttributeEvent.ATTITUDE_UPDATED.equals(action)) { - if (mAppPrefs.isRealtimeFootprintsEnabled()) { - if (drone.getGps().isValid()) { - CameraProxy camera = drone.getCamera(); - if(camera != null && camera.getCurrentFieldOfView() != null) - mMapFragment.updateRealTimeFootprint(camera.getCurrentFieldOfView()); - } - - } - } + switch (action) { + case MissionProxy.ACTION_MISSION_PROXY_UPDATE: + postUpdate(); + break; + case AttributeEvent.GPS_POSITION: { + mMapFragment.updateMarker(graphicDrone); + mMapFragment.updateDroneLeashPath(guided); + final Gps droneGps = drone.getAttribute(AttributeType.GPS); + if (droneGps != null && droneGps.isValid()) { + mMapFragment.addFlightPathPoint(droneGps.getPosition()); + } + break; + } + + case AttributeEvent.GUIDED_POINT_UPDATED: + mMapFragment.updateMarker(guided); + mMapFragment.updateDroneLeashPath(guided); + break; + + case AttributeEvent.HEARTBEAT_FIRST: + case AttributeEvent.HEARTBEAT_RESTORED: + mMapFragment.updateMarker(graphicDrone); + break; + case AttributeEvent.STATE_DISCONNECTED: + case AttributeEvent.HEARTBEAT_TIMEOUT: + mMapFragment.updateMarker(graphicDrone); + break; + case AttributeEvent.CAMERA_FOOTPRINTS_UPDATED: { + CameraProxy camera = drone.getAttribute(AttributeType.CAMERA); + if (camera != null && camera.getLastFootPrint() != null) + mMapFragment.addCameraFootprint(camera.getLastFootPrint()); + break; + } + + case AttributeEvent.ATTITUDE_UPDATED: { + if (mAppPrefs.isRealtimeFootprintsEnabled()) { + final Gps droneGps = drone.getAttribute(AttributeType.GPS); + if (droneGps.isValid()) { + CameraProxy camera = drone.getAttribute(AttributeType.CAMERA); + if (camera != null && camera.getCurrentFieldOfView() != null) + mMapFragment.updateRealTimeFootprint(camera.getCurrentFieldOfView()); + } + + } + break; + } + } } }; diff --git a/Android/src/org/droidplanner/android/fragments/EditorMapFragment.java b/Android/src/org/droidplanner/android/fragments/EditorMapFragment.java index e4570029a9..28cbe3d4b4 100644 --- a/Android/src/org/droidplanner/android/fragments/EditorMapFragment.java +++ b/Android/src/org/droidplanner/android/fragments/EditorMapFragment.java @@ -17,6 +17,7 @@ import android.widget.Toast; import com.o3dr.services.android.lib.coordinate.LatLong; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.property.Home; @@ -133,9 +134,9 @@ public void zoomToFit() { final List visibleCoords = missionProxy.getVisibleCoords(); // add home coord if visible - Home home = drone.getHome(); + Home home = drone.getAttribute(AttributeType.HOME); if(home != null ) { - final LatLong homeCoord = drone.getHome().getCoordinate(); + final LatLong homeCoord = home.getCoordinate(); if (homeCoord != null && homeCoord.getLongitude() != 0 && homeCoord.getLatitude() != 0) visibleCoords.add(homeCoord); } diff --git a/Android/src/org/droidplanner/android/fragments/FlightActionsFragment.java b/Android/src/org/droidplanner/android/fragments/FlightActionsFragment.java index bb65af7613..2d823a2145 100644 --- a/Android/src/org/droidplanner/android/fragments/FlightActionsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/FlightActionsFragment.java @@ -13,6 +13,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Type; import org.droidplanner.android.R; @@ -21,7 +22,7 @@ public class FlightActionsFragment extends ApiListenerFragment { interface SlidingUpHeader { - boolean isSlidingUpPanelEnabled(Drone api); + boolean isSlidingUpPanelEnabled(Drone drone); } private static final IntentFilter eventFilter = new IntentFilter(AttributeEvent.TYPE_UPDATED); @@ -31,7 +32,7 @@ interface SlidingUpHeader { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (AttributeEvent.TYPE_UPDATED.equals(action)) { - Type type = getDrone().getType(); + Type type = getDrone().getAttribute(AttributeType.TYPE); selectActionsBar(type == null ? -1 : type.getDroneType()); } } @@ -47,8 +48,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onApiConnected() { Drone drone = getDrone(); - if(drone.isConnected()) - selectActionsBar(drone.getType().getDroneType()); + if(drone.isConnected()) { + Type type = getDrone().getAttribute(AttributeType.TYPE); + selectActionsBar(type.getDroneType()); + } else{ selectActionsBar(-1); } diff --git a/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java b/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java index b3de224110..41769e2da2 100644 --- a/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java +++ b/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java @@ -7,7 +7,6 @@ import org.droidplanner.android.maps.MarkerInfo; import org.droidplanner.android.utils.DroneHelper; import org.droidplanner.android.utils.prefs.AutoPanMode; -import org.droidplanner.android.utils.prefs.DroidPlannerPrefs; import android.content.BroadcastReceiver; import android.content.Context; @@ -24,7 +23,10 @@ import com.google.android.gms.maps.model.LatLng; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Gps; +import com.o3dr.services.android.lib.drone.property.GuidedState; +import com.o3dr.services.android.lib.drone.property.State; public class FlightMapFragment extends DroneMap implements DPMap.OnMapLongClickListener, DPMap.OnMarkerClickListener, DPMap.OnMarkerDragListener, GuidedDialogListener { @@ -51,7 +53,8 @@ public class FlightMapFragment extends DroneMap implements DPMap.OnMapLongClickL public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if(AttributeEvent.STATE_ARMING.equals(action)){ - if (drone.getState().isArmed()) { + final State droneState = drone.getAttribute(AttributeType.STATE); + if (droneState.isArmed()) { mMapFragment.clearFlightPath(); } } @@ -117,7 +120,8 @@ public void onApiDisconnected(){ @Override public void onMapLongClick(LatLong coord) { if (drone != null && drone.isConnected()) { - if (drone.getGuidedState().isInitialized()) { + final GuidedState guidedState = drone.getAttribute(AttributeType.GUIDED_STATE); + if (guidedState.isInitialized()) { drone.sendGuidedPoint(coord, false); } else { if (guidedModeOnLongPress) { @@ -178,7 +182,7 @@ public void goToMyLocation() { public void goToDroneLocation() { super.goToDroneLocation(); - final Gps droneGps = this.drone.getGps(); + final Gps droneGps = this.drone.getAttribute(AttributeType.GPS); if (droneGps == null || !droneGps.isValid()) return; diff --git a/Android/src/org/droidplanner/android/fragments/GenericActionsFragment.java b/Android/src/org/droidplanner/android/fragments/GenericActionsFragment.java index fda52b6c74..28b47b7901 100644 --- a/Android/src/org/droidplanner/android/fragments/GenericActionsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/GenericActionsFragment.java @@ -42,7 +42,7 @@ public void onClick(View v) { } @Override - public boolean isSlidingUpPanelEnabled(Drone api) { + public boolean isSlidingUpPanelEnabled(Drone drone) { return false; } } diff --git a/Android/src/org/droidplanner/android/fragments/ParamsFragment.java b/Android/src/org/droidplanner/android/fragments/ParamsFragment.java index 94e9b0d5ca..d5026204a7 100644 --- a/Android/src/org/droidplanner/android/fragments/ParamsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/ParamsFragment.java @@ -1,23 +1,5 @@ package org.droidplanner.android.fragments; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.droidplanner.android.R; -import org.droidplanner.android.dialogs.EditInputDialog; -import org.droidplanner.android.dialogs.openfile.OpenFileDialog; -import org.droidplanner.android.dialogs.openfile.OpenParameterDialog; -import org.droidplanner.android.dialogs.parameters.DialogParameterInfo; -import org.droidplanner.android.fragments.helpers.ApiListenerListFragment; -import org.droidplanner.android.utils.file.FileStream; -import org.droidplanner.android.utils.file.IO.ParameterWriter; -import org.droidplanner.android.utils.prefs.DroidPlannerPrefs; -import org.droidplanner.android.widgets.adapterViews.ParamsAdapter; -import org.droidplanner.android.widgets.adapterViews.ParamsAdapterItem; - import android.app.ProgressDialog; import android.content.BroadcastReceiver; import android.content.Context; @@ -46,20 +28,38 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Parameter; import com.o3dr.services.android.lib.drone.property.Parameters; +import org.droidplanner.android.R; +import org.droidplanner.android.dialogs.EditInputDialog; +import org.droidplanner.android.dialogs.openfile.OpenFileDialog; +import org.droidplanner.android.dialogs.openfile.OpenParameterDialog; +import org.droidplanner.android.dialogs.parameters.DialogParameterInfo; +import org.droidplanner.android.fragments.helpers.ApiListenerListFragment; +import org.droidplanner.android.utils.file.FileStream; +import org.droidplanner.android.utils.file.IO.ParameterWriter; +import org.droidplanner.android.utils.prefs.DroidPlannerPrefs; +import org.droidplanner.android.widgets.adapterViews.ParamsAdapter; +import org.droidplanner.android.widgets.adapterViews.ParamsAdapterItem; + +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; + public class ParamsFragment extends ApiListenerListFragment { - static final String TAG = ParamsFragment.class.getSimpleName(); + static final String TAG = ParamsFragment.class.getSimpleName(); - public static final String ADAPTER_ITEMS = ParamsFragment.class.getName() + ".adapter.items"; + public static final String ADAPTER_ITEMS = ParamsFragment.class.getName() + ".adapter.items"; private static final String PREF_PARAMS_FILTER_ON = "pref_params_filter_on"; private static final boolean DEFAULT_PARAMS_FILTER_ON = true; private static final String EXTRA_OPENED_PARAMS_FILENAME = "extra_opened_params_filename"; private final static IntentFilter intentFilter = new IntentFilter(); + static { intentFilter.addAction(AttributeEvent.PARAMETERS_REFRESH_STARTED); intentFilter.addAction(AttributeEvent.PARAMETERS_REFRESH_ENDED); @@ -70,29 +70,33 @@ public class ParamsFragment extends ApiListenerListFragment { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - if(AttributeEvent.PARAMETERS_REFRESH_STARTED.equals(action)){ - startProgress(); - } - else if(AttributeEvent.PARAMETERS_REFRESH_ENDED.equals(action)){ - if(getDrone().isConnected()) { - loadAdapter(getDrone().getParameters().getParameters(), false); - } - stopProgress(); - } - else if(AttributeEvent.PARAMETERS_RECEIVED.equals(action)){ - final int defaultValue = -1; - int index = intent.getIntExtra(AttributeEventExtra.EXTRA_PARAMETER_INDEX, defaultValue); - int count = intent.getIntExtra(AttributeEventExtra.EXTRA_PARAMETERS_COUNT, defaultValue); + switch (action) { + case AttributeEvent.PARAMETERS_REFRESH_STARTED: + startProgress(); + break; + + case AttributeEvent.PARAMETERS_REFRESH_ENDED: + stopProgress(); + /*** FALL - THROUGH ***/ + case AttributeEvent.TYPE_UPDATED: + if (getDrone().isConnected()) { + final Parameters droneParams = getDrone().getAttribute(AttributeType.PARAMETERS); + loadAdapter(droneParams.getParameters(), false); + } + break; - if(index != defaultValue && count != defaultValue) - updateProgress(index, count); - } - else if(AttributeEvent.STATE_DISCONNECTED.equals(action)){ - stopProgress(); - } - else if(AttributeEvent.TYPE_UPDATED.equals(action)){ - if(getDrone().isConnected()) - loadAdapter(getDrone().getParameters().getParameters(), false); + case AttributeEvent.PARAMETERS_RECEIVED: + final int defaultValue = -1; + int index = intent.getIntExtra(AttributeEventExtra.EXTRA_PARAMETER_INDEX, defaultValue); + int count = intent.getIntExtra(AttributeEventExtra.EXTRA_PARAMETERS_COUNT, defaultValue); + + if (index != defaultValue && count != defaultValue) + updateProgress(index, count); + break; + + case AttributeEvent.STATE_DISCONNECTED: + stopProgress(); + break; } } }; @@ -103,54 +107,54 @@ else if(AttributeEvent.TYPE_UPDATED.equals(action)){ private EditText mParamsFilter; private DroidPlannerPrefs mPrefs; - private ParamsAdapter adapter; + private ParamsAdapter adapter; /** * If the parameters were loaded from a file, the filename is stored here. */ private String openedParamsFilename; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); setHasOptionsMenu(true); mPrefs = new DroidPlannerPrefs(getActivity().getApplicationContext()); - // create adapter - if (savedInstanceState != null) { + // create adapter + if (savedInstanceState != null) { this.openedParamsFilename = savedInstanceState.getString(EXTRA_OPENED_PARAMS_FILENAME); - // load adapter items - @SuppressWarnings("unchecked") - final ArrayList pwms = savedInstanceState.getParcelableArrayList + // load adapter items + @SuppressWarnings("unchecked") + final ArrayList pwms = savedInstanceState.getParcelableArrayList (ADAPTER_ITEMS); - adapter = new ParamsAdapter(getActivity(), R.layout.row_params, pwms); - - } else { - // empty adapter - adapter = new ParamsAdapter(getActivity(), R.layout.row_params); - } - setListAdapter(adapter); - - // help handler - adapter.setOnInfoListener(new ParamsAdapter.OnInfoListener() { - @Override - public void onHelp(int position, EditText valueView) { - showInfo(position, valueView); - } - }); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // bind & initialize UI - return inflater.inflate(R.layout.fragment_params, container, false); - } + adapter = new ParamsAdapter(getActivity(), R.layout.row_params, pwms); + + } else { + // empty adapter + adapter = new ParamsAdapter(getActivity(), R.layout.row_params); + } + setListAdapter(adapter); + + // help handler + adapter.setOnInfoListener(new ParamsAdapter.OnInfoListener() { + @Override + public void onHelp(int position, EditText valueView) { + showInfo(position, valueView); + } + }); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // bind & initialize UI + return inflater.inflate(R.layout.fragment_params, container, false); + } @Override - public void onViewCreated(View view, Bundle savedInstanceState){ + public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mLoadingProgress = (ProgressBar) view.findViewById(R.id.reload_progress); @@ -168,7 +172,7 @@ public void onFocusChange(View v, boolean hasFocus) { mParamsFilter.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { - switch(event.getAction()){ + switch (event.getAction()) { case MotionEvent.ACTION_UP: enableParameterFilter(); break; @@ -178,10 +182,12 @@ public boolean onTouch(View v, MotionEvent event) { }); mParamsFilter.addTextChangedListener(new TextWatcher() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + } @Override public void afterTextChanged(Editable s) { @@ -193,7 +199,7 @@ public void afterTextChanged(Editable s) { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { filterInput(v.getText()); - if(actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_SEARCH){ + if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_SEARCH) { mParamsFilter.clearFocus(); } return true; @@ -229,25 +235,24 @@ private void disableParameterFilter() { final Context context = getActivity(); final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context .INPUT_METHOD_SERVICE); - if(imm != null) { + if (imm != null) { imm.hideSoftInputFromWindow(mParamsFilter.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); } } - private void filterInput(CharSequence input){ - if(TextUtils.isEmpty(input)){ + private void filterInput(CharSequence input) { + if (TextUtils.isEmpty(input)) { adapter.getFilter().filter(""); - } - else{ + } else { adapter.getFilter().filter(input); } } @Override public void onApiConnected() { - Parameters droneParams = getDrone().getParameters(); + final Parameters droneParams = getDrone().getAttribute(AttributeType.PARAMETERS); - if(adapter.isEmpty() && droneParams != null) { + if (adapter.isEmpty() && droneParams != null) { List parametersList = droneParams.getParameters(); if (!parametersList.isEmpty()) loadAdapter(parametersList, false); @@ -263,71 +268,69 @@ public void onApiDisconnected() { getBroadcastManager().unregisterReceiver(broadcastReceiver); } - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); - // save adapter items - final ArrayList pwms = new ArrayList(adapter + // save adapter items + final ArrayList pwms = new ArrayList(adapter .getOriginalValues()); - outState.putParcelableArrayList(ADAPTER_ITEMS, pwms); - + outState.putParcelableArrayList(ADAPTER_ITEMS, pwms); + outState.putString(EXTRA_OPENED_PARAMS_FILENAME, this.openedParamsFilename); - } + } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.menu_parameters, menu); - } + inflater.inflate(R.menu.menu_parameters, menu); + } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - adapter.clearFocus(); + @Override + public boolean onOptionsItemSelected(MenuItem item) { + adapter.clearFocus(); - switch (item.getItemId()) { - case R.id.menu_load_parameters: - refreshParameters(); - break; + switch (item.getItemId()) { + case R.id.menu_load_parameters: + refreshParameters(); + break; - case R.id.menu_write_parameters: - writeModifiedParametersToDrone(); - break; + case R.id.menu_write_parameters: + writeModifiedParametersToDrone(); + break; - case R.id.menu_open_parameters: - openParametersFromFile(); - break; + case R.id.menu_open_parameters: + openParametersFromFile(); + break; - case R.id.menu_save_parameters: - saveParametersToFile(); - break; + case R.id.menu_save_parameters: + saveParametersToFile(); + break; - case R.id.menu_filter_params: - final boolean isEnabled = !isParameterFilterVisible(); - toggleParameterFilter(isEnabled, isEnabled); - break; + case R.id.menu_filter_params: + final boolean isEnabled = !isParameterFilterVisible(); + toggleParameterFilter(isEnabled, isEnabled); + break; - default: - return super.onOptionsItemSelected(item); - } - return true; - } + default: + return super.onOptionsItemSelected(item); + } + return true; + } - private void toggleParameterFilter(boolean isVisible, boolean enableInput){ - if(isVisible){ + private void toggleParameterFilter(boolean isVisible, boolean enableInput) { + if (isVisible) { //Show the parameter filter mParamsFilter.setVisibility(View.VISIBLE); filterInput(mParamsFilter.getText()); - if(enableInput) { + if (enableInput) { enableParameterFilter(); - } - else{ + } else { disableParameterFilter(); } - } - else{ + } else { //Hide the parameter filter disableParameterFilter(); mParamsFilter.setVisibility(View.GONE); @@ -337,64 +340,64 @@ private void toggleParameterFilter(boolean isVisible, boolean enableInput){ mPrefs.prefs.edit().putBoolean(PREF_PARAMS_FILTER_ON, isVisible).apply(); } - private boolean isParameterFilterVisible(){ + private boolean isParameterFilterVisible() { return mPrefs.prefs.getBoolean(PREF_PARAMS_FILTER_ON, DEFAULT_PARAMS_FILTER_ON); } - private void showInfo(int position, EditText valueView) { - final ParamsAdapterItem item = adapter.getItem(position); - if (!item.getParameter().hasInfo()) - return; + private void showInfo(int position, EditText valueView) { + final ParamsAdapterItem item = adapter.getItem(position); + if (!item.getParameter().hasInfo()) + return; - DialogParameterInfo.build(item, valueView, getActivity()).show(); - } + DialogParameterInfo.build(item, valueView, getActivity()).show(); + } - private void refreshParameters() { - if (getDrone().isConnected()) { - getDrone().refreshParameters(); - } else { - Toast.makeText(getActivity(), R.string.msg_connect_first, Toast.LENGTH_SHORT).show(); - } - } + private void refreshParameters() { + if (getDrone().isConnected()) { + getDrone().refreshParameters(); + } else { + Toast.makeText(getActivity(), R.string.msg_connect_first, Toast.LENGTH_SHORT).show(); + } + } - private void writeModifiedParametersToDrone() { + private void writeModifiedParametersToDrone() { final Drone drone = getDrone(); - if(!drone.isConnected()) + if (!drone.isConnected()) return; final int adapterCount = adapter.getCount(); List parametersList = new ArrayList(adapterCount); - for (int i = 0; i < adapterCount; i++) { - final ParamsAdapterItem item = adapter.getItem(i); - if (!item.isDirty()) - continue; + for (int i = 0; i < adapterCount; i++) { + final ParamsAdapterItem item = adapter.getItem(i); + if (!item.isDirty()) + continue; parametersList.add(item.getParameter()); - item.commit(); - } + item.commit(); + } final int parametersCount = parametersList.size(); - if (parametersCount > 0) { + if (parametersCount > 0) { drone.writeParameters(new Parameters(parametersList)); adapter.notifyDataSetChanged(); Toast.makeText(getActivity(), parametersCount + " " + getString(R.string.msg_parameters_written_to_drone), Toast.LENGTH_SHORT).show(); } - } + } - private void openParametersFromFile() { - OpenFileDialog dialog = new OpenParameterDialog() { - @Override - public void parameterFileLoaded(List parameters) { + private void openParametersFromFile() { + OpenFileDialog dialog = new OpenParameterDialog() { + @Override + public void parameterFileLoaded(List parameters) { openedParamsFilename = getSelectedFilename(); - loadAdapter(parameters, true); - } - }; - dialog.openDialog(getActivity()); - } + loadAdapter(parameters, true); + } + }; + dialog.openDialog(getActivity()); + } - private void saveParametersToFile() { + private void saveParametersToFile() { final Context context = getActivity().getApplicationContext(); final String defaultFilename = TextUtils.isEmpty(openedParamsFilename) ? FileStream.getParameterFilename("Parameters-") @@ -419,38 +422,37 @@ public void onOk(CharSequence input) { } @Override - public void onCancel() {} + public void onCancel() { + } }); dialog.show(getChildFragmentManager(), "Parameters filename"); - } + } - private void loadAdapter(List parameters, boolean isUpdate){ - if(parameters == null || parameters.isEmpty()){ + private void loadAdapter(List parameters, boolean isUpdate) { + if (parameters == null || parameters.isEmpty()) { return; } TreeMap prunedParameters = new TreeMap(); - for(Parameter parameter: parameters){ + for (Parameter parameter : parameters) { prunedParameters.put(parameter.getName(), parameter); } - if(isUpdate){ + if (isUpdate) { adapter.updateParameters(prunedParameters); - } - else { + } else { adapter.loadParameters(prunedParameters); } - if(mParamsFilter != null && mParamsFilter.getVisibility() == View.VISIBLE){ + if (mParamsFilter != null && mParamsFilter.getVisibility() == View.VISIBLE) { mParamsFilter.setText(""); - } - else{ + } else { filterInput(null); } } - private void startProgress(){ + private void startProgress() { progressDialog = new ProgressDialog(getActivity()); progressDialog.setTitle(R.string.refreshing_parameters); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); diff --git a/Android/src/org/droidplanner/android/fragments/PlaneFlightActionsFragment.java b/Android/src/org/droidplanner/android/fragments/PlaneFlightActionsFragment.java index d0a8fe4916..96dec4594a 100644 --- a/Android/src/org/droidplanner/android/fragments/PlaneFlightActionsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/PlaneFlightActionsFragment.java @@ -15,6 +15,8 @@ import com.google.android.gms.analytics.HitBuilders; import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.GuidedState; import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.VehicleMode; import com.o3dr.services.android.lib.gcs.follow.FollowState; @@ -56,59 +58,65 @@ public class PlaneFlightActionsFragment extends ApiListenerFragment implements @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - if (AttributeEvent.STATE_CONNECTED.equals(action) || AttributeEvent.STATE_DISCONNECTED.equals(action) - || AttributeEvent.STATE_UPDATED.equals(action)) { - setupButtonsByFlightState(); - } else if (AttributeEvent.STATE_VEHICLE_MODE.equals(action)) { - updateFlightModeButtons(); - } else if (AttributeEvent.FOLLOW_START.equals(action) - || AttributeEvent.FOLLOW_STOP.equals(action) - || AttributeEvent.FOLLOW_UPDATE.equals(action)) { - updateFlightModeButtons(); - updateFollowButton(); - - if((AttributeEvent.FOLLOW_START.equals(action) - || AttributeEvent.FOLLOW_STOP.equals(action))) { - final FollowState followState = getDrone().getFollowState(); - if (followState != null) { - String eventLabel = null; - switch (followState.getState()) { - case FollowState.STATE_START: - eventLabel = "FollowMe enabled"; - break; - - case FollowState.STATE_RUNNING: - eventLabel = "FollowMe running"; - break; - - case FollowState.STATE_END: - eventLabel = "FollowMe disabled"; - break; - - case FollowState.STATE_INVALID: - eventLabel = "FollowMe error: invalid state"; - break; - - case FollowState.STATE_DRONE_DISCONNECTED: - eventLabel = "FollowMe error: drone not connected"; - break; - - case FollowState.STATE_DRONE_NOT_ARMED: - eventLabel = "FollowMe error: drone not armed"; - break; - } + switch (action) { + case AttributeEvent.STATE_CONNECTED: + case AttributeEvent.STATE_DISCONNECTED: + case AttributeEvent.STATE_UPDATED: + setupButtonsByFlightState(); + break; - if (eventLabel != null) { - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder() - .setCategory(GAUtils.Category.FLIGHT) - .setAction(ACTION_FLIGHT_ACTION_BUTTON) - .setLabel(eventLabel); - GAUtils.sendEvent(eventBuilder); + case AttributeEvent.STATE_VEHICLE_MODE: + updateFlightModeButtons(); + break; - Toast.makeText(getActivity(), eventLabel, Toast.LENGTH_SHORT).show(); + case AttributeEvent.FOLLOW_START: + case AttributeEvent.FOLLOW_STOP: + case AttributeEvent.FOLLOW_UPDATE: + updateFlightModeButtons(); + updateFollowButton(); + + if ((AttributeEvent.FOLLOW_START.equals(action) || AttributeEvent.FOLLOW_STOP.equals(action))) { + final FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE); + if (followState != null) { + String eventLabel = null; + switch (followState.getState()) { + case FollowState.STATE_START: + eventLabel = "FollowMe enabled"; + break; + + case FollowState.STATE_RUNNING: + eventLabel = "FollowMe running"; + break; + + case FollowState.STATE_END: + eventLabel = "FollowMe disabled"; + break; + + case FollowState.STATE_INVALID: + eventLabel = "FollowMe error: invalid state"; + break; + + case FollowState.STATE_DRONE_DISCONNECTED: + eventLabel = "FollowMe error: drone not connected"; + break; + + case FollowState.STATE_DRONE_NOT_ARMED: + eventLabel = "FollowMe error: drone not armed"; + break; + } + + if (eventLabel != null) { + HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder() + .setCategory(GAUtils.Category.FLIGHT) + .setAction(ACTION_FLIGHT_ACTION_BUTTON) + .setLabel(eventLabel); + GAUtils.sendEvent(eventBuilder); + + Toast.makeText(getActivity(), eventLabel, Toast.LENGTH_SHORT).show(); + } } } - } + break; } } }; @@ -142,7 +150,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) { } private void updateFollowButton() { - switch (getDrone().getFollowState().getState()) { + final FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE); + switch (followState.getState()) { case FollowState.STATE_START: followBtn.setBackgroundColor(Color.RED); break; @@ -161,7 +170,8 @@ private void updateFlightModeButtons() { resetFlightModeButtons(); final Drone drone = getDrone(); - final VehicleMode flightMode = drone.getState().getVehicleMode(); + final State droneState = drone.getAttribute(AttributeType.STATE); + final VehicleMode flightMode = droneState.getVehicleMode(); if(flightMode != null) { switch (flightMode) { case PLANE_AUTO: @@ -169,7 +179,9 @@ private void updateFlightModeButtons() { break; case PLANE_GUIDED: - if (drone.getGuidedState().isInitialized() && !drone.getFollowState().isEnabled()) { + final GuidedState guidedState = drone.getAttribute(AttributeType.GUIDED_STATE); + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + if (guidedState.isInitialized() && !followState.isEnabled()) { pauseBtn.setActivated(true); } break; @@ -227,14 +239,16 @@ public void onClick(View v) { .setLabel(VehicleMode.PLANE_RTL.getLabel()); break; - case R.id.mc_pause: - if (drone.getFollowState().isEnabled()) { - drone.disableFollowMe(); - } + case R.id.mc_pause: { + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + if (followState.isEnabled()){ + drone.disableFollowMe(); + } - drone.pauseAtCurrentLocation(); - eventBuilder.setAction(ACTION_FLIGHT_ACTION_BUTTON).setLabel("Pause"); - break; + drone.pauseAtCurrentLocation(); + eventBuilder.setAction(ACTION_FLIGHT_ACTION_BUTTON).setLabel("Pause"); + break; + } case R.id.mc_autoBtn: drone.changeVehicleMode(VehicleMode.PLANE_AUTO); @@ -242,12 +256,14 @@ public void onClick(View v) { .setLabel(VehicleMode.PLANE_AUTO.getLabel()); break; - case R.id.mc_follow: - if(drone.getFollowState().isEnabled()) + case R.id.mc_follow: { + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + if (followState.isEnabled()) { drone.disableFollowMe(); - else + } else drone.enableFollowMe(FollowType.LEASH); - break; + break; + } default: eventBuilder = null; @@ -260,7 +276,8 @@ public void onClick(View v) { } @Override - public boolean isSlidingUpPanelEnabled(Drone api) { - return api.isConnected() && api.getState().isArmed(); + public boolean isSlidingUpPanelEnabled(Drone drone) { + final State droneState = drone.getAttribute(AttributeType.STATE); + return droneState.isConnected() && droneState.isArmed(); } } diff --git a/Android/src/org/droidplanner/android/fragments/SettingsFragment.java b/Android/src/org/droidplanner/android/fragments/SettingsFragment.java index 7f3c9855a6..9fcb8f4404 100644 --- a/Android/src/org/droidplanner/android/fragments/SettingsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/SettingsFragment.java @@ -28,6 +28,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.connection.ConnectionType; import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.Type; @@ -100,7 +101,8 @@ public void onReceive(Context context, Intent intent) { } else if (AttributeEvent.TYPE_UPDATED.equals(action)) { Drone drone = dpApp.getDrone(); if (drone.isConnected()) { - updateFirmwareVersionPreference(drone.getType().getFirmwareVersion()); + Type droneType = drone.getAttribute(AttributeType.TYPE); + updateFirmwareVersionPreference(droneType.getFirmwareVersion()); } else updateFirmwareVersionPreference(null); } @@ -499,8 +501,8 @@ public void onPause() { @Override public void onApiConnected() { Drone drone = dpApp.getDrone(); - State droneState = drone.getState(); - Type droneType = drone.getType(); + State droneState = drone.getAttribute(AttributeType.STATE); + Type droneType = drone.getAttribute(AttributeType.TYPE); final int mavlinkVersion = droneState == null ? State.INVALID_MAVLINK_VERSION : droneState.getMavlinkVersion(); diff --git a/Android/src/org/droidplanner/android/fragments/TelemetryFragment.java b/Android/src/org/droidplanner/android/fragments/TelemetryFragment.java index 2060cd897a..3d28d5113a 100644 --- a/Android/src/org/droidplanner/android/fragments/TelemetryFragment.java +++ b/Android/src/org/droidplanner/android/fragments/TelemetryFragment.java @@ -14,6 +14,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Altitude; import com.o3dr.services.android.lib.drone.property.Attitude; import com.o3dr.services.android.lib.drone.property.Speed; @@ -35,11 +36,21 @@ public class TelemetryFragment extends ApiListenerFragment { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); final Drone drone = getDrone(); - if (AttributeEvent.ATTITUDE_UPDATED.equals(action)) { - onOrientationUpdate(drone.getAttitude()); - } else if (AttributeEvent.SPEED_UPDATED.equals(action)) { - onSpeedAltitudeAndClimbRateUpdate(drone.getSpeed(), drone.getAltitude()); - } + + switch (action) { + case AttributeEvent.ATTITUDE_UPDATED: + final Attitude attitude = drone.getAttribute(AttributeType.ATTITUDE); + onOrientationUpdate(attitude); + break; + + case AttributeEvent.SPEED_UPDATED: + final Speed droneSpeed = drone.getAttribute(AttributeType.SPEED); + onSpeedUpdate(droneSpeed); + + final Altitude droneAltitude = drone.getAttribute(AttributeType.ALTITUDE); + onAltitudeUpdate(droneAltitude); + break; + } } }; @@ -111,13 +122,15 @@ public void onOrientationUpdate(Attitude droneAttitude) { } - public void onSpeedAltitudeAndClimbRateUpdate(Speed speed, Altitude altitude) { + private void onSpeedUpdate(Speed speed) { if(speed != null) { airSpeed.setText(String.format("%3.1f", speed.getAirSpeed())); groundSpeed.setText(String.format("%3.1f", speed.getGroundSpeed())); climbRate.setText(String.format("%3.1f", speed.getVerticalSpeed())); } + } + private void onAltitudeUpdate(Altitude altitude){ if(altitude != null) { double alt = altitude.getAltitude(); double targetAlt = altitude.getTargetAltitude(); @@ -125,6 +138,6 @@ public void onSpeedAltitudeAndClimbRateUpdate(Speed speed, Altitude altitude) { this.altitude.setText(String.format("%3.1f", alt)); targetAltitude.setText(String.format("%3.1f", targetAlt)); } - } + } } diff --git a/Android/src/org/droidplanner/android/fragments/calibration/imu/FragmentSetupIMU.java b/Android/src/org/droidplanner/android/fragments/calibration/imu/FragmentSetupIMU.java index d5615b486a..ec3fa2b5c6 100644 --- a/Android/src/org/droidplanner/android/fragments/calibration/imu/FragmentSetupIMU.java +++ b/Android/src/org/droidplanner/android/fragments/calibration/imu/FragmentSetupIMU.java @@ -19,6 +19,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.State; import org.droidplanner.android.R; @@ -148,7 +149,7 @@ private void resetCalibration(){ @Override public void onApiConnected() { Drone drone = getDrone(); - State droneState = drone.getState(); + State droneState = drone.getAttribute(AttributeType.STATE); if (drone.isConnected() && !droneState.isFlying()) { btnStep.setEnabled(true); if (droneState.isCalibrating()) { diff --git a/Android/src/org/droidplanner/android/fragments/calibration/mag/FragmentSetupMAG.java b/Android/src/org/droidplanner/android/fragments/calibration/mag/FragmentSetupMAG.java index f1400b4310..b7449fcb1a 100644 --- a/Android/src/org/droidplanner/android/fragments/calibration/mag/FragmentSetupMAG.java +++ b/Android/src/org/droidplanner/android/fragments/calibration/mag/FragmentSetupMAG.java @@ -17,6 +17,8 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.State; import org.droidplanner.android.R; import org.droidplanner.android.fragments.helpers.ApiListenerFragment; @@ -308,7 +310,8 @@ public static CharSequence getTitle(Context context) { @Override public void onApiConnected() { Drone drone = getDrone(); - if (drone.isConnected() && !drone.getState().isFlying()) { + State droneState = drone.getAttribute(AttributeType.STATE); + if (droneState.isConnected() && !droneState.isFlying()) { buttonStep.setEnabled(true); } else { cancelCalibration(); diff --git a/Android/src/org/droidplanner/android/fragments/mode/FlightModePanel.java b/Android/src/org/droidplanner/android/fragments/mode/FlightModePanel.java index 63b420d1a8..840a59d1d9 100644 --- a/Android/src/org/droidplanner/android/fragments/mode/FlightModePanel.java +++ b/Android/src/org/droidplanner/android/fragments/mode/FlightModePanel.java @@ -12,7 +12,10 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.VehicleMode; +import com.o3dr.services.android.lib.gcs.follow.FollowState; import org.droidplanner.android.R; import org.droidplanner.android.fragments.helpers.ApiListenerFragment; @@ -56,19 +59,19 @@ public void onApiDisconnected() { getBroadcastManager().unregisterReceiver(eventReceiver); } - private void onModeUpdate(Drone dpApi) { + private void onModeUpdate(Drone drone) { // Update the info panel fragment - dpApi = getDrone(); + drone = getDrone(); + final State droneState = drone.getAttribute(AttributeType.STATE); Fragment infoPanel; - if (dpApi == null || !dpApi.isConnected()) { + if (!droneState.isConnected()) { infoPanel = new ModeDisconnectedFragment(); } else { - VehicleMode mode = dpApi.getState().getVehicleMode(); + VehicleMode mode = droneState.getVehicleMode(); if(mode == null){ infoPanel = new ModeDisconnectedFragment(); } else { - switch (mode) { case COPTER_RTL: case PLANE_RTL: @@ -112,7 +115,8 @@ private void onModeUpdate(Drone dpApi) { case COPTER_GUIDED: case PLANE_GUIDED: case ROVER_GUIDED: - if (dpApi.getFollowState().isEnabled()) { + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + if (followState.isEnabled()) { infoPanel = new ModeFollowFragment(); } else { infoPanel = new ModeGuidedFragment(); diff --git a/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java b/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java index 6f5cce1c20..4c0bddaf9f 100644 --- a/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java +++ b/Android/src/org/droidplanner/android/fragments/mode/ModeFollowFragment.java @@ -15,6 +15,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.gcs.follow.FollowState; import com.o3dr.services.android.lib.gcs.follow.FollowType; @@ -31,7 +32,7 @@ public class ModeFollowFragment extends ModeGuidedFragment implements OnItemSele public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (AttributeEvent.FOLLOW_UPDATE.equals(action)) { - final FollowState followState = getDrone().getFollowState(); + final FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE); if (followState != null) { spinner.setSelection(adapter.getPosition(followState.getMode())); } @@ -110,7 +111,8 @@ public void onScrollingEnded(CardWheelHorizontalView cardWheel, int oldValue, in private void updateCurrentRadius() { final Drone drone = getDrone(); if (mRadiusWheel != null && drone.isConnected()) { - mRadiusWheel.setCurrentValue((int) drone.getFollowState().getRadius()); + final FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE); + mRadiusWheel.setCurrentValue((int) followState.getRadius()); } } diff --git a/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java b/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java index 7fa9bd12ec..7bc71cdf3e 100644 --- a/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java +++ b/Android/src/org/droidplanner/android/fragments/mode/ModeGuidedFragment.java @@ -6,6 +6,7 @@ import android.view.ViewGroup; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.GuidedState; import org.droidplanner.android.R; @@ -70,7 +71,7 @@ public void onScrollingEnded(CardWheelHorizontalView cardWheel, int startValue, @Override public void onApiConnected() { if (mAltitudeWheel != null) { - GuidedState guidedState = getDrone().getGuidedState(); + GuidedState guidedState = getDrone().getAttribute(AttributeType.GUIDED_STATE); final int initialValue = (int) Math.max(guidedState == null ? DEFAULT_ALTITUDE diff --git a/Android/src/org/droidplanner/android/graphic/map/GraphicDrone.java b/Android/src/org/droidplanner/android/graphic/map/GraphicDrone.java index be03d7e5b5..66dcef779d 100644 --- a/Android/src/org/droidplanner/android/graphic/map/GraphicDrone.java +++ b/Android/src/org/droidplanner/android/graphic/map/GraphicDrone.java @@ -9,6 +9,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.coordinate.LatLong; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Attitude; import com.o3dr.services.android.lib.drone.property.Gps; @@ -32,7 +33,8 @@ public float getAnchorV() { @Override public LatLong getPosition() { - return isValid() ? drone.getGps().getPosition() : null; + Gps droneGps = drone.getAttribute(AttributeType.GPS); + return isValid() ? droneGps.getPosition() : null; } @Override @@ -56,12 +58,12 @@ public boolean isFlat() { @Override public float getRotation() { - Attitude attitude = drone.getAttitude(); + Attitude attitude = drone.getAttribute(AttributeType.ATTITUDE); return attitude == null ? 0 : (float) attitude.getYaw(); } public boolean isValid() { - Gps droneGps = drone.getGps(); + Gps droneGps = drone.getAttribute(AttributeType.GPS); return droneGps != null && droneGps.isValid(); } } diff --git a/Android/src/org/droidplanner/android/graphic/map/GraphicGuided.java b/Android/src/org/droidplanner/android/graphic/map/GraphicGuided.java index 9e084db7e2..8467191a1a 100644 --- a/Android/src/org/droidplanner/android/graphic/map/GraphicGuided.java +++ b/Android/src/org/droidplanner/android/graphic/map/GraphicGuided.java @@ -14,6 +14,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.coordinate.LatLong; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Gps; import com.o3dr.services.android.lib.drone.property.GuidedState; @@ -30,9 +31,9 @@ public GraphicGuided(Drone drone) { @Override public List getPathPoints() { List path = new ArrayList(); - GuidedState guidedPoint = drone.getGuidedState(); + GuidedState guidedPoint = drone.getAttribute(AttributeType.GUIDED_STATE); if (guidedPoint != null && guidedPoint.isActive()) { - Gps gps = drone.getGps(); + Gps gps = drone.getAttribute(AttributeType.GPS); if (gps != null && gps.isValid()) { path.add(gps.getPosition()); } @@ -43,7 +44,7 @@ public List getPathPoints() { @Override public boolean isVisible() { - GuidedState guidedPoint = drone.getGuidedState(); + GuidedState guidedPoint = drone.getAttribute(AttributeType.GUIDED_STATE); return guidedPoint != null && guidedPoint.isActive(); } @@ -59,7 +60,7 @@ public float getAnchorV() { @Override public LatLong getPosition() { - GuidedState guidedPoint = drone.getGuidedState(); + GuidedState guidedPoint = drone.getAttribute(AttributeType.GUIDED_STATE); return guidedPoint == null ? null : guidedPoint.getCoordinate(); } diff --git a/Android/src/org/droidplanner/android/graphic/map/GraphicHome.java b/Android/src/org/droidplanner/android/graphic/map/GraphicHome.java index eddc857b8f..ef6eb91115 100644 --- a/Android/src/org/droidplanner/android/graphic/map/GraphicHome.java +++ b/Android/src/org/droidplanner/android/graphic/map/GraphicHome.java @@ -9,6 +9,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.coordinate.LatLong; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Home; public class GraphicHome extends MarkerInfo.SimpleMarkerInfo { @@ -25,7 +26,7 @@ public float getAnchorU() { } public boolean isValid() { - Home droneHome = drone.getHome(); + Home droneHome = drone.getAttribute(AttributeType.HOME); return droneHome != null && droneHome.isValid(); } @@ -41,7 +42,7 @@ public Bitmap getIcon(Resources res) { @Override public LatLong getPosition() { - Home droneHome = drone.getHome(); + Home droneHome = drone.getAttribute(AttributeType.HOME); if(droneHome == null) return null; return droneHome.getCoordinate(); @@ -49,7 +50,7 @@ public LatLong getPosition() { @Override public String getSnippet() { - Home droneHome = drone.getHome(); + Home droneHome = drone.getAttribute(AttributeType.HOME); return "Home " + (droneHome == null ? "N/A" : droneHome.getCoordinate().getAltitude()); } diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java b/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java index 26d0d8220b..25e68f5fbe 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java @@ -44,6 +44,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.FootPrint; import com.o3dr.services.android.lib.drone.property.Gps; @@ -94,7 +95,7 @@ public void onReceive(Context context, Intent intent) { if (!drone.isConnected()) return; - final Gps droneGps = drone.getGps(); + final Gps droneGps = drone.getAttribute(AttributeType.GPS); if (droneGps == null) return; @@ -688,7 +689,7 @@ public void goToDroneLocation() { if (!dpApi.isConnected()) return; - Gps gps = dpApi.getGps(); + Gps gps = dpApi.getAttribute(AttributeType.GPS); if (!gps.isValid()) { Toast.makeText(getActivity().getApplicationContext(), R.string.drone_no_location, Toast.LENGTH_SHORT).show(); return; diff --git a/Android/src/org/droidplanner/android/notifications/NotificationHandler.java b/Android/src/org/droidplanner/android/notifications/NotificationHandler.java index b7ef1ecc9e..3e43fd5d99 100644 --- a/Android/src/org/droidplanner/android/notifications/NotificationHandler.java +++ b/Android/src/org/droidplanner/android/notifications/NotificationHandler.java @@ -9,6 +9,8 @@ import com.google.android.gms.analytics.HitBuilders; import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.State; import org.droidplanner.android.utils.analytics.GAUtils; @@ -36,9 +38,10 @@ interface NotificationProvider { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (AttributeEvent.AUTOPILOT_FAILSAFE.equals(action)) { + State droneState = drone.getAttribute(AttributeType.STATE); final HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder() .setCategory(GAUtils.Category.FAILSAFE).setAction("Autopilot warning") - .setLabel(drone.getState().getFailsafeWarning()); + .setLabel(droneState.getFailsafeWarning()); GAUtils.sendEvent(eventBuilder); } } diff --git a/Android/src/org/droidplanner/android/notifications/PebbleNotificationProvider.java b/Android/src/org/droidplanner/android/notifications/PebbleNotificationProvider.java index eba575f646..9dcf1ddac6 100644 --- a/Android/src/org/droidplanner/android/notifications/PebbleNotificationProvider.java +++ b/Android/src/org/droidplanner/android/notifications/PebbleNotificationProvider.java @@ -16,6 +16,11 @@ import com.getpebble.android.kit.util.PebbleDictionary; import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.Altitude; +import com.o3dr.services.android.lib.drone.property.Battery; +import com.o3dr.services.android.lib.drone.property.GuidedState; +import com.o3dr.services.android.lib.drone.property.Speed; import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.VehicleMode; import com.o3dr.services.android.lib.gcs.follow.FollowState; @@ -56,7 +61,7 @@ else if((AttributeEvent.FOLLOW_START.equals(action) || AttributeEvent.FOLLOW_STOP.equals(action))) { sendDataToWatchIfTimeHasElapsed(dpApi); - FollowState followState = dpApi.getFollowState(); + FollowState followState = dpApi.getAttribute(AttributeType.FOLLOW_STATE); if(followState != null) { String eventLabel = null; switch (followState.getState()) { @@ -146,8 +151,8 @@ public void sendDataToWatchIfTimeHasElapsed(Drone drone) { * @param drone */ public void sendDataToWatchNow(Drone drone) { - final FollowState followState = drone.getFollowState(); - final State droneState = drone.getState(); + final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE); + final State droneState = drone.getAttribute(AttributeType.STATE); if(followState == null || droneState == null) return; @@ -157,12 +162,13 @@ public void sendDataToWatchNow(Drone drone) { if(mode == null) return; + final GuidedState guidedState = drone.getAttribute(AttributeType.GUIDED_STATE); String modeLabel = mode.getLabel(); if (!droneState.isArmed()) modeLabel = "Disarmed"; else if (followState.isEnabled()) modeLabel = "Follow"; - else if (drone.getGuidedState().isIdle()) + else if (guidedState.isIdle()) modeLabel = "Paused"; data.addString(KEY_MODE, modeLabel); @@ -173,14 +179,17 @@ else if (drone.getGuidedState().isIdle()) } else data.addString(KEY_FOLLOW_TYPE, "none"); - Double battVoltage = drone.getBattery().getBatteryVoltage(); + final Battery droneBattery = drone.getAttribute(AttributeType.BATTERY); + Double battVoltage = droneBattery.getBatteryVoltage(); if(battVoltage != null) battVoltage = 0.0; String bat = "Bat:" + Double.toString(roundToOneDecimal(battVoltage)) + "V"; - String speed = "Speed: " + Double.toString(roundToOneDecimal( - drone.getSpeed().getAirSpeed())); - String altitude = "Alt: " - + Double.toString(roundToOneDecimal(drone.getAltitude().getAltitude())); + + final Speed droneSpeed = drone.getAttribute(AttributeType.SPEED); + String speed = "Speed: " + Double.toString(roundToOneDecimal(droneSpeed.getAirSpeed())); + + final Altitude droneAltitude = drone.getAttribute(AttributeType.ALTITUDE); + String altitude = "Alt: " + Double.toString(roundToOneDecimal(droneAltitude.getAltitude())); String telem = bat + "\n" + altitude + "\n" + speed; data.addString(KEY_TELEM, telem); @@ -207,7 +216,7 @@ protected PebbleReceiverHandler(UUID id) { @Override public void receiveData(Context context, int transactionId, PebbleDictionary data) { - FollowState followMe = dpApi.getFollowState(); + FollowState followMe = dpApi.getAttribute(AttributeType.FOLLOW_STATE); if(followMe == null) return ; PebbleKit.sendAckToPebble(applicationContext, transactionId); diff --git a/Android/src/org/droidplanner/android/notifications/StatusBarNotificationProvider.java b/Android/src/org/droidplanner/android/notifications/StatusBarNotificationProvider.java index df742e1500..cf7b73a0e6 100644 --- a/Android/src/org/droidplanner/android/notifications/StatusBarNotificationProvider.java +++ b/Android/src/org/droidplanner/android/notifications/StatusBarNotificationProvider.java @@ -20,6 +20,7 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Battery; import com.o3dr.services.android.lib.drone.property.Gps; import com.o3dr.services.android.lib.drone.property.Home; @@ -205,7 +206,7 @@ private void updateRadio(Drone drone) { if (mInboxBuilder == null) return; - Signal droneSignal = drone.getSignal(); + Signal droneSignal = drone.getAttribute(AttributeType.SIGNAL); String update = droneSignal == null ? "--" : String.format("%d%%", MathUtils.getSignalStrength(droneSignal .getFadeMargin(), droneSignal.getRemFadeMargin())); mInboxBuilder.setLine(4, SpannableUtils.normal("Signal: ", SpannableUtils.bold(update))); @@ -216,8 +217,8 @@ private void updateHome(Drone drone) { return; String update = "--"; - final Gps droneGps = this.drone.getGps(); - final Home droneHome = this.drone.getHome(); + final Gps droneGps = this.drone.getAttribute(AttributeType.GPS); + final Home droneHome = this.drone.getAttribute(AttributeType.HOME); if(droneGps != null && droneGps.isValid() && droneHome != null && droneHome.isValid()) { double distanceToHome = MathUtils.getDistance(droneHome.getCoordinate(), droneGps.getPosition()); @@ -231,7 +232,7 @@ private void updateGps(Drone drone) { if (mInboxBuilder == null) return; - Gps droneGps = drone.getGps(); + Gps droneGps = drone.getAttribute(AttributeType.GPS); String update = droneGps == null ? "--" : String.format( "%d, %s", droneGps.getSatellitesCount(), droneGps.getFixType()); mInboxBuilder.setLine(1, SpannableUtils.normal("Satellite: ", SpannableUtils.bold(update))); @@ -241,7 +242,7 @@ private void updateBattery(Drone drone) { if (mInboxBuilder == null) return; - Battery droneBattery = drone.getBattery(); + Battery droneBattery = drone.getAttribute(AttributeType.BATTERY); String update = droneBattery == null ? "--" : String.format( "%2.1fv (%2.0f%%)", droneBattery.getBatteryVoltage(), droneBattery.getBatteryRemain()); @@ -263,7 +264,7 @@ private void updateFlightMode(Drone drone) { if (mNotificationBuilder == null) return; - State droneState = drone.getState(); + State droneState = drone.getAttribute(AttributeType.STATE); VehicleMode mode = droneState == null ? null : droneState.getVehicleMode(); String update = mode == null ? "--" : mode.getLabel(); final CharSequence modeSummary = SpannableUtils.normal("Flight Mode: ", SpannableUtils.bold(update)); diff --git a/Android/src/org/droidplanner/android/notifications/TTSNotificationProvider.java b/Android/src/org/droidplanner/android/notifications/TTSNotificationProvider.java index 62adeafa8a..d3921087c3 100644 --- a/Android/src/org/droidplanner/android/notifications/TTSNotificationProvider.java +++ b/Android/src/org/droidplanner/android/notifications/TTSNotificationProvider.java @@ -17,8 +17,12 @@ import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.Altitude; import com.o3dr.services.android.lib.drone.property.Battery; import com.o3dr.services.android.lib.drone.property.Gps; +import com.o3dr.services.android.lib.drone.property.Signal; +import com.o3dr.services.android.lib.drone.property.Speed; import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.VehicleMode; @@ -104,8 +108,11 @@ private class Watchdog implements Runnable { public void run() { handler.removeCallbacks(watchdogCallback); - if (drone != null && drone.isConnected() && drone.getState().isArmed()) { - speakPeriodic(drone); + + if (drone != null) { + final State droneState = drone.getAttribute(AttributeType.STATE); + if(droneState.isConnected() && droneState.isArmed()) + speakPeriodic(drone); } if (statusInterval != 0) { @@ -120,23 +127,24 @@ private void speakPeriodic(Drone drone) { mMessageBuilder.setLength(0); if (speechPrefs.get(R.string.pref_tts_periodic_bat_volt_key)) { - mMessageBuilder.append(String.format("battery %2.1f volts. ", drone - .getBattery().getBatteryVoltage())); + final Battery droneBattery = drone.getAttribute(AttributeType.BATTERY); + mMessageBuilder.append(String.format("battery %2.1f volts. ", droneBattery.getBatteryVoltage())); } if (speechPrefs.get(R.string.pref_tts_periodic_alt_key)) { - mMessageBuilder.append("altitude, " + (int) (drone.getAltitude().getAltitude()) - + " meters. "); + final Altitude altitude = drone.getAttribute(AttributeType.ALTITUDE); + mMessageBuilder.append("altitude, ").append((int) (altitude.getAltitude())).append(" meters. "); } if (speechPrefs.get(R.string.pref_tts_periodic_airspeed_key)) { - mMessageBuilder.append("airspeed, " + (int) (drone.getSpeed().getAirSpeed()) - + " meters per second. "); + final Speed droneSpeed = drone.getAttribute(AttributeType.SPEED); + mMessageBuilder.append("airspeed, ").append((int) (droneSpeed.getAirSpeed())) + .append(" meters per second. "); } if (speechPrefs.get(R.string.pref_tts_periodic_rssi_key)) { - mMessageBuilder.append("r s s i, " + (int) drone.getSignal().getRssi() - + " decibels"); + final Signal signal = drone.getAttribute(AttributeType.SIGNAL); + mMessageBuilder.append("r s s i, ").append((int) signal.getRssi()).append(" decibels"); } speak(mMessageBuilder.toString(), true, PERIODIC_STATUS_UTTERANCE_ID); @@ -269,13 +277,13 @@ public void onReceive(Context context, Intent intent) { return; final String action = intent.getAction(); - State droneState = drone.getState(); + State droneState = drone.getAttribute(AttributeType.STATE); if (AttributeEvent.STATE_ARMING.equals(action)) { if(droneState != null) speakArmedState(droneState.isArmed()); } else if (AttributeEvent.BATTERY_UPDATED.equals(action)) { - Battery droneBattery = drone.getBattery(); + Battery droneBattery = drone.getAttribute(AttributeType.BATTERY); if(droneBattery != null) batteryDischargeNotification(droneBattery.getBatteryRemain()); } else if (AttributeEvent.STATE_VEHICLE_MODE.equals(action)) { @@ -285,7 +293,7 @@ public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Waypoints sent", Toast.LENGTH_SHORT).show(); speak("Waypoints saved to Drone"); } else if (AttributeEvent.GPS_FIX.equals(action)) { - Gps droneGps = drone.getGps(); + Gps droneGps = drone.getAttribute(AttributeType.GPS); if(droneGps != null) speakGpsMode(droneGps.getFixType()); } else if (AttributeEvent.MISSION_RECEIVED.equals(action)) { diff --git a/Android/src/org/droidplanner/android/proxy/mission/MissionProxy.java b/Android/src/org/droidplanner/android/proxy/mission/MissionProxy.java index ce30c94146..fac191d49f 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/MissionProxy.java +++ b/Android/src/org/droidplanner/android/proxy/mission/MissionProxy.java @@ -15,6 +15,7 @@ import org.droidplanner.android.maps.DPMap; import org.droidplanner.android.maps.MarkerInfo; import org.droidplanner.android.proxy.mission.item.MissionItemProxy; +import org.droidplanner.android.utils.Utils; import org.droidplanner.android.utils.analytics.GAUtils; import org.droidplanner.android.utils.file.IO.MissionReader; import org.droidplanner.android.utils.file.IO.MissionWriter; @@ -24,6 +25,7 @@ import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.mission.Mission; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; @@ -43,10 +45,7 @@ */ public class MissionProxy implements DPMap.PathSource { - private static final String CLAZZ_NAME = MissionProxy.class.getName(); - - public static final String ACTION_MISSION_PROXY_UPDATE = CLAZZ_NAME + "" + - ".ACTION_MISSION_PROXY_UPDATE"; + public static final String ACTION_MISSION_PROXY_UPDATE = Utils.PACKAGE_NAME + ".ACTION_MISSION_PROXY_UPDATE"; private static final double DEFAULT_ALTITUDE = 20; //meters @@ -64,11 +63,19 @@ public void onReceive(Context context, Intent intent) { if(AttributeEvent.MISSION_DRONIE_CREATED.equals(action) || AttributeEvent.MISSION_UPDATED.equals(action) || AttributeEvent.MISSION_RECEIVED.equals(action)){ - load(drone.getMission()); + Mission droneMission = drone.getAttribute(AttributeType.MISSION); + load(droneMission); } } }; + private final Drone.OnMissionItemsBuiltCallback missionItemsBuiltListener = new Drone.OnMissionItemsBuiltCallback() { + @Override + public void onMissionItemsBuilt(MissionItem.ComplexItem[] complexItems) { + notifyMissionUpdate(); + } + }; + /** * Stores all the mission item renders for this mission render. */ @@ -552,29 +559,27 @@ public void removeSelection(MissionSelection missionSelection) { notifyMissionUpdate(); } - public void move(MissionItemProxy item, LatLong position) { + public void move(MissionItemProxy item, LatLong position) { MissionItem missionItem = item.getMissionItem(); if(missionItem instanceof SpatialItem){ SpatialItem spatialItem = (SpatialItem) missionItem; spatialItem.setCoordinate(new LatLongAlt(position.getLatitude(), position.getLongitude(), spatialItem.getCoordinate().getAltitude())); - if(spatialItem instanceof StructureScanner) - this.drone.buildComplexMissionItem((StructureScanner) spatialItem); - notifyMissionUpdate(); + if(spatialItem instanceof StructureScanner){ + this.drone.buildMissionItemsAsync(missionItemsBuiltListener, (StructureScanner) spatialItem); + } } - } + } public List getVisibleCoords() { return getVisibleCoords(missionItemProxies); } - public void movePolygonPoint(Survey survey, int index, LatLong position) { + public void movePolygonPoint(Survey survey, int index, LatLong position) { survey.getPolygonPoints().get(index).set(position); - this.drone.buildComplexMissionItem(survey); - - notifyMissionUpdate(); - } + this.drone.buildMissionItemsAsync(missionItemsBuiltListener, survey); + } public static List getVisibleCoords(List mipList){ final List coords = new ArrayList(); diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/MissionItemProxy.java b/Android/src/org/droidplanner/android/proxy/mission/item/MissionItemProxy.java index c039388fe7..7019779b48 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/MissionItemProxy.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/MissionItemProxy.java @@ -17,6 +17,7 @@ import android.view.ViewGroup; import android.widget.TextView; +import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.mission.Mission; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; @@ -34,7 +35,14 @@ */ public class MissionItemProxy { - /** + private final Drone.OnMissionItemsBuiltCallback missionItemBuiltListener = new Drone.OnMissionItemsBuiltCallback() { + @Override + public void onMissionItemsBuilt(MissionItem.ComplexItem[] complexItems) { + } + }; + + + /** * This is the mission item object this class is built around. */ private final MissionItem mMissionItem; @@ -55,10 +63,10 @@ public MissionItemProxy(MissionProxy mission, MissionItem missionItem) { mMarkerInfos = MissionItemMarkerInfo.newInstance(this); if(mMissionItem instanceof Survey){ - mMission.getDrone().buildComplexMissionItem((Survey) mMissionItem); + mMission.getDrone().buildMissionItemsAsync(missionItemBuiltListener, (Survey) mMissionItem); } else if(mMissionItem instanceof StructureScanner){ - mMission.getDrone().buildComplexMissionItem((StructureScanner) mMissionItem); + mMission.getDrone().buildMissionItemsAsync(missionItemBuiltListener, (StructureScanner) mMissionItem); } } diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java index 042ea64f10..dde17450b3 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionStructureScannerFragment.java @@ -7,6 +7,7 @@ import android.widget.Spinner; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.mission.Mission; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; @@ -45,7 +46,7 @@ public void onApiConnected() { typeSpinner.setSelection(commandAdapter.getPosition(MissionItemType.STRUCTURE_SCANNER)); - CameraProxy camera = getDrone().getCamera(); + CameraProxy camera = getDrone().getAttribute(AttributeType.CAMERA); List cameraDetails = camera == null ? Collections.emptyList() : camera.getAvailableCameraInfos(); diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java index 1b5defbb5f..a2f4dc7b31 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java @@ -11,6 +11,7 @@ import android.widget.TextView; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.mission.item.complex.CameraDetail; @@ -82,7 +83,7 @@ public void onApiConnected() { final View view = getView(); final Context context = getActivity().getApplicationContext(); - CameraProxy camera = getDrone().getCamera(); + CameraProxy camera = getDrone().getAttribute(AttributeType.CAMERA); List cameraDetails = camera == null ? Collections.emptyList() : camera.getAvailableCameraInfos(); diff --git a/Android/src/org/droidplanner/android/utils/Utils.java b/Android/src/org/droidplanner/android/utils/Utils.java index bef72e2548..a822fac35f 100644 --- a/Android/src/org/droidplanner/android/utils/Utils.java +++ b/Android/src/org/droidplanner/android/utils/Utils.java @@ -14,6 +14,8 @@ */ public class Utils { + public static final String PACKAGE_NAME = "org.droidplanner.android"; + /** * Returns the map provider selected by the user. * diff --git a/Android/src/org/droidplanner/android/widgets/actionProviders/InfoBarItem.java b/Android/src/org/droidplanner/android/widgets/actionProviders/InfoBarItem.java index 2c1d82a657..1fe6b7748f 100644 --- a/Android/src/org/droidplanner/android/widgets/actionProviders/InfoBarItem.java +++ b/Android/src/org/droidplanner/android/widgets/actionProviders/InfoBarItem.java @@ -22,10 +22,13 @@ import com.google.android.gms.analytics.HitBuilders; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Battery; import com.o3dr.services.android.lib.drone.property.Gps; import com.o3dr.services.android.lib.drone.property.Home; import com.o3dr.services.android.lib.drone.property.Signal; +import com.o3dr.services.android.lib.drone.property.State; +import com.o3dr.services.android.lib.drone.property.Type; import com.o3dr.services.android.lib.drone.property.VehicleMode; import com.o3dr.services.android.lib.util.MathUtils; @@ -115,8 +118,8 @@ public void updateItemView(final Context context, final Drone drone) { if (mItemView != null) { String update = "--"; if(drone != null && drone.isConnected()) { - final Gps droneGps = drone.getGps(); - final Home droneHome = drone.getHome(); + final Gps droneGps = drone.getAttribute(AttributeType.GPS); + final Home droneHome = drone.getAttribute(AttributeType.HOME); if(droneGps.isValid() && droneHome.isValid()) { double distanceToHome = MathUtils.getDistance(droneHome.getCoordinate(), droneGps.getPosition()); @@ -149,7 +152,7 @@ public void updateItemView(final Context context, final Drone drone) { if (drone == null || !drone.isConnected()) { update = "--"; } else{ - Gps droneGps = drone.getGps(); + Gps droneGps = drone.getAttribute(AttributeType.GPS); if (mAppPrefs.shouldGpsHdopBeDisplayed()) { update = String.format(Locale.ENGLISH, "Satellite\n%d, %.1f", droneGps .getSatellitesCount(), droneGps.getGpsEph()); @@ -334,7 +337,7 @@ public void updateItemView(Context context, Drone drone) { String infoUpdate; Battery droneBattery; - if (drone == null || !drone.isConnected() || ((droneBattery = drone.getBattery()) == + if (drone == null || !drone.isConnected() || ((droneBattery = drone.getAttribute(AttributeType.BATTERY)) == null)) { infoUpdate = sDefaultValue; currentView.setText(sDefaultValue); @@ -426,17 +429,18 @@ public void updateItemView(Context context, final Drone drone) { if (drone == null || !drone.isConnected()) { setDefaultValues(); - }else if (!drone.getSignal().isValid()){ - setDefaultValues(); - }else{ - setValuesFromRadio(drone); - } - + }else { + final Signal droneSignal = drone.getAttribute(AttributeType.SIGNAL); + if (!droneSignal.isValid()) { + setDefaultValues(); + } else { + setValuesFromRadio(droneSignal); + } + } mPopup.update(); } - private void setValuesFromRadio(final Drone drone) { - Signal droneSignal = drone.getSignal(); + private void setValuesFromRadio(final Signal droneSignal) { ((TextView) mItemView).setText(String.format(Locale.ENGLISH, "%d%%", MathUtils.getSignalStrength(droneSignal.getFadeMargin(), droneSignal.getRemFadeMargin()))); @@ -524,9 +528,17 @@ public void updateItemView(final Context context, final Drone drone) { if (mItemView == null) return; + final boolean isDroneConnected = drone != null && mDrone.isConnected(); final SpinnerSelfSelect modesSpinner = (SpinnerSelfSelect) mItemView; - final int droneType = drone == null || !drone.isConnected() ? -1 : drone.getType() - .getDroneType(); + final int droneType; + if(isDroneConnected){ + Type type = mDrone.getAttribute(AttributeType.TYPE); + droneType = type.getDroneType(); + } + else{ + droneType = -1; + } + if (droneType != mLastDroneType) { final List flightModes = VehicleMode.getVehicleModePerDroneType(droneType); @@ -537,9 +549,9 @@ public void updateItemView(final Context context, final Drone drone) { mLastDroneType = droneType; } - if (mDrone != null && mDrone.isConnected()) { - modesSpinner.forcedSetSelection(mModeAdapter.getPosition(mDrone.getState() - .getVehicleMode())); + if (isDroneConnected) { + final State droneState = mDrone.getAttribute(AttributeType.STATE); + modesSpinner.forcedSetSelection(mModeAdapter.getPosition(droneState.getVehicleMode())); } } } diff --git a/Android/src/org/droidplanner/android/widgets/checklist/CheckListSysLink.java b/Android/src/org/droidplanner/android/widgets/checklist/CheckListSysLink.java index d6210bf473..15f45c6ebc 100644 --- a/Android/src/org/droidplanner/android/widgets/checklist/CheckListSysLink.java +++ b/Android/src/org/droidplanner/android/widgets/checklist/CheckListSysLink.java @@ -3,6 +3,7 @@ import android.content.Context; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Battery; import com.o3dr.services.android.lib.drone.property.Gps; import com.o3dr.services.android.lib.drone.property.State; @@ -22,7 +23,7 @@ public void getSystemData(CheckListItem mListItem, String mSysTag) { if (mSysTag == null) return; - Battery batt = drone.getBattery(); + Battery batt = drone.getAttribute(AttributeType.BATTERY); if (batt != null) { if (mSysTag.equalsIgnoreCase("SYS_BATTREM_LVL")) { mListItem.setSys_value(batt.getBatteryRemain()); @@ -33,14 +34,14 @@ public void getSystemData(CheckListItem mListItem, String mSysTag) { } } - Gps gps = drone.getGps(); + Gps gps = drone.getAttribute(AttributeType.GPS); if (gps != null) { if (mSysTag.equalsIgnoreCase("SYS_GPS3D_LVL")) { mListItem.setSys_value(gps.getSatellitesCount()); } } - State state = drone.getState(); + State state = drone.getAttribute(AttributeType.STATE); if (state != null) { if (mSysTag.equalsIgnoreCase("SYS_ARM_STATE")) { mListItem.setSys_activated(state.isArmed()); @@ -69,8 +70,9 @@ public void setSystemData(CheckListItem checkListItem) { } private void doSysArm(CheckListItem checkListItem) { - if (drone.isConnected()) { - if (checkListItem.isSys_activated() && !drone.getState().isArmed()) { + final State droneState = drone.getAttribute(AttributeType.STATE); + if (droneState.isConnected()) { + if (checkListItem.isSys_activated() && !droneState.isArmed()) { drone.arm(true); } else { drone.arm(false); diff --git a/Android/src/org/droidplanner/android/widgets/checklist/row/ListRow.java b/Android/src/org/droidplanner/android/widgets/checklist/row/ListRow.java index 16f8e60fbb..23cdd6ddae 100644 --- a/Android/src/org/droidplanner/android/widgets/checklist/row/ListRow.java +++ b/Android/src/org/droidplanner/android/widgets/checklist/row/ListRow.java @@ -10,6 +10,10 @@ import android.widget.Toast; import com.o3dr.android.client.Drone; +import com.o3dr.services.android.lib.drone.attribute.AttributeType; +import com.o3dr.services.android.lib.drone.property.Battery; +import com.o3dr.services.android.lib.drone.property.Gps; +import com.o3dr.services.android.lib.drone.property.State; public class ListRow implements ListRow_Interface, OnClickListener, OnLongClickListener { protected final CheckListItem checkListItem; @@ -64,20 +68,27 @@ public void setOnRowItemChangeListener(OnRowItemChangeListener mListener) { protected void getDroneVariable(Drone mDrone, CheckListItem mListItem) { String sys_tag = mListItem.getSys_tag(); + final Battery droneBattery = mDrone.getAttribute(AttributeType.BATTERY); if (sys_tag.equalsIgnoreCase("SYS_BATTREM_LVL")) { - mListItem.setSys_value(mDrone.getBattery().getBatteryRemain()); + mListItem.setSys_value(droneBattery.getBatteryRemain()); } else if (sys_tag.equalsIgnoreCase("SYS_BATTVOL_LVL")) { - mListItem.setSys_value(mDrone.getBattery().getBatteryVoltage()); + mListItem.setSys_value(droneBattery.getBatteryVoltage()); } else if (sys_tag.equalsIgnoreCase("SYS_BATTCUR_LVL")) { - mListItem.setSys_value(mDrone.getBattery().getBatteryCurrent()); - } else if (sys_tag.equalsIgnoreCase("SYS_GPS3D_LVL")) { - mListItem.setSys_value(mDrone.getGps().getSatellitesCount()); - } else if (sys_tag.equalsIgnoreCase("SYS_ARM_STATE")) { - mListItem.setSys_activated(mDrone.getState().isArmed()); + mListItem.setSys_value(droneBattery.getBatteryCurrent()); + } + + final Gps droneGps = mDrone.getAttribute(AttributeType.GPS); + if (sys_tag.equalsIgnoreCase("SYS_GPS3D_LVL")) { + mListItem.setSys_value(droneGps.getSatellitesCount()); + } + + final State droneState = mDrone.getAttribute(AttributeType.STATE); + if (sys_tag.equalsIgnoreCase("SYS_ARM_STATE")) { + mListItem.setSys_activated(droneState.isArmed()); } else if (sys_tag.equalsIgnoreCase("SYS_FAILSAFE_STATE")) { - mListItem.setSys_activated(mDrone.getState().isWarning()); + mListItem.setSys_activated(droneState.isWarning()); } else if (sys_tag.equalsIgnoreCase("SYS_CONNECTION_STATE")) { - mListItem.setSys_activated(mDrone.isConnected()); + mListItem.setSys_activated(droneState.isConnected()); } } From a54e1c4b71c97bb2d406ef99e214d79f383e281b Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Mon, 22 Dec 2014 07:19:30 -0800 Subject: [PATCH 4/7] fixed survey mission item editor issue. update the 3dr services client lib. --- Android/build.gradle | 2 +- .../org/droidplanner/android/fragments/EditorListFragment.java | 3 +-- .../proxy/mission/item/fragments/MissionSurveyFragment.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Android/build.gradle b/Android/build.gradle index 1f6ba539b8..9f327806b0 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -11,7 +11,7 @@ dependencies { compile 'com.android.support:cardview-v7:21.0.2' compile 'com.android.support:recyclerview-v7:21.0.2' - compile 'com.o3dr:3dr-services-lib:2.1.22' + compile 'com.o3dr:3dr-services-lib:2.1.23' compile files('libs/droneapi-java.jar') compile files('libs/j2xx.jar') diff --git a/Android/src/org/droidplanner/android/fragments/EditorListFragment.java b/Android/src/org/droidplanner/android/fragments/EditorListFragment.java index 332be4c542..b266a2bd98 100644 --- a/Android/src/org/droidplanner/android/fragments/EditorListFragment.java +++ b/Android/src/org/droidplanner/android/fragments/EditorListFragment.java @@ -24,8 +24,7 @@ public class EditorListFragment extends ApiListenerFragment implements MissionSelection.OnSelectionUpdateListener { - private final static IntentFilter eventFilter = new IntentFilter(MissionProxy - .ACTION_MISSION_PROXY_UPDATE); + private final static IntentFilter eventFilter = new IntentFilter(MissionProxy.ACTION_MISSION_PROXY_UPDATE); private final BroadcastReceiver eventReceiver = new BroadcastReceiver() { @Override diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java index a2f4dc7b31..424ba49201 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionSurveyFragment.java @@ -120,8 +120,8 @@ public void onApiConnected() { numberOfStripsView = (TextView) view.findViewById(id.numberOfStripsTextView); lengthView = (TextView) view.findViewById(id.lengthTextView); - updateCamera(); updateViews(); + updateCamera(); mAnglePicker.addScrollListener(this); mOverlapPicker.addScrollListener(this); From ce488217896009ff52c0264e20df1cd3acd9de1e Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Mon, 22 Dec 2014 08:47:30 -0800 Subject: [PATCH 5/7] realtime footprint bug fix. --- .../android/fragments/DroneMap.java | 5 +++ .../android/fragments/SettingsFragment.java | 40 ++++++++++++------- .../google_map/GoogleMapFragment.java | 40 +++++++++++++------ 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/Android/src/org/droidplanner/android/fragments/DroneMap.java b/Android/src/org/droidplanner/android/fragments/DroneMap.java index 5632a1d242..c5f884efce 100644 --- a/Android/src/org/droidplanner/android/fragments/DroneMap.java +++ b/Android/src/org/droidplanner/android/fragments/DroneMap.java @@ -83,10 +83,12 @@ public void onReceive(Context context, Intent intent) { case AttributeEvent.HEARTBEAT_RESTORED: mMapFragment.updateMarker(graphicDrone); break; + case AttributeEvent.STATE_DISCONNECTED: case AttributeEvent.HEARTBEAT_TIMEOUT: mMapFragment.updateMarker(graphicDrone); break; + case AttributeEvent.CAMERA_FOOTPRINTS_UPDATED: { CameraProxy camera = drone.getAttribute(AttributeType.CAMERA); if (camera != null && camera.getLastFootPrint() != null) @@ -104,6 +106,9 @@ public void onReceive(Context context, Intent intent) { } } + else{ + mMapFragment.updateRealTimeFootprint(null); + } break; } } diff --git a/Android/src/org/droidplanner/android/fragments/SettingsFragment.java b/Android/src/org/droidplanner/android/fragments/SettingsFragment.java index 9fcb8f4404..e4979f7746 100644 --- a/Android/src/org/droidplanner/android/fragments/SettingsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/SettingsFragment.java @@ -87,24 +87,34 @@ public class SettingsFragment extends PreferenceFragment implements private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { + final Activity activity = getActivity(); + if(activity == null) + return; + final String action = intent.getAction(); - if (AttributeEvent.STATE_DISCONNECTED.equals(action)) { - updateMavlinkVersionPreference(null); - updateFirmwareVersionPreference(null); - } else if (AttributeEvent.HEARTBEAT_FIRST.equals(action) - || AttributeEvent.HEARTBEAT_RESTORED.equals(action)) { - int mavlinkVersion = intent.getIntExtra(AttributeEventExtra.EXTRA_MAVLINK_VERSION, -1); - if (mavlinkVersion == -1) + switch (action) { + case AttributeEvent.STATE_DISCONNECTED: updateMavlinkVersionPreference(null); - else - updateMavlinkVersionPreference(String.valueOf(mavlinkVersion)); - } else if (AttributeEvent.TYPE_UPDATED.equals(action)) { - Drone drone = dpApp.getDrone(); - if (drone.isConnected()) { - Type droneType = drone.getAttribute(AttributeType.TYPE); - updateFirmwareVersionPreference(droneType.getFirmwareVersion()); - } else updateFirmwareVersionPreference(null); + break; + + case AttributeEvent.HEARTBEAT_FIRST: + case AttributeEvent.HEARTBEAT_RESTORED: + int mavlinkVersion = intent.getIntExtra(AttributeEventExtra.EXTRA_MAVLINK_VERSION, -1); + if (mavlinkVersion == -1) + updateMavlinkVersionPreference(null); + else + updateMavlinkVersionPreference(String.valueOf(mavlinkVersion)); + break; + + case AttributeEvent.TYPE_UPDATED: + Drone drone = dpApp.getDrone(); + if (drone.isConnected()) { + Type droneType = drone.getAttribute(AttributeType.TYPE); + updateFirmwareVersionPreference(droneType.getFirmwareVersion()); + } else + updateFirmwareVersionPreference(null); + break; } } }; diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java b/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java index 25e68f5fbe..944bb78872 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java @@ -63,6 +63,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -858,21 +859,34 @@ public void skipMarkerClickEvents(boolean skip) { @Override public void updateRealTimeFootprint(FootPrint footprint) { - if (footprintPoly == null) { - PolygonOptions pathOptions = new PolygonOptions(); - pathOptions.strokeColor(FOOTPRINT_DEFAULT_COLOR).strokeWidth(FOOTPRINT_DEFAULT_WIDTH); - pathOptions.fillColor(FOOTPRINT_FILL_COLOR); - - for (LatLong vertex : footprint.getVertexInGlobalFrame()) { - pathOptions.add(DroneHelper.CoordToLatLang(vertex)); + List pathPoints = footprint == null + ? Collections.emptyList() + : footprint.getVertexInGlobalFrame(); + + if(pathPoints.isEmpty()){ + if(footprintPoly != null) { + footprintPoly.remove(); + footprintPoly = null; } - footprintPoly = getMap().addPolygon(pathOptions); - } else { - List list = new ArrayList(); - for (LatLong vertex : footprint.getVertexInGlobalFrame()) { - list.add(DroneHelper.CoordToLatLang(vertex)); + } + else { + if (footprintPoly == null) { + PolygonOptions pathOptions = new PolygonOptions() + .strokeColor(FOOTPRINT_DEFAULT_COLOR) + .strokeWidth(FOOTPRINT_DEFAULT_WIDTH) + .fillColor(FOOTPRINT_FILL_COLOR); + + for (LatLong vertex : pathPoints) { + pathOptions.add(DroneHelper.CoordToLatLang(vertex)); + } + footprintPoly = getMap().addPolygon(pathOptions); + } else { + List list = new ArrayList(); + for (LatLong vertex : pathPoints) { + list.add(DroneHelper.CoordToLatLang(vertex)); + } + footprintPoly.setPoints(list); } - footprintPoly.setPoints(list); } } From bb5ad2d248c1d1020ffd9a0428d80f3bd7e10b98 Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Mon, 22 Dec 2014 10:37:17 -0800 Subject: [PATCH 6/7] added preference options for the display of the advanced menu category. --- Android/AndroidManifest.xml | 3 +- Android/res/menu/menu_super_activiy.xml | 34 ++++++++++++------- Android/res/values/preferences_keys.xml | 1 + Android/res/values/strings.xml | 2 ++ Android/res/xml/preferences.xml | 7 ++++ .../android/activities/helpers/SuperUI.java | 22 +++++++++--- .../android/fragments/SettingsFragment.java | 32 ++++++++++++----- .../org/droidplanner/android/utils/Utils.java | 2 ++ .../utils/prefs/DroidPlannerPrefs.java | 4 +++ 9 files changed, 80 insertions(+), 27 deletions(-) diff --git a/Android/AndroidManifest.xml b/Android/AndroidManifest.xml index ae3c4a5309..80f075bc5c 100644 --- a/Android/AndroidManifest.xml +++ b/Android/AndroidManifest.xml @@ -1,6 +1,5 @@ + > - - - + + android:id="@+id/menu_advanced" + android:enabled="false" + android:visible="false" + android:title="Advanced" + app:showAsAction="never"> + + + + + + + pref_connection_param_type pref_map_type pref_advanced_use_offline_maps + pref_advanced_menu_toggle pref_baud_type pref_server_ip pref_server_port diff --git a/Android/res/values/strings.xml b/Android/res/values/strings.xml index a4ba4968c6..3c5110ae84 100644 --- a/Android/res/values/strings.xml +++ b/Android/res/values/strings.xml @@ -535,5 +535,7 @@ dronie. No waypoint(s) selected. Unable to start calibration! + Advanced Menu + Enable advanced menu options. diff --git a/Android/res/xml/preferences.xml b/Android/res/xml/preferences.xml index 7b866921a0..0b21830b02 100644 --- a/Android/res/xml/preferences.xml +++ b/Android/res/xml/preferences.xml @@ -354,6 +354,13 @@ android:summary="@string/pref_ui_gps_hdop_summary" android:title="@string/pref_ui_gps_hdop_title" /> + + + Date: Mon, 22 Dec 2014 12:46:05 -0800 Subject: [PATCH 7/7] string resources cleanup. --- Android/res/menu/menu_super_activiy.xml | 8 ++++---- Android/res/values-de/strings.xml | 4 ++-- Android/res/values-it/strings.xml | 4 ++-- Android/res/values-zh-rCN/strings.xml | 4 ++-- Android/res/values-zh-rTW/strings.xml | 4 ++-- Android/res/values/strings.xml | 7 ++----- .../droidplanner/android/activities/helpers/SuperUI.java | 8 ++++---- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Android/res/menu/menu_super_activiy.xml b/Android/res/menu/menu_super_activiy.xml index 51298929fc..ec33a303e6 100644 --- a/Android/res/menu/menu_super_activiy.xml +++ b/Android/res/menu/menu_super_activiy.xml @@ -14,13 +14,13 @@ /> + android:title="@string/upload_mission"/> + android:title="@string/download_mission"/> Hilfe Drohnen-Setup Editor - Mission senden - Mission laden + Mission senden + Mission laden Tuning diff --git a/Android/res/values-it/strings.xml b/Android/res/values-it/strings.xml index 60f2a5c75a..9b0817764f 100644 --- a/Android/res/values-it/strings.xml +++ b/Android/res/values-it/strings.xml @@ -8,8 +8,8 @@ Impostazioni App Dati volo Editore - Invia missione - Carica missione + Invia missione + Carica missione Messa a punto diff --git a/Android/res/values-zh-rCN/strings.xml b/Android/res/values-zh-rCN/strings.xml index b3cb619d50..6c4cb9f8bd 100644 --- a/Android/res/values-zh-rCN/strings.xml +++ b/Android/res/values-zh-rCN/strings.xml @@ -11,8 +11,8 @@ 应用设置 飞行数据 编辑器 - 发送任务 - 加载任务 + 发送任务 + 加载任务 ne0fhyk.ighceofk diff --git a/Android/res/values-zh-rTW/strings.xml b/Android/res/values-zh-rTW/strings.xml index e2d51e4418..746090b645 100644 --- a/Android/res/values-zh-rTW/strings.xml +++ b/Android/res/values-zh-rTW/strings.xml @@ -8,8 +8,8 @@ App 設定 飛行數據 編輯器 - 發送任務 - 載入任務 + 發送任務 + 載入任務 調整參數 diff --git a/Android/res/values/strings.xml b/Android/res/values/strings.xml index 3c5110ae84..093cb5c5b4 100644 --- a/Android/res/values/strings.xml +++ b/Android/res/values/strings.xml @@ -11,11 +11,8 @@ App Settings Flight Data Editor - Send Mission - Load Mission - - - ne0fhyk.ighceofk + Upload Mission + Download Mission Tuning diff --git a/Android/src/org/droidplanner/android/activities/helpers/SuperUI.java b/Android/src/org/droidplanner/android/activities/helpers/SuperUI.java index 682ab8f077..4cf0b06707 100644 --- a/Android/src/org/droidplanner/android/activities/helpers/SuperUI.java +++ b/Android/src/org/droidplanner/android/activities/helpers/SuperUI.java @@ -198,11 +198,11 @@ public boolean onCreateOptionsMenu(Menu menu) { final boolean areMissionMenusEnabled = enableMissionMenus(); - final MenuItem sendMission = menu.findItem(R.id.menu_send_mission); + final MenuItem sendMission = menu.findItem(R.id.menu_upload_mission); sendMission.setEnabled(areMissionMenusEnabled); sendMission.setVisible(areMissionMenusEnabled); - final MenuItem loadMission = menu.findItem(R.id.menu_load_mission); + final MenuItem loadMission = menu.findItem(R.id.menu_download_mission); loadMission.setEnabled(areMissionMenusEnabled); loadMission.setVisible(areMissionMenusEnabled); @@ -237,7 +237,7 @@ public boolean onOptionsItemSelected(MenuItem item) { toggleDroneConnection(); return true; - case R.id.menu_send_mission: { + case R.id.menu_upload_mission: { final MissionProxy missionProxy = dpApp.getMissionProxy(); if (missionProxy.getItems().isEmpty() || missionProxy.hasTakeoffAndLandOrRTL()) { missionProxy.sendMissionToAPM(dpApi); @@ -266,7 +266,7 @@ public void onNo() { return true; } - case R.id.menu_load_mission: + case R.id.menu_download_mission: dpApi.loadWaypoints(); return true; case R.id.menu_triggerCamera: