summaryrefslogtreecommitdiff
path: root/android/src
diff options
context:
space:
mode:
Diffstat (limited to 'android/src')
-rw-r--r--android/src/com/artifex/mupdf/LinkInfo.java14
-rw-r--r--android/src/com/artifex/mupdf/LinkInfoExternal.java14
-rw-r--r--android/src/com/artifex/mupdf/LinkInfoInternal.java14
-rw-r--r--android/src/com/artifex/mupdf/LinkInfoVisitor.java6
-rw-r--r--android/src/com/artifex/mupdf/MuPDFActivity.java17
-rw-r--r--android/src/com/artifex/mupdf/MuPDFCore.java5
-rw-r--r--android/src/com/artifex/mupdf/MuPDFPageView.java8
-rw-r--r--android/src/com/artifex/mupdf/PageView.java8
8 files changed, 65 insertions, 21 deletions
diff --git a/android/src/com/artifex/mupdf/LinkInfo.java b/android/src/com/artifex/mupdf/LinkInfo.java
index c2a395e7..8b52d7f7 100644
--- a/android/src/com/artifex/mupdf/LinkInfo.java
+++ b/android/src/com/artifex/mupdf/LinkInfo.java
@@ -2,11 +2,13 @@ package com.artifex.mupdf;
import android.graphics.RectF;
-public class LinkInfo extends RectF {
- public int pageNumber;
+public class LinkInfo {
+ final public RectF rect;
- public LinkInfo(float l, float t, float r, float b, int p) {
- super(l, t, r, b);
- pageNumber = p;
+ public LinkInfo(float l, float t, float r, float b) {
+ rect = new RectF(l, t, r, b);
}
-}
+
+ public void acceptVisitor(LinkInfoVisitor visitor) {
+ }
+} \ No newline at end of file
diff --git a/android/src/com/artifex/mupdf/LinkInfoExternal.java b/android/src/com/artifex/mupdf/LinkInfoExternal.java
new file mode 100644
index 00000000..fce1eae0
--- /dev/null
+++ b/android/src/com/artifex/mupdf/LinkInfoExternal.java
@@ -0,0 +1,14 @@
+package com.artifex.mupdf;
+
+public class LinkInfoExternal extends LinkInfo {
+ final public String url;
+
+ public LinkInfoExternal(float l, float t, float r, float b, String u) {
+ super(l, t, r, b);
+ url = u;
+ }
+
+ public void acceptVisitor(LinkInfoVisitor visitor) {
+ visitor.visitExternal(this);
+ }
+}
diff --git a/android/src/com/artifex/mupdf/LinkInfoInternal.java b/android/src/com/artifex/mupdf/LinkInfoInternal.java
new file mode 100644
index 00000000..9d34fcb7
--- /dev/null
+++ b/android/src/com/artifex/mupdf/LinkInfoInternal.java
@@ -0,0 +1,14 @@
+package com.artifex.mupdf;
+
+public class LinkInfoInternal extends LinkInfo {
+ final public int pageNumber;
+
+ public LinkInfoInternal(float l, float t, float r, float b, int p) {
+ super(l, t, r, b);
+ pageNumber = p;
+ }
+
+ public void acceptVisitor(LinkInfoVisitor visitor) {
+ visitor.visitInternal(this);
+ }
+}
diff --git a/android/src/com/artifex/mupdf/LinkInfoVisitor.java b/android/src/com/artifex/mupdf/LinkInfoVisitor.java
new file mode 100644
index 00000000..348334a7
--- /dev/null
+++ b/android/src/com/artifex/mupdf/LinkInfoVisitor.java
@@ -0,0 +1,6 @@
+package com.artifex.mupdf;
+
+abstract public class LinkInfoVisitor {
+ public abstract void visitInternal(LinkInfoInternal li);
+ public abstract void visitExternal(LinkInfoExternal li);
+}
diff --git a/android/src/com/artifex/mupdf/MuPDFActivity.java b/android/src/com/artifex/mupdf/MuPDFActivity.java
index 283ed761..4a548637 100644
--- a/android/src/com/artifex/mupdf/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdf/MuPDFActivity.java
@@ -352,12 +352,21 @@ public class MuPDFActivity extends Activity
} else if (e.getX() > super.getWidth()*(TAP_PAGE_MARGIN-1)/TAP_PAGE_MARGIN) {
super.moveToNext();
} else {
- int linkPage = -1;
+ LinkInfo link = null;
if (mLinkHighlight && pageView != null) {
- linkPage = pageView.hitLinkPage(e.getX(), e.getY());
+ link = pageView.hitLink(e.getX(), e.getY());
}
- if (linkPage != -1) {
- mDocView.setDisplayedViewIndex(linkPage);
+ if (link != null) {
+ link.acceptVisitor(new LinkInfoVisitor() {
+ @Override
+ public void visitInternal(LinkInfoInternal li) {
+ mDocView.setDisplayedViewIndex(li.pageNumber);
+ }
+ @Override
+ public void visitExternal(LinkInfoExternal li) {
+ // Clicked on an external link: li.url
+ }
+ });
} else {
if (!mButtonsVisible) {
showButtons();
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java
index c86867c3..15c90e17 100644
--- a/android/src/com/artifex/mupdf/MuPDFCore.java
+++ b/android/src/com/artifex/mupdf/MuPDFCore.java
@@ -33,7 +33,6 @@ public class MuPDFCore
int patchX, int patchY,
int patchW, int patchH);
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();
@@ -173,10 +172,6 @@ public class MuPDFCore
setFocusedWidgetChoiceSelectedInternal(selected);
}
- public synchronized int hitLinkPage(int page, float x, float y) {
- return getPageLink(page, x, y);
- }
-
public synchronized LinkInfo [] getPageLinks(int page) {
return getPageLinksInternal(page);
}
diff --git a/android/src/com/artifex/mupdf/MuPDFPageView.java b/android/src/com/artifex/mupdf/MuPDFPageView.java
index 8c8ec7e0..68031837 100644
--- a/android/src/com/artifex/mupdf/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdf/MuPDFPageView.java
@@ -104,7 +104,7 @@ public class MuPDFPageView extends PageView {
mChoiceEntryBuilder.setTitle("MuPDF: choose value");
}
- public int hitLinkPage(float x, float y) {
+ public LinkInfo hitLink(float x, float y) {
// Since link highlighting was implemented, the super class
// PageView has had sufficient information to be able to
// perform this method directly. Making that change would
@@ -113,7 +113,11 @@ public class MuPDFPageView extends PageView {
float docRelX = (x - getLeft())/scale;
float docRelY = (y - getTop())/scale;
- return mCore.hitLinkPage(mPageNumber, docRelX, docRelY);
+ for (LinkInfo l: mLinks)
+ if (l.rect.contains(docRelX, docRelY))
+ return l;
+
+ return null;
}
private void invokeTextDialog(String text) {
diff --git a/android/src/com/artifex/mupdf/PageView.java b/android/src/com/artifex/mupdf/PageView.java
index f07ea8d8..bdbed438 100644
--- a/android/src/com/artifex/mupdf/PageView.java
+++ b/android/src/com/artifex/mupdf/PageView.java
@@ -62,7 +62,7 @@ public abstract class PageView extends ViewGroup {
private BitmapHolder mPatchBm;
private AsyncTask<PatchInfo,Void,PatchInfo> mDrawPatch;
private RectF mSearchBoxes[];
- private LinkInfo mLinks[];
+ protected LinkInfo mLinks[];
private View mSearchView;
private boolean mIsBlank;
private boolean mHighlightLinks;
@@ -250,9 +250,9 @@ public abstract class PageView extends ViewGroup {
// Work out current total scale factor
// from source to view
paint.setColor(LINK_COLOR);
- for (RectF rect : mLinks)
- canvas.drawRect(rect.left*scale, rect.top*scale,
- rect.right*scale, rect.bottom*scale,
+ for (LinkInfo link : mLinks)
+ canvas.drawRect(link.rect.left*scale, link.rect.top*scale,
+ link.rect.right*scale, link.rect.bottom*scale,
paint);
}
}