diff options
-rw-r--r-- | android/res/drawable-ldpi/ic_trash.png | bin | 0 -> 246 bytes | |||
-rw-r--r-- | android/res/drawable-mdpi/ic_trash.png | bin | 0 -> 291 bytes | |||
-rw-r--r-- | android/res/layout/buttons.xml | 18 | ||||
-rw-r--r-- | android/res/values/strings.xml | 1 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFActivity.java | 54 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFPageView.java | 10 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFReaderView.java | 70 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFReflowView.java | 4 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFView.java | 4 |
9 files changed, 106 insertions, 55 deletions
diff --git a/android/res/drawable-ldpi/ic_trash.png b/android/res/drawable-ldpi/ic_trash.png Binary files differnew file mode 100644 index 00000000..465d1245 --- /dev/null +++ b/android/res/drawable-ldpi/ic_trash.png diff --git a/android/res/drawable-mdpi/ic_trash.png b/android/res/drawable-mdpi/ic_trash.png Binary files differnew file mode 100644 index 00000000..3006fec3 --- /dev/null +++ b/android/res/drawable-mdpi/ic_trash.png diff --git a/android/res/layout/buttons.xml b/android/res/layout/buttons.xml index 2d5732f1..b89848bb 100644 --- a/android/res/layout/buttons.xml +++ b/android/res/layout/buttons.xml @@ -169,6 +169,24 @@ android:src="@drawable/ic_clipboard" /> </RelativeLayout> + + <RelativeLayout + android:id="@+id/topBar4" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/toolbar" > + + <ImageButton + android:id="@+id/deleteButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerVertical="true" + android:layout_alignParentRight="true" + android:contentDescription="@string/delete" + android:background="@drawable/button" + android:src="@drawable/ic_trash" /> + + </RelativeLayout> </ViewAnimator> <RelativeLayout diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 06ff9983..47453fb3 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -21,4 +21,5 @@ <string name="search">Search</string> <string name="copy">Copy</string> <string name="strike_out">Strike out</string> + <string name="delete">Delete</string> </resources> 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(); |