altosdroid: Make altosdroid code more resilient to weird androidisms
authorKeith Packard <keithp@keithp.com>
Fri, 18 Oct 2019 08:05:15 +0000 (01:05 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 18 Oct 2019 08:05:15 +0000 (01:05 -0700)
Sometimes altosdroid was crashing when messing with configuration bits
like selecting different themes. These fixes seem to make that happen
less.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosMapOnline.java

index f2e0acd7d02c0b3b8f6dada5d591cdecc9477f14..2854836c44069fa3552d51e0dbb686bd9681cda2 100644 (file)
@@ -595,7 +595,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                        mTab.update_ui(telem_state, state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
                AltosDebug.debug("quiet %b\n", quiet);
-               if (mAltosVoice != null)
+               if (mAltosVoice != null && mTabsAdapter.currentItem() != null)
                        mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem(), quiet);
 
        }
index 29979a07cdbf79b871f8e210e03339dd11f4c3d6..272744a35c8355b93eef7178f63c935616668321 100644 (file)
@@ -110,8 +110,6 @@ public class AltosMapOnline implements AltosDroidMapInterface, GoogleMap.OnMarke
        private boolean pad_set;
        private Polyline mPolyline;
 
-       private View map_view;
-
        private double mapAccuracy = -1;
 
        private AltosLatLon my_position = null;
@@ -121,25 +119,38 @@ public class AltosMapOnline implements AltosDroidMapInterface, GoogleMap.OnMarke
 
        public static class AltosOnlineMapFragment extends SupportMapFragment {
                AltosMapOnline c;
+               View map_view;
 
                public AltosOnlineMapFragment(AltosMapOnline c) {
                        this.c = c;
                }
 
+               public AltosOnlineMapFragment() {
+               }
+
                @Override
                public void onActivityCreated(Bundle savedInstanceState) {
                        super.onActivityCreated(savedInstanceState);
-                       getMapAsync(c);
+                       if (c != null)
+                               getMapAsync(c);
                }
                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-                       c.map_view = super.onCreateView(inflater, container, savedInstanceState);
-                       return c.map_view;
+                       map_view = super.onCreateView(inflater, container, savedInstanceState);
+                       return map_view;
                }
                @Override
                public void onDestroyView() {
                        super.onDestroyView();
-                       c.map_view = null;
+                       map_view = null;
+               }
+               public void set_visible(boolean visible) {
+                       if (map_view == null)
+                               return;
+                       if (visible)
+                               map_view.setVisibility(View.VISIBLE);
+                       else
+                               map_view.setVisibility(View.GONE);
                }
        }
 
@@ -259,12 +270,8 @@ public class AltosMapOnline implements AltosDroidMapInterface, GoogleMap.OnMarke
        }
 
        public void set_visible(boolean visible) {
-               if (map_view == null)
-                       return;
-               if (visible)
-                       map_view.setVisibility(View.VISIBLE);
-               else
-                       map_view.setVisibility(View.GONE);
+               if (mMapFragment != null)
+                       mMapFragment.set_visible(visible);
        }
 
        public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {