summaryrefslogtreecommitdiff
path: root/android/src/com/artifex
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2013-02-04 14:44:47 +0000
committerPaul Gardiner <paulg.artifex@glidos.net>2013-02-04 14:44:47 +0000
commit21f987ab2584486d68e97029f2c932e88a35a1a6 (patch)
tree27d6287c313236eee159d35d4baaf1f2997b7475 /android/src/com/artifex
parent05f86ac0cfd2dca99e27120a5e35db6cba703eec (diff)
downloadmupdf-21f987ab2584486d68e97029f2c932e88a35a1a6.tar.xz
Android: add hooks for zooming in reflow mode
Diffstat (limited to 'android/src/com/artifex')
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFActivity.java5
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFPageView.java5
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFReflowView.java3
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFView.java1
-rw-r--r--android/src/com/artifex/mupdfdemo/ReaderView.java33
5 files changed, 37 insertions, 10 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index f627cc0f..3617f9f2 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -561,6 +561,11 @@ public class MuPDFActivity extends Activity
protected void onNotInUse(View v) {
((MuPDFView)v).releaseResources();
}
+
+ @Override
+ protected void onScaleChild(View v, Float scale) {
+ ((MuPDFView)v).setScale(scale);
+ }
};
mDocView.setAdapter(new MuPDFPageAdapter(this, core));
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
index 9dcae615..cf5e1af5 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
@@ -245,4 +245,9 @@ public class MuPDFPageView extends PageView implements MuPDFView {
super.setPage(page, size);
}
+
+ public void setScale(float scale) {
+ // This type of view scales automatically to fit the size
+ // determined by the parent view groups during layout
+ }
}
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
index 8a26c8e6..e5992e46 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
@@ -66,6 +66,9 @@ public class MuPDFReflowView extends WebView implements MuPDFView {
return mPage;
}
+ public void setScale(float scale) {
+ }
+
public void blank(int page) {
}
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFView.java b/android/src/com/artifex/mupdfdemo/MuPDFView.java
index 4be7f271..919ac516 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFView.java
@@ -6,6 +6,7 @@ import android.graphics.RectF;
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);
diff --git a/android/src/com/artifex/mupdfdemo/ReaderView.java b/android/src/com/artifex/mupdfdemo/ReaderView.java
index 78eef71c..f16b39b3 100644
--- a/android/src/com/artifex/mupdfdemo/ReaderView.java
+++ b/android/src/com/artifex/mupdfdemo/ReaderView.java
@@ -315,6 +315,8 @@ public class ReaderView extends AdapterView<Adapter>
protected void onNotInUse(View v) {};
+ protected void onScaleChild(View v, Float scale) {};
+
public View getDisplayedView() {
return mChildViews.get(mCurrent);
}
@@ -423,17 +425,27 @@ public class ReaderView extends AdapterView<Adapter>
public boolean onScale(ScaleGestureDetector detector) {
float previousScale = mScale;
mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE);
- float factor = mScale/previousScale;
- View v = mChildViews.get(mCurrent);
- if (v != null) {
- // Work out the focus point relative to the view top left
- int viewFocusX = (int)detector.getFocusX() - (v.getLeft() + mXScroll);
- int viewFocusY = (int)detector.getFocusY() - (v.getTop() + mYScroll);
- // Scroll to maintain the focus point
- mXScroll += viewFocusX - viewFocusX * factor;
- mYScroll += viewFocusY - viewFocusY * factor;
- requestLayout();
+ if (mReflow) {
+ applyToChildren(new ViewMapper() {
+ @Override
+ void applyToView(View view) {
+ onScaleChild(view, mScale);
+ }
+ });
+ } else {
+ float factor = mScale/previousScale;
+
+ View v = mChildViews.get(mCurrent);
+ if (v != null) {
+ // Work out the focus point relative to the view top left
+ int viewFocusX = (int)detector.getFocusX() - (v.getLeft() + mXScroll);
+ int viewFocusY = (int)detector.getFocusY() - (v.getTop() + mYScroll);
+ // Scroll to maintain the focus point
+ mXScroll += viewFocusX - viewFocusX * factor;
+ mYScroll += viewFocusY - viewFocusY * factor;
+ requestLayout();
+ }
}
return true;
}
@@ -664,6 +676,7 @@ public class ReaderView extends AdapterView<Adapter>
addAndMeasureChild(i, v);
}
onChildSetup(i, v);
+ onScaleChild(v, mScale);
return v;
}