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_13.*;
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) {
75 synchronized(backend) {
76 active_device_address = address;
77 if (active_device_address != null) {
78 backend.putString(activeDeviceAddressPreference, active_device_address.address);
79 backend.putString(activeDeviceNamePreference, active_device_address.name);
81 backend.remove(activeDeviceAddressPreference);
82 backend.remove(activeDeviceNamePreference);
88 public static DeviceAddress active_device() {
89 synchronized(backend) {
90 return active_device_address;
94 static LinkedList<AltosDroidMapSourceListener> map_source_listeners;
96 public static void set_map_source(int map_source) {
97 synchronized(backend) {
98 AltosDroidPreferences.map_source = map_source;
99 backend.putInt(mapSourcePreference, map_source);
102 if (map_source_listeners != null) {
103 for (AltosDroidMapSourceListener l : map_source_listeners) {
104 l.map_source_changed(map_source);
109 public static int map_source() {
110 synchronized(backend) {
115 public static void register_map_source_listener(AltosDroidMapSourceListener l) {
116 synchronized(backend) {
117 if (map_source_listeners == null)
118 map_source_listeners = new LinkedList<AltosDroidMapSourceListener>();
119 map_source_listeners.add(l);
123 public static void unregister_map_source_listener(AltosDroidMapSourceListener l) {
124 synchronized(backend) {
125 map_source_listeners.remove(l);
129 public static int font_size() {
130 synchronized (backend) {
135 public static void set_font_size(int new_font_size) {
136 synchronized (backend) {
137 if (font_size != new_font_size) {
138 font_size = new_font_size;
139 backend.putInt(fontSizePreference, font_size);
146 public static int tracker_sort() {
147 synchronized(backend) {
152 public static void set_tracker_sort(int new_tracker_sort) {
153 synchronized(backend) {
154 if (tracker_sort != new_tracker_sort) {
155 tracker_sort = new_tracker_sort;
156 backend.putInt(trackerSortPreference, tracker_sort);