altoslib: Create display-independent map support code
[fw/altos] / altoslib / AltosPreferences.java
index 5aa45d3f5d992745bf03afceddd983bde97ecb37..9c4cadff87e951fbc3b07dc07c2e7a3c187f4302 100644 (file)
@@ -118,6 +118,13 @@ public class AltosPreferences {
 
        public final static String      unitsPreference = "IMPERIAL-UNITS";
 
+       /* Maps cache size preference name */
+       final static String mapCachePreference = "MAP-CACHE";
+
+       static LinkedList<AltosMapCacheListener> map_cache_listeners;
+
+       public static int map_cache = 9;
+
        public static AltosFrequency[] load_common_frequencies() {
                AltosFrequency[] frequencies = null;
                boolean existing = false;
@@ -208,6 +215,9 @@ public class AltosPreferences {
                common_frequencies = load_common_frequencies();
 
                AltosConvert.imperial_units = backend.getBoolean(unitsPreference, false);
+
+               map_cache = backend.getInt(mapCachePreference, 9);
+               map_cache_listeners = new LinkedList<AltosMapCacheListener>();
        }
 
        public static void flush_preferences() {
@@ -548,4 +558,33 @@ public class AltosPreferences {
                        units_listeners.remove(l);
                }
        }
+
+
+       public static void register_map_cache_listener(AltosMapCacheListener l) {
+               synchronized(backend) {
+                       map_cache_listeners.add(l);
+               }
+       }
+
+       public static void unregister_map_cache_listener(AltosMapCacheListener l) {
+               synchronized (backend) {
+                       map_cache_listeners.remove(l);
+               }
+       }
+
+       public static void set_map_cache(int new_map_cache) {
+               synchronized(backend) {
+                       map_cache = new_map_cache;
+                       backend.putInt(mapCachePreference, map_cache);
+                       flush_preferences();
+                       for (AltosMapCacheListener l: map_cache_listeners)
+                               l.map_cache_changed(map_cache);
+               }
+       }
+
+       public static int map_cache() {
+               synchronized(backend) {
+                       return map_cache;
+               }
+       }
 }