Adapt to new API for link and outline destinations.
diff --git a/lib/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java b/lib/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java
index a0d28a4..a2bb41e 100644
--- a/lib/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java
+++ b/lib/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java
@@ -69,7 +69,7 @@
layoutW = w;
layoutH = h;
layoutEM = em;
- long mark = doc.makeBookmark(oldPage);
+ long mark = doc.makeBookmark(doc.locationFromPageNumber(oldPage));
doc.layout(layoutW, layoutH, layoutEM);
currentPage = -1;
pageCount = doc.countPages();
@@ -79,7 +79,7 @@
} catch (Exception ex) {
/* ignore error */
}
- return doc.findBookmark(mark);
+ return doc.pageNumberFromLocation(doc.findBookmark(mark));
}
return oldPage;
}
@@ -158,6 +158,10 @@
return page.getLinks();
}
+ public synchronized int resolveLink(Link link) {
+ return doc.pageNumberFromLocation(doc.resolveLink(link));
+ }
+
public synchronized Quad[] searchPage(int pageNum, String text) {
gotoPage(pageNum);
return page.search(text);
@@ -176,8 +180,10 @@
private void flattenOutlineNodes(ArrayList<OutlineActivity.Item> result, Outline list[], String indent) {
for (Outline node : list) {
- if (node.title != null)
- result.add(new OutlineActivity.Item(indent + node.title, node.page));
+ if (node.title != null) {
+ int page = doc.pageNumberFromLocation(doc.resolveLink(node));
+ result.add(new OutlineActivity.Item(indent + node.title, page));
+ }
if (node.down != null)
flattenOutlineNodes(result, node.down, indent + " ");
}
diff --git a/lib/src/main/java/com/artifex/mupdf/viewer/PageView.java b/lib/src/main/java/com/artifex/mupdf/viewer/PageView.java
index 7ca5610..f929270 100644
--- a/lib/src/main/java/com/artifex/mupdf/viewer/PageView.java
+++ b/lib/src/main/java/com/artifex/mupdf/viewer/PageView.java
@@ -12,6 +12,7 @@
import android.content.ClipData;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.graphics.Bitmap.Config;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -488,7 +489,18 @@
return true;
}
- public Link hitLink(float x, float y) {
+ public int hitLink(Link link) {
+ if (link.isExternal()) {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link.uri));
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); // API>=21: FLAG_ACTIVITY_NEW_DOCUMENT
+ mContext.startActivity(intent);
+ return 0;
+ } else {
+ return mCore.resolveLink(link);
+ }
+ }
+
+ public int 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
@@ -500,8 +512,8 @@
if (mLinks != null)
for (Link l: mLinks)
if (l.bounds.contains(docRelX, docRelY))
- return l;
- return null;
+ return hitLink(l);
+ return 0;
}
protected CancellableTaskDefinition<Void, Void> getDrawPageTask(final Bitmap bm, final int sizeX, final int sizeY,
diff --git a/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java b/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java
index 526769e..5fed6f1 100644
--- a/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java
+++ b/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java
@@ -7,7 +7,6 @@
import java.util.Stack;
import android.content.Context;
-import android.content.Intent;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
@@ -912,14 +911,11 @@
Link link = null;
if (!tapDisabled) {
PageView pageView = (PageView) getDisplayedView();
- if (mLinksEnabled && pageView != null && (link = pageView.hitLink(e.getX(), e.getY())) != null) {
- if (link.uri != null) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link.uri));
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); // API>=21: FLAG_ACTIVITY_NEW_DOCUMENT
- mContext.startActivity(intent);
- } else {
+ if (mLinksEnabled && pageView != null) {
+ int page = pageView.hitLink(e.getX(), e.getY());
+ if (page > 0) {
pushHistory();
- setDisplayedViewIndex(link.page);
+ setDisplayedViewIndex(page);
}
} else if (e.getX() < tapPageMargin) {
smartMoveBackwards();