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 static DeviceAddress active_device_address;
33 /* Map source preference name */
34 final static String mapSourcePreference = "MAP-SOURCE";
36 static final int MAP_SOURCE_OFFLINE = 0;
37 static final int MAP_SOURCE_ONLINE = 1;
39 static int map_source;
41 public static void init(Context context) {
45 AltosPreferences.init(new AltosDroidPreferencesBackend(context));
47 String address = backend.getString(activeDeviceAddressPreference, null);
48 String name = backend.getString(activeDeviceNamePreference, null);
50 if (address != null && name != null)
51 active_device_address = new DeviceAddress (address, name);
53 map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
56 public static void set_active_device(DeviceAddress address) {
57 synchronized(backend) {
58 active_device_address = address;
59 if (active_device_address != null) {
60 backend.putString(activeDeviceAddressPreference, active_device_address.address);
61 backend.putString(activeDeviceNamePreference, active_device_address.name);
63 backend.remove(activeDeviceAddressPreference);
64 backend.remove(activeDeviceNamePreference);
70 public static DeviceAddress active_device() {
71 synchronized(backend) {
72 return active_device_address;
76 static LinkedList<AltosDroidMapSourceListener> map_source_listeners;
78 public static void set_map_source(int map_source) {
79 synchronized(backend) {
80 AltosDroidPreferences.map_source = map_source;
81 backend.putInt(mapSourcePreference, map_source);
84 if (map_source_listeners != null) {
85 for (AltosDroidMapSourceListener l : map_source_listeners) {
86 l.map_source_changed(map_source);
91 public static int map_source() {
92 synchronized(backend) {
97 public static void register_map_source_listener(AltosDroidMapSourceListener l) {
98 synchronized(backend) {
99 if (map_source_listeners == null)
100 map_source_listeners = new LinkedList<AltosDroidMapSourceListener>();
101 map_source_listeners.add(l);
105 public static void unregister_map_source_listener(AltosDroidMapSourceListener l) {
106 synchronized(backend) {
107 map_source_listeners.remove(l);