summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/res/drawable-ldpi/ic_dir.pngbin0 -> 157 bytes
-rw-r--r--android/res/drawable-ldpi/ic_doc.pngbin0 -> 167 bytes
-rw-r--r--android/res/drawable-ldpi/ic_updir.pngbin0 -> 268 bytes
-rw-r--r--android/res/drawable-mdpi/ic_arrow_up.pngbin0 -> 297 bytes
-rw-r--r--android/res/drawable-mdpi/ic_dir.pngbin0 -> 165 bytes
-rw-r--r--android/res/drawable-mdpi/ic_doc.pngbin0 -> 181 bytes
-rw-r--r--android/res/layout/picker_entry.xml32
-rw-r--r--android/src/com/artifex/mupdf/ChoosePDFActivity.java68
-rw-r--r--android/src/com/artifex/mupdf/ChoosePDFAdapter.java64
-rw-r--r--android/src/com/artifex/mupdf/ChoosePDFItem.java15
10 files changed, 158 insertions, 21 deletions
diff --git a/android/res/drawable-ldpi/ic_dir.png b/android/res/drawable-ldpi/ic_dir.png
new file mode 100644
index 00000000..2236f2f8
--- /dev/null
+++ b/android/res/drawable-ldpi/ic_dir.png
Binary files differ
diff --git a/android/res/drawable-ldpi/ic_doc.png b/android/res/drawable-ldpi/ic_doc.png
new file mode 100644
index 00000000..75f29a07
--- /dev/null
+++ b/android/res/drawable-ldpi/ic_doc.png
Binary files differ
diff --git a/android/res/drawable-ldpi/ic_updir.png b/android/res/drawable-ldpi/ic_updir.png
new file mode 100644
index 00000000..b923e429
--- /dev/null
+++ b/android/res/drawable-ldpi/ic_updir.png
Binary files differ
diff --git a/android/res/drawable-mdpi/ic_arrow_up.png b/android/res/drawable-mdpi/ic_arrow_up.png
new file mode 100644
index 00000000..de2726ce
--- /dev/null
+++ b/android/res/drawable-mdpi/ic_arrow_up.png
Binary files differ
diff --git a/android/res/drawable-mdpi/ic_dir.png b/android/res/drawable-mdpi/ic_dir.png
new file mode 100644
index 00000000..e15200c5
--- /dev/null
+++ b/android/res/drawable-mdpi/ic_dir.png
Binary files differ
diff --git a/android/res/drawable-mdpi/ic_doc.png b/android/res/drawable-mdpi/ic_doc.png
new file mode 100644
index 00000000..0d6e9def
--- /dev/null
+++ b/android/res/drawable-mdpi/ic_doc.png
Binary files differ
diff --git a/android/res/layout/picker_entry.xml b/android/res/layout/picker_entry.xml
index 1b7038e6..e4d53a59 100644
--- a/android/res/layout/picker_entry.xml
+++ b/android/res/layout/picker_entry.xml
@@ -1,10 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
- android:paddingLeft="12dp"
- android:paddingRight="12dp"
- android:textAppearance="?android:attr/textAppearanceLarge" >
-</TextView>
+ android:layout_height="wrap_content"
+ android:paddingLeft="8dp" >
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_alignParentLeft="true"
+ android:contentDescription="@string/link_control" />
+
+ <TextView
+ android:id="@+id/name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@+id/icon"
+ android:paddingBottom="8dp"
+ android:paddingLeft="12dp"
+ android:paddingRight="12dp"
+ android:paddingTop="8dp"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+</RelativeLayout> \ No newline at end of file
diff --git a/android/src/com/artifex/mupdf/ChoosePDFActivity.java b/android/src/com/artifex/mupdf/ChoosePDFActivity.java
index 441fab4b..ae97dd87 100644
--- a/android/src/com/artifex/mupdf/ChoosePDFActivity.java
+++ b/android/src/com/artifex/mupdf/ChoosePDFActivity.java
@@ -1,7 +1,7 @@
package com.artifex.mupdf;
import java.io.File;
-import java.io.FilenameFilter;
+import java.io.FileFilter;
import java.util.Arrays;
import java.util.Comparator;
@@ -17,15 +17,16 @@ import android.os.Environment;
import android.os.FileObserver;
import android.os.Handler;
import android.view.View;
-import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ChoosePDFActivity extends ListActivity {
- private File mDirectory;
+ static private File mDirectory;
+ private File mParent;
+ private File [] mDirs;
private File [] mFiles;
private Handler mHandler;
private Runnable mUpdateFiles;
- private ArrayAdapter<String> adapter;
+ private ChoosePDFAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -55,30 +56,43 @@ public class ChoosePDFActivity extends ListActivity {
alert.show();
return;
}
-
}
@Override
protected void onResume() {
super.onResume();
- mDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
+ if (mDirectory == null)
+ mDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Create a list adapter...
- adapter = new ArrayAdapter<String>(this, R.layout.picker_entry);
+ adapter = new ChoosePDFAdapter(getLayoutInflater());
setListAdapter(adapter);
// ...that is updated dynamically when files are scanned
mHandler = new Handler();
mUpdateFiles = new Runnable() {
public void run() {
- mFiles = mDirectory.listFiles(new FilenameFilter() {
- public boolean accept(File file, String name) {
- if (name.toLowerCase().endsWith(".pdf"))
+ mParent = mDirectory.getParentFile();
+
+ mDirs = mDirectory.listFiles(new FileFilter() {
+
+ public boolean accept(File file) {
+ return file.isDirectory();
+ }
+ });
+
+ mFiles = mDirectory.listFiles(new FileFilter() {
+
+ public boolean accept(File file) {
+ if (file.isDirectory())
+ return false;
+ String fname = file.getName().toLowerCase();
+ if (fname.endsWith(".pdf"))
return true;
- if (name.toLowerCase().endsWith(".xps"))
+ if (fname.endsWith(".xps"))
return true;
- if (name.toLowerCase().endsWith(".cbz"))
+ if (fname.endsWith(".cbz"))
return true;
return false;
}
@@ -90,10 +104,21 @@ public class ChoosePDFActivity extends ListActivity {
}
});
+ Arrays.sort(mDirs, new Comparator<File>() {
+ public int compare(File arg0, File arg1) {
+ return arg0.getName().compareToIgnoreCase(arg1.getName());
+ }
+ });
+
adapter.clear();
+ if (mParent != null)
+ adapter.add(new ChoosePDFItem(ChoosePDFItem.Type.PARENT, ".."));
+ if (mDirs != null)
+ for (File f : mDirs)
+ adapter.add(new ChoosePDFItem(ChoosePDFItem.Type.DIR, f.getName()));
if (mFiles != null)
for (File f : mFiles)
- adapter.add(f.getName());
+ adapter.add(new ChoosePDFItem(ChoosePDFItem.Type.DOC, f.getName()));
}
};
@@ -112,6 +137,23 @@ public class ChoosePDFActivity extends ListActivity {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
+
+ if (position < (mParent == null ? 0 : 1)) {
+ mDirectory = mParent;
+ mHandler.post(mUpdateFiles);
+ return;
+ }
+
+ position -= (mParent == null ? 0 : 1);
+
+ if (position < mDirs.length) {
+ mDirectory = mDirs[position];
+ mHandler.post(mUpdateFiles);
+ return;
+ }
+
+ position -= mDirs.length;
+
Uri uri = Uri.parse(mFiles[position].getAbsolutePath());
Intent intent = new Intent(this,MuPDFActivity.class);
intent.setAction(Intent.ACTION_VIEW);
diff --git a/android/src/com/artifex/mupdf/ChoosePDFAdapter.java b/android/src/com/artifex/mupdf/ChoosePDFAdapter.java
new file mode 100644
index 00000000..15e4a2fe
--- /dev/null
+++ b/android/src/com/artifex/mupdf/ChoosePDFAdapter.java
@@ -0,0 +1,64 @@
+package com.artifex.mupdf;
+
+import java.util.LinkedList;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public class ChoosePDFAdapter extends BaseAdapter {
+ private final LinkedList<ChoosePDFItem> mItems;
+ private final LayoutInflater mInflater;
+
+ public ChoosePDFAdapter(LayoutInflater inflater) {
+ mInflater = inflater;
+ mItems = new LinkedList<ChoosePDFItem>();
+ }
+
+ public void clear() {
+ mItems.clear();
+ }
+
+ public void add(ChoosePDFItem item) {
+ mItems.add(item);
+ notifyDataSetChanged();
+ }
+
+ public int getCount() {
+ return mItems.size();
+ }
+
+ public Object getItem(int i) {
+ return null;
+ }
+
+ public long getItemId(int arg0) {
+ return 0;
+ }
+
+ private int iconForType(ChoosePDFItem.Type type) {
+ switch (type) {
+ case PARENT: return R.drawable.ic_arrow_up;
+ case DIR: return R.drawable.ic_dir;
+ case DOC: return R.drawable.ic_doc;
+ default: return 0;
+ }
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v;
+ if (convertView == null) {
+ v = mInflater.inflate(R.layout.picker_entry, null);
+ } else {
+ v = convertView;
+ }
+ ChoosePDFItem item = mItems.get(position);
+ ((TextView)v.findViewById(R.id.name)).setText(item.name);
+ ((ImageView)v.findViewById(R.id.icon)).setBackgroundResource(iconForType(item.type));
+ return v;
+ }
+
+}
diff --git a/android/src/com/artifex/mupdf/ChoosePDFItem.java b/android/src/com/artifex/mupdf/ChoosePDFItem.java
new file mode 100644
index 00000000..d9c2bb37
--- /dev/null
+++ b/android/src/com/artifex/mupdf/ChoosePDFItem.java
@@ -0,0 +1,15 @@
+package com.artifex.mupdf;
+
+public class ChoosePDFItem {
+ enum Type {
+ PARENT, DIR, DOC
+ }
+
+ final public Type type;
+ final public String name;
+
+ public ChoosePDFItem (Type t, String n) {
+ type = t;
+ name = n;
+ }
+}