Check if the directory is readable. If it is not, then display a dialog. Try to...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 21 Feb 2012 02:42:08 +0000 (02:42 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 21 Feb 2012 02:42:08 +0000 (02:42 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@432 180e2498-e6e9-4542-8430-84ac67f01cd8

android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java

index f7204de43bd9d5a5beea01c42ffe5b11f79135a4..85c51b0243dcfc633fb93efdb0be43e1c79e677f 100644 (file)
@@ -2,7 +2,6 @@ package net.sf.openrocket.android.filebrowser;
 \r
 import java.io.File;\r
 import java.io.FileFilter;\r
-import java.text.Collator;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.Comparator;\r
@@ -11,6 +10,7 @@ import java.util.List;
 import net.sf.openrocket.R;\r
 import net.sf.openrocket.android.actionbarcompat.ActionBarListActivity;\r
 import android.app.AlertDialog;\r
+import android.app.Dialog;\r
 import android.content.DialogInterface;\r
 import android.content.Intent;\r
 import android.content.SharedPreferences;\r
@@ -31,6 +31,8 @@ public class SimpleFileBrowser extends ActionBarListActivity {
        private List<File> path = null;\r
        private final static File root = new File("/");\r
 \r
+       private File previousDirectory = root;\r
+       \r
        private String baseDirPrefKey;\r
        private String baseDirName;\r
 \r
@@ -102,7 +104,35 @@ public class SimpleFileBrowser extends ActionBarListActivity {
 \r
        }\r
 \r
-       private void getDir(File dirPath) {\r
+       private void getDir(final File dirPath) {\r
+               \r
+               // A little sanity check.  It could be possible the directory saved in the preference\r
+               // is no longer mounted, is not a directory (any more), or cannot be read.\r
+               // if any of these are the case, we display a little dialog, then revert to the\r
+               // previousDirectory.\r
+               if ( !dirPath.exists() || !dirPath.isDirectory() || !dirPath.canRead() ) {\r
+                       \r
+                       AlertDialog.Builder builder = new AlertDialog.Builder(this);\r
+                       builder.setTitle("Unable to open directory " + dirPath.getAbsolutePath() );\r
+                       builder.setCancelable(true);\r
+                       builder.setOnCancelListener( new Dialog.OnCancelListener() {\r
+\r
+                               @Override\r
+                               public void onCancel(DialogInterface arg0) {\r
+                                       if ( root.getAbsolutePath().equals(dirPath.getAbsolutePath()) ) {\r
+                                               SimpleFileBrowser.this.finish();\r
+                                       } else {\r
+                                               SimpleFileBrowser.this.getDir( previousDirectory );\r
+                                       }\r
+                               }\r
+                               \r
+                       });\r
+                       builder.show();\r
+                       return;\r
+               }\r
+               \r
+               previousDirectory = dirPath;\r
+               \r
                setTitle(dirPath.getAbsolutePath());\r
                path = new ArrayList<File>();\r
 \r