diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index 2fa501acd..6ae3d51fd 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -77,6 +77,7 @@
android:label="@string/MotorListTitle" />
-
+
+
\ No newline at end of file
diff --git a/android/res/layout/simplefilebrowser.xml b/android/res/layout/simplefilebrowser.xml
new file mode 100644
index 000000000..3d89e59f7
--- /dev/null
+++ b/android/res/layout/simplefilebrowser.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/src/net/sf/openrocket/android/Main.java b/android/src/net/sf/openrocket/android/Main.java
index bd80c9fd0..cdb7366a0 100644
--- a/android/src/net/sf/openrocket/android/Main.java
+++ b/android/src/net/sf/openrocket/android/Main.java
@@ -1,13 +1,14 @@
package net.sf.openrocket.android;
import net.sf.openrocket.R;
+import net.sf.openrocket.android.filebrowser.SimpleFileBrowser;
import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;
import android.app.Activity;
+import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
-import android.view.Window;
public class Main extends Activity {
@@ -39,9 +40,15 @@ public class Main extends Activity {
}
public void pickOrkFiles( View v ) {
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType("file/*");
- startActivityForResult(intent,PICK_ORK_FILE_RESULT);
+ try {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType("file/*");
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);
+ } catch ( ActivityNotFoundException ex ) {
+ // No activity for ACTION_GET_CONTENT use internal file browser
+ Intent intent = new Intent(Main.this, SimpleFileBrowser.class);
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);
+ }
}
public void browseMotors( View v ) {
diff --git a/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java b/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java
new file mode 100644
index 000000000..853f48897
--- /dev/null
+++ b/android/src/net/sf/openrocket/android/filebrowser/SimpleFileBrowser.java
@@ -0,0 +1,146 @@
+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;
+import java.util.List;
+
+import net.sf.openrocket.R;
+import android.app.AlertDialog;
+import android.app.ListActivity;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Environment;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+public class SimpleFileBrowser extends ListActivity {
+
+ private List item = null;
+ private List path = null;
+ private String root = "/";
+ private TextView myPath;
+
+ private static final OrkFileFilter filter = new OrkFileFilter();
+ private static final Collator sorter = Collator.getInstance();
+ static {
+ sorter.setStrength(Collator.TERTIARY);
+ sorter.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.simplefilebrowser);
+ myPath = (TextView) findViewById(R.id.path);
+ getDir( Environment.getExternalStorageDirectory().getAbsolutePath() );
+ }
+
+ private static class OrkFileFilter implements FileFilter {
+
+ /* (non-Javadoc)
+ * @see java.io.FileFilter#accept(java.io.File)
+ */
+ @Override
+ public boolean accept(File arg0) {
+ if ( arg0.isDirectory() ) {
+ return true;
+ }
+ if ( arg0.getName().endsWith(".ork") ) {
+ return true;
+ }
+ return false;
+ }
+
+ }
+
+ private static class FileComparator implements Comparator {
+
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(File arg0, File arg1) {
+ // Directories come before files, otherwise alpha.
+ if ( arg0.isDirectory() ) {
+ if ( ! arg1.isDirectory() ) {
+ return -1;
+ }
+ return sorter.compare(arg0.getName(), arg1.getName());
+ }
+
+ // arg0 is not a directory.
+ if ( arg1.isDirectory() ) {
+ return 1;
+ }
+
+ return sorter.compare(arg0.getName(), arg1.getName());
+ }
+
+ }
+
+ private void getDir(String dirPath) {
+ myPath.setText("Location: " + dirPath);
+ item = new ArrayList();
+ path = new ArrayList();
+
+ File f = new File(dirPath);
+ File[] files = f.listFiles(filter);
+
+ if (!dirPath.equals(root)) {
+ item.add(root);
+ path.add(root);
+ item.add("../");
+ path.add(f.getParent());
+ }
+
+ Arrays.sort(files, new FileComparator() );
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ path.add(file.getPath());
+ if (file.isDirectory())
+ item.add(file.getName() + "/");
+ else
+ item.add(file.getName());
+ }
+
+ ArrayAdapter fileList = new ArrayAdapter(this, android.R.layout.simple_list_item_1, item);
+ setListAdapter(fileList);
+
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ final File file = new File(path.get(position));
+ if (file.isDirectory()) {
+ if (file.canRead())
+ getDir(path.get(position));
+ else {
+ new AlertDialog.Builder(this).setIcon(R.drawable.or_launcher)
+ .setTitle("[" + file.getName() + "] folder can't be read!")
+ .setPositiveButton("OK",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // TODO Auto-generated method stub
+ }
+ }).show();
+ }
+ }
+ else
+ {
+ Intent resultData = new Intent(Intent.ACTION_VIEW);
+ resultData.setData( Uri.fromFile(file) );
+ setResult(RESULT_OK,resultData);
+ finish();
+ }
+ }
+}