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 AltosPreferencesBackend node(String key) {
42 return new AltosDroidPreferences(context, key);
49 public String[] keys() {
50 Map<String, ?> data = prefs.getAll();
51 String[] keys = new String[data.size()];
52 data.keySet().toArray(keys);
56 public boolean nodeExists(String key) {
57 return prefs.contains(key);
60 public boolean getBoolean(String key, boolean def) {
61 return prefs.getBoolean(key, def);
64 public double getDouble(String key, double def) {
65 Float f = Float.valueOf(prefs.getFloat(key, (float)def));
66 return f.doubleValue();
69 public int getInt(String key, int def) {
70 return prefs.getInt(key, def);
73 public String getString(String key, String def) {
74 return prefs.getString(key, def);
77 public void putBoolean(String key, boolean value) {
78 editor.putBoolean(key, value);
81 public void putDouble(String key, double value) {
82 editor.putFloat(key, (float)value);
85 public void putInt(String key, int value) {
86 editor.putInt(key, value);
89 public void putString(String key, String value) {
90 editor.putString(key, value);
93 public void remove(String key) {