altosdroid: Work without GPS available
authorKeith Packard <keithp@keithp.com>
Mon, 21 Jun 2021 00:06:28 +0000 (17:06 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 21 Jun 2021 00:06:28 +0000 (17:06 -0700)
On devices without GPS receivers, use network location instead of
crashing.

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/PreloadMapActivity.java
icon/Makefile.am

index 404b63ace7df8582e90c2e50ecb06ff6c04d1169..5caee5f87aab5323ea0032cf54f865649ff22a8b 100644 (file)
@@ -742,14 +742,23 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
        private void enable_location_updates() {
                // Listen for GPS and Network position updates
                LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
-               locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
 
-               location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+               if (locationManager != null)
+               {
+                       try {
+                               locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
+                               location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+                       } catch (Exception e) {
+                               locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
+                               location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+                       }
 
-               if (location != null)
-                       AltosDebug.debug("Resume, location is %f,%f\n",
-                                        location.getLatitude(),
-                                        location.getLongitude());
+                       if (location != null)
+                               AltosDebug.debug("Resume, location is %f,%f\n",
+                                                location.getLatitude(),
+                                                location.getLongitude());
+                       AltosDebug.debug("Failed to get GPS updates\n");
+               }
 
                update_ui(telemetry_state, state, true);
        }
index f911e1ee85e0ef597ae5e69ff9f04a40ada364ab..eb1230116c7cf4406486a7490d89432a95e9e09f 100644 (file)
@@ -356,8 +356,11 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
 
                // Listen for GPS and Network position updates
                LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
-
-               locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
+               try {
+                       locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
+               } catch (Exception e) {
+                       locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
+               }
 
                new AltosLaunchSites(this);
        }
index 9ce9cba8fb02ba23c6b2e8b0ea48802bb8563422..0f4389d0b5d5c08cdf6b18fdf6e5c1203ceb8e3b 100644 (file)
@@ -1,7 +1,8 @@
 JAVA_RES=16 32 48 64 128 256
 MAC_RES=16 32 128 256 512
 WIN_RES=16 24 32 48 64 72 96 128 180 256
-RES=$(shell echo $(JAVA_RES) $(MAC_RES) $(WIN_RES) | awk '{ for (i = 1; i <= NF; i++) printf("%s\n", $$i); }' | sort -n -u)
+AMAZON_RES=114 512
+RES=$(shell echo $(JAVA_RES) $(MAC_RES) $(WIN_RES) $(AMAZON_RES)| awk '{ for (i = 1; i <= NF; i++) printf("%s\n", $$i); }' | sort -n -u)
 
 # Application icon base names
 
@@ -73,6 +74,10 @@ JAVA_TG_FILES        = $(shell for i in $(JAVA_RES); do echo $(TG_NAME)-$$i.png; done)
 
 JAVA_FILES     = $(JAVA_AM_FILES) $(JAVA_MP_FILES) $(JAVA_TG_FILES)
 
+# Files needed for Amazon store
+
+AMAZON_FILES   = $(shell for i in $(AMAZON_RES); do echo $(AM_NAME)-$$i.png; done)
+
 # PNG files needed by anyone
 
 AM_FILES       = $(shell for i in $(RES); do echo $(AM_NAME)-$$i.png; done)
@@ -120,7 +125,7 @@ java-telegps:
 
 fat: all $(ICO_FILES) $(ICNS_FILES) $(EXE_FILES)
 
-all-local: $(JAVA_FILES) $(AM_XPM) $(LED_ICONS)
+all-local: $(JAVA_FILES) $(AM_XPM) $(LED_ICONS) $(AMAZON_FILES)
 
 clean-local:
        $(RM) $(AM_NAME)-*.png $(TG_NAME)-*.png $(MP_NAME)-*.png