changeset 0:46783e4c83e2

Initial commit
author Brad Greco
date Sat, 04 Jun 2011 18:03:37 -0400
parents
children adceb82e0818
files .classpath .project AndroidManifest.xml default.properties proguard.cfg res/drawable/icon.png res/layout/chooser_list.xml res/layout/list_item.xml res/values/strings.xml src/net/bgreco/DirectoryPicker.java
diffstat 10 files changed, 258 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.classpath	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.project	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>DirectoryPicker</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AndroidManifest.xml	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="net.bgreco"
+      android:versionCode="1"
+      android:versionName="1.0">
+
+    <application android:icon="@drawable/icon" android:label="@string/app_name">
+        <activity android:name=".DirectoryPicker"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+    </application>
+</manifest>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/default.properties	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,12 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-4
+android.library=true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/proguard.cfg	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,36 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+    native <methods>;
+}
+
+-keepclasseswithmembernames class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembernames class * {
+    public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+  public static final android.os.Parcelable$Creator *;
+}
Binary file res/drawable/icon.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/chooser_list.xml	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+   <ListView android:id="@android:id/list"
+   		android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_weight="1"/>
+   <Button android:text="Choose"
+   		android:id="@+id/btnChoose"
+   		android:layout_width="fill_parent"
+   		android:layout_height="wrap_content"/>
+
+</LinearLayout>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/list_item.xml	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:padding="10dp"
+    android:textSize="16sp" >
+</TextView>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/values/strings.xml	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name"></string>
+</resources>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/net/bgreco/DirectoryPicker.java	Sat Jun 04 18:03:37 2011 -0400
@@ -0,0 +1,126 @@
+package net.bgreco;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import android.app.ListActivity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Environment;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.Toast;
+
+public class DirectoryPicker extends ListActivity {
+
+	public static final String START_DIR = "startDir";
+	public static final String ONLY_DIRS = "onlyDirs";
+	public static final String SHOW_HIDDEN = "showHidden";
+	public static final String CHOSEN_DIRECTORY = "chosenDir";
+	public static final int PICK_DIRECTORY = 43522432;
+	private File dir;
+	
+	@Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Bundle extras = getIntent().getExtras();
+        dir = Environment.getExternalStorageDirectory();
+        String preferredStartDir = extras.getString(START_DIR);
+        final boolean showHidden = extras.getBoolean(SHOW_HIDDEN, false);
+        final boolean onlyDirs = extras.getBoolean(ONLY_DIRS, true);
+        if(preferredStartDir != null) {
+        	File startDir = new File(preferredStartDir);
+        	if(startDir.isDirectory()) {
+        		dir = startDir;
+        	}
+        }
+        
+        setContentView(R.layout.chooser_list);
+        setTitle(dir.getAbsolutePath());
+        Button btnChoose = (Button) findViewById(R.id.btnChoose);
+        String name = dir.getName();
+        if(name.length() == 0)
+        	name = "/";
+        btnChoose.setText("Choose " + "'" + name + "'");
+        btnChoose.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+            	returnDir(dir.getAbsolutePath());
+            }
+        });
+        
+        ListView lv = getListView();
+        lv.setTextFilterEnabled(true);
+        
+        if(!dir.canRead()) {
+        	Context context = getApplicationContext();
+        	String msg = "Could not read folder contents.";
+        	Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
+        	toast.show();
+        	return;
+        }
+        
+        final ArrayList<File> files = filter(dir.listFiles(), onlyDirs, showHidden);
+        String[] names = names(files);
+        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, names));        	
+        
+
+        lv.setOnItemClickListener(new OnItemClickListener() {
+        	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+        		if(!files.get(position).isDirectory())
+        			return;
+        		String path = files.get(position).getAbsolutePath();
+                Intent intent = new Intent(DirectoryPicker.this, DirectoryPicker.class);
+                intent.putExtra(DirectoryPicker.START_DIR, path);
+                intent.putExtra(DirectoryPicker.SHOW_HIDDEN, showHidden);
+                intent.putExtra(DirectoryPicker.ONLY_DIRS, onlyDirs);
+                startActivityForResult(intent, PICK_DIRECTORY);
+        	}
+        });
+    }
+	
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+    	if(requestCode == PICK_DIRECTORY && resultCode == RESULT_OK) {
+	    	Bundle extras = data.getExtras();
+	    	String path = (String) extras.get(DirectoryPicker.CHOSEN_DIRECTORY);
+	        returnDir(path);
+    	}
+    }
+	
+    private void returnDir(String path) {
+    	Intent result = new Intent();
+    	result.putExtra(CHOSEN_DIRECTORY, path);
+        setResult(RESULT_OK, result);
+    	finish();    	
+    }
+
+	public ArrayList<File> filter(File[] file_list, boolean onlyDirs, boolean showHidden) {
+		ArrayList<File> files = new ArrayList<File>();
+		for(File file: file_list) {
+			if(onlyDirs && !file.isDirectory())
+				continue;
+			if(!showHidden && file.isHidden())
+				continue;
+			files.add(file);
+		}
+		Collections.sort(files);
+		return files;
+	}
+	
+	public String[] names(ArrayList<File> files) {
+		String[] names = new String[files.size()];
+		int i = 0;
+		for(File file: files) {
+			names[i] = file.getName();
+			i++;
+		}
+		return names;
+	}
+}
+