X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroidPreferences.java;h=8bb78c00dce6fd915551aca270bcbe99e062b648;hp=72b8488bfbb85c395eef0b0b5e1d5528021565f5;hb=4a257455b2dc57069c41e1845daf66239c5cbe1d;hpb=0b70ea04e807c69a987d5976ab217f9f65fb1e09 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index 72b8488b..8bb78c00 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,33 +17,96 @@ */ package org.altusmetrum.AltosDroid; +import java.io.*; +import java.util.*; +import java.text.*; + import android.content.Context; -import org.altusmetrum.altoslib_5.*; +import org.altusmetrum.altoslib_13.*; public class AltosDroidPreferences extends AltosPreferences { /* Active device preference name */ - final static String activeDevicePreference = "ACTIVE-DEVICE"; + final static String activeDeviceAddressPreference = "ACTIVE-DEVICE-ADDRESS"; + final static String activeDeviceNamePreference = "ACTIVE-DEVICE-NAME"; + + static DeviceAddress active_device_address; + + /* Map source preference name */ + final static String mapSourcePreference = "MAP-SOURCE"; + + static final int MAP_SOURCE_OFFLINE = 0; + static final int MAP_SOURCE_ONLINE = 1; - static String active_device_address; + static int map_source; public static void init(Context context) { + if (backend != null) + return; + AltosPreferences.init(new AltosDroidPreferencesBackend(context)); - active_device_address = backend.getString(activeDevicePreference, null); + String address = backend.getString(activeDeviceAddressPreference, null); + String name = backend.getString(activeDeviceNamePreference, null); + + if (address != null && name != null) + active_device_address = new DeviceAddress (address, name); + + map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE); } - public static void set_active_device(String address) { + public static void set_active_device(DeviceAddress address) { synchronized(backend) { active_device_address = address; - backend.putString(activeDevicePreference, active_device_address); + if (active_device_address != null) { + backend.putString(activeDeviceAddressPreference, active_device_address.address); + backend.putString(activeDeviceNamePreference, active_device_address.name); + } else { + backend.remove(activeDeviceAddressPreference); + backend.remove(activeDeviceNamePreference); + } flush_preferences(); } } - public static String active_device() { + public static DeviceAddress active_device() { synchronized(backend) { return active_device_address; } } + + static LinkedList map_source_listeners; + + public static void set_map_source(int map_source) { + synchronized(backend) { + AltosDroidPreferences.map_source = map_source; + backend.putInt(mapSourcePreference, map_source); + flush_preferences(); + } + if (map_source_listeners != null) { + for (AltosDroidMapSourceListener l : map_source_listeners) { + l.map_source_changed(map_source); + } + } + } + + public static int map_source() { + synchronized(backend) { + return map_source; + } + } + + public static void register_map_source_listener(AltosDroidMapSourceListener l) { + synchronized(backend) { + if (map_source_listeners == null) + map_source_listeners = new LinkedList(); + map_source_listeners.add(l); + } + } + + public static void unregister_map_source_listener(AltosDroidMapSourceListener l) { + synchronized(backend) { + map_source_listeners.remove(l); + } + } }