diff options
author | fredrossperry <fredrossperry@gmail.com> | 2016-06-23 13:32:36 -0700 |
---|---|---|
committer | fredrossperry <fredrossperry@gmail.com> | 2016-07-06 11:14:49 -0700 |
commit | 01d5f0bc4185c001179ca6fd36530516acc16eeb (patch) | |
tree | 53622c9ef5aea76a6e781fb18380138d9f70d9bb /platform/android/example/app/src/main/java/com | |
parent | cb894e713b2f60fef0a7e83ccb3a3d29589193bc (diff) | |
download | mupdf-01d5f0bc4185c001179ca6fd36530516acc16eeb.tar.xz |
Android example: modify to use new JNI, N-up page display
- uses AndroidDrawDevice for rendering
- very simple sample app
- mupdf-specific functionality in a module called "mupdf"
- N-up page display
- page rendering in a background task
Signed-off-by: fredrossperry <fredrossperry@gmail.com>
Diffstat (limited to 'platform/android/example/app/src/main/java/com')
-rw-r--r-- | platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java | 93 |
1 files changed, 9 insertions, 84 deletions
diff --git a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java index a0e989ff..32f2cecd 100644 --- a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java +++ b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java @@ -1,105 +1,30 @@ package com.artifex.mupdf.example; import android.app.Activity; -import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; -import com.artifex.mupdf.fitz.ColorSpace; -import com.artifex.mupdf.fitz.Document; -import com.artifex.mupdf.fitz.Matrix; -import com.artifex.mupdf.fitz.Page; -import com.artifex.mupdf.fitz.Pixmap; +import com.artifex.mupdf.android.DocView; public class DocViewActivity extends Activity { - private int mPageCount; - private int mCurrentPage; - - Document mDocument; - Page mPage; - Bitmap mBitmap = null; - - ImageView mImageView; - TextView mTextView; + private DocView mDocView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_doc_view); - mImageView = (ImageView)findViewById(R.id.image_view); - mTextView = (TextView)findViewById(R.id.page_text); + // set up UI + setContentView(R.layout.activity_doc_view); + mDocView = (DocView)findViewById(R.id.doc_view); - // load the doc + // get the file path Uri uri = getIntent().getData(); - String path = Uri.decode(uri.getEncodedPath()); - mDocument = new Document(path); - mPageCount = mDocument.countPages(); - - // show the first page - mCurrentPage = 0; - displayCurrentPage(); - } + final String path = Uri.decode(uri.getEncodedPath()); - public void onFirstPageButton(final View v) - { - mCurrentPage = 0; - displayCurrentPage(); - } - - public void onPreviousPageButton(final View v) - { - if (mCurrentPage > 0) - { - mCurrentPage--; - displayCurrentPage(); - } + // start the view + mDocView.start(path); } - public void onNextPageButton(final View v) - { - if (mCurrentPage < mPageCount-1) - { - mCurrentPage++; - displayCurrentPage(); - } - } - - public void onLastPageButton(final View v) - { - mCurrentPage = mPageCount-1; - displayCurrentPage(); - } - - private void displayCurrentPage() - { - // report the page number - mTextView.setText(String.format("page %d of %d",mCurrentPage+1,mPageCount)); - - // get the page - mPage = mDocument.loadPage(mCurrentPage); - - // create a matrix that renders at 300 DPI - Matrix m = new Matrix(); - m.scale(300.0f/72.0f); - - // create a new bitmap for the page - Bitmap old = mBitmap; - Pixmap pixmap = mPage.toPixmap(m, ColorSpace.DeviceBGR); - mBitmap = Bitmap.createBitmap(pixmap.getWidth(), pixmap.getHeight(), Bitmap.Config.ARGB_8888); - int [] pixels = pixmap.getPixels(); - mBitmap.setPixels(pixels, 0, pixmap.getWidth(), 0, 0, pixmap.getWidth(), pixmap.getHeight()); - - // set the bitmap in the UI - mImageView.setImageBitmap(mBitmap); - - // recycle the old bitmap - if (old!=null) - old.recycle(); - } } |