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 {
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;
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;
}
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) {
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);
}
}
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) {
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);
}
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) {
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);
public AltosDroidPreferencesBackend(Context in_context, String in_prefs) {
context = in_context;
prefs = context.getSharedPreferences(in_prefs, 0);
- editor = prefs.edit();
}
public String[] keys() {
}
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() {
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;
}
}
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))
void
position_permission() {
- if (mMap != null)
- mMap.setMyLocationEnabled(true);
+ if (mMap != null) {
+ try {
+ mMap.setMyLocationEnabled(true);
+ } catch (SecurityException e) {
+ }
+ }
}
@Override
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);
package org.altusmetrum.AltosDroid;
+import java.util.*;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.location.Location;
}
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() {
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));
package org.altusmetrum.AltosDroid;
+import java.util.*;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
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() {
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;
}
}
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);
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();
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) {
}
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);
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));
package org.altusmetrum.AltosDroid;
+import java.util.*;
+
import org.altusmetrum.altoslib_14.*;
import android.app.Activity;
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 {
package org.altusmetrum.AltosDroid;
+import java.util.*;
+
import org.altusmetrum.altoslib_14.*;
import android.os.Bundle;
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");
package org.altusmetrum.AltosDroid;
+import java.util.*;
import org.altusmetrum.altoslib_14.*;
import android.os.Bundle;
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)
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);
}
}