From 21f987ab2584486d68e97029f2c932e88a35a1a6 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Mon, 4 Feb 2013 14:44:47 +0000 Subject: Android: add hooks for zooming in reflow mode --- .../src/com/artifex/mupdfdemo/MuPDFActivity.java | 5 ++++ .../src/com/artifex/mupdfdemo/MuPDFPageView.java | 5 ++++ .../src/com/artifex/mupdfdemo/MuPDFReflowView.java | 3 ++ android/src/com/artifex/mupdfdemo/MuPDFView.java | 1 + android/src/com/artifex/mupdfdemo/ReaderView.java | 33 +++++++++++++++------- 5 files changed, 37 insertions(+), 10 deletions(-) (limited to 'android/src/com/artifex/mupdfdemo') 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 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 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 addAndMeasureChild(i, v); } onChildSetup(i, v); + onScaleChild(v, mScale); return v; } -- cgit v1.2.3