projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altosdroid: Can only use message once
[fw/altos]
/
altosdroid
/
src
/
org
/
altusmetrum
/
AltosDroid
/
AltosDroidPreferences.java
diff --git
a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
index 7ba328f4e2d8bbf00d61d442750956084d8d2d42..bd3bd9421f54a8cbf99d91fa8193ad99c4a4e911 100644
(file)
--- a/
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
+++ b/
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
@@
-1,5
+1,5
@@
/*
/*
- * Copyright © 201
2 Mike Beattie <mike@ethernal.org
>
+ * Copyright © 201
4 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
*
* 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,84
+14,68
@@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
* 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;
package org.altusmetrum.AltosDroid;
-import java.util.Map;
import android.content.Context;
import android.content.Context;
-import android.content.SharedPreferences;
-import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altoslib_10.*;
-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 activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS"
;
+ final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME";
- public AltosDroidPreferences(Context in_context, String in_prefs) {
- context = in_context;
- prefs = context.getSharedPreferences(in_prefs, 0);
- editor = prefs.edit();
- }
+ static DeviceAddress active_device_address;
- public AltosPreferencesBackend node(String key) {
- return new AltosDroidPreferences(context, key);
- }
+ /* Map source preference name */
+ final static String mapSourcePreference = "MAP-SOURCE";
- public void flush() {
- editor.apply();
- }
+ static final int MAP_SOURCE_OFFLINE = 0;
+ static final int MAP_SOURCE_ONLINE = 1;
- public String[] keys() {
- Map<String, ?> data = prefs.getAll();
- String[] keys = new String[data.size()];
- data.keySet().toArray(keys);
- return keys;
- }
+ static int map_source;
- public
boolean nodeExists(String key
) {
- return prefs.contains(key);
- }
+ public
static void init(Context context
) {
+ if (backend != null)
+ return;
- 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();
- }
+ AltosPreferences.init(new AltosDroidPreferencesBackend(context));
- public int getInt(String key, int def) {
- return prefs.getInt(key, def);
- }
+ String address = backend.getString(activeDeviceAddressPreference, null);
+ String name = backend.getString(activeDeviceNamePreference, null);
- public String getString(String key, String def) {
- return prefs.getString(key, def);
- }
+ if (address != null && name != null)
+ active_device_address = new DeviceAddress (address, name);
- public void putBoolean(String key, boolean value) {
- editor.putBoolean(key, value);
+ map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
}
}
- public void putDouble(String key, double value) {
- editor.putFloat(key, (float)value);
+ public static void set_active_device(DeviceAddress address) {
+ synchronized(backend) {
+ active_device_address = address;
+ backend.putString(activeDeviceAddressPreference, active_device_address.address);
+ backend.putString(activeDeviceNamePreference, active_device_address.name);
+ flush_preferences();
+ }
}
}
- public void putInt(String key, int value) {
- editor.putInt(key, value);
+ public static DeviceAddress active_device() {
+ synchronized(backend) {
+ return active_device_address;
+ }
}
}
- public void putString(String key, String value) {
- editor.putString(key, value);
+ public static void set_map_source(int map_source) {
+ synchronized(backend) {
+ AltosDroidPreferences.map_source = map_source;
+ backend.putInt(mapSourcePreference, map_source);
+ flush_preferences();
+ }
}
}
- public void remove(String key) {
- editor.remove(key);
+ public static int map_source() {
+ synchronized(backend) {
+ return map_source;
+ }
}
}
-
}
}