From 01d5f0bc4185c001179ca6fd36530516acc16eeb Mon Sep 17 00:00:00 2001 From: fredrossperry Date: Thu, 23 Jun 2016 13:32:36 -0700 Subject: 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 --- platform/android/example/.gitignore | 10 + platform/android/example/README | 12 - platform/android/example/app/.gitignore | 1 + platform/android/example/app/build.gradle | 64 +- .../example/app/src/main/AndroidManifest.xml | 2 +- .../com/artifex/mupdf/example/DocViewActivity.java | 93 +-- .../app/src/main/res/layout/activity_doc_view.xml | 60 +- platform/android/example/build.gradle | 27 +- platform/android/example/local.properties.sample | 5 - platform/android/example/mupdf/.gitignore | 1 + platform/android/example/mupdf/build.gradle | 80 +- .../example/mupdf/src/main/AndroidManifest.xml | 18 +- .../com/artifex/mupdf/android/DocPageView.java | 462 +++++++++++ .../java/com/artifex/mupdf/android/DocView.java | 918 +++++++++++++++++++++ .../com/artifex/mupdf/android/PageAdapter.java | 61 ++ .../com/artifex/mupdf/android/RenderListener.java | 6 + .../java/com/artifex/mupdf/android/Stepper.java | 42 + .../com/artifex/mupdf/fitz/AndroidDrawDevice.java | 25 + .../example/mupdf/src/main/res/values/strings.xml | 2 +- platform/java/mupdf_native.c | 7 +- 20 files changed, 1626 insertions(+), 270 deletions(-) create mode 100644 platform/android/example/.gitignore delete mode 100644 platform/android/example/README create mode 100644 platform/android/example/app/.gitignore delete mode 100644 platform/android/example/local.properties.sample create mode 100644 platform/android/example/mupdf/.gitignore create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/PageAdapter.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/RenderListener.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/Stepper.java create mode 100644 platform/android/example/mupdf/src/main/java/com/artifex/mupdf/fitz/AndroidDrawDevice.java diff --git a/platform/android/example/.gitignore b/platform/android/example/.gitignore new file mode 100644 index 00000000..c474948d --- /dev/null +++ b/platform/android/example/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/* +.DS_Store +/build +/captures +/gradle +/gradlew +/gradlew.bat diff --git a/platform/android/example/README b/platform/android/example/README deleted file mode 100644 index 9a2acc77..00000000 --- a/platform/android/example/README +++ /dev/null @@ -1,12 +0,0 @@ -This is a very basic example viewer using the new JNI classes. - -The build system is a bit incomplete. - -You need gradle 2.10 (exactly!). - -Copy the libmupdf_java.so file from the original viewer build: - $ cd ../viewer && ndk-build - $ cp ../viewer/libs/armeabi-v7a/libmupdf_java.so mupdf/libs/armeabi-v7a/libmupdf_java.so - -Build and install on device: - $ gradle-2.10 installArmDebug diff --git a/platform/android/example/app/.gitignore b/platform/android/example/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/platform/android/example/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/platform/android/example/app/build.gradle b/platform/android/example/app/build.gradle index 5d433deb..3a1b25b3 100644 --- a/platform/android/example/app/build.gradle +++ b/platform/android/example/app/build.gradle @@ -1,46 +1,26 @@ -apply plugin: 'com.android.model.application' - -model { - - android { - compileSdkVersion = 23 - buildToolsVersion = "23.0.2" - - defaultConfig.with { - applicationId = "com.artifex.mupdf.example" - minSdkVersion.apiLevel = 8 - targetSdkVersion.apiLevel = 16 - versionCode = 1 - versionName = "1.0" - } - } - - android.buildTypes { - release { - minifyEnabled = false - proguardFiles.add(file('proguard-rules.pro')) - } - } - - android.productFlavors { - create("arm") { - ndk.with { - // You can customize the NDK configurations for each - // productFlavors and buildTypes. - abiFilters.add("armeabi") - } - - } - } - - /* This is important, it will run lint checks but won't abort build */ - android.lintOptions { - abortOnError false - } - +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "com.artifex.mupdf.example" + minSdkVersion 16 + targetSdkVersion 16 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar','*.so']) - compile project(':mupdf') + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:23.4.0' + compile project(':mupdf') } diff --git a/platform/android/example/app/src/main/AndroidManifest.xml b/platform/android/example/app/src/main/AndroidManifest.xml index c1dc4e52..bdd8e804 100644 --- a/platform/android/example/app/src/main/AndroidManifest.xml +++ b/platform/android/example/app/src/main/AndroidManifest.xml @@ -3,7 +3,7 @@ package="com.artifex.mupdf.example"> 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(); - } } diff --git a/platform/android/example/app/src/main/res/layout/activity_doc_view.xml b/platform/android/example/app/src/main/res/layout/activity_doc_view.xml index 05cee21a..7f5ece24 100644 --- a/platform/android/example/app/src/main/res/layout/activity_doc_view.xml +++ b/platform/android/example/app/src/main/res/layout/activity_doc_view.xml @@ -4,64 +4,10 @@ android:layout_height="match_parent" android:orientation="vertical"> - - -