diff options
author | Keith Packard <keithp@keithp.com> | 2014-08-29 15:22:43 -0500 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2014-08-29 15:22:43 -0500 |
commit | 810f9a4f79b0480973d84595140d3f8948ce26d9 (patch) | |
tree | f0449f475eb57d23a669e0191f8195a3de569afd /altosdroid/src | |
parent | 5872bd10df14b47de0e541bff16d9220af0558aa (diff) |
altosdroid: start restoring from log data on startup
Remember which flight was last being received and reload that file
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosdroid/src')
-rw-r--r-- | altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java | 16 | ||||
-rw-r--r-- | altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java | 89 |
2 files changed, 26 insertions, 79 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index c9c38d98..c94f36fd 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -101,9 +101,6 @@ public class AltosDroid extends FragmentActivity { private Messenger mService = null; final Messenger mMessenger = new Messenger(new IncomingHandler(this)); - // Preferences - private AltosDroidPreferences prefs = null; - // TeleBT Config data private AltosConfigData mConfigData = null; // Local Bluetooth adapter @@ -343,8 +340,7 @@ public class AltosDroid extends FragmentActivity { } // Initialise preferences - prefs = new AltosDroidPreferences(this); - AltosPreferences.init(prefs); + AltosDroidPreferences.init(this); // Set up the window layout requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); @@ -480,9 +476,7 @@ public class AltosDroid extends FragmentActivity { } } - private void connectDevice(Intent data) { - // Get the device MAC address - String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); + private void connectDevice(String address) { // Get the BLuetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // Attempt to connect to the device @@ -493,6 +487,12 @@ public class AltosDroid extends FragmentActivity { } } + private void connectDevice(Intent data) { + // Get the device MAC address + String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); + connectDevice(address); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index 70d7def8..7c12c9a0 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright © 2012 Mike Beattie <mike@ethernal.org> + * Copyright © 2014 Keith Packard <keithp@keithp.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,88 +14,35 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ - package org.altusmetrum.AltosDroid; -import java.io.File; -import java.util.Map; import android.content.Context; -import android.content.SharedPreferences; -import android.os.Environment; - import org.altusmetrum.altoslib_5.*; -public class AltosDroidPreferences implements AltosPreferencesBackend { - public final static String NAME = "org.altusmetrum.AltosDroid"; - private Context context = null; - private SharedPreferences prefs = null; - private SharedPreferences.Editor editor = null; +public class AltosDroidPreferences extends AltosPreferences { - public AltosDroidPreferences(Context in_context) { - this(in_context, NAME); - } + /* Active device preference name */ + final static String activeDevicePreference = "ACTIVE-DEVICE"; - public AltosDroidPreferences(Context in_context, String in_prefs) { - context = in_context; - prefs = context.getSharedPreferences(in_prefs, 0); - editor = prefs.edit(); - } + static String active_device_address; - public String[] keys() { - Map<String, ?> all = prefs.getAll(); - return (String[])all.keySet().toArray(); - } - - public AltosPreferencesBackend node(String key) { - return new AltosDroidPreferences(context, key); - } - - public boolean nodeExists(String key) { - return prefs.contains(key); - } - - public boolean getBoolean(String key, boolean def) { - return prefs.getBoolean(key, def); - } - - public double getDouble(String key, double def) { - Float f = Float.valueOf(prefs.getFloat(key, (float)def)); - return f.doubleValue(); - } - - public int getInt(String key, int def) { - return prefs.getInt(key, def); - } - - public String getString(String key, String def) { - return prefs.getString(key, def); - } - - public void putBoolean(String key, boolean value) { - editor.putBoolean(key, value); - } - - public void putDouble(String key, double value) { - editor.putFloat(key, (float)value); - } - - public void putInt(String key, int value) { - editor.putInt(key, value); - } - - public void putString(String key, String value) { - editor.putString(key, value); - } + public static void init(Context context) { + AltosPreferences.init(new AltosDroidPreferencesBackend(context)); - public void remove(String key) { - editor.remove(key); + active_device_address = backend.getGetString(activeDevicePreference, null); } - public void flush() { - editor.apply(); + public static void set_active_device(String address) { + synchronized(backend) { + active_device_address = address; + backend.putString(activeDevicePreference, active_device_address); + flush_preferences(); + } } - public File homeDirectory() { - return Environment.getExternalStorageDirectory(); + public static String active_device() { + synchronized(backend) { + return active_device_address; + } } } |