From 03a7b530fc05426f4b9537784b6dab5e45a337f6 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Wed, 6 Mar 2013 11:10:29 +0000 Subject: Add another input mode for drawing ink annotations --- .../src/com/artifex/mupdfdemo/MuPDFActivity.java | 12 ++++---- .../src/com/artifex/mupdfdemo/MuPDFReaderView.java | 32 ++++++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'android') diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index be8dca89..41a71405 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -471,7 +471,7 @@ public class MuPDFActivity extends Activity // Activate the select button mSelectButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - mDocView.setSelectionMode(true); + mDocView.setMode(MuPDFReaderView.Mode.Selecting); mTopBarMode = TopBarMode.Text; mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } @@ -482,7 +482,7 @@ public class MuPDFActivity extends Activity MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); if (pageView != null) pageView.deselectText(); - mDocView.setSelectionMode(false); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); mTopBarMode = TopBarMode.Main; mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } @@ -495,7 +495,7 @@ public class MuPDFActivity extends Activity boolean copied = false; if (pageView != null) copied = pageView.copySelection(); - mDocView.setSelectionMode(false); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); mTopBarMode = TopBarMode.Main; mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); mInfoView.setText(copied?"Copied to clipboard":"No text selected"); @@ -536,7 +536,7 @@ public class MuPDFActivity extends Activity MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); if (pageView != null) pageView.markupSelection(Annotation.Type.HIGHLIGHT); - mDocView.setSelectionMode(false); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); mTopBarMode = TopBarMode.Main; mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } @@ -547,7 +547,7 @@ public class MuPDFActivity extends Activity MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); if (pageView != null) pageView.markupSelection(Annotation.Type.UNDERLINE); - mDocView.setSelectionMode(false); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); mTopBarMode = TopBarMode.Main; mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } @@ -558,7 +558,7 @@ public class MuPDFActivity extends Activity MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); if (pageView != null) pageView.markupSelection(Annotation.Type.STRIKEOUT); - mDocView.setSelectionMode(false); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); mTopBarMode = TopBarMode.Main; mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); } diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java index 13575dc7..6ddb69da 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java @@ -10,9 +10,10 @@ import android.view.ScaleGestureDetector; import android.view.View; public class MuPDFReaderView extends ReaderView { + enum Mode {Viewing, Selecting, Drawing} private final Context mContext; private boolean mLinksEnabled = false; - private boolean mSelecting = false; + private Mode mMode = Mode.Viewing; private boolean tapDisabled = false; private int tapPageMargin; @@ -25,8 +26,8 @@ public class MuPDFReaderView extends ReaderView { resetupChildren(); } - public void setSelectionMode(boolean b) { - mSelecting = b; + public void setMode(Mode m) { + mMode = m; } public MuPDFReaderView(Activity act) { @@ -51,7 +52,7 @@ public class MuPDFReaderView extends ReaderView { public boolean onSingleTapUp(MotionEvent e) { LinkInfo link = null; - if (!mSelecting && !tapDisabled) { + if (mMode == Mode.Viewing && !tapDisabled) { MuPDFView pageView = (MuPDFView) getDisplayedView(); Hit item = pageView.passClickEvent(e.getX(), e.getY()); onHit(item); @@ -93,28 +94,43 @@ public class MuPDFReaderView extends ReaderView { return super.onSingleTapUp(e); } + @Override + public void onShowPress(MotionEvent e) { + switch (mMode) { + case Drawing: + break; + } + } + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - if (!mSelecting) { + switch (mMode) { + case Viewing: if (!tapDisabled) onDocMotion(); return super.onScroll(e1, e2, distanceX, distanceY); - } else { + case Selecting: MuPDFView pageView = (MuPDFView)getDisplayedView(); if (pageView != null) pageView.selectText(e1.getX(), e1.getY(), e2.getX(), e2.getY()); return true; + case Drawing: + return true; + default: + return true; } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - if (!mSelecting) + switch (mMode) { + case Viewing: return super.onFling(e1, e2, velocityX, velocityY); - else + default: return true; + } } public boolean onScaleBegin(ScaleGestureDetector d) { -- cgit v1.2.3