projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[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 b8487d073a7fb7a3dcc27294f6b9d93d4e0e9e4f..a4e27006ee37ab0d2d19e745877f305760ec524b 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,82
+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_8.*;
-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 String[] keys() {
- Map<String, ?> all = prefs.getAll();
- return (String[])all.keySet().toArray();
- }
+ /* Map source preference name */
+ final static String mapSourcePreference = "MAP-SOURCE";
- public AltosPreferencesBackend node(String key) {
- return new AltosDroidPreferences(context, key);
- }
+ static final int MAP_SOURCE_OFFLINE = 0;
+ static final int MAP_SOURCE_ONLINE = 1;
- public boolean nodeExists(String key) {
- return prefs.contains(key);
- }
+ static int map_source;
- public
boolean getBoolean(String key, boolean def
) {
- return prefs.getBoolean(key, def);
- }
+ public
static void init(Context context
) {
+ if (backend != null)
+ return;
- 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);
- }
+ AltosPreferences.init(new AltosDroidPreferencesBackend(context));
- public String getString(String key, String def) {
- return prefs.getString(key, def);
- }
+ String address = backend.getString(activeDeviceAddressPreference, null);
+ String name = backend.getString(activeDeviceNamePreference, null);
- public void putBoolean(String key, boolean value) {
- editor.putBoolean(key, value);
- }
+ if (address != null && name != null)
+ active_device_address = new DeviceAddress (address, name);
- public void putDouble(String key, double value) {
- editor.putFloat(key, (float)value);
+ map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
}
}
- public void putInt(String key, int value) {
- editor.putInt(key, 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 putString(String key, String value) {
- editor.putString(key, value);
+ public static DeviceAddress active_device() {
+ synchronized(backend) {
+ return active_device_address;
+ }
}
}
- public void remove(String key) {
- editor.remove(key);
+ 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 flush() {
- editor.apply();
+ public static int map_source() {
+ synchronized(backend) {
+ return map_source;
+ }
}
}
-
}
}