altoslib: Add getBytes/putBytes interface to AltosPreferencesBackend
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroidPreferencesBackend.java
index be41ae7cf35b345b157d11127730c73971618bdc..09a2a7a2d9fb70dc93bec13a82025e5993b7c0dc 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Map;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Environment;
+import android.util.*;
 
 import org.altusmetrum.altoslib_5.*;
 
@@ -71,6 +72,16 @@ public class AltosDroidPreferencesBackend implements AltosPreferencesBackend {
                return prefs.getString(key, def);
        }
 
+       public byte[] getBytes(String key, byte[] def) {
+               String save = prefs.getString(key, null);
+
+               if (save == null)
+                       return def;
+
+               byte[] bytes = Base64.decode(save, Base64.DEFAULT);
+               return bytes;
+       }
+
        public void putBoolean(String key, boolean value) {
                editor.putBoolean(key, value);
        }
@@ -87,6 +98,11 @@ public class AltosDroidPreferencesBackend implements AltosPreferencesBackend {
                editor.putString(key, value);
        }
 
+       public void putBytes(String key, byte[] bytes) {
+               String save = Base64.encodeToString(bytes, Base64.DEFAULT);
+               editor.putString(key, save);
+       }
+
        public void remove(String key) {
                editor.remove(key);
        }