summaryrefslogtreecommitdiff
path: root/android/src
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2012-10-11 11:38:32 +0100
committerPaul Gardiner <paulg.artifex@glidos.net>2012-10-11 11:38:32 +0100
commit84f84d86e6d7f079e12139fa3306c3bc71713f77 (patch)
treec97062f75ed879cd3cb8b7e08a0fb63be23030b2 /android/src
parenteae647babea3730d2af1d1882707db355bd660ac (diff)
downloadmupdf-84f84d86e6d7f079e12139fa3306c3bc71713f77.tar.xz
Android Forms: pass in mouse events and handle updating
Also add a function to report whether the core has javascript support, so that the additional features can be enabled only when the javascript engine is present
Diffstat (limited to 'android/src')
-rw-r--r--android/src/com/artifex/mupdf/MuPDFActivity.java38
-rw-r--r--android/src/com/artifex/mupdf/MuPDFCore.java42
-rw-r--r--android/src/com/artifex/mupdf/MuPDFPageView.java57
-rw-r--r--android/src/com/artifex/mupdf/PageView.java33
4 files changed, 141 insertions, 29 deletions
diff --git a/android/src/com/artifex/mupdf/MuPDFActivity.java b/android/src/com/artifex/mupdf/MuPDFActivity.java
index c530b01b..81d5e6ee 100644
--- a/android/src/com/artifex/mupdf/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdf/MuPDFActivity.java
@@ -212,26 +212,30 @@ public class MuPDFActivity extends Activity
private boolean showButtonsDisabled;
public boolean onSingleTapUp(MotionEvent e) {
- if (e.getX() < super.getWidth()/TAP_PAGE_MARGIN) {
- super.moveToPrevious();
- } else if (e.getX() > super.getWidth()*(TAP_PAGE_MARGIN-1)/TAP_PAGE_MARGIN) {
- super.moveToNext();
- } else if (!showButtonsDisabled) {
- int linkPage = -1;
- if (mLinkState != LinkState.INHIBIT) {
- MuPDFPageView pageView = (MuPDFPageView) mDocView.getDisplayedView();
- if (pageView != null) {
+ if (!showButtonsDisabled) {
+ MuPDFPageView pageView = (MuPDFPageView) mDocView.getDisplayedView();
+ if (MuPDFCore.javascriptSupported() && pageView.passClickEvent(e.getX(), e.getY())) {
+ // If the page consumes the event do nothing else
+ } else if (e.getX() < super.getWidth()/TAP_PAGE_MARGIN) {
+ super.moveToPrevious();
+ } else if (e.getX() > super.getWidth()*(TAP_PAGE_MARGIN-1)/TAP_PAGE_MARGIN) {
+ super.moveToNext();
+ } else {
+ int linkPage = -1;
+ if (mLinkState != LinkState.INHIBIT) {
+ if (pageView != null) {
// XXX linkPage = pageView.hitLinkPage(e.getX(), e.getY());
+ }
}
- }
- if (linkPage != -1) {
- mDocView.setDisplayedViewIndex(linkPage);
- } else {
- if (!mButtonsVisible) {
- showButtons();
+ if (linkPage != -1) {
+ mDocView.setDisplayedViewIndex(linkPage);
} else {
- hideButtons();
+ if (!mButtonsVisible) {
+ showButtons();
+ } else {
+ hideButtons();
+ }
}
}
}
@@ -284,7 +288,7 @@ public class MuPDFActivity extends Activity
protected void onSettle(View v) {
// When the layout has settled ask the page to render
// in HQ
- ((PageView)v).addHq();
+ ((PageView)v).addHq(false);
}
protected void onUnsettle(View v) {
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java
index b52a3682..e7653f9e 100644
--- a/android/src/com/artifex/mupdf/MuPDFCore.java
+++ b/android/src/com/artifex/mupdf/MuPDFCore.java
@@ -20,21 +20,26 @@ public class MuPDFCore
/* The native functions */
private static native int openFile(String filename);
private static native int countPagesInternal();
+ private static native void markDirtyInternal(int page);
private static native void gotoPageInternal(int localActionPageNum);
private static native float getPageWidth();
private static native float getPageHeight();
- public static native void drawPage(Bitmap bitmap,
+ private static native void drawPage(Bitmap bitmap,
int pageW, int pageH,
int patchX, int patchY,
int patchW, int patchH);
- public static native RectF[] searchPage(String text);
- public static native int getPageLink(int page, float x, float y);
- public static native LinkInfo [] getPageLinksInternal(int page);
- public static native OutlineItem [] getOutlineInternal();
- public static native boolean hasOutlineInternal();
- public static native boolean needsPasswordInternal();
- public static native boolean authenticatePasswordInternal(String password);
- public static native void destroying();
+ private static native RectF[] searchPage(String text);
+ private static native int getPageLink(int page, float x, float y);
+ private static native int passClickEventInternal(int page, float x, float y);
+ private static native LinkInfo [] getPageLinksInternal(int page);
+ private static native RectF[] getWidgetAreasInternal(int page);
+ private static native OutlineItem [] getOutlineInternal();
+ private static native boolean hasOutlineInternal();
+ private static native boolean needsPasswordInternal();
+ private static native boolean authenticatePasswordInternal(String password);
+ private static native void destroying();
+
+ public static native boolean javascriptSupported();
public MuPDFCore(String filename) throws Exception
{
@@ -57,7 +62,7 @@ public class MuPDFCore
}
/* Shim function */
- public void gotoPage(int page)
+ private void gotoPage(int page)
{
if (page > numPages-1)
page = numPages-1;
@@ -90,6 +95,19 @@ public class MuPDFCore
return bm;
}
+ public synchronized boolean passClickEvent(int page, float x, float y) {
+ boolean changed = passClickEventInternal(page, x, y) != 0;
+
+ if (changed) {
+ if (page == pageNum)
+ pageNum = -1;
+
+ markDirtyInternal(page);
+ }
+
+ return changed;
+ }
+
public synchronized int hitLinkPage(int page, float x, float y) {
return getPageLink(page, x, y);
}
@@ -98,6 +116,10 @@ public class MuPDFCore
return getPageLinksInternal(page);
}
+ public synchronized RectF [] getWidgetAreas(int page) {
+ return getWidgetAreasInternal(page);
+ }
+
public synchronized RectF [] searchPage(int page, String text) {
gotoPage(page);
return searchPage(text);
diff --git a/android/src/com/artifex/mupdf/MuPDFPageView.java b/android/src/com/artifex/mupdf/MuPDFPageView.java
index 6294bc55..9cb430ef 100644
--- a/android/src/com/artifex/mupdf/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdf/MuPDFPageView.java
@@ -3,9 +3,14 @@ package com.artifex.mupdf;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
+import android.graphics.PointF;
+import android.graphics.RectF;
public class MuPDFPageView extends PageView {
private final MuPDFCore mCore;
+ private SafeAsyncTask<Void,Void,Boolean> mPassClick;
+ private RectF mWidgetAreas[];
+ private SafeAsyncTask<Void,Void,RectF[]> mLoadWidgetAreas;
public MuPDFPageView(Context c, MuPDFCore core, Point parentSize) {
super(c, parentSize);
@@ -24,6 +29,39 @@ public class MuPDFPageView extends PageView {
return mCore.hitLinkPage(mPageNumber, docRelX, docRelY);
}
+ public boolean 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;
+ boolean hitWidget = false;
+
+ if (mWidgetAreas != null) {
+ for (int i = 0; i < mWidgetAreas.length && !hitWidget; i++)
+ if (mWidgetAreas[i].contains(docRelX, docRelY))
+ hitWidget = true;
+ }
+
+ if (hitWidget) {
+ mPassClick = new SafeAsyncTask<Void,Void,Boolean>() {
+ @Override
+ protected Boolean doInBackground(Void... arg0) {
+ return mCore.passClickEvent(mPageNumber, docRelX, docRelY);
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ if (result) {
+ update();
+ }
+ }
+ };
+
+ mPassClick.execute();
+ }
+
+ return hitWidget;
+ }
+
@Override
protected Bitmap drawPage(int sizeX, int sizeY,
int patchX, int patchY, int patchWidth, int patchHeight) {
@@ -34,4 +72,23 @@ public class MuPDFPageView extends PageView {
protected LinkInfo[] getLinkInfo() {
return mCore.getPageLinks(mPageNumber);
}
+
+ @Override
+ public void setPage(final int page, PointF size) {
+ mLoadWidgetAreas = new SafeAsyncTask<Void,Void,RectF[]> () {
+ @Override
+ protected RectF[] doInBackground(Void... arg0) {
+ return mCore.getWidgetAreas(page);
+ }
+
+ @Override
+ protected void onPostExecute(RectF[] result) {
+ mWidgetAreas = result;
+ }
+ };
+
+ mLoadWidgetAreas.execute();
+
+ super.setPage(page, size);
+ }
}
diff --git a/android/src/com/artifex/mupdf/PageView.java b/android/src/com/artifex/mupdf/PageView.java
index 32ff7e74..072036f4 100644
--- a/android/src/com/artifex/mupdf/PageView.java
+++ b/android/src/com/artifex/mupdf/PageView.java
@@ -317,7 +317,7 @@ public abstract class PageView extends ViewGroup {
}
}
- public void addHq() {
+ public void addHq(boolean force) {
Rect viewArea = new Rect(getLeft(),getTop(),getRight(),getBottom());
// If the viewArea's size matches the unzoomed size, there is no need for an hq patch
if (viewArea.width() != mSize.x || viewArea.height() != mSize.y) {
@@ -332,7 +332,7 @@ public abstract class PageView extends ViewGroup {
patchArea.offset(-viewArea.left, -viewArea.top);
// If being asked for the same area as last time, nothing to do
- if (patchArea.equals(mPatchArea) && patchViewSize.equals(mPatchViewSize))
+ if (patchArea.equals(mPatchArea) && patchViewSize.equals(mPatchViewSize) && !force)
return;
// Stop the drawing of previous patch if still going
@@ -373,6 +373,35 @@ public abstract class PageView extends ViewGroup {
}
}
+ public void update() {
+ // Cancel pending render task
+ if (mDrawEntire != null) {
+ mDrawEntire.cancel(true);
+ mDrawEntire = null;
+ }
+
+ if (mDrawPatch != null) {
+ mDrawPatch.cancel(true);
+ mDrawPatch = null;
+ }
+
+ // Render the page in the background
+ mDrawEntire = new SafeAsyncTask<Void,Void,Bitmap>() {
+ protected Bitmap doInBackground(Void... v) {
+ return drawPage(mSize.x, mSize.y, 0, 0, mSize.x, mSize.y);
+ }
+
+ protected void onPostExecute(Bitmap bm) {
+ mEntire.setImageBitmap(bm);
+ invalidate();
+ }
+ };
+
+ mDrawEntire.safeExecute();
+
+ addHq(true);
+ }
+
public void removeHq() {
// Stop the drawing of the patch if still going
if (mDrawPatch != null) {