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;
22 import android.content.Context;
23 import android.content.SharedPreferences;
24 import android.os.Environment;
26 import org.altusmetrum.altoslib_1.*;
28 public class AltosDroidPreferences implements AltosPreferencesBackend {
29 public final static String NAME = "org.altusmetrum.AltosDroid";
30 private Context context = null;
31 private SharedPreferences prefs = null;
32 private SharedPreferences.Editor editor = null;
34 public AltosDroidPreferences(Context in_context) {
35 this(in_context, NAME);
38 public AltosDroidPreferences(Context in_context, String in_prefs) {
40 prefs = context.getSharedPreferences(in_prefs, 0);
41 editor = prefs.edit();
44 public String[] keys() {
45 Map<String, ?> all = prefs.getAll();
46 return (String[])all.keySet().toArray();
49 public AltosPreferencesBackend node(String key) {
50 return new AltosDroidPreferences(context, key);
53 public boolean nodeExists(String key) {
54 return prefs.contains(key);
57 public boolean getBoolean(String key, boolean def) {
58 return prefs.getBoolean(key, def);
61 public double getDouble(String key, double def) {
62 Float f = Float.valueOf(prefs.getFloat(key, (float)def));
63 return f.doubleValue();
66 public int getInt(String key, int def) {
67 return prefs.getInt(key, def);
70 public String getString(String key, String def) {
71 return prefs.getString(key, def);
74 public void putBoolean(String key, boolean value) {
75 editor.putBoolean(key, value);
78 public void putDouble(String key, double value) {
79 editor.putFloat(key, (float)value);
82 public void putInt(String key, int value) {
83 editor.putInt(key, value);
86 public void putString(String key, String value) {
87 editor.putString(key, value);
90 public void remove(String key) {
98 public File homeDirectory() {
99 return Environment.getExternalStorageDirectory();