From 5e6e1793723b139a7ed702cf6dc48955fb27300e Mon Sep 17 00:00:00 2001 From: fred ross-perry Date: Tue, 19 Jul 2016 10:53:40 -0700 Subject: 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 --- .../artifex/mupdf/example/ChooseDocActivity.java | 78 +- .../artifex/mupdf/example/ChooseDocAdapter.java | 51 +- .../com/artifex/mupdf/example/ChooseDocItem.java | 9 +- .../com/artifex/mupdf/example/DocViewActivity.java | 15 +- .../app/src/main/res/layout/activity_doc_view.xml | 17 +- .../com/artifex/mupdf/android/DocActivityView.java | 343 +++++++ .../artifex/mupdf/android/DocListPagesView.java | 107 ++ .../com/artifex/mupdf/android/DocPageView.java | 374 +++++-- .../java/com/artifex/mupdf/android/DocView.java | 976 ++++--------------- .../com/artifex/mupdf/android/DocViewBase.java | 1030 ++++++++++++++++++++ .../java/com/artifex/mupdf/android/DragHandle.java | 179 ++++ .../artifex/mupdf/android/DragHandleListener.java | 10 + .../com/artifex/mupdf/android/PageAdapter.java | 24 +- .../java/com/artifex/mupdf/android/Stepper.java | 31 +- .../example/mupdf/src/main/res/drawable/button.xml | 30 + .../mupdf/src/main/res/drawable/icon_back.xml | 16 + .../mupdf/src/main/res/drawable/icon_find.xml | 19 + .../mupdf/src/main/res/drawable/icon_find_next.xml | 24 + .../src/main/res/drawable/icon_find_previous.xml | 24 + .../mupdf/src/main/res/drawable/icon_redo.xml | 17 + .../mupdf/src/main/res/drawable/icon_save.xml | 33 + .../res/drawable/icon_selection_drag_handle.xml | 12 + .../src/main/res/drawable/icon_selection_hand.xml | 96 ++ .../main/res/drawable/icon_selection_rotate.xml | 27 + .../mupdf/src/main/res/drawable/icon_undo.xml | 17 + .../mupdf/src/main/res/drawable/search_button.xml | 33 + .../src/main/res/drawable/search_input_wrapper.xml | 11 + .../src/main/res/drawable/search_text_input.xml | 15 + .../src/main/res/drawable/tab_left_selected.xml | 27 + .../src/main/res/drawable/tab_left_selector.xml | 20 + .../src/main/res/drawable/tab_left_unselected.xml | 27 + .../src/main/res/drawable/tab_right_selected.xml | 27 + .../src/main/res/drawable/tab_right_selector.xml | 20 + .../src/main/res/drawable/tab_right_unselected.xml | 27 + .../mupdf/src/main/res/drawable/tab_selected.xml | 17 + .../mupdf/src/main/res/drawable/tab_selector.xml | 20 + .../src/main/res/drawable/tab_text_selector.xml | 8 + .../mupdf/src/main/res/drawable/tab_unselected.xml | 17 + .../mupdf/src/main/res/drawable/toolbar_button.xml | 30 + .../mupdf/src/main/res/layout/annotate_toolbar.xml | 52 + .../example/mupdf/src/main/res/layout/doc_view.xml | 203 ++++ .../mupdf/src/main/res/layout/drag_handle.xml | 16 + .../mupdf/src/main/res/layout/file_toolbar.xml | 52 + .../mupdf/src/main/res/layout/pages_toolbar.xml | 52 + .../mupdf/src/main/res/layout/resize_handle.xml | 16 + .../mupdf/src/main/res/layout/rotate_handle.xml | 16 + .../mupdf/src/main/res/layout/search_toolbar.xml | 79 ++ .../example/mupdf/src/main/res/layout/tab.xml | 18 + .../example/mupdf/src/main/res/layout/tab_left.xml | 18 + .../mupdf/src/main/res/layout/tab_right.xml | 18 + .../example/mupdf/src/main/res/values/colors.xml | 49 + .../example/mupdf/src/main/res/values/integers.xml | 14 + .../example/mupdf/src/main/res/values/strings.xml | 8 + 53 files changed, 3472 insertions(+), 997 deletions(-) create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocListPagesView.java mode change 100755 => 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java create mode 100755 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DragHandle.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DragHandleListener.java create mode 100644 platform/android/example/mupdf/src/main/res/drawable/button.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/icon_back.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/icon_find.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/icon_find_next.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/icon_find_previous.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/icon_redo.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/icon_save.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/icon_selection_drag_handle.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/icon_selection_hand.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/icon_selection_rotate.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/icon_undo.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/search_button.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/search_input_wrapper.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/search_text_input.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/tab_left_selected.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/tab_left_selector.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/tab_left_unselected.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/tab_right_selected.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/tab_right_selector.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/tab_right_unselected.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/tab_selected.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/tab_selector.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/tab_text_selector.xml create mode 100755 platform/android/example/mupdf/src/main/res/drawable/tab_unselected.xml create mode 100644 platform/android/example/mupdf/src/main/res/drawable/toolbar_button.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/annotate_toolbar.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/doc_view.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/drag_handle.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/file_toolbar.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/pages_toolbar.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/resize_handle.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/rotate_handle.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/search_toolbar.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/tab.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/tab_left.xml create mode 100644 platform/android/example/mupdf/src/main/res/layout/tab_right.xml create mode 100644 platform/android/example/mupdf/src/main/res/values/colors.xml create mode 100644 platform/android/example/mupdf/src/main/res/values/integers.xml (limited to 'platform/android/example') 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() { - public int compare(File arg0, File arg1) { + Arrays.sort(mFiles, new Comparator() + { + public int compare(File arg0, File arg1) + { return arg0.getName().compareToIgnoreCase(arg1.getName()); } }); - Arrays.sort(mDirs, new Comparator() { - public int compare(File arg0, File arg1) { + Arrays.sort(mDirs, new Comparator() + { + 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 mItems; private final LayoutInflater mInflater; - public ChooseDocAdapter(LayoutInflater inflater) { + public ChooseDocAdapter(LayoutInflater inflater) + { mInflater = inflater; mItems = new LinkedList(); } - 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"> - - -