diff options
author | fred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local> | 2016-07-19 10:53:40 -0700 |
---|---|---|
committer | fred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local> | 2016-08-08 14:20:56 -0700 |
commit | 5e6e1793723b139a7ed702cf6dc48955fb27300e (patch) | |
tree | 62908437f3aeae2da759de02e5e10c65cf7a66e5 /platform/android/example/app | |
parent | d0fcfca2a309623a04809f64de2846c439761c1d (diff) | |
download | mupdf-5e6e1793723b139a7ed702cf6dc48955fb27300e.tar.xz |
Android example - collected changes
- move UI into the "mupdf" module.
The app simply sets up a DocView and starts it with a file path.
The app can call DocView.showUI to determine whether the built-in UI
is used. The plan is for apps to be able to use the built-in UI,
or supply their own.
Also includes some rudimentary UI for show/hiding annotations, and
listing links and outlines. Just for testing JNI features.
- add toolbar and tabs at the top of the view.
- refactoring
DocView becomes DocActivityView, DocViewInner becomes DocView.
- add Pages toolbar and page list view.
make the page list a little narrower.
give the document view and the pages view separate bitmaps,
and have DocPageView implement clipping when it draws.
- fix tabbing and brace style.
- add simple text selection and highlighting.
This is still a work in progress.
- various code review items.
fix tabs and brace styles
remove function calls from loop statements
use "highlight", not "hilight"
put a few strings into resources
avoid Right Hand Drift (tm)
Rects are inclusive...exclusive for the purpose of testing limits
put "else" on a separate line
put "catch" and "finally" on separate lines
Diffstat (limited to 'platform/android/example/app')
5 files changed, 94 insertions, 76 deletions
diff --git a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocActivity.java b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocActivity.java index 3fcb3064..4561bc4a 100644 --- a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocActivity.java +++ b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocActivity.java @@ -43,25 +43,28 @@ public class ChooseDocActivity String storageState = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(storageState) && - !Environment.MEDIA_MOUNTED_READ_ONLY.equals(storageState)) + !Environment.MEDIA_MOUNTED_READ_ONLY.equals(storageState)) { showMessage(getResources().getString(R.string.no_media_warning), - getResources().getString(R.string.no_media_hint), - getResources().getString(R.string.dismiss)); + getResources().getString(R.string.no_media_hint), + getResources().getString(R.string.dismiss)); return; } - if (mDirectory == null) { + if (mDirectory == null) + { mDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); mStartingDirectory = mDirectory; // remember where we started } // Create the list... - mListView = (ListView)findViewById(R.id.fileListView); - mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + mListView = (ListView) findViewById(R.id.fileListView); + mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() + { @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + public void onItemClick(AdapterView<?> parent, View view, int position, long id) + { onListItemClick(mListView, view, position, id); } }); @@ -71,8 +74,10 @@ public class ChooseDocActivity mListView.setAdapter(adapter); // ...that is updated dynamically when files are scanned - mUpdateFiles = new Runnable() { - public void run() { + mUpdateFiles = new Runnable() + { + public void run() + { Resources res = getResources(); String appName = res.getString(R.string.app_name); String version = res.getString(R.string.version); @@ -81,18 +86,22 @@ public class ChooseDocActivity mParent = mDirectory.getParentFile(); - mDirs = mDirectory.listFiles(new FileFilter() { + mDirs = mDirectory.listFiles(new FileFilter() + { - public boolean accept(File file) { + public boolean accept(File file) + { return file.isDirectory(); } }); if (mDirs == null) mDirs = new File[0]; - mFiles = mDirectory.listFiles(new FileFilter() { + mFiles = mDirectory.listFiles(new FileFilter() + { - public boolean accept(File file) { + public boolean accept(File file) + { if (file.isDirectory()) return false; @@ -129,14 +138,18 @@ public class ChooseDocActivity if (mFiles == null) mFiles = new File[0]; - Arrays.sort(mFiles, new Comparator<File>() { - public int compare(File arg0, File arg1) { + Arrays.sort(mFiles, new Comparator<File>() + { + public int compare(File arg0, File arg1) + { return arg0.getName().compareToIgnoreCase(arg1.getName()); } }); - Arrays.sort(mDirs, new Comparator<File>() { - public int compare(File arg0, File arg1) { + Arrays.sort(mDirs, new Comparator<File>() + { + public int compare(File arg0, File arg1) + { return arg0.getName().compareToIgnoreCase(arg1.getName()); } }); @@ -159,8 +172,10 @@ public class ChooseDocActivity mHandler.post(mUpdateFiles); // ...and observe the directory and scan files upon changes. - FileObserver observer = new FileObserver(mDirectory.getPath(), FileObserver.CREATE | FileObserver.DELETE) { - public void onEvent(int event, String path) { + FileObserver observer = new FileObserver(mDirectory.getPath(), FileObserver.CREATE | FileObserver.DELETE) + { + public void onEvent(int event, String path) + { mHandler.post(mUpdateFiles); } }; @@ -171,7 +186,7 @@ public class ChooseDocActivity { ChooseDocItem item = (ChooseDocItem) v.getTag(); File f = new File(item.path); - if (item.type== ChooseDocItem.Type.PARENT || item.type== ChooseDocItem.Type.DIR) + if (item.type == ChooseDocItem.Type.PARENT || item.type == ChooseDocItem.Type.DIR) { mDirectory = f; mHandler.post(mUpdateFiles); @@ -188,12 +203,14 @@ public class ChooseDocActivity } @Override - protected void onPause() { + protected void onPause() + { super.onPause(); } @Override - protected void onResume() { + protected void onResume() + { super.onResume(); // do another file scan to pick up changes to files since we were away @@ -202,23 +219,28 @@ public class ChooseDocActivity // this hides the activity @Override - public void onBackPressed() { - moveTaskToBack (true); + public void onBackPressed() + { + moveTaskToBack(true); } private void showMessage(final String title, final String body, final String okLabel) { final Activity activity = this; - runOnUiThread(new Runnable() { + runOnUiThread(new Runnable() + { @Override - public void run() { + public void run() + { new AlertDialog.Builder(activity) .setTitle(title) .setMessage(body) .setCancelable(false) - .setPositiveButton(okLabel, new DialogInterface.OnClickListener() { + .setPositiveButton(okLabel, new DialogInterface.OnClickListener() + { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(DialogInterface dialog, int which) + { dialog.dismiss(); } }).create().show(); diff --git a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocAdapter.java b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocAdapter.java index 4b889a06..98d6b3ff 100644 --- a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocAdapter.java +++ b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocAdapter.java @@ -9,33 +9,40 @@ import android.widget.TextView; import java.util.LinkedList; -public class ChooseDocAdapter extends BaseAdapter { +public class ChooseDocAdapter extends BaseAdapter +{ private final LinkedList<ChooseDocItem> mItems; private final LayoutInflater mInflater; - public ChooseDocAdapter(LayoutInflater inflater) { + public ChooseDocAdapter(LayoutInflater inflater) + { mInflater = inflater; mItems = new LinkedList<ChooseDocItem>(); } - public void clear() { + public void clear() + { mItems.clear(); } - public void add(ChooseDocItem item) { + public void add(ChooseDocItem item) + { mItems.add(item); notifyDataSetChanged(); } - public int getCount() { + public int getCount() + { return mItems.size(); } - public Object getItem(int i) { + public Object getItem(int i) + { return null; } - public long getItemId(int arg0) { + public long getItemId(int arg0) + { return 0; } @@ -43,30 +50,34 @@ public class ChooseDocAdapter extends BaseAdapter { { switch (type) { - case PARENT: - return R.drawable.ic_explorer_up; + case PARENT: + return R.drawable.ic_explorer_up; - case DIR: - return R.drawable.ic_explorer_fldr; + case DIR: + return R.drawable.ic_explorer_fldr; - case DOC: - return R.drawable.ic_explorer_any; + case DOC: + return R.drawable.ic_explorer_any; - default: - return 0; + default: + return 0; } } - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(int position, View convertView, ViewGroup parent) + { View v; - if (convertView == null) { + if (convertView == null) + { v = mInflater.inflate(R.layout.picker_entry, null); - } else { + } + else + { v = convertView; } ChooseDocItem item = mItems.get(position); - ((TextView)v.findViewById(R.id.name)).setText(item.name); - ((ImageView)v.findViewById(R.id.icon)).setImageResource(iconForType(item.type, item.name)); + ((TextView) v.findViewById(R.id.name)).setText(item.name); + ((ImageView) v.findViewById(R.id.icon)).setImageResource(iconForType(item.type, item.name)); v.setTag(item); diff --git a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocItem.java b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocItem.java index 194db0f3..df49e5c2 100644 --- a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocItem.java +++ b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/ChooseDocItem.java @@ -1,7 +1,9 @@ package com.artifex.mupdf.example; -public class ChooseDocItem { - public enum Type { +public class ChooseDocItem +{ + public enum Type + { PARENT, DIR, DOC } @@ -9,7 +11,8 @@ public class ChooseDocItem { final public String name; final public String path; - public ChooseDocItem(Type t, String n, String p) { + public ChooseDocItem(Type t, String n, String p) + { type = t; name = n; path = p; diff --git a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java index f17bcb83..4d07c8dd 100755 --- a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java +++ b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java @@ -3,13 +3,12 @@ package com.artifex.mupdf.example; import android.app.Activity; import android.net.Uri; import android.os.Bundle; -import android.view.View; -import com.artifex.mupdf.android.DocView; +import com.artifex.mupdf.android.DocActivityView; public class DocViewActivity extends Activity { - private DocView mDocView; + private DocActivityView mDocActivityView; @Override protected void onCreate(Bundle savedInstanceState) @@ -18,18 +17,14 @@ public class DocViewActivity extends Activity // set up UI setContentView(R.layout.activity_doc_view); - mDocView = (DocView)findViewById(R.id.doc_view); + mDocActivityView = (DocActivityView) findViewById(R.id.doc_view); // get the file path Uri uri = getIntent().getData(); final String path = Uri.decode(uri.getEncodedPath()); // start the view - mDocView.start(path); - } - - public void onToggleAnnotations(View v) - { - mDocView.toggleAnnotations(); + mDocActivityView.showUI(true); // set to false for no built-in UI + mDocActivityView.start(path); } } diff --git a/platform/android/example/app/src/main/res/layout/activity_doc_view.xml b/platform/android/example/app/src/main/res/layout/activity_doc_view.xml index e21c4a04..00065cf6 100755 --- a/platform/android/example/app/src/main/res/layout/activity_doc_view.xml +++ b/platform/android/example/app/src/main/res/layout/activity_doc_view.xml @@ -4,23 +4,10 @@ android:layout_height="match_parent" android:orientation="vertical"> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal"> - - <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="Annotations" - android:onClick="onToggleAnnotations"/> - - </LinearLayout> - - <com.artifex.mupdf.android.DocView + <com.artifex.mupdf.android.DocActivityView android:id="@+id/doc_view" android:layout_width="match_parent" android:layout_height="match_parent"> - </com.artifex.mupdf.android.DocView> + </com.artifex.mupdf.android.DocActivityView> </LinearLayout> |