diff options
Diffstat (limited to 'android/src')
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFCore.java | 22 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFPageView.java | 86 |
2 files changed, 89 insertions, 19 deletions
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java index 1f9da3a6..fc950e9b 100644 --- a/android/src/com/artifex/mupdf/MuPDFCore.java +++ b/android/src/com/artifex/mupdf/MuPDFCore.java @@ -35,6 +35,9 @@ public class MuPDFCore private native RectF[] searchPage(String text); private native int getPageLink(int page, float x, float y); private native int passClickEventInternal(int page, float x, float y); + private native void setFocusedWidgetChoiceSelectedInternal(String [] selected); + private native String [] getFocusedWidgetChoiceSelected(); + private native String [] getFocusedWidgetChoiceOptions(); private native int setFocusedWidgetTextInternal(String text); private native String getFocusedWidgetTextInternal(); private native int getFocusedWidgetTypeInternal(); @@ -144,21 +147,18 @@ public class MuPDFCore public synchronized PassClickResult passClickEvent(int page, float x, float y) { boolean changed = passClickEventInternal(page, x, y) != 0; - int type = getFocusedWidgetTypeInternal(); - WidgetType wtype = WidgetType.values()[type]; - String text; - switch (wtype) + switch (WidgetType.values()[getFocusedWidgetTypeInternal()]) { case TEXT: - text = getFocusedWidgetTextInternal(); - break; + return new PassClickResultText(changed, getFocusedWidgetTextInternal()); + case LISTBOX: + case COMBOBOX: + return new PassClickResultChoice(changed, getFocusedWidgetChoiceOptions(), getFocusedWidgetChoiceSelected()); default: - text = ""; - break; + return null; } - return new PassClickResult(changed, wtype, text); } public synchronized boolean setFocusedWidgetText(int page, String text) { @@ -169,6 +169,10 @@ public class MuPDFCore return success; } + public synchronized void setFocusedWidgetChoiceSelected(String [] selected) { + setFocusedWidgetChoiceSelectedInternal(selected); + } + public synchronized int hitLinkPage(int page, float x, float y) { return getPageLink(page, x, y); } diff --git a/android/src/com/artifex/mupdf/MuPDFPageView.java b/android/src/com/artifex/mupdf/MuPDFPageView.java index 0c7b7654..bc7b6223 100644 --- a/android/src/com/artifex/mupdf/MuPDFPageView.java +++ b/android/src/com/artifex/mupdf/MuPDFPageView.java @@ -10,16 +10,47 @@ import android.view.LayoutInflater; import android.view.WindowManager; import android.widget.EditText; -class PassClickResult { +abstract class PassClickResultVisitor { + public abstract void visitText(PassClickResultText result); + public abstract void visitChoice(PassClickResultChoice result); +} + +abstract class PassClickResult { public final boolean changed; - public final WidgetType type; - public final String text; - public PassClickResult(boolean _changed, WidgetType _type, String _text) { + public PassClickResult(boolean _changed) { changed = _changed; - type = _type; + } + + public abstract void acceptVisitor(PassClickResultVisitor vistor); +} + +class PassClickResultText extends PassClickResult { + public final String text; + + public PassClickResultText(boolean _changed, String _text) { + super(_changed); text = _text; } + + public void acceptVisitor(PassClickResultVisitor visitor) { + visitor.visitText(this); + } +} + +class PassClickResultChoice extends PassClickResult { + public final String [] options; + public final String [] selected; + + public PassClickResultChoice(boolean _changed, String [] _options, String [] _selected) { + super(_changed); + options = _options; + selected = _selected; + } + + public void acceptVisitor(PassClickResultVisitor visitor) { + visitor.visitChoice(this); + } } public class MuPDFPageView extends PageView { @@ -28,9 +59,11 @@ public class MuPDFPageView extends PageView { private RectF mWidgetAreas[]; private AsyncTask<Void,Void,RectF[]> mLoadWidgetAreas; private AlertDialog.Builder mTextEntryBuilder; + private AlertDialog.Builder mChoiceEntryBuilder; private AlertDialog mTextEntry; private EditText mEditText; private AsyncTask<String,Void,Boolean> mSetWidgetText; + private AsyncTask<String,Void,Void> mSetWidgetChoice; private Runnable changeReporter; public MuPDFPageView(Context c, MuPDFCore core, Point parentSize) { @@ -65,6 +98,9 @@ public class MuPDFPageView extends PageView { } }); mTextEntry = mTextEntryBuilder.create(); + + mChoiceEntryBuilder = new AlertDialog.Builder(c); + mChoiceEntryBuilder.setTitle("MuPDF: choose value"); } public int hitLinkPage(float x, float y) { @@ -85,6 +121,30 @@ public class MuPDFPageView extends PageView { mTextEntry.show(); } + private void invokeChoiceDialog(final String [] options) { + mChoiceEntryBuilder.setItems(options, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + mSetWidgetChoice = new AsyncTask<String,Void,Void>() { + @Override + protected Void doInBackground(String... params) { + String [] sel = {params[0]}; + mCore.setFocusedWidgetChoiceSelected(sel); + return null; + } + + @Override + protected void onPostExecute(Void result) { + changeReporter.run(); + } + }; + + mSetWidgetChoice.execute(options[which]); + } + }); + AlertDialog dialog = mChoiceEntryBuilder.create(); + dialog.show(); + } + public void setChangeReporter(Runnable reporter) { changeReporter = reporter; } @@ -114,11 +174,17 @@ public class MuPDFPageView extends PageView { changeReporter.run(); } - switch(result.type) { - case TEXT: - invokeTextDialog(result.text); - break; - } + result.acceptVisitor(new PassClickResultVisitor() { + @Override + public void visitText(PassClickResultText result) { + invokeTextDialog(result.text); + } + + @Override + public void visitChoice(PassClickResultChoice result) { + invokeChoiceDialog(result.options); + } + }); } }; |