2 * Copyright © 2012 Mike Beattie <mike@ethernal.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.AltosDroid;
21 import android.content.Context;
22 import android.content.SharedPreferences;
23 import org.altusmetrum.AltosLib.*;
25 public class AltosDroidPreferences implements AltosPreferencesBackend {
26 public final static String NAME = "org.altusmetrum.AltosDroid";
27 private Context context = null;
28 private SharedPreferences prefs = null;
29 private SharedPreferences.Editor editor = null;
31 public AltosDroidPreferences(Context in_context) {
32 this(in_context, NAME);
35 public AltosDroidPreferences(Context in_context, String in_prefs) {
37 prefs = context.getSharedPreferences(in_prefs, 0);
38 editor = prefs.edit();
41 public String[] keys() {
42 Map<String, ?> all = prefs.getAll();
43 return (String[])all.keySet().toArray();
46 public AltosPreferencesBackend node(String key) {
47 return new AltosDroidPreferences(context, key);
50 public boolean nodeExists(String key) {
51 return prefs.contains(key);
54 public boolean getBoolean(String key, boolean def) {
55 return prefs.getBoolean(key, def);
58 public double getDouble(String key, double def) {
59 Float f = Float.valueOf(prefs.getFloat(key, (float)def));
60 return f.doubleValue();
63 public int getInt(String key, int def) {
64 return prefs.getInt(key, def);
67 public String getString(String key, String def) {
68 return prefs.getString(key, def);
71 public void putBoolean(String key, boolean value) {
72 editor.putBoolean(key, value);
75 public void putDouble(String key, double value) {
76 editor.putFloat(key, (float)value);
79 public void putInt(String key, int value) {
80 editor.putInt(key, value);
83 public void putString(String key, String value) {
84 editor.putString(key, value);
87 public void remove(String key) {