]> git.gag.com Git - fw/altos/commitdiff
altosdroid: Reduce lint in java code
authorKeith Packard <keithp@keithp.com>
Tue, 6 Aug 2024 05:14:42 +0000 (22:14 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 26 Sep 2024 15:25:06 +0000 (08:25 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
13 files changed:
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosMapOffline.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosMapOnline.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosVoice.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/IdleModeActivity.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/IgniterActivity.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/PreloadMapActivity.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/SelectTrackerActivity.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/TabMap.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/TabPad.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/TabRecover.java
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/Tracker.java

index 6d70872123954b1a88ba3fc3b897529e9b4da9f8..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) {
@@ -779,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);
                        }
@@ -1328,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) {
index 170353ab4838098035f6e1dc37768bb0ee41f9f4..024ca1b9a923148ec8fbce9c23348b48a112cc6f 100644 (file)
@@ -31,7 +31,6 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend {
        public final static String        NAME    = "org.altusmetrum.AltosDroid";
        private Context                   context = null;
        private SharedPreferences         prefs   = null;
-       private SharedPreferences.Editor  editor  = null;
 
        public AltosDroidPreferencesBackend(Context in_context) {
                this(in_context, NAME);
@@ -40,7 +39,6 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend {
        public AltosDroidPreferencesBackend(Context in_context, String in_prefs) {
                context = in_context;
                prefs   = context.getSharedPreferences(in_prefs, 0);
-               editor  = prefs.edit();
        }
 
        public String[] keys() {
@@ -104,37 +102,48 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend {
        }
 
        public void putBoolean(String key, boolean value) {
+               SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean(key, value);
+               editor.apply();
        }
 
        public void putDouble(String key, double value) {
+               SharedPreferences.Editor editor = prefs.edit();
                editor.putFloat(key, (float)value);
+               editor.apply();
        }
 
        public void putInt(String key, int value) {
+               SharedPreferences.Editor editor = prefs.edit();
                editor.putInt(key, value);
+               editor.apply();
        }
 
        public void putString(String key, String value) {
+               SharedPreferences.Editor editor = prefs.edit();
 //             AltosDebug.debug("AltosDroidPreferencesBackend put string %s:\n", key);
 //             String[] lines = value.split("\n");
 //             for (String l : lines)
 //                     AltosDebug.debug("        %s\n", l);
                editor.putString(key, value);
+               editor.apply();
        }
 
        public void putBytes(String key, byte[] bytes) {
+               SharedPreferences.Editor editor = prefs.edit();
                String save = Base64.encodeToString(bytes, Base64.DEFAULT);
                editor.putString(key, save);
+               editor.apply();
        }
 
        public void remove(String key) {
+               SharedPreferences.Editor editor = prefs.edit();
                AltosDebug.debug("remove preference %s\n", key);
                editor.remove(key);
+               editor.apply();
        }
 
        public void flush() {
-               editor.apply();
        }
 
        public File homeDirectory() {
index 7bd57a4ca39ebfcd19e44a130c91ef20c15db2a8..ab841b10ee9c6e952e60340b92fc67b40f823a4b 100644 (file)
@@ -70,7 +70,7 @@ class Rocket implements Comparable {
 
        Rocket(int serial, AltosMapOffline map_offline) {
                this.serial = serial;
-               this.name = String.format("%d", serial);
+               this.name = String.format(Locale.ROOT, "%d", serial);
                this.map_offline = map_offline;
        }
 }
index 76cd990be7f5b474f38fbddea13f3c8653db1341..70fb5c65a1d7ad5395aa9a4cc90dedbe49dc0103 100644 (file)
@@ -90,7 +90,7 @@ class RocketOnline implements Comparable {
 
        RocketOnline(Context context, int serial, GoogleMap map, double lat, double lon, long last_packet) {
                this.serial = serial;
-               String name = String.format("%d", serial);
+               String name = String.format(Locale.ROOT, "%d", serial);
                this.marker = map.addMarker(new MarkerOptions()
                                            .icon(BitmapDescriptorFactory.fromBitmap(rocket_bitmap(context, name)))
                                            .position(new LatLng(lat, lon))
@@ -207,8 +207,12 @@ public class AltosMapOnline implements AltosDroidMapInterface, GoogleMap.OnMarke
 
        void
        position_permission() {
-               if (mMap != null)
-                       mMap.setMyLocationEnabled(true);
+               if (mMap != null) {
+                       try {
+                               mMap.setMyLocationEnabled(true);
+                       } catch (SecurityException e) {
+                       }
+               }
        }
 
        @Override
@@ -218,7 +222,7 @@ public class AltosMapOnline implements AltosDroidMapInterface, GoogleMap.OnMarke
                if (mMap != null) {
                        map_type_changed(map_type);
                        if (altos_droid.have_location_permission)
-                               mMap.setMyLocationEnabled(true);
+                               position_permission();
                        else
                                altos_droid.tell_map_permission(this);
                        mMap.getUiSettings().setTiltGesturesEnabled(false);
index 2049c79654b958c645846d298423912605ddabed..f86f60cb3d3ec39cf36ffc9466d510955f2bb803 100644 (file)
@@ -19,6 +19,7 @@
 
 package org.altusmetrum.AltosDroid;
 
+import java.util.*;
 import android.speech.tts.TextToSpeech;
 import android.speech.tts.TextToSpeech.OnInitListener;
 import android.location.Location;
@@ -90,7 +91,7 @@ public class AltosVoice {
        }
 
        public synchronized void speak(String format, Object ... arguments) {
-               speak(String.format(format, arguments));
+               speak(String.format(Locale.getDefault(), format, arguments));
        }
 
        public synchronized boolean is_speaking() {
@@ -269,7 +270,7 @@ public class AltosVoice {
 
                String direction = AltosDroid.direction(from_receiver, receiver);
                if (direction == null)
-                       direction = String.format("Bearing %d", (int) (from_receiver.bearing + 0.5));
+                       direction = String.format(Locale.getDefault(), "Bearing %d", (int) (from_receiver.bearing + 0.5));
 
                speak("%s, distance %s.", direction,
                      AltosConvert.distance.say_units(from_receiver.distance));
index 9b9095bdefc28979a9ff66786d2f2ed57dc54227..2e77530d11560559ed49a60dd4b4631d44048899 100644 (file)
@@ -18,6 +18,7 @@
 
 package org.altusmetrum.AltosDroid;
 
+import java.util.*;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
@@ -87,7 +88,7 @@ public class IdleModeActivity extends Activity {
 
                frequency = getIntent().getDoubleExtra(AltosDroid.EXTRA_FREQUENCY, 0.0);
                frequencyView = (TextView) findViewById(R.id.frequency);
-               frequencyView.setText(String.format("Frequency: %7.3f MHz", frequency));
+               frequencyView.setText(String.format(Locale.getDefault(), "Frequency: %7.3f MHz", frequency));
 
                connect = (Button) findViewById(R.id.connect_idle);
                connect.setOnClickListener(new OnClickListener() {
index 752558206accf3f89d3880d9c95d3cf1fbb68a48..f75961c377d909f9ce026030f689e7c72803fcac 100644 (file)
@@ -275,8 +275,8 @@ public class IgniterActivity extends Activity {
                set_igniter(status, "drogue", "Apogee");
                set_igniter(status, "main", "Main");
                for (int extra = 0;; extra++) {
-                       String  name = String.format("%d", extra);
-                       String  pretty = String.format("%c", 'A' + extra);
+                       String  name = String.format(Locale.getDefault(), "%d", extra);
+                       String  pretty = String.format(Locale.getDefault(), "%c", 'A' + extra);
                        if (!set_igniter(status, name, pretty))
                                break;
                }
@@ -291,7 +291,7 @@ public class IgniterActivity extends Activity {
        }
 
        private void arm_set_text() {
-               String  text = String.format("Armed %d", arm_remaining);
+               String  text = String.format(Locale.getDefault(), "Armed %d", arm_remaining);
 
                if (arm.isChecked())
                        arm.setText(text);
index eb1230116c7cf4406486a7490d89432a95e9e09f..cd0ce70b0e1c8e2ea34d6dad8729c7993c4bcbee 100644 (file)
@@ -134,8 +134,8 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
                        if (selected_item != null)
                                known_sites_spinner.setSelection(known_sites_adapter.getPosition(selected_item));
                        else {
-                               latitude.setText(new StringBuffer(String.format("%12.6f", current_location_site.latitude)));
-                               longitude.setText(new StringBuffer(String.format("%12.6f", current_location_site.longitude)));
+                               latitude.setText(new StringBuffer(String.format(Locale.getDefault(), "%12.6f", current_location_site.latitude)));
+                               longitude.setText(new StringBuffer(String.format(Locale.getDefault(), "%12.6f", current_location_site.longitude)));
                        }
                } else {
                        current_location_site.latitude = location.getLatitude();
@@ -279,8 +279,8 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
        class SiteListListener implements OnItemSelectedListener {
                public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                        AltosLaunchSite site = (AltosLaunchSite) parent.getItemAtPosition(pos);
-                       latitude.setText(new StringBuffer(String.format("%12.6f", site.latitude)));
-                       longitude.setText(new StringBuffer(String.format("%12.6f", site.longitude)));
+                       latitude.setText(new StringBuffer(String.format(Locale.getDefault(), "%12.6f", site.latitude)));
+                       longitude.setText(new StringBuffer(String.format(Locale.getDefault(), "%12.6f", site.longitude)));
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
@@ -358,8 +358,11 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
                LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
                try {
                        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
-               } catch (Exception e) {
-                       locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
+               } catch (SecurityException e) {
+                       try {
+                               locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
+                       } catch (SecurityException se) {
+                       }
                }
 
                new AltosLaunchSites(this);
index 1815331ef2e29aeb22875b8d858e215d084e7543..36e2898031a98f0d966662dac0f4f98e65972f1f 100644 (file)
@@ -195,13 +195,13 @@ public class SelectTrackerActivity extends Activity implements OnTouchListener {
                if (tracker.serial == 0)
                        ((TextView) row.findViewById(R.id.serial_view)).setText("");
                else
-                       ((TextView) row.findViewById(R.id.serial_view)).setText(String.format("%d", tracker.serial));
+                       ((TextView) row.findViewById(R.id.serial_view)).setText(String.format(Locale.getDefault(), "%d", tracker.serial));
                if (tracker.frequency == 0.0)
                        ((TextView) row.findViewById(R.id.frequency_view)).setText("");
                else if (tracker.frequency == AltosLib.MISSING)
                        ((TextView) row.findViewById(R.id.frequency_view)).setText("");
                else
-                       ((TextView) row.findViewById(R.id.frequency_view)).setText(String.format("%7.3f", tracker.frequency));
+                       ((TextView) row.findViewById(R.id.frequency_view)).setText(String.format(Locale.getDefault(), "%7.3f", tracker.frequency));
                if (tracker.received_time != 0) {
                        int age = (int) ((start_time - tracker.received_time + 500) / 1000);
                        ((TextView) row.findViewById(R.id.age_view)).setText(AltosDroid.age_string(age));
index 55acd5d68a88201b3b6bfb64372b9c1c2af5f2bd..8e8fd7743d87462d6d5cd26f500a6bcb0a70f037 100644 (file)
@@ -18,6 +18,8 @@
 
 package org.altusmetrum.AltosDroid;
 
+import java.util.*;
+
 import org.altusmetrum.altoslib_14.*;
 
 import android.app.Activity;
@@ -95,7 +97,7 @@ public class TabMap extends AltosDroidTab implements AltosDroidMapSourceListener
                                mBearingView.setText(direction);
                        } else {
                                mBearingLabel.setText("Bearing");
-                               mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+                               mBearingView.setText(String.format(Locale.getDefault(), "%3.0f°", from_receiver.bearing));
                        }
                        set_value(mDistanceView, AltosConvert.distance, 6, from_receiver.distance);
                } else {
index fd997612725530357ab9a593b802835d729c632d..558be4f87f5cd3135f7ba602be782d8cceaadba2 100644 (file)
@@ -18,6 +18,8 @@
 
 package org.altusmetrum.AltosDroid;
 
+import java.util.*;
+
 import org.altusmetrum.altoslib_14.*;
 
 import android.os.Bundle;
@@ -213,7 +215,7 @@ public class TabPad extends AltosDroidTab {
                        if (state.gps != null) {
                                int soln = state.gps.nsat;
                                int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
-                               gps_locked_view.setText(String.format("%d in soln, %d in view", soln, nsat));
+                               gps_locked_view.setText(String.format(Locale.getDefault(), "%d in soln, %d in view", soln, nsat));
                                gps_locked_lights.set(state.gps.locked && state.gps.nsat >= 4, false);
                                if (state.gps_ready)
                                        gps_ready_view.setText("Ready");
index df1ee8fa36202a14c5acd12ea654ca07664c27cb..93a645c20e549799c573a5b8f65b53e1247f8cb9 100644 (file)
@@ -18,6 +18,7 @@
 
 package org.altusmetrum.AltosDroid;
 
+import java.util.*;
 import org.altusmetrum.altoslib_14.*;
 
 import android.os.Bundle;
@@ -61,7 +62,7 @@ public class TabRecover extends AltosDroidTab {
 
        public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (from_receiver != null) {
-                       mBearingView.setText(String.format("%1.0f°", from_receiver.bearing));
+                       mBearingView.setText(String.format(Locale.getDefault(), "%1.0f°", from_receiver.bearing));
                        set_value(mDistanceView, AltosConvert.distance, 1, from_receiver.distance);
                        String direction = AltosDroid.direction(from_receiver, receiver);
                        if (direction == null)
index 614b4c2cfd5a03becf2a6263c0ae8dd145827fa4..3992395fcf246aa65191f988ef85c0310719f2ec 100644 (file)
@@ -62,9 +62,9 @@ public class Tracker implements CharSequence, Comparable, Parcelable {
                if (frequency == 0.0)
                        display = "Auto";
                else if (frequency == AltosLib.MISSING) {
-                       display = String.format("%-8.8s  %6d", call, serial);
+                       display = String.format(Locale.getDefault(), "%-8.8s  %6d", call, serial);
                } else {
-                       display = String.format("%-8.8s %7.3f %6d", call, frequency, serial);
+                       display = String.format(Locale.getDefault(), "%-8.8s %7.3f %6d", call, frequency, serial);
                }
        }