Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just another PR to fix the decoding crash issue, and also updated gradle & android sdk to its latest #171

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local.properties

# Android Studio
.idea
build/
*/local.properties
*/out
*/build/**
Expand All @@ -29,4 +30,4 @@ local.properties
*.swp

# gradle
.gradle
.gradle
10 changes: 2 additions & 8 deletions android-pdfview-sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joanzapata.pdfview.sample"
android:versionCode="3"
android:versionName="1.0.1" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
package="com.joanzapata.pdfview.sample" >

<application
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme"
android:label="@string/app_name" >
<activity
android:name="com.joanzapata.PDFViewActivity_"
android:name="com.joanzapata.PDFViewActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Binary file modified android-pdfview-sample/assets/sample.pdf
Binary file not shown.
14 changes: 7 additions & 7 deletions android-pdfview-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'android'
description = 'android-pdfview-sample'

android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 8
targetSdkVersion 19
minSdkVersion 14
targetSdkVersion 23
versionCode 2
versionName "1.0.1"
}
Expand All @@ -27,7 +27,7 @@ android {

dependencies {
compile project(':android-pdfview')
provided 'com.googlecode.androidannotations:androidannotations:2.7.1'
compile 'com.googlecode.androidannotations:androidannotations-api:2.7.1'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
5 changes: 3 additions & 2 deletions android-pdfview-sample/res/menu/actionbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
along with Android-pdfview. If not, see <http://www.gnu.org/licenses/>.

-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/about"
android:icon="@drawable/ic_about"
android:title="About"
android:showAsAction="ifRoom|withText" />
app:showAsAction="always" />
</menu>
2 changes: 1 addition & 1 deletion android-pdfview-sample/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
-->
<resources>

<style name="AppTheme" parent="@style/Theme.Sherlock.Light" />
<style name="AppTheme" parent="@style/Theme.AppCompat.Light" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,62 @@
*/
package com.joanzapata;

import android.content.Intent;
import android.util.Log;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.googlecode.androidannotations.annotations.*;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.joanzapata.pdfview.PDFView;
import com.joanzapata.pdfview.listener.OnErrorListener;
import com.joanzapata.pdfview.listener.OnPageChangeListener;
import com.joanzapata.pdfview.sample.R;

import butterknife.Bind;
import butterknife.ButterKnife;

import static java.lang.String.format;

@EActivity(R.layout.activity_main)
@OptionsMenu(R.menu.actionbar)
public class PDFViewActivity extends SherlockActivity implements OnPageChangeListener {
public class PDFViewActivity extends AppCompatActivity implements OnPageChangeListener {

public static final String SAMPLE_FILE = "sample.pdf";

public static final String ABOUT_FILE = "about.pdf";

@ViewById
PDFView pdfView;
@Bind(R.id.pdfView) PDFView pdfView;

@NonConfigurationInstance
String pdfName = SAMPLE_FILE;

@NonConfigurationInstance
Integer pageNumber = 1;

@AfterViews
void afterViews() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
ButterKnife.bind(this);

display(pdfName, false);
}

@OptionsItem
public void about() {
if (!displaying(ABOUT_FILE))
display(ABOUT_FILE, true);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.actionbar, menu);

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.about:
if (!displaying(ABOUT_FILE)) {
display(ABOUT_FILE, true);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}

private void display(String assetFileName, boolean jumpToFirstPage) {
Expand All @@ -64,6 +83,12 @@ private void display(String assetFileName, boolean jumpToFirstPage) {
pdfView.fromAsset(assetFileName)
.defaultPage(pageNumber)
.onPageChange(this)
.onError(new OnErrorListener() {
@Override
public void onError(Throwable t) {
Toast.makeText(PDFViewActivity.this, "Ops, got an error: " + t.toString(), Toast.LENGTH_LONG).show();
}
})
.load();
}

Expand Down
14 changes: 6 additions & 8 deletions android-pdfview/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joanzapata.pdfview"
android:versionCode="1"
android:versionName="1.0.0">

<!-- Min version 8 (2.2) -->
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="17"/>

package="com.joanzapata.pdfview" >

<application>

</application>

</manifest>
22 changes: 17 additions & 5 deletions android-pdfview/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
apply plugin: 'android-library'

description = 'android-pdfview'
apply plugin: 'com.android.library'

android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
compileSdkVersion 23
buildToolsVersion '23.0.2'

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
jniLibs.srcDirs = [ 'libs' ]
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@

import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

import com.joanzapata.pdfview.PDFView;

import org.vudroid.core.DecodeService;
import org.vudroid.core.DecodeServiceBase;
import org.vudroid.pdfdroid.codec.PdfContext;

class DecodingAsyncTask extends AsyncTask<Void, Void, Void> {
class DecodingAsyncTask extends AsyncTask<Void, Void, Throwable> {

/** The decode service used for decoding the PDF */
private DecodeService decodeService;
Expand All @@ -43,17 +40,27 @@ public DecodingAsyncTask(Uri uri, PDFView pdfView) {
this.cancelled = false;
this.pdfView = pdfView;
this.uri = uri;
}

@Override
protected Void doInBackground(Void... params) {
decodeService = new DecodeServiceBase(new PdfContext());
decodeService.setContentResolver(pdfView.getContext().getContentResolver());
decodeService.open(uri);
return null;
}

protected void onPostExecute(Void result) {
@Override
protected Throwable doInBackground(Void... params) {
try {
decodeService.open(uri);
return null;
} catch (Throwable t) {
return t;
}
}

protected void onPostExecute(Throwable t) {
if (t != null) {
pdfView.loadError(t);
return;
}

if (!cancelled) {
pdfView.loadComplete(decodeService);
}
Expand Down
34 changes: 28 additions & 6 deletions android-pdfview/src/main/java/com/joanzapata/pdfview/PDFView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceView;
import com.joanzapata.pdfview.exception.FileNotFoundException;
import com.joanzapata.pdfview.listener.OnDrawListener;
import com.joanzapata.pdfview.listener.OnErrorListener;
import com.joanzapata.pdfview.listener.OnLoadCompleteListener;
import com.joanzapata.pdfview.listener.OnPageChangeListener;
import com.joanzapata.pdfview.model.PagePart;
Expand Down Expand Up @@ -58,7 +60,7 @@
* - DocumentPage = A page of the PDF document.
* - UserPage = A page as defined by the user.
* By default, they're the same. But the user can change the pages order
* using {@link #load(Uri, OnLoadCompleteListener, int[])}. In this
* using {@link #load(Uri, OnLoadCompleteListener, OnErrorListener, int[])}. In this
* particular case, a userPage of 5 can refer to a documentPage of 17.
*/
public class PDFView extends SurfaceView {
Expand Down Expand Up @@ -148,6 +150,8 @@ public class PDFView extends SurfaceView {
/** Call back object to call when the PDF is loaded */
private OnLoadCompleteListener onLoadCompleteListener;

private OnErrorListener onErrorListener;

/** Call back object to call when the page has changed */
private OnPageChangeListener onPageChangeListener;

Expand Down Expand Up @@ -209,11 +213,11 @@ public PDFView(Context context, AttributeSet set) {
setWillNotDraw(false);
}

private void load(Uri uri, OnLoadCompleteListener listener) {
load(uri, listener, null);
private void load(Uri uri, OnLoadCompleteListener listener, OnErrorListener onErrorListener) {
load(uri, listener, onErrorListener, null);
}

private void load(Uri uri, OnLoadCompleteListener onLoadCompleteListener, int[] userPages) {
private void load(Uri uri, OnLoadCompleteListener onLoadCompleteListener, OnErrorListener onErrorListener, int[] userPages) {

if (!recycled) {
throw new IllegalStateException("Don't call load on a PDF View without recycling it first.");
Expand All @@ -227,6 +231,7 @@ private void load(Uri uri, OnLoadCompleteListener onLoadCompleteListener, int[]
}

this.onLoadCompleteListener = onLoadCompleteListener;
this.onErrorListener = onErrorListener;

// Start decoding document
decodingAsyncTask = new DecodingAsyncTask(uri, this);
Expand Down Expand Up @@ -315,6 +320,8 @@ public void recycle() {
@Override
protected void onDetachedFromWindow() {
recycle();

super.onDetachedFromWindow();
}

@Override
Expand Down Expand Up @@ -657,6 +664,14 @@ public void loadComplete(DecodeService decodeService) {
}
}

public void loadError(Throwable t) {
if (this.onErrorListener != null) {
this.onErrorListener.onError(t);
} else {
Log.e("PDFView", "load pdf error", t);
}
}

/**
* Called when a rendering task is over and
* a PagePart has been freshly created.
Expand Down Expand Up @@ -993,6 +1008,8 @@ public class Configurator {

private OnLoadCompleteListener onLoadCompleteListener;

private OnErrorListener onErrorListener;

private OnPageChangeListener onPageChangeListener;

private int defaultPage = 1;
Expand Down Expand Up @@ -1034,6 +1051,11 @@ public Configurator onLoad(OnLoadCompleteListener onLoadCompleteListener) {
return this;
}

public Configurator onError(OnErrorListener onErrorListener) {
this.onErrorListener = onErrorListener;
return this;
}

public Configurator onPageChange(OnPageChangeListener onPageChangeListener) {
this.onPageChangeListener = onPageChangeListener;
return this;
Expand Down Expand Up @@ -1074,9 +1096,9 @@ public void load() {
PDFView.this.maskPaint.setColor(maskColor);
PDFView.this.maskPaint.setAlpha(maskAlpha);
if (pageNumbers != null) {
PDFView.this.load(uri, onLoadCompleteListener, pageNumbers);
PDFView.this.load(uri, onLoadCompleteListener, onErrorListener, pageNumbers);
} else {
PDFView.this.load(uri, onLoadCompleteListener);
PDFView.this.load(uri, onLoadCompleteListener, onErrorListener);
}
}

Expand Down
Loading