diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-02-18 15:09:07 +0000 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-02-22 12:21:24 +0000 |
commit | 860f401dc6c349d9f838d6dc90bc921876dca58e (patch) | |
tree | 186a5411b8d96a38f6b25d0e3520dab53b1c88a3 /android/src | |
parent | f72c3f422ab2790fd55a056e5bbdbfdb388c0811 (diff) | |
download | mupdf-860f401dc6c349d9f838d6dc90bc921876dca58e.tar.xz |
Android: support selection of annotation
Diffstat (limited to 'android/src')
6 files changed, 91 insertions, 5 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java index 0c47c327..e2023265 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java @@ -64,7 +64,9 @@ public class MuPDFPageView extends PageView implements MuPDFView { private final MuPDFCore mCore; private AsyncTask<Void,Void,PassClickResult> mPassClick; private RectF mWidgetAreas[]; + private Annotation mAnnotations[]; private AsyncTask<Void,Void,RectF[]> mLoadWidgetAreas; + private AsyncTask<Void,Void,Annotation[]> mLoadAnnotations; private AlertDialog.Builder mTextEntryBuilder; private AlertDialog.Builder mChoiceEntryBuilder; private AlertDialog mTextEntry; @@ -165,15 +167,37 @@ public class MuPDFPageView extends PageView implements MuPDFView { float scale = mSourceScale*(float)getWidth()/(float)mSize.x; final float docRelX = (x - getLeft())/scale; final float docRelY = (y - getTop())/scale; - boolean hitWidget = false; + boolean hit = false; + int i; + + if (mAnnotations != null) { + for (i = 0; i < mAnnotations.length; i++) + if (mAnnotations[i].contains(docRelX, docRelY)) { + hit = true; + break; + } + + if (hit) { + switch (mAnnotations[i].type) { + case HIGHLIGHT: + case UNDERLINE: + case SQUIGGLY: + case STRIKEOUT: + setItemSelectBox(mAnnotations[i]); + return true; + } + } + } + + setItemSelectBox(null); if (mWidgetAreas != null) { - for (int i = 0; i < mWidgetAreas.length && !hitWidget; i++) + for (i = 0; i < mWidgetAreas.length && !hit; i++) if (mWidgetAreas[i].contains(docRelX, docRelY)) - hitWidget = true; + hit = true; } - if (hitWidget) { + if (hit) { mPassClick = new AsyncTask<Void,Void,PassClickResult>() { @Override protected PassClickResult doInBackground(Void... arg0) { @@ -203,7 +227,7 @@ public class MuPDFPageView extends PageView implements MuPDFView { mPassClick.execute(); } - return hitWidget; + return hit; } public boolean copySelection() { @@ -282,6 +306,7 @@ public class MuPDFPageView extends PageView implements MuPDFView { @Override protected void onPostExecute(Void result) { + loadAnnotations(); update(); } }; @@ -318,8 +343,29 @@ public class MuPDFPageView extends PageView implements MuPDFView { mCore.addStrikeOutAnnotation(mPageNumber, lines); } + private void loadAnnotations() { + mAnnotations = null; + if (mLoadAnnotations != null) + mLoadAnnotations.cancel(true); + mLoadAnnotations = new AsyncTask<Void,Void,Annotation[]> () { + @Override + protected Annotation[] doInBackground(Void... params) { + return mCore.getAnnoations(mPageNumber); + } + + @Override + protected void onPostExecute(Annotation[] result) { + mAnnotations = result; + } + }; + + mLoadAnnotations.execute(); + } + @Override public void setPage(final int page, PointF size) { + loadAnnotations(); + mLoadWidgetAreas = new AsyncTask<Void,Void,RectF[]> () { @Override protected RectF[] doInBackground(Void... arg0) { @@ -354,6 +400,11 @@ public class MuPDFPageView extends PageView implements MuPDFView { mLoadWidgetAreas = null; } + if (mLoadAnnotations != null) { + mLoadAnnotations.cancel(true); + mLoadAnnotations = null; + } + if (mSetWidgetText != null) { mSetWidgetText.cancel(true); mSetWidgetText = null; diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java index 7d0fb89b..95298b6c 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java @@ -159,6 +159,13 @@ public class MuPDFReaderView extends ReaderView { } } + @Override + protected void onMoveOffChild(int i) { + View v = getView(i); + if (v != null) + ((MuPDFView)v).setItemSelectBox(null); + } + protected void onSettle(View v) { // When the layout has settled ask the page to render // in HQ diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java index 301dc2b0..71b15d8a 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java @@ -108,6 +108,9 @@ public class MuPDFReflowView extends WebView implements MuPDFView { public void setLinkHighlighting(boolean f) { } + public void setItemSelectBox(RectF rect) { + } + public void setChangeReporter(Runnable reporter) { } diff --git a/android/src/com/artifex/mupdfdemo/MuPDFView.java b/android/src/com/artifex/mupdfdemo/MuPDFView.java index d2b8ac10..d032c7a0 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFView.java @@ -16,6 +16,7 @@ public interface MuPDFView { public void strikeOutSelection(); public void setSearchBoxes(RectF searchBoxes[]); public void setLinkHighlighting(boolean f); + public void setItemSelectBox(RectF rect); public void setChangeReporter(Runnable reporter); public void update(); public void addHq(boolean update); diff --git a/android/src/com/artifex/mupdfdemo/PageView.java b/android/src/com/artifex/mupdfdemo/PageView.java index ccc0e4fb..849dbc1f 100644 --- a/android/src/com/artifex/mupdfdemo/PageView.java +++ b/android/src/com/artifex/mupdfdemo/PageView.java @@ -101,6 +101,7 @@ class TextSelector { public abstract class PageView extends ViewGroup { private static final int HIGHLIGHT_COLOR = 0x802572AC; private static final int LINK_COLOR = 0x80AC7225; + private static final int BOX_COLOR = 0xFF4444FF; private static final int BACKGROUND_COLOR = 0xFFFFFFFF; private static final int PROGRESS_DIALOG_DELAY = 200; protected final Context mContext; @@ -124,6 +125,7 @@ public abstract class PageView extends ViewGroup { protected LinkInfo mLinks[]; private RectF mSelectBox; private TextWord mText[][]; + private RectF mItemSelectBox; private View mSearchView; private boolean mIsBlank; private boolean mHighlightLinks; @@ -191,6 +193,7 @@ public abstract class PageView extends ViewGroup { mLinks = null; mSelectBox = null; mText = null; + mItemSelectBox = null; } public void releaseResources() { @@ -337,6 +340,12 @@ public abstract class PageView extends ViewGroup { } }); } + + if (mItemSelectBox != null) { + paint.setStyle(Paint.Style.STROKE); + paint.setColor(BOX_COLOR); + canvas.drawRect(mItemSelectBox.left*scale, mItemSelectBox.top*scale, mItemSelectBox.right*scale, mItemSelectBox.bottom*scale, paint); + } } }; @@ -397,6 +406,12 @@ public abstract class PageView extends ViewGroup { (new TextSelector(mText, mSelectBox)).select(tp); } + public void setItemSelectBox(RectF rect) { + mItemSelectBox = rect; + if (mSearchView != null) + mSearchView.invalidate(); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int x, y; diff --git a/android/src/com/artifex/mupdfdemo/ReaderView.java b/android/src/com/artifex/mupdfdemo/ReaderView.java index d1e7c086..4df67ed0 100644 --- a/android/src/com/artifex/mupdfdemo/ReaderView.java +++ b/android/src/com/artifex/mupdfdemo/ReaderView.java @@ -88,6 +88,7 @@ public class ReaderView extends AdapterView<Adapter> public void setDisplayedViewIndex(int i) { if (0 <= i && i < mAdapter.getCount()) { + onMoveOffChild(mCurrent); mCurrent = i; onMoveToChild(i); mResetLayout = true; @@ -309,6 +310,8 @@ public class ReaderView extends AdapterView<Adapter> protected void onMoveToChild(int i) {} + protected void onMoveOffChild(int i) {} + protected void onSettle(View v) {}; protected void onUnsettle(View v) {}; @@ -317,6 +320,10 @@ public class ReaderView extends AdapterView<Adapter> protected void onScaleChild(View v, Float scale) {}; + public View getView(int i) { + return mChildViews.get(i); + } + public View getDisplayedView() { return mChildViews.get(mCurrent); } @@ -533,6 +540,7 @@ public class ReaderView extends AdapterView<Adapter> // where we must set hq area for the new current view post(this); + onMoveOffChild(mCurrent); mCurrent++; onMoveToChild(mCurrent); } @@ -543,6 +551,7 @@ public class ReaderView extends AdapterView<Adapter> // where we must set hq area for the new current view post(this); + onMoveOffChild(mCurrent); mCurrent--; onMoveToChild(mCurrent); } |