summaryrefslogtreecommitdiff
path: root/platform/android/src/com
diff options
context:
space:
mode:
authorPaul Gardiner <paul.gardiner@artifex.com>2013-12-18 15:09:08 +0000
committerPaul Gardiner <paul.gardiner@artifex.com>2013-12-18 15:12:29 +0000
commite87dc713a74d9d0ab18931e8dd9633ea80767fc3 (patch)
treeeacf5090f4f7fa1bd97e5ad9b4bd813f19cd9e5d /platform/android/src/com
parent2f264787e9dac0fdcbadfe431f549f18b4d3aafb (diff)
downloadmupdf-e87dc713a74d9d0ab18931e8dd9633ea80767fc3.tar.xz
Android: a few improvements to the view handling
While scrolling, avoid some overheads to do with image scaling that need updating only on a zoom-level change Remove a pointless invalidate call. Avoid calls to removeViewInLayout and removeAllViewsInLayout that were being made in functions not called from onLayout
Diffstat (limited to 'platform/android/src/com')
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/PageView.java9
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/ReaderView.java22
2 files changed, 16 insertions, 15 deletions
diff --git a/platform/android/src/com/artifex/mupdfdemo/PageView.java b/platform/android/src/com/artifex/mupdfdemo/PageView.java
index cc00e004..3e30d1e5 100644
--- a/platform/android/src/com/artifex/mupdfdemo/PageView.java
+++ b/platform/android/src/com/artifex/mupdfdemo/PageView.java
@@ -539,9 +539,11 @@ public abstract class PageView extends ViewGroup {
int h = bottom-top;
if (mEntire != null) {
- mEntireMat.setScale(w/(float)mSize.x, h/(float)mSize.y);
- mEntire.setImageMatrix(mEntireMat);
- mEntire.invalidate();
+ if (mEntire.getWidth() != w || mEntire.getHeight() != h) {
+ mEntireMat.setScale(w/(float)mSize.x, h/(float)mSize.y);
+ mEntire.setImageMatrix(mEntireMat);
+ mEntire.invalidate();
+ }
mEntire.layout(0, 0, w, h);
}
@@ -631,7 +633,6 @@ public abstract class PageView extends ViewGroup {
// Calling requestLayout here doesn't lead to a later call to layout. No idea
// why, but apparently others have run into the problem.
mPatch.layout(mPatchArea.left, mPatchArea.top, mPatchArea.right, mPatchArea.bottom);
- invalidate();
}
};
diff --git a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java
index f779372b..fe183945 100644
--- a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java
+++ b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java
@@ -47,6 +47,7 @@ public class ReaderView
private int mXScroll; // Scroll amounts recorded from events.
private int mYScroll; // and then accounted for in onLayout
private boolean mReflow = false;
+ private boolean mReflowChanged = false;
private final GestureDetector
mGestureDetector;
private final ScaleGestureDetector
@@ -289,19 +290,12 @@ public class ReaderView
public void refresh(boolean reflow) {
mReflow = reflow;
+ mReflowChanged = true;
+ mResetLayout = true;
mScale = 1.0f;
mXScroll = mYScroll = 0;
- int numChildren = mChildViews.size();
- for (int i = 0; i < numChildren; i++) {
- View v = mChildViews.valueAt(i);
- onNotInUse(v);
- removeViewInLayout(v);
- }
- mChildViews.clear();
- mViewCache.clear();
-
requestLayout();
}
@@ -590,6 +584,13 @@ public class ReaderView
removeViewInLayout(v);
}
mChildViews.clear();
+
+ // Don't reuse cached views if the adapter has changed
+ if (mReflowChanged) {
+ mReflowChanged = false;
+ mViewCache.clear();
+ }
+
// post to ensure generation of hq area
post(this);
}
@@ -668,8 +669,7 @@ public class ReaderView
@Override
public void setAdapter(Adapter adapter) {
mAdapter = adapter;
- mChildViews.clear();
- removeAllViewsInLayout();
+
requestLayout();
}