diff options
| author | Keith Packard <keithp@keithp.com> | 2015-06-06 20:35:32 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2015-06-06 20:35:32 -0700 | 
| commit | f79d569dfe333621d63a1d4001c85a88f736ad58 (patch) | |
| tree | 56baa9fe4b1051e53248970f11cfc4308b3a3538 /altoslib/AltosPreferences.java | |
| parent | 64ca3d2e7d2b23aedfdf98ef8ebd760bd3291534 (diff) | |
altoslib: Add preferences for saving/restoring multiple flight states
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosPreferences.java')
| -rw-r--r-- | altoslib/AltosPreferences.java | 34 | 
1 files changed, 34 insertions, 0 deletions
| diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 2fad96fd..cdff93f6 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -19,6 +19,7 @@ package org.altusmetrum.altoslib_7;  import java.io.*;  import java.util.*; +import java.text.*;  public class AltosPreferences {  	public static AltosPreferencesBackend backend = null; @@ -42,7 +43,9 @@ public class AltosPreferences {  	public final static String logfilePreferenceFormat = "LOGFILE-%d";  	/* state preference name */ +	public final static String statePreferenceHead = "STATE-";  	public final static String statePreferenceFormat = "STATE-%d"; +	public final static String statePreferenceLatest = "STATE-LATEST";  	/* voice preference name */  	public final static String voicePreference = "VOICE"; @@ -360,12 +363,43 @@ public class AltosPreferences {  			synchronized(backend) {  				backend.putBytes(String.format(statePreferenceFormat, serial), bytes); +				backend.putInt(statePreferenceLatest, serial);  				flush_preferences();  			}  		} catch (IOException ie) {  		}  	} +	public static ArrayList<Integer> list_states() { +		String[]		keys = backend.keys(); +		ArrayList<Integer>	states = new ArrayList<Integer>(); + +		for (String key : keys) { +			if (key.startsWith(statePreferenceHead)) { +				try { +					int serial = AltosParse.parse_int(key.substring(statePreferenceHead.length())); +					states.add(serial); +				} catch (ParseException pe) { +				} +			} +		} +		return states; +	} + +	public static void remove_state(int serial) { +		synchronized(backend) { +			backend.remove(String.format(statePreferenceFormat, serial)); +		} +	} + +	public static int latest_state() { +		int	latest = 0; +		synchronized (backend) { +			latest = backend.getInt(statePreferenceLatest, 0); +		} +		return latest; +	} +  	public static AltosSavedState state(int serial) {  		byte[] bytes = null; | 
