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

Added support for files inside assets subfolders #126

Open
wants to merge 14 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Android PDFView is **available in Maven Central**.
<dependency>
<groupId>com.joanzapata.pdfview</groupId>
<artifactId>android-pdfview</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<type>apklib</type>
</dependency>
```

Or via gradle:

```
compile 'com.joanzapata.pdfview:android-pdfview:1.0.3@aar'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'
```

# Include PDFView in your layout
Expand Down
2 changes: 1 addition & 1 deletion android-pdfview-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.joanzapata.pdfview</groupId>
<artifactId>android-pdfview-parent</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion android-pdfview/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.joanzapata.pdfview</groupId>
<artifactId>android-pdfview-parent</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public DragPinchManager(PDFView pdfView) {
dragPinchListener.setOnDoubleTapListener(this);
pdfView.setOnTouchListener(dragPinchListener);
}


public void enableDoubletap(boolean enableDoubletap){
if (enableDoubletap) {
dragPinchListener.setOnDoubleTapListener(this);
} else {
dragPinchListener.setOnDoubleTapListener(null);
}
}

@Override
public void onPinch(float dr, PointF pivot) {
float wantedZoom = pdfView.getZoom() * dr;
Expand Down
16 changes: 14 additions & 2 deletions android-pdfview/src/main/java/com/joanzapata/pdfview/PDFView.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ public int getPageCount() {
public void enableSwipe(boolean enableSwipe) {
dragPinchManager.setSwipeEnabled(enableSwipe);
}


public void enableDoubletap(boolean enableDoubletap){
this.dragPinchManager.enableDoubletap(enableDoubletap);
}

private void setOnPageChangeListener(OnPageChangeListener onPageChangeListener) {
this.onPageChangeListener = onPageChangeListener;
}
Expand Down Expand Up @@ -983,6 +987,8 @@ public class Configurator {

private boolean enableSwipe = true;

private boolean enableDoubletap = true ;

private OnDrawListener onDrawListener;

private OnLoadCompleteListener onLoadCompleteListener;
Expand Down Expand Up @@ -1012,7 +1018,12 @@ public Configurator enableSwipe(boolean enableSwipe) {
this.enableSwipe = enableSwipe;
return this;
}


public Configurator enableDoubletap(boolean enableDoubletap){
this.enableDoubletap = enableDoubletap ;
return this ;
}

public Configurator onDraw(OnDrawListener onDrawListener) {
this.onDrawListener = onDrawListener;
return this;
Expand Down Expand Up @@ -1054,6 +1065,7 @@ public void load() {
PDFView.this.setOnDrawListener(onDrawListener);
PDFView.this.setOnPageChangeListener(onPageChangeListener);
PDFView.this.enableSwipe(enableSwipe);
PDFView.this.enableDoubletap(enableDoubletap);
PDFView.this.setDefaultPage(defaultPage);
PDFView.this.setUserWantsMinimap(showMinimap);
PDFView.this.setSwipeVertical(swipeVertical);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

import android.os.Handler;
/**
* @author Joan Zapata
* <p/>
Expand Down Expand Up @@ -53,7 +53,17 @@ public class DragPinchListener implements OnTouchListener {
private static final float MAX_DOUBLE_CLICK_TIME = 280;

private static final int POINTER1 = 0, POINTER2 = 1;

/**
* Handler used for perfom click (only if it's not a double tap)
*/
private final Handler handlerClick = new Handler();
private View mView ;
private final Runnable runnableClick = new Runnable() {
@Override
public void run() {
mView.performClick();
}
};
/** Implement this interface to receive Drag events */
public static interface OnDragListener {

Expand Down Expand Up @@ -116,6 +126,7 @@ enum State {NONE, ZOOM, DRAG}

@Override
public boolean onTouch(View v, MotionEvent event) {
mView = v ;
switch (event.getAction()) {

// NORMAL CASE : FIRST POINTER DOWN
Expand Down Expand Up @@ -149,13 +160,17 @@ public boolean onTouch(View v, MotionEvent event) {
// Treat clicks
if (isClick(event, lastDownX, lastDownY, event.getX(), event.getY())) {
long time = System.currentTimeMillis();
if (time - lastClickTime < MAX_DOUBLE_CLICK_TIME) {
if (onDoubleTapListener != null) {
handlerClick.removeCallbacks(runnableClick);
if (onDoubleTapListener != null) {
if (time - lastClickTime < MAX_DOUBLE_CLICK_TIME) {
onDoubleTapListener.onDoubleTap(event.getX(), event.getY());
lastClickTime = 0;
} else {
lastClickTime = System.currentTimeMillis();
handlerClick.postDelayed(runnableClick, MAX_CLICK_TIME);
}
lastClickTime = 0;
} else {
lastClickTime = System.currentTimeMillis();
handlerClick.postDelayed(runnableClick,0);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private FileUtils() {

public static File fileFromAsset(Context context, String assetName) throws IOException {
File outFile = new File(context.getCacheDir(), assetName + "-pdfview.pdf");
new File(outFile.getParent()).mkdirs();
copy(context.getAssets().open(assetName), outFile);
return outFile;
}
Expand Down
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<name>Android PDFView parent</name>
<description>An easy-to-use Android PDFView component with swipe and zoom</description>
<packaging>pom</packaging>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
<url>http://joanzapata.com/android-pdfview/</url>
<inceptionYear>2013</inceptionYear>

Expand Down Expand Up @@ -80,6 +80,22 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>

Expand Down