diff options
author | Paul Gardiner <paul@glidos.net> | 2012-04-26 16:37:12 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-06-12 16:55:53 +0100 |
commit | 6fcc55dfd7bf4b25c62ca8d405b5ec0f47ee9909 (patch) | |
tree | 533664c73e16615f7a62fff07ca127b2ca86231a /android | |
parent | 15f43c4cccc960559ea6967c7fe1439cde54b0aa (diff) | |
download | mupdf-6fcc55dfd7bf4b25c62ca8d405b5ec0f47ee9909.tar.xz |
Android app: explicitly release resources when page moves out of cache area
Diffstat (limited to 'android')
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFActivity.java | 5 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/PageView.java | 35 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/ReaderView.java | 5 |
3 files changed, 44 insertions, 1 deletions
diff --git a/android/src/com/artifex/mupdf/MuPDFActivity.java b/android/src/com/artifex/mupdf/MuPDFActivity.java index bdc1971f..5696ea0b 100644 --- a/android/src/com/artifex/mupdf/MuPDFActivity.java +++ b/android/src/com/artifex/mupdf/MuPDFActivity.java @@ -289,6 +289,11 @@ public class MuPDFActivity extends Activity // no longer appropriate, tell the page to remove HQ ((PageView)v).removeHq(); } + + @Override + protected void onNotInUse(View v) { + ((PageView)v).releaseResources(); + } }; mDocView.setAdapter(new MuPDFPageAdapter(this, core)); diff --git a/android/src/com/artifex/mupdf/PageView.java b/android/src/com/artifex/mupdf/PageView.java index 123d5037..7a0fcfa9 100644 --- a/android/src/com/artifex/mupdf/PageView.java +++ b/android/src/com/artifex/mupdf/PageView.java @@ -81,6 +81,36 @@ public abstract class PageView extends ViewGroup { protected abstract void drawPage(Bitmap bm, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight); protected abstract LinkInfo[] getLinkInfo(); + public void releaseResources() { + // Cancel pending render task + if (mDrawEntire != null) { + mDrawEntire.cancel(true); + mDrawEntire = null; + } + + if (mDrawPatch != null) { + mDrawPatch.cancel(true); + mDrawPatch = null; + } + + mIsBlank = true; + mPageNumber = 0; + + if (mSize == null) + mSize = mParentSize; + + if (mEntire != null) + mEntire.setImageBitmap(null); + + if (mPatch != null) + mPatch.setImageBitmap(null); + + if (mBusyIndicator != null) { + removeView(mBusyIndicator); + mBusyIndicator = null; + } + } + public void blank(int page) { // Cancel pending render task if (mDrawEntire != null) { @@ -88,6 +118,11 @@ public abstract class PageView extends ViewGroup { mDrawEntire = null; } + if (mDrawPatch != null) { + mDrawPatch.cancel(true); + mDrawPatch = null; + } + mIsBlank = true; mPageNumber = page; diff --git a/android/src/com/artifex/mupdf/ReaderView.java b/android/src/com/artifex/mupdf/ReaderView.java index 76bf0eee..fc031471 100644 --- a/android/src/com/artifex/mupdf/ReaderView.java +++ b/android/src/com/artifex/mupdf/ReaderView.java @@ -115,6 +115,8 @@ public class ReaderView extends AdapterView<Adapter> protected void onUnsettle(View v) {}; + protected void onNotInUse(View v) {}; + public View getDisplayedView() { return mChildViews.get(mCurrent); } @@ -342,6 +344,7 @@ public class ReaderView extends AdapterView<Adapter> int ai = childIndices[i]; if (ai < mCurrent - 1 || ai > mCurrent + 1) { View v = mChildViews.get(ai); + onNotInUse(v); mViewCache.add(v); removeViewInLayout(v); mChildViews.remove(ai); @@ -355,7 +358,7 @@ public class ReaderView extends AdapterView<Adapter> int numChildren = mChildViews.size(); for (int i = 0; i < numChildren; i++) { View v = mChildViews.valueAt(i); - postUnsettle(v); + onNotInUse(v); mViewCache.add(v); removeViewInLayout(v); } |