diff options
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFCore.java | 11 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFPageView.java | 9 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/PageView.java | 79 |
3 files changed, 54 insertions, 45 deletions
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java index 21a22fc2..bcef1605 100644 --- a/android/src/com/artifex/mupdf/MuPDFCore.java +++ b/android/src/com/artifex/mupdf/MuPDFCore.java @@ -119,7 +119,7 @@ public class MuPDFCore globals = 0; } - public synchronized void drawPage(BitmapHolder h, int page, + public synchronized Bitmap drawPage(BitmapHolder h, int page, int pageW, int pageH, int patchX, int patchY, int patchW, int patchH) { @@ -128,10 +128,10 @@ public class MuPDFCore h.setBm(null); Bitmap bm = Bitmap.createBitmap(patchW, patchH, Config.ARGB_8888); drawPage(bm, pageW, pageH, patchX, patchY, patchW, patchH); - h.setBm(bm); + return bm; } - public synchronized void updatePage(BitmapHolder h, int page, + public synchronized Bitmap updatePage(BitmapHolder h, int page, int pageW, int pageH, int patchX, int patchY, int patchW, int patchH) { @@ -139,14 +139,13 @@ public class MuPDFCore Bitmap old_bm = h.getBm(); if (old_bm == null) - return; + return null; bm = old_bm.copy(Bitmap.Config.ARGB_8888, false); old_bm = null; - h.setBm(bm); - updatePageInternal(bm, page, pageW, pageH, patchX, patchY, patchW, patchH); + return bm; } public synchronized PassClickResult passClickEvent(int page, float x, float y) { diff --git a/android/src/com/artifex/mupdf/MuPDFPageView.java b/android/src/com/artifex/mupdf/MuPDFPageView.java index 8360ba09..3e4ba70f 100644 --- a/android/src/com/artifex/mupdf/MuPDFPageView.java +++ b/android/src/com/artifex/mupdf/MuPDFPageView.java @@ -3,6 +3,7 @@ package com.artifex.mupdf; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Bitmap; import android.graphics.Point; import android.graphics.PointF; import android.graphics.RectF; @@ -200,15 +201,15 @@ public class MuPDFPageView extends PageView { } @Override - protected void drawPage(BitmapHolder h, int sizeX, int sizeY, + protected Bitmap drawPage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight) { - mCore.drawPage(h, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight); + return mCore.drawPage(h, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight); } @Override - protected void updatePage(BitmapHolder h, int sizeX, int sizeY, + protected Bitmap updatePage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight) { - mCore.updatePage(h, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight); + return mCore.updatePage(h, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight); } @Override diff --git a/android/src/com/artifex/mupdf/PageView.java b/android/src/com/artifex/mupdf/PageView.java index 53f35fcf..04383796 100644 --- a/android/src/com/artifex/mupdf/PageView.java +++ b/android/src/com/artifex/mupdf/PageView.java @@ -6,6 +6,7 @@ import java.util.Iterator; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; @@ -19,13 +20,15 @@ import android.widget.ImageView; import android.widget.ProgressBar; class PatchInfo { - public BitmapHolder bm; + public BitmapHolder bmh; + public Bitmap bm; public Point patchViewSize; public Rect patchArea; public boolean completeRedraw; - public PatchInfo(Point aPatchViewSize, Rect aPatchArea, BitmapHolder aBm, boolean aCompleteRedraw) { - bm = aBm; + public PatchInfo(Point aPatchViewSize, Rect aPatchArea, BitmapHolder aBmh, boolean aCompleteRedraw) { + bmh = aBmh; + bm = null; patchViewSize = aPatchViewSize; patchArea = aPatchArea; completeRedraw = aCompleteRedraw; @@ -107,15 +110,15 @@ public abstract class PageView extends ViewGroup { protected float mSourceScale; private ImageView mEntire; // Image rendered at minimum zoom - private BitmapHolder mEntireBm; + private BitmapHolder mEntireBmh; private AsyncTask<Void,Void,TextWord[][]> mGetText; private AsyncTask<Void,Void,LinkInfo[]> mGetLinkInfo; - private AsyncTask<Void,Void,Void> mDrawEntire; + private AsyncTask<Void,Void,Bitmap> mDrawEntire; private Point mPatchViewSize; // View size on the basis of which the patch was created private Rect mPatchArea; private ImageView mPatch; - private BitmapHolder mPatchBm; + private BitmapHolder mPatchBmh; private AsyncTask<PatchInfo,Void,PatchInfo> mDrawPatch; private RectF mSearchBoxes[]; protected LinkInfo mLinks[]; @@ -133,12 +136,12 @@ public abstract class PageView extends ViewGroup { mContext = c; mParentSize = parentSize; setBackgroundColor(BACKGROUND_COLOR); - mEntireBm = new BitmapHolder(); - mPatchBm = new BitmapHolder(); + mEntireBmh = new BitmapHolder(); + mPatchBmh = new BitmapHolder(); } - protected abstract void drawPage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight); - protected abstract void updatePage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight); + protected abstract Bitmap drawPage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight); + protected abstract Bitmap updatePage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight); protected abstract LinkInfo[] getLinkInfo(); protected abstract TextWord[][] getText(); @@ -171,13 +174,13 @@ public abstract class PageView extends ViewGroup { mSize = mParentSize; if (mEntire != null) { - mEntireBm.setBm(null); mEntire.setImageBitmap(null); + mEntireBmh.setBm(null); } if (mPatch != null) { - mPatchBm.setBm(null); mPatch.setImageBitmap(null); + mPatchBmh.setBm(null); } mPatchViewSize = null; @@ -232,8 +235,8 @@ public abstract class PageView extends ViewGroup { Point newSize = new Point((int)(size.x*mSourceScale), (int)(size.y*mSourceScale)); mSize = newSize; - mEntireBm.setBm(null); mEntire.setImageBitmap(null); + mEntireBmh.setBm(null); // Get the link info in the background mGetLinkInfo = new AsyncTask<Void,Void,LinkInfo[]>() { @@ -250,15 +253,14 @@ public abstract class PageView extends ViewGroup { mGetLinkInfo.execute(); // Render the page in the background - mDrawEntire = new AsyncTask<Void,Void,Void>() { - protected Void doInBackground(Void... v) { - drawPage(mEntireBm, mSize.x, mSize.y, 0, 0, mSize.x, mSize.y); - return null; + mDrawEntire = new AsyncTask<Void,Void,Bitmap>() { + protected Bitmap doInBackground(Void... v) { + return drawPage(mEntireBmh, mSize.x, mSize.y, 0, 0, mSize.x, mSize.y); } protected void onPreExecute() { - mEntireBm.setBm(null); mEntire.setImageBitmap(null); + mEntireBmh.setBm(null); if (mBusyIndicator == null) { mBusyIndicator = new ProgressBar(mContext); @@ -275,10 +277,11 @@ public abstract class PageView extends ViewGroup { } } - protected void onPostExecute(Void v) { + protected void onPostExecute(Bitmap bm) { removeView(mBusyIndicator); mBusyIndicator = null; - mEntire.setImageBitmap(mEntireBm.getBm()); + mEntire.setImageBitmap(bm); + mEntireBmh.setBm(bm); invalidate(); } }; @@ -477,8 +480,8 @@ public abstract class PageView extends ViewGroup { mPatchViewSize = null; mPatchArea = null; if (mPatch != null) { - mPatchBm.setBm(null); mPatch.setImageBitmap(null); + mPatchBmh.setBm(null); } } else { mPatch.layout(mPatchArea.left, mPatchArea.top, mPatchArea.right, mPatchArea.bottom); @@ -526,8 +529,8 @@ public abstract class PageView extends ViewGroup { // previously invoked task, and possibly for a different // area, so we cannot risk the bitmap generated by this task // being passed to it - mPatchBm.setBm(null); - mPatchBm = new BitmapHolder(); + mPatchBmh.setBm(null); + mPatchBmh = new BitmapHolder(); } // Create and add the image view if not already done @@ -541,11 +544,11 @@ public abstract class PageView extends ViewGroup { mDrawPatch = new AsyncTask<PatchInfo,Void,PatchInfo>() { protected PatchInfo doInBackground(PatchInfo... v) { if (v[0].completeRedraw) { - drawPage(v[0].bm, v[0].patchViewSize.x, v[0].patchViewSize.y, + v[0].bm = drawPage(v[0].bmh, v[0].patchViewSize.x, v[0].patchViewSize.y, v[0].patchArea.left, v[0].patchArea.top, v[0].patchArea.width(), v[0].patchArea.height()); } else { - updatePage(v[0].bm, v[0].patchViewSize.x, v[0].patchViewSize.y, + v[0].bm = updatePage(v[0].bmh, v[0].patchViewSize.x, v[0].patchViewSize.y, v[0].patchArea.left, v[0].patchArea.top, v[0].patchArea.width(), v[0].patchArea.height()); } @@ -554,10 +557,14 @@ public abstract class PageView extends ViewGroup { } protected void onPostExecute(PatchInfo v) { - if (mPatchBm == v.bm) { + if (mPatchBmh == v.bmh) { mPatchViewSize = v.patchViewSize; mPatchArea = v.patchArea; - mPatch.setImageBitmap(v.bm.getBm()); + if (v.bm != null) { + mPatch.setImageBitmap(v.bm); + v.bmh.setBm(v.bm); + v.bm = null; + } //requestLayout(); // Calling requestLayout here doesn't lead to a later call to layout. No idea // why, but apparently others have run into the problem. @@ -567,7 +574,7 @@ public abstract class PageView extends ViewGroup { } }; - mDrawPatch.execute(new PatchInfo(patchViewSize, patchArea, mPatchBm, completeRedraw)); + mDrawPatch.execute(new PatchInfo(patchViewSize, patchArea, mPatchBmh, completeRedraw)); } } @@ -584,17 +591,19 @@ public abstract class PageView extends ViewGroup { } // Render the page in the background - mDrawEntire = new AsyncTask<Void,Void,Void>() { - protected Void doInBackground(Void... v) { + mDrawEntire = new AsyncTask<Void,Void,Bitmap>() { + protected Bitmap doInBackground(Void... v) { // Pass the current bitmap as a basis for the update, but use a bitmap // holder so that the held bitmap will be nulled and not hold on to // memory, should this view become redundant. - updatePage(mEntireBm, mSize.x, mSize.y, 0, 0, mSize.x, mSize.y); - return null; + return updatePage(mEntireBmh, mSize.x, mSize.y, 0, 0, mSize.x, mSize.y); } - protected void onPostExecute(Void v) { - mEntire.setImageBitmap(mEntireBm.getBm()); + protected void onPostExecute(Bitmap bm) { + if (bm != null) { + mEntire.setImageBitmap(bm); + mEntireBmh.setBm(bm); + } invalidate(); } }; @@ -615,8 +624,8 @@ public abstract class PageView extends ViewGroup { mPatchViewSize = null; mPatchArea = null; if (mPatch != null) { - mPatchBm.setBm(null); mPatch.setImageBitmap(null); + mPatchBmh.setBm(null); } } |