altos{lib,ui,droid}: move OS specific code out of altoslib
authorMike Beattie <mike@ethernal.org>
Tue, 18 Sep 2012 11:46:17 +0000 (23:46 +1200)
committerMike Beattie <mike@ethernal.org>
Tue, 18 Sep 2012 11:46:17 +0000 (23:46 +1200)
This is to allow the usage of AltosLog on Android - no swing, so
we need to push the "home directory" code used to pick a default
telemetry logging path - using the PreferencesBackend interface
for now.

Signed-off-by: Mike Beattie <mike@ethernal.org>
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
altoslib/AltosPreferences.java
altoslib/AltosPreferencesBackend.java
altosui/AltosUIPreferencesBackend.java

index b8487d073a7fb7a3dcc27294f6b9d93d4e0e9e4f..3b4bdcf85ecac3f1e7c50792a7cd8198403542b6 100644 (file)
 
 package org.altusmetrum.AltosDroid;
 
+import java.io.File;
 import java.util.Map;
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.os.Environment;
+
 import org.altusmetrum.AltosLib.*;
 
 public class AltosDroidPreferences implements AltosPreferencesBackend {
@@ -92,4 +95,7 @@ public class AltosDroidPreferences implements AltosPreferencesBackend {
                editor.apply();
        }
 
+       public File homeDirectory() {
+               return Environment.getExternalStorageDirectory();
+       }
 }
index a82ea3f67f0e4ba5229a5dc6d2abb0314c9ab663..47196d6e70b89342ef3f876207bef574bcb941f4 100644 (file)
@@ -19,7 +19,6 @@ package org.altusmetrum.AltosLib;
 
 import java.io.*;
 import java.util.*;
-import javax.swing.filechooser.FileSystemView;
 
 public class AltosPreferences {
        public static AltosPreferencesBackend backend = null;
@@ -145,8 +144,7 @@ public class AltosPreferences {
                if (logdir_string != null)
                        logdir = new File(logdir_string);
                else {
-                       /* Use the file system view default directory */
-                       logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName);
+                       logdir = new File(backend.homeDirectory(), logdirName);
                        if (!logdir.exists())
                                logdir.mkdirs();
                }
index 3fc4b0aab93ad3d4dee1662c3c217beb9329e48b..a1184c0bc54c54dde9ca6ffcfeb592b5d72144eb 100644 (file)
@@ -17,6 +17,8 @@
 
 package org.altusmetrum.AltosLib;
 
+import java.io.File;
+
 public interface AltosPreferencesBackend {
 
        public String  getString(String key, String def);
@@ -38,4 +40,6 @@ public interface AltosPreferencesBackend {
        public void    remove(String key);
 
        public void    flush();
+
+       public File homeDirectory();
 }
index 210dcb8bb14cdebb536ce18fb29637ade64f038c..3131fd3286ce917de9f3cf5c7eee1e23d5cc716f 100644 (file)
 
 package altosui;
 
+import java.io.File;
 import java.util.prefs.*;
 import org.altusmetrum.AltosLib.*;
+import javax.swing.filechooser.FileSystemView;
 
 public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
 
@@ -92,4 +94,8 @@ public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
                }
        }
 
+       public File homeDirectory() {
+               /* Use the file system view default directory */
+               return FileSystemView.getFileSystemView().getDefaultDirectory();
+       }
 }