diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-02-18 16:22:25 +0000 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-02-22 12:21:25 +0000 |
commit | 4553555e8bab6f749ae007664ad6745ee816e4bf (patch) | |
tree | 0992cac8b4d53339cbc6d8e07816da299930849f /android/src/com/artifex/mupdfdemo | |
parent | 860f401dc6c349d9f838d6dc90bc921876dca58e (diff) | |
download | mupdf-4553555e8bab6f749ae007664ad6745ee816e4bf.tar.xz |
Android: add annotation-editing menu, triggered on annotation selection
Diffstat (limited to 'android/src/com/artifex/mupdfdemo')
5 files changed, 87 insertions, 55 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index a9729725..f0c94c6a 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -44,6 +44,8 @@ class ThreadPerTaskExecutor implements Executor { public class MuPDFActivity extends Activity { /* The core rendering instance */ + enum TopBarMode {Main, Search, Text, Annotation}; + private MuPDFCore core; private String mFileName; private MuPDFReaderView mDocView; @@ -65,7 +67,7 @@ public class MuPDFActivity extends Activity private ImageButton mOutlineButton; private ViewAnimator mTopBarSwitcher; private ImageButton mLinkButton; - private boolean mTopBarIsSearch; + private TopBarMode mTopBarMode; private ImageButton mSearchBack; private ImageButton mSearchFwd; private EditText mSearchText; @@ -389,6 +391,24 @@ public class MuPDFActivity extends Activity protected void onDocMotion() { hideButtons(); } + + @Override + protected void onHit(Hit item) { + switch (item) { + case Annotation: + showButtons(); + mTopBarMode = TopBarMode.Annotation; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + break; + case Widget: + case Nothing: + if (mTopBarMode == TopBarMode.Annotation) { + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + } + break; + } + } }; mDocView.setAdapter(new MuPDFPageAdapter(this, core)); @@ -447,7 +467,8 @@ public class MuPDFActivity extends Activity mSelectButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mDocView.setSelectionMode(true); - mTopBarSwitcher.setDisplayedChild(2); + mTopBarMode = TopBarMode.Text; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } }); @@ -457,7 +478,8 @@ public class MuPDFActivity extends Activity if (pageView != null) pageView.deselectText(); mDocView.setSelectionMode(false); - mTopBarSwitcher.setDisplayedChild(0); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } }); @@ -469,7 +491,8 @@ public class MuPDFActivity extends Activity if (pageView != null) copied = pageView.copySelection(); mDocView.setSelectionMode(false); - mTopBarSwitcher.setDisplayedChild(0); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); mInfoView.setText(copied?"Copied to clipboard":"No text selected"); int currentApiVersion = android.os.Build.VERSION.SDK_INT; @@ -509,7 +532,8 @@ public class MuPDFActivity extends Activity if (pageView != null) pageView.strikeOutSelection(); mDocView.setSelectionMode(false); - mTopBarSwitcher.setDisplayedChild(0); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } }); @@ -676,7 +700,7 @@ public class MuPDFActivity extends Activity if (!mButtonsVisible) outState.putBoolean("ButtonsHidden", true); - if (mTopBarIsSearch) + if (mTopBarMode == TopBarMode.Search) outState.putBoolean("SearchMode", true); } @@ -716,7 +740,7 @@ public class MuPDFActivity extends Activity updatePageNumView(index); mPageSlider.setMax((core.countPages()-1)*mPageSliderRes); mPageSlider.setProgress(index*mPageSliderRes); - if (mTopBarIsSearch) { + if (mTopBarMode == TopBarMode.Search) { mSearchText.requestFocus(); showKeyboard(); } @@ -779,20 +803,20 @@ public class MuPDFActivity extends Activity } void searchModeOn() { - if (!mTopBarIsSearch) { - mTopBarIsSearch = true; + if (mTopBarMode != TopBarMode.Search) { + mTopBarMode = TopBarMode.Search; //Focus on EditTextWidget mSearchText.requestFocus(); showKeyboard(); - mTopBarSwitcher.setDisplayedChild(1); + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } } void searchModeOff() { - if (mTopBarIsSearch) { - mTopBarIsSearch = false; + if (mTopBarMode == TopBarMode.Search) { + mTopBarMode = TopBarMode.Main; hideKeyboard(); - mTopBarSwitcher.setDisplayedChild(0); + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); SearchTaskResult.set(null); // Make the ReaderView act on the change to mSearchTaskResult // via overridden onChildSetup method. @@ -853,7 +877,7 @@ public class MuPDFActivity extends Activity @Override public boolean onSearchRequested() { - if (mButtonsVisible && mTopBarIsSearch) { + if (mButtonsVisible && mTopBarMode == TopBarMode.Search) { hideButtons(); } else { showButtons(); @@ -864,7 +888,7 @@ public class MuPDFActivity extends Activity @Override public boolean onPrepareOptionsMenu(Menu menu) { - if (mButtonsVisible && !mTopBarIsSearch) { + if (mButtonsVisible && mTopBarMode != TopBarMode.Search) { hideButtons(); } else { showButtons(); diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java index e2023265..ae206c1e 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java @@ -163,7 +163,7 @@ public class MuPDFPageView extends PageView implements MuPDFView { changeReporter = reporter; } - public boolean passClickEvent(float x, float y) { + public Hit passClickEvent(float x, float y) { float scale = mSourceScale*(float)getWidth()/(float)mSize.x; final float docRelX = (x - getLeft())/scale; final float docRelY = (y - getTop())/scale; @@ -184,13 +184,16 @@ public class MuPDFPageView extends PageView implements MuPDFView { case SQUIGGLY: case STRIKEOUT: setItemSelectBox(mAnnotations[i]); - return true; + return Hit.Annotation; } } } setItemSelectBox(null); + if (!MuPDFCore.javascriptSupported()) + return Hit.Nothing; + if (mWidgetAreas != null) { for (i = 0; i < mWidgetAreas.length && !hit; i++) if (mWidgetAreas[i].contains(docRelX, docRelY)) @@ -225,9 +228,10 @@ public class MuPDFPageView extends PageView implements MuPDFView { }; mPassClick.execute(); + return Hit.Widget; } - return hit; + return Hit.Nothing; } public boolean copySelection() { diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java index 95298b6c..dfb7cf0b 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java @@ -18,6 +18,7 @@ public class MuPDFReaderView extends ReaderView { protected void onTapMainDocArea() {} protected void onDocMotion() {} + protected void onHit(Hit item) {}; public void setLinksEnabled(boolean b) { mLinksEnabled = b; @@ -52,40 +53,41 @@ public class MuPDFReaderView extends ReaderView { if (!mSelecting && !tapDisabled) { MuPDFView pageView = (MuPDFView) getDisplayedView(); - if (MuPDFCore.javascriptSupported() - && pageView.passClickEvent(e.getX(), e.getY())) { - // If the page consumes the event do nothing else - } else if (mLinksEnabled && pageView != null - && (link = pageView.hitLink(e.getX(), e.getY())) != null) { - link.acceptVisitor(new LinkInfoVisitor() { - @Override - public void visitInternal(LinkInfoInternal li) { - // Clicked on an internal (GoTo) link - setDisplayedViewIndex(li.pageNumber); - } - - @Override - public void visitExternal(LinkInfoExternal li) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri - .parse(li.url)); - mContext.startActivity(intent); - } - - @Override - public void visitRemote(LinkInfoRemote li) { - // Clicked on a remote (GoToR) link - } - }); - } else if (e.getX() < tapPageMargin) { - super.smartMoveBackwards(); - } else if (e.getX() > super.getWidth() - tapPageMargin) { - super.smartMoveForwards(); - } else if (e.getY() < tapPageMargin) { - super.smartMoveBackwards(); - } else if (e.getY() > super.getHeight() - tapPageMargin) { - super.smartMoveForwards(); - } else { - onTapMainDocArea(); + Hit item = pageView.passClickEvent(e.getX(), e.getY()); + onHit(item); + if (item == Hit.Nothing) { + if (mLinksEnabled && pageView != null + && (link = pageView.hitLink(e.getX(), e.getY())) != null) { + link.acceptVisitor(new LinkInfoVisitor() { + @Override + public void visitInternal(LinkInfoInternal li) { + // Clicked on an internal (GoTo) link + setDisplayedViewIndex(li.pageNumber); + } + + @Override + public void visitExternal(LinkInfoExternal li) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri + .parse(li.url)); + mContext.startActivity(intent); + } + + @Override + public void visitRemote(LinkInfoRemote li) { + // Clicked on a remote (GoToR) link + } + }); + } else if (e.getX() < tapPageMargin) { + super.smartMoveBackwards(); + } else if (e.getX() > super.getWidth() - tapPageMargin) { + super.smartMoveForwards(); + } else if (e.getY() < tapPageMargin) { + super.smartMoveBackwards(); + } else if (e.getY() > super.getHeight() - tapPageMargin) { + super.smartMoveForwards(); + } else { + onTapMainDocArea(); + } } } return super.onSingleTapUp(e); diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java index 71b15d8a..789314f5 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java @@ -81,8 +81,8 @@ public class MuPDFReflowView extends WebView implements MuPDFView { public void blank(int page) { } - public boolean passClickEvent(float x, float y) { - return false; + public Hit passClickEvent(float x, float y) { + return Hit.Nothing; } public LinkInfo hitLink(float x, float y) { diff --git a/android/src/com/artifex/mupdfdemo/MuPDFView.java b/android/src/com/artifex/mupdfdemo/MuPDFView.java index d032c7a0..d16fc818 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFView.java @@ -3,12 +3,14 @@ package com.artifex.mupdfdemo; import android.graphics.PointF; import android.graphics.RectF; +enum Hit {Nothing, Widget, Annotation}; + public interface MuPDFView { public void setPage(int page, PointF size); public void setScale(float scale); public int getPage(); public void blank(int page); - public boolean passClickEvent(float x, float y); + public Hit passClickEvent(float x, float y); public LinkInfo hitLink(float x, float y); public void selectText(float x0, float y0, float x1, float y1); public void deselectText(); |