altosdroid: Class of offline map view widget changed
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroidPreferences.java
1 /*
2  * Copyright © 2014 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17 package org.altusmetrum.AltosDroid;
18
19 import android.content.Context;
20 import org.altusmetrum.altoslib_7.*;
21
22 public class AltosDroidPreferences extends AltosPreferences {
23
24         /* Active device preference name */
25         final static String activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS";
26         final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME";
27
28         static DeviceAddress    active_device_address;
29
30         /* Map source preference name */
31         final static String mapSourcePreference = "MAP-SOURCE";
32
33         static final int        MAP_SOURCE_OFFLINE = 0;
34         static final int        MAP_SOURCE_ONLINE = 1;
35
36         static int      map_source;
37
38         public static void init(Context context) {
39                 if (backend != null)
40                         return;
41
42                 AltosPreferences.init(new AltosDroidPreferencesBackend(context));
43
44                 String address = backend.getString(activeDeviceAddressPreference, null);
45                 String name = backend.getString(activeDeviceNamePreference, null);
46
47                 if (address != null && name != null)
48                         active_device_address = new DeviceAddress (address, name);
49
50                 map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
51         }
52
53         public static void set_active_device(DeviceAddress address) {
54                 synchronized(backend) {
55                         active_device_address = address;
56                         backend.putString(activeDeviceAddressPreference, active_device_address.address);
57                         backend.putString(activeDeviceNamePreference, active_device_address.name);
58                         flush_preferences();
59                 }
60         }
61
62         public static DeviceAddress active_device() {
63                 synchronized(backend) {
64                         return active_device_address;
65                 }
66         }
67
68         public static void set_map_source(int map_source) {
69                 synchronized(backend) {
70                         AltosDroidPreferences.map_source = map_source;
71                         backend.putInt(mapSourcePreference, map_source);
72                         flush_preferences();
73                 }
74         }
75
76         public static int map_source() {
77                 synchronized(backend) {
78                         return map_source;
79                 }
80         }
81 }