X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroidPreferences.java;h=a4e27006ee37ab0d2d19e745877f305760ec524b;hp=067cb6208a014ce745feb1e556ac6abf4e1624de;hb=87c8bb3956897830da1f7aaca2990a9571767b73;hpb=b89fb51a963635e2effe3a31f803bfc29c2c46b7 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index 067cb620..a4e27006 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 + * Copyright © 2014 Keith Packard * * 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,68 @@ * 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_8.*; -import org.altusmetrum.altoslib_3.*; +public class AltosDroidPreferences extends AltosPreferences { -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; + /* Active device preference name */ + final static String activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS"; + final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME"; - public AltosDroidPreferences(Context in_context) { - this(in_context, NAME); - } + static DeviceAddress active_device_address; - public AltosDroidPreferences(Context in_context, String in_prefs) { - context = in_context; - prefs = context.getSharedPreferences(in_prefs, 0); - editor = prefs.edit(); - } + /* Map source preference name */ + final static String mapSourcePreference = "MAP-SOURCE"; - public String[] keys() { - Map all = prefs.getAll(); - return (String[])all.keySet().toArray(); - } + static final int MAP_SOURCE_OFFLINE = 0; + static final int MAP_SOURCE_ONLINE = 1; - public AltosPreferencesBackend node(String key) { - return new AltosDroidPreferences(context, key); - } + 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); - } + AltosPreferences.init(new AltosDroidPreferencesBackend(context)); - public double getDouble(String key, double def) { - Float f = Float.valueOf(prefs.getFloat(key, (float)def)); - return f.doubleValue(); - } + String address = backend.getString(activeDeviceAddressPreference, null); + String name = backend.getString(activeDeviceNamePreference, null); - 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); - } + if (address != null && name != null) + active_device_address = new DeviceAddress (address, name); - public void putInt(String key, int value) { - editor.putInt(key, value); + map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE); } - public void putString(String key, String value) { - editor.putString(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 remove(String key) { - editor.remove(key); + public static DeviceAddress active_device() { + synchronized(backend) { + return active_device_address; + } } - public void flush() { - editor.apply(); + public static void set_map_source(int map_source) { + synchronized(backend) { + AltosDroidPreferences.map_source = map_source; + backend.putInt(mapSourcePreference, map_source); + flush_preferences(); + } } - public File homeDirectory() { - return Environment.getExternalStorageDirectory(); + public static int map_source() { + synchronized(backend) { + return map_source; + } } }