X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroidPreferences.java;h=9cef131905abad0c1437dc1722aa155a0cbfba38;hp=59fef84279d6c2b6985f9d192e05fd69e894dd48;hb=18671803d078aa798b603c67b741c3ba4374f41d;hpb=488a527267decece48e6682e0e0c7fc29cbed329 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index 59fef842..9cef1319 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,38 @@ * 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_2.*; - -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 AltosDroidPreferences(Context in_context) { - this(in_context, NAME); - } - - public AltosDroidPreferences(Context in_context, String in_prefs) { - context = in_context; - prefs = context.getSharedPreferences(in_prefs, 0); - editor = prefs.edit(); - } - - public String[] keys() { - Map 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); - } +import org.altusmetrum.altoslib_5.*; - public String getString(String key, String def) { - return prefs.getString(key, def); - } +public class AltosDroidPreferences extends AltosPreferences { - public void putBoolean(String key, boolean value) { - editor.putBoolean(key, value); - } + /* Active device preference name */ + final static String activeDevicePreference = "ACTIVE-DEVICE"; - public void putDouble(String key, double value) { - editor.putFloat(key, (float)value); - } + static String active_device_address; - public void putInt(String key, int value) { - editor.putInt(key, value); - } + public static void init(Context context) { + if (backend != null) + return; - public void putString(String key, String value) { - editor.putString(key, value); - } + AltosPreferences.init(new AltosDroidPreferencesBackend(context)); - public void remove(String key) { - editor.remove(key); + active_device_address = backend.getString(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; + } } }