From 3461b9d70c9fab7348464b493a0f02b8ff84cd11 Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Fri, 30 Jan 2015 14:15:30 -0800 Subject: [PATCH] bug fixes. --- Android/build.gradle | 2 +- .../fragments/EditorToolsFragment.java | 41 +++++++++++++------ .../android/fragments/FlightMapFragment.java | 3 ++ .../android/fragments/ParamsFragment.java | 5 ++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Android/build.gradle b/Android/build.gradle index 05520a294a..66a7c10483 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -28,7 +28,7 @@ android { applicationId 'org.droidplanner.android' minSdkVersion 14 targetSdkVersion 21 - versionCode 30016 + versionCode 30017 versionName getGitVersion() } diff --git a/Android/src/org/droidplanner/android/fragments/EditorToolsFragment.java b/Android/src/org/droidplanner/android/fragments/EditorToolsFragment.java index d401c3a39e..f01c15e35e 100644 --- a/Android/src/org/droidplanner/android/fragments/EditorToolsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/EditorToolsFragment.java @@ -238,7 +238,7 @@ public void onSaveInstanceState(Bundle savedInstanceState) { // Store the currently selected tool savedInstanceState.putString(STATE_SELECTED_TOOL, tool.name()); - for(EditorToolsImpl toolImpl : editorToolsImpls){ + for (EditorToolsImpl toolImpl : editorToolsImpls) { toolImpl.onSaveInstanceState(savedInstanceState); } } @@ -399,9 +399,11 @@ void setMissionProxy(MissionProxy missionProxy) { this.missionProxy = missionProxy; } - void onSaveInstanceState(Bundle outState){} + void onSaveInstanceState(Bundle outState) { + } - void onRestoreInstanceState(Bundle savedState){} + void onRestoreInstanceState(Bundle savedState) { + } public void onMapClick(LatLong point) { if (missionProxy == null) return; @@ -451,13 +453,13 @@ private static class MarkerToolsImpl extends EditorToolsImpl implements AdapterV super(fragment); } - void onSaveInstanceState(Bundle outState){ + void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - if(selectedType != null) + if (selectedType != null) outState.putString(EXTRA_SELECTED_MARKER_MISSION_ITEM_TYPE, selectedType.name()); } - void onRestoreInstanceState(Bundle savedState){ + void onRestoreInstanceState(Bundle savedState) { super.onRestoreInstanceState(savedState); final String selectedTypeName = savedState.getString(EXTRA_SELECTED_MARKER_MISSION_ITEM_TYPE, MARKER_ITEMS_TYPE[0].name()); @@ -495,7 +497,8 @@ public void setup() { listener.skipMarkerClickEvents(true); } - missionProxy.selection.clearSelection(); + if (missionProxy != null) + missionProxy.selection.clearSelection(); } @Override @@ -530,13 +533,13 @@ private static class DrawToolsImpl extends EditorToolsImpl implements AdapterVie super(fragment); } - void onSaveInstanceState(Bundle outState){ + void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - if(selectedType != null) + if (selectedType != null) outState.putString(EXTRA_SELECTED_DRAW_MISSION_ITEM_TYPE, selectedType.name()); } - void onRestoreInstanceState(Bundle savedState){ + void onRestoreInstanceState(Bundle savedState) { super.onRestoreInstanceState(savedState); final String selectedTypeName = savedState.getString(EXTRA_SELECTED_DRAW_MISSION_ITEM_TYPE, DRAW_ITEMS_TYPE[0].name()); @@ -556,7 +559,8 @@ public void setup() { listener.skipMarkerClickEvents(false); } - missionProxy.selection.clearSelection(); + if (missionProxy != null) + missionProxy.selection.clearSelection(); if (selectedType == MissionItemType.SURVEY) { Toast.makeText(editorToolsFragment.getContext(), R.string.draw_the_survey_region, Toast.LENGTH_SHORT).show(); @@ -641,6 +645,9 @@ private static class TrashToolsImpl extends EditorToolsImpl implements OnClickLi @Override public void onListItemClick(MissionItemProxy item) { + if (missionProxy == null) + return; + missionProxy.removeItem(item); missionProxy.selection.clearSelection(); @@ -708,7 +715,7 @@ public void onYes() { @Override public void onNo() { - if(missionProxy != null) + if (missionProxy != null) missionProxy.selection.clearSelection(); } }); @@ -733,6 +740,9 @@ private static class SelectorToolsImpl extends EditorToolsImpl implements OnClic @Override public void onListItemClick(MissionItemProxy item) { + if (missionProxy == null) + return; + if (missionProxy.selection.selectionContains(item)) { missionProxy.selection.removeItemFromSelection(item); } else { @@ -741,6 +751,9 @@ public void onListItemClick(MissionItemProxy item) { } private void selectAll() { + if (missionProxy == null) + return; + missionProxy.selection.setSelectionTo(missionProxy.getItems()); EditorToolListener listener = editorToolsFragment.listener; if (listener != null) @@ -762,7 +775,9 @@ public void setup() { Toast.makeText(editorToolsFragment.getContext(), "Click on mission items to select them.", Toast.LENGTH_SHORT).show(); - missionProxy.selection.clearSelection(); + + if (missionProxy != null) + missionProxy.selection.clearSelection(); } @Override diff --git a/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java b/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java index f4fc8eab16..d6f8531ea4 100644 --- a/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java +++ b/Android/src/org/droidplanner/android/fragments/FlightMapFragment.java @@ -188,6 +188,9 @@ public void goToMyLocation() { public void goToDroneLocation() { super.goToDroneLocation(); + if(this.drone == null) + return; + final Gps droneGps = this.drone.getAttribute(AttributeType.GPS); if (droneGps == null || !droneGps.isValid()) return; diff --git a/Android/src/org/droidplanner/android/fragments/ParamsFragment.java b/Android/src/org/droidplanner/android/fragments/ParamsFragment.java index f045353115..b3ce470854 100644 --- a/Android/src/org/droidplanner/android/fragments/ParamsFragment.java +++ b/Android/src/org/droidplanner/android/fragments/ParamsFragment.java @@ -79,8 +79,9 @@ public void onReceive(Context context, Intent intent) { stopProgress(); /*** FALL - THROUGH ***/ case AttributeEvent.TYPE_UPDATED: - if (getDrone().isConnected()) { - final Parameters droneParams = getDrone().getAttribute(AttributeType.PARAMETERS); + final Drone drone = getDrone(); + if (drone != null && drone.isConnected()) { + final Parameters droneParams = drone.getAttribute(AttributeType.PARAMETERS); loadAdapter(droneParams.getParameters(), false); } break;