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; version 2 of the License.
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.
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.
17 package org.altusmetrum.AltosDroid;
19 import android.content.Context;
20 import org.altusmetrum.altoslib_7.*;
22 public class AltosDroidPreferences extends AltosPreferences {
24 /* Active device preference name */
25 final static String activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS";
26 final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME";
28 static DeviceAddress active_device_address;
30 public static void init(Context context) {
34 AltosPreferences.init(new AltosDroidPreferencesBackend(context));
36 String address = backend.getString(activeDeviceAddressPreference, null);
37 String name = backend.getString(activeDeviceNamePreference, null);
39 if (address != null && name != null)
40 active_device_address = new DeviceAddress (address, name);
43 public static void set_active_device(DeviceAddress address) {
44 synchronized(backend) {
45 active_device_address = address;
46 backend.putString(activeDeviceAddressPreference, active_device_address.address);
47 backend.putString(activeDeviceNamePreference, active_device_address.name);
52 public static DeviceAddress active_device() {
53 synchronized(backend) {
54 return active_device_address;