From 9fd21369c4d25396ff00debb75c262fd23555cf4 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Tue, 21 Feb 2012 02:42:08 +0000 Subject: [PATCH] Check if the directory is readable. If it is not, then display a dialog. Try to show the previous directory selected, but if that cannot be, just exit. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@432 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../filebrowser/SimpleFileBrowser.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java b/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java index f7204de4..85c51b02 100644 --- a/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java +++ b/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java @@ -2,7 +2,6 @@ package net.sf.openrocket.android.filebrowser; import java.io.File; import java.io.FileFilter; -import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -11,6 +10,7 @@ import java.util.List; import net.sf.openrocket.R; import net.sf.openrocket.android.actionbarcompat.ActionBarListActivity; import android.app.AlertDialog; +import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -31,6 +31,8 @@ public class SimpleFileBrowser extends ActionBarListActivity { private List path = null; private final static File root = new File("/"); + private File previousDirectory = root; + private String baseDirPrefKey; private String baseDirName; @@ -102,7 +104,35 @@ public class SimpleFileBrowser extends ActionBarListActivity { } - private void getDir(File dirPath) { + private void getDir(final File dirPath) { + + // A little sanity check. It could be possible the directory saved in the preference + // is no longer mounted, is not a directory (any more), or cannot be read. + // if any of these are the case, we display a little dialog, then revert to the + // previousDirectory. + if ( !dirPath.exists() || !dirPath.isDirectory() || !dirPath.canRead() ) { + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Unable to open directory " + dirPath.getAbsolutePath() ); + builder.setCancelable(true); + builder.setOnCancelListener( new Dialog.OnCancelListener() { + + @Override + public void onCancel(DialogInterface arg0) { + if ( root.getAbsolutePath().equals(dirPath.getAbsolutePath()) ) { + SimpleFileBrowser.this.finish(); + } else { + SimpleFileBrowser.this.getDir( previousDirectory ); + } + } + + }); + builder.show(); + return; + } + + previousDirectory = dirPath; + setTitle(dirPath.getAbsolutePath()); path = new ArrayList(); -- 2.47.2