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;
24 import android.content.Context;
25 import org.altusmetrum.altoslib_11.*;
27 public class AltosDroidPreferences extends AltosPreferences {
29 /* Active device preference name */
30 final static String activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS";
31 final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME";
33 static DeviceAddress active_device_address;
35 /* Map source preference name */
36 final static String mapSourcePreference = "MAP-SOURCE";
38 static final int MAP_SOURCE_OFFLINE = 0;
39 static final int MAP_SOURCE_ONLINE = 1;
41 static int map_source;
43 public static void init(Context context) {
47 AltosPreferences.init(new AltosDroidPreferencesBackend(context));
49 String address = backend.getString(activeDeviceAddressPreference, null);
50 String name = backend.getString(activeDeviceNamePreference, null);
52 if (address != null && name != null)
53 active_device_address = new DeviceAddress (address, name);
55 map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
58 public static void set_active_device(DeviceAddress address) {
59 synchronized(backend) {
60 active_device_address = address;
61 if (active_device_address != null) {
62 backend.putString(activeDeviceAddressPreference, active_device_address.address);
63 backend.putString(activeDeviceNamePreference, active_device_address.name);
65 backend.remove(activeDeviceAddressPreference);
66 backend.remove(activeDeviceNamePreference);
72 public static DeviceAddress active_device() {
73 synchronized(backend) {
74 return active_device_address;
78 static LinkedList<AltosDroidMapSourceListener> map_source_listeners;
80 public static void set_map_source(int map_source) {
81 synchronized(backend) {
82 AltosDroidPreferences.map_source = map_source;
83 backend.putInt(mapSourcePreference, map_source);
86 if (map_source_listeners != null) {
87 for (AltosDroidMapSourceListener l : map_source_listeners) {
88 l.map_source_changed(map_source);
93 public static int map_source() {
94 synchronized(backend) {
99 public static void register_map_source_listener(AltosDroidMapSourceListener l) {
100 synchronized(backend) {
101 if (map_source_listeners == null)
102 map_source_listeners = new LinkedList<AltosDroidMapSourceListener>();
103 map_source_listeners.add(l);
107 public static void unregister_map_source_listener(AltosDroidMapSourceListener l) {
108 synchronized(backend) {
109 map_source_listeners.remove(l);