X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroidPreferences.java;h=0670005a26efded41f5d69b259c01114ca2ceeb0;hp=bd3bd9421f54a8cbf99d91fa8193ad99c4a4e911;hb=a61217f0a6d0ef48b6471f632c4600255867e831;hpb=21d176f161b90f18f236ef887cef9676d712eee3 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index bd3bd942..0670005a 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,8 +17,12 @@ */ package org.altusmetrum.AltosDroid; +import java.io.*; +import java.util.*; +import java.text.*; + import android.content.Context; -import org.altusmetrum.altoslib_10.*; +import org.altusmetrum.altoslib_12.*; public class AltosDroidPreferences extends AltosPreferences { @@ -53,8 +58,13 @@ public class AltosDroidPreferences extends AltosPreferences { public static void set_active_device(DeviceAddress address) { synchronized(backend) { active_device_address = address; - backend.putString(activeDeviceAddressPreference, active_device_address.address); - backend.putString(activeDeviceNamePreference, active_device_address.name); + 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(); } } @@ -65,12 +75,19 @@ public class AltosDroidPreferences extends AltosPreferences { } } + 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() { @@ -78,4 +95,18 @@ public class AltosDroidPreferences extends AltosPreferences { 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); + } + } }