From 6db192898eebf750c4d51516eff7916bc4da493b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 31 Dec 2012 11:38:53 -0800 Subject: [PATCH] altoslib: Add units change notification list This allows the UI to automatically respond to changes in the preferred units. Signed-off-by: Keith Packard --- altoslib/AltosPreferences.java | 21 +++++++++++++++++++++ altoslib/AltosUnitsListener.java | 22 ++++++++++++++++++++++ altoslib/Makefile.am | 1 + 3 files changed, 44 insertions(+) create mode 100644 altoslib/AltosUnitsListener.java diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 47196d6e..e50b9b5c 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -367,6 +367,8 @@ public class AltosPreferences { set_common_frequencies(new_frequencies); } + static LinkedList units_listeners; + public static boolean imperial_units() { synchronized(backend) { return AltosConvert.imperial_units; @@ -379,5 +381,24 @@ public class AltosPreferences { backend.putBoolean(unitsPreference, imperial_units); flush_preferences(); } + if (units_listeners != null) { + for (AltosUnitsListener l : units_listeners) { + l.units_changed(imperial_units); + } + } + } + + public static void register_units_listener(AltosUnitsListener l) { + synchronized(backend) { + if (units_listeners == null) + units_listeners = new LinkedList(); + units_listeners.add(l); + } + } + + public static void unregister_units_listener(AltosUnitsListener l) { + synchronized(backend) { + units_listeners.remove(l); + } } } diff --git a/altoslib/AltosUnitsListener.java b/altoslib/AltosUnitsListener.java new file mode 100644 index 00000000..50a00cdf --- /dev/null +++ b/altoslib/AltosUnitsListener.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2012 Keith Packard + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public interface AltosUnitsListener { + public void units_changed(boolean imperial_units); +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 0086bc65..1b03c925 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -69,6 +69,7 @@ AltosLib_JAVA = \ $(SRC)/AltosTelemetryRecordSensor.java \ $(SRC)/AltosTelemetryRecordMegaSensor.java \ $(SRC)/AltosTelemetryRecordMegaData.java \ + $(SRC)/AltosUnitsListener.java \ $(SRC)/AltosMs5607.java \ $(SRC)/AltosIMU.java \ $(SRC)/AltosMag.java \ -- 2.30.2