]> git.gag.com Git - fw/altos/blobdiff - altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java
doc: Add 1.9.22 release notes
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / AltosDroid.java
index 05a023acde3d60f51d27b3caddc1043291336b3c..fd16197072ec30d2a46a45ff6f742ca8824b73f7 100644 (file)
@@ -276,10 +276,10 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                switch (telemetry_state.connect) {
                case TelemetryState.CONNECT_CONNECTED:
                        if (telemetry_state.config != null) {
-                               String str = String.format("S/N %d %6.3f MHz%s", telemetry_state.config.serial,
+                               String str = String.format(Locale.getDefault(), "S/N %d %6.3f MHz%s", telemetry_state.config.serial,
                                                           telemetry_state.frequency, telemetry_state.idle_mode ? " (idle)" : "");
                                if (telemetry_state.telemetry_rate != AltosLib.ao_telemetry_rate_38400)
-                                       str = str.concat(String.format(" %d bps",
+                                       str = str.concat(String.format(Locale.getDefault(), " %d bps",
                                                                       AltosLib.ao_telemetry_rate_values[telemetry_state.telemetry_rate]));
                                setTitle(str);
                        } else {
@@ -288,7 +288,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                        break;
                case TelemetryState.CONNECT_CONNECTING:
                        if (telemetry_state.address != null)
-                               setTitle(String.format("Connecting to %s...", telemetry_state.address.name));
+                               setTitle(String.format(Locale.getDefault(), "Connecting to %s...", telemetry_state.address.name));
                        else
                                setTitle("Connecting to something...");
                        break;
@@ -423,13 +423,13 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
        static String age_string(int age) {
                String  text;
                if (age < 60)
-                       text = String.format("%ds", age);
+                       text = String.format(Locale.getDefault(), "%ds", age);
                else if (age < 60 * 60)
-                       text = String.format("%dm", age / 60);
+                       text = String.format(Locale.getDefault(), "%dm", age / 60);
                else if (age < 60 * 60 * 24)
-                       text = String.format("%dh", age / (60 * 60));
+                       text = String.format(Locale.getDefault(), "%dh", age / (60 * 60));
                else
-                       text = String.format("%dd", age / (24 * 60 * 60));
+                       text = String.format(Locale.getDefault(), "%dd", age / (24 * 60 * 60));
                return text;
        }
 
@@ -522,13 +522,13 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                if (state.cal_data().serial == AltosLib.MISSING)
                                        mSerialView.setText("");
                                else
-                                       mSerialView.setText(String.format("%d", state.cal_data().serial));
+                                       mSerialView.setText(String.format(Locale.getDefault(), "%d", state.cal_data().serial));
                        }
                        if (saved_state == null || state.cal_data().flight != saved_state.flight) {
                                if (state.cal_data().flight == AltosLib.MISSING)
                                        mFlightView.setText("");
                                else
-                                       mFlightView.setText(String.format("%d", state.cal_data().flight));
+                                       mFlightView.setText(String.format(Locale.getDefault(), "%d", state.cal_data().flight));
                        }
                        if (saved_state == null || state.state() != saved_state.state) {
                                if (state.state() == AltosLib.ao_flight_stateless) {
@@ -542,7 +542,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                if (state.rssi == AltosLib.MISSING)
                                        mRSSIView.setText("");
                                else
-                                       mRSSIView.setText(String.format("%d", state.rssi));
+                                       mRSSIView.setText(String.format(Locale.getDefault(), "%d", state.rssi));
                        }
                        saved_state = new SavedState(state);
                }
@@ -575,19 +575,19 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                }
                int deg = (int) Math.floor(p);
                double min = (p - Math.floor(p)) * 60.0;
-               return String.format("%d° %7.4f\" %s", deg, min, h);
+               return String.format(Locale.getDefault(), "%d° %7.4f\" %s", deg, min, h);
        }
 
        static String number(String format, double value) {
                if (value == AltosLib.MISSING)
                        return "";
-               return String.format(format, value);
+               return String.format(Locale.getDefault(), format, value);
        }
 
        static String integer(String format, int value) {
                if (value == AltosLib.MISSING)
                        return "";
-               return String.format(format, value);
+               return String.format(Locale.getDefault(), format, value);
        }
 
        private View create_tab_view(String label) {
@@ -674,7 +674,13 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
                if (device != null) {
                        Intent          i = new Intent(this, AltosDroid.class);
-                       PendingIntent   pi = PendingIntent.getActivity(this, 0, new Intent("hello world", null, this, AltosDroid.class), 0);
+                       int             flag;
+
+                       if (android.os.Build.VERSION.SDK_INT >= 31) // android.os.Build.VERSION_CODES.S
+                               flag = 33554432; // PendingIntent.FLAG_MUTABLE
+                       else
+                               flag = 0;
+                       PendingIntent   pi = PendingIntent.getActivity(this, 0, new Intent("hello world", null, this, AltosDroid.class), flag);
 
                        if (AltosUsb.request_permission(this, device, pi)) {
                                connectUsb(device);
@@ -773,7 +779,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                        try {
                                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
                                location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
-                       } catch (Exception e) {
+                       } catch (SecurityException e) {
                                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
                                location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        }
@@ -793,8 +799,14 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
 
        public boolean have_location_permission = false;
        public boolean have_storage_permission = false;
+       public boolean have_bluetooth_permission = false;
+       public boolean have_bluetooth_connect_permission = false;
+       public boolean have_bluetooth_scan_permission = false;
        public boolean asked_permission = false;
 
+       static final String BLUETOOTH_CONNECT = "android.permission.BLUETOOTH_CONNECT";
+       static final String BLUETOOTH_SCAN = "android.permission.BLUETOOTH_SCAN";
+
        AltosMapOnline map_online;
 
        void
@@ -817,6 +829,15 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                                        if (permissions[i].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                                have_storage_permission = true;
                                        }
+                                       if (permissions[i].equals(Manifest.permission.BLUETOOTH)) {
+                                               have_bluetooth_permission = true;
+                                       }
+                                       if (permissions[i].equals(BLUETOOTH_CONNECT)) {
+                                               have_bluetooth_connect_permission = true;
+                                       }
+                                       if (permissions[i].equals(BLUETOOTH_SCAN)) {
+                                               have_bluetooth_scan_permission = true;
+                                       }
                                }
                        }
                }
@@ -842,15 +863,49 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                        {
                                have_storage_permission = true;
                        }
-                       int count = (have_location_permission ? 0 : 1) + (have_storage_permission ? 0 : 1);
+                       if (ActivityCompat.checkSelfPermission(this,
+                                                              Manifest.permission.BLUETOOTH)
+                           == PackageManager.PERMISSION_GRANTED)
+                       {
+                               have_bluetooth_permission = true;
+                       }
+                       if (ActivityCompat.checkSelfPermission(this,
+                                                              BLUETOOTH_CONNECT)
+                           == PackageManager.PERMISSION_GRANTED)
+                       {
+                               have_bluetooth_connect_permission = true;
+                       }
+                       if (ActivityCompat.checkSelfPermission(this,
+                                                              BLUETOOTH_SCAN)
+                           == PackageManager.PERMISSION_GRANTED)
+                       {
+                               have_bluetooth_scan_permission = true;
+                       }
+                       int count = 0;
+                       if (!have_location_permission)
+                               count += 1;
+                       if (!have_storage_permission)
+                               count += 1;
+                       if (!have_bluetooth_permission)
+                               count += 1;
+                       if (!have_bluetooth_connect_permission)
+                               count += 1;
+                       if (!have_bluetooth_scan_permission)
+                               count += 1;
                        if (count > 0)
                        {
                                String[] permissions = new String[count];
                                int i = 0;
                                if (!have_location_permission)
                                        permissions[i++] = Manifest.permission.ACCESS_FINE_LOCATION;
-                               if (!have_location_permission)
+                               if (!have_storage_permission)
                                        permissions[i++] = Manifest.permission.WRITE_EXTERNAL_STORAGE;
+                               if (!have_bluetooth_permission)
+                                       permissions[i++] = Manifest.permission.BLUETOOTH;
+                               if (!have_bluetooth_connect_permission)
+                                       permissions[i++] = BLUETOOTH_CONNECT;
+                               if (!have_bluetooth_scan_permission)
+                                       permissions[i++] = BLUETOOTH_SCAN;
                                ActivityCompat.requestPermissions(this, permissions, MY_PERMISSION_REQUEST);
                        }
                }
@@ -1273,9 +1328,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                else if (iheading < -179 || 179 < iheading)
                        return "backwards";
                else if (iheading < 0)
-                       return String.format("left %d°", -iheading);
+                       return String.format(Locale.getDefault(), "left %d°", -iheading);
                else
-                       return String.format("right %d°", iheading);
+                       return String.format(Locale.getDefault(), "right %d°", iheading);
        }
 
        public void onLocationChanged(Location location) {