2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.AltosDroid;
22 import android.content.Context;
23 import org.altusmetrum.altoslib_14.*;
25 public class AltosDroidPreferences extends AltosPreferences {
27 /* Active device preference name */
28 final static String activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS";
29 final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME";
31 public static final int font_size_small = 0;
32 public static final int font_size_medium = 1;
33 public static final int font_size_large = 2;
34 public static final int font_size_extra = 3;
36 final static String fontSizePreference = "FONT-SIZE";
38 static int font_size = font_size_medium;
40 static DeviceAddress active_device_address;
42 /* Map source preference name */
43 final static String mapSourcePreference = "MAP-SOURCE";
45 static final int MAP_SOURCE_OFFLINE = 0;
46 static final int MAP_SOURCE_ONLINE = 1;
48 static int map_source;
50 /* Tracker sort selection */
51 final static String trackerSortPreference = "TRACKER-SORT";
53 static int tracker_sort;
55 public static void init(Context context) {
59 AltosPreferences.init(new AltosDroidPreferencesBackend(context));
61 font_size = backend.getInt(fontSizePreference, font_size_medium);
63 String address = backend.getString(activeDeviceAddressPreference, null);
64 String name = backend.getString(activeDeviceNamePreference, null);
66 if (address != null && name != null)
67 active_device_address = new DeviceAddress (address, name);
69 map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
71 tracker_sort = backend.getInt(trackerSortPreference, 0);
74 public static void set_active_device(DeviceAddress address) {
77 synchronized(backend) {
78 active_device_address = address;
79 if (active_device_address != null) {
80 backend.putString(activeDeviceAddressPreference, active_device_address.address);
81 backend.putString(activeDeviceNamePreference, active_device_address.name);
83 backend.remove(activeDeviceAddressPreference);
84 backend.remove(activeDeviceNamePreference);
90 public static DeviceAddress active_device() {
94 synchronized(backend) {
95 return active_device_address;
99 static LinkedList<AltosDroidMapSourceListener> map_source_listeners;
101 public static void set_map_source(int map_source) {
104 synchronized(backend) {
105 AltosDroidPreferences.map_source = map_source;
106 backend.putInt(mapSourcePreference, map_source);
109 if (map_source_listeners != null) {
110 for (AltosDroidMapSourceListener l : map_source_listeners) {
111 l.map_source_changed(map_source);
116 public static int map_source() {
118 return MAP_SOURCE_ONLINE;
119 synchronized(backend) {
124 public static void register_map_source_listener(AltosDroidMapSourceListener l) {
128 synchronized(backend) {
129 if (map_source_listeners == null)
130 map_source_listeners = new LinkedList<AltosDroidMapSourceListener>();
131 map_source_listeners.add(l);
135 public static void unregister_map_source_listener(AltosDroidMapSourceListener l) {
138 synchronized(backend) {
139 map_source_listeners.remove(l);
143 public static int font_size() {
145 return font_size_medium;
147 synchronized (backend) {
152 public static void set_font_size(int new_font_size) {
155 synchronized (backend) {
156 if (font_size != new_font_size) {
157 font_size = new_font_size;
158 backend.putInt(fontSizePreference, font_size);
165 public static int tracker_sort() {
169 synchronized(backend) {
174 public static void set_tracker_sort(int new_tracker_sort) {
178 synchronized(backend) {
179 if (tracker_sort != new_tracker_sort) {
180 tracker_sort = new_tracker_sort;
181 backend.putInt(trackerSortPreference, tracker_sort);