summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorPaul Gardiner <paul@glidos.net>2012-04-26 16:37:12 +0100
committerPaul Gardiner <paul@glidos.net>2012-05-31 16:40:40 +0100
commitd9982f81e105d5e1084283225ed72b1943ca3693 (patch)
tree62279fc1e7295f5177dfa26ace0a5238e78a14f7 /android
parent09f4fac813c208229ba2d33334db2f84be679d58 (diff)
downloadmupdf-d9982f81e105d5e1084283225ed72b1943ca3693.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.java5
-rw-r--r--android/src/com/artifex/mupdf/PageView.java35
-rw-r--r--android/src/com/artifex/mupdf/ReaderView.java5
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);
}