\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
import java.util.List;\r
\r
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
import android.widget.ListView;\r
import android.widget.TextView;\r
\r
-public class SimpleFileBrowser extends ActionBarListActivity {\r
+import com.actionbarsherlock.app.SherlockListActivity;\r
+\r
+public class SimpleFileBrowser extends SherlockListActivity {\r
\r
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
\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
final File file = path.get(position);\r
if (file.isDirectory()) {\r
if (file.canRead())\r
- getDir(path.get(position));\r
+ getDir(file);\r
else {\r
new AlertDialog.Builder(this).setIcon(R.drawable.or_launcher)\r
.setTitle("[" + file.getName() + "] folder can't be read!")\r
}\r
}\r
\r
- // Set the "base directory" thing.\r
+ // Set the "favorite directory" thing.\r
{\r
ImageView v = (ImageView) (convertView.findViewById(R.id.filebrowser_list_item_homeicon));\r
- if ( !file.isDirectory() ) {\r
- v.setVisibility(View.INVISIBLE);\r
- v.setClickable(false);\r
- } else {\r
+ if ( file.isDirectory() && hasUp && position > 1 ) {\r
v.setVisibility(View.VISIBLE);\r
if ( baseDirName.equals( file.getAbsolutePath() ) ) {\r
v.setSelected(true);\r
v.setClickable(true);\r
v.setOnClickListener( new ChangeBaseDirectory(file.getAbsolutePath()));\r
}\r
+ } else {\r
+ v.setVisibility(View.INVISIBLE);\r
+ v.setClickable(false);\r
}\r
}\r
return convertView;\r
if ( v.isSelected() == false ) {\r
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(SimpleFileBrowser.this);\r
baseDirName = dirname;\r
- pref.edit().putString(baseDirPrefKey, dirname).apply();\r
- SimpleFileBrowser.this.getDir(new File(dirname));\r
+ pref.edit().putString(baseDirPrefKey, dirname).commit();\r
+ ((BaseAdapter)SimpleFileBrowser.this.getListAdapter()).notifyDataSetChanged();\r
}\r
}\r
\r