diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-03-30 17:49:04 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-03-31 13:00:41 +0200 |
commit | d68576c3785572c1f5d41f83015b8fe6bbcbe9e8 (patch) | |
tree | 431a86edfac640864ba7f406611e8fe9929908cd /platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFPageAdapter.java | |
parent | 32cdb2246eeb9e8109a712ec2a5dd2938e30e9b6 (diff) | |
download | mupdf-d68576c3785572c1f5d41f83015b8fe6bbcbe9e8.tar.xz |
Reorganize java and android source.
platform/java and platform/android are reorganized:
platform/java
The new JNI Java classes, mupdf_native.{c,h}, Makefile and Makejar.
platform/java/example
The example desktop viewer classes.
platform/android/viewer
The original demo viewer.
ndk-build is used to build libmupdf_java.so,
making reference to mupdf_native.{c,h} in platform/java.
Diffstat (limited to 'platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFPageAdapter.java')
-rw-r--r-- | platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFPageAdapter.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFPageAdapter.java b/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFPageAdapter.java new file mode 100644 index 00000000..abdac845 --- /dev/null +++ b/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFPageAdapter.java @@ -0,0 +1,87 @@ +package com.artifex.mupdfdemo; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Point; +import android.graphics.PointF; +import android.util.SparseArray; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; + +public class MuPDFPageAdapter extends BaseAdapter { + private final Context mContext; + private final FilePicker.FilePickerSupport mFilePickerSupport; + private final MuPDFCore mCore; + private final SparseArray<PointF> mPageSizes = new SparseArray<PointF>(); + private Bitmap mSharedHqBm; + + public MuPDFPageAdapter(Context c, FilePicker.FilePickerSupport filePickerSupport, MuPDFCore core) { + mContext = c; + mFilePickerSupport = filePickerSupport; + mCore = core; + } + + public int getCount() { + return mCore.countPages(); + } + + public Object getItem(int position) { + return null; + } + + public long getItemId(int position) { + return 0; + } + + public void releaseBitmaps() + { + // recycle and release the shared bitmap. + if (mSharedHqBm!=null) + mSharedHqBm.recycle(); + mSharedHqBm = null; + } + + public View getView(final int position, View convertView, ViewGroup parent) { + final MuPDFPageView pageView; + if (convertView == null) { + if (mSharedHqBm == null || mSharedHqBm.getWidth() != parent.getWidth() || mSharedHqBm.getHeight() != parent.getHeight()) + mSharedHqBm = Bitmap.createBitmap(parent.getWidth(), parent.getHeight(), Bitmap.Config.ARGB_8888); + + pageView = new MuPDFPageView(mContext, mFilePickerSupport, mCore, new Point(parent.getWidth(), parent.getHeight()), mSharedHqBm); + } else { + pageView = (MuPDFPageView) convertView; + } + + PointF pageSize = mPageSizes.get(position); + if (pageSize != null) { + // We already know the page size. Set it up + // immediately + pageView.setPage(position, pageSize); + } else { + // Page size as yet unknown. Blank it for now, and + // start a background task to find the size + pageView.blank(position); + AsyncTask<Void,Void,PointF> sizingTask = new AsyncTask<Void,Void,PointF>() { + @Override + protected PointF doInBackground(Void... arg0) { + return mCore.getPageSize(position); + } + + @Override + protected void onPostExecute(PointF result) { + super.onPostExecute(result); + // We now know the page size + mPageSizes.put(position, result); + // Check that this view hasn't been reused for + // another page since we started + if (pageView.getPage() == position) + pageView.setPage(position, result); + } + }; + + sizingTask.execute((Void)null); + } + return pageView; + } +} |