Skip to content

OnLongPresslistener for 2.X #7

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

Open
wants to merge 20 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
55 changes: 39 additions & 16 deletions android-pdf-viewer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,45 +1,68 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'

group = 'com.github.barteksc.devjtafork'
version = '2.8.3'

uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenLocal().getUrl())
}
}
}


ext {
bintrayRepo = 'maven'
bintrayName = 'android-pdf-viewer'

publishedGroupId = 'com.github.barteksc'
publishedGroupId = 'com.github.barteksc.devjtafork'
libraryName = 'AndroidPdfViewer'
artifact = 'android-pdf-viewer'

libraryDescription = 'Android view for displaying PDFs rendered with PdfiumAndroid'

siteUrl = 'https://github.com/barteksc/AndroidPdfViewer'
gitUrl = 'https://github.com/barteksc/AndroidPdfViewer.git'
siteUrl = 'https://github.com/devjta/AndroidPdfViewerV2'
gitUrl = 'https://github.com/devjta/AndroidPdfViewerV2.git'

libraryVersion = '2.8.2'
libraryVersion = '2.8.3'

developerId = 'barteksc'
developerName = 'Bartosz Schiller'
developerEmail = '[email protected]'
developerId = 'devjta'
developerName = 'Joerg Taschek'
developerEmail = '[email protected]'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 11
targetSdkVersion 25
/* ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' // <- only the supported ones
}*/
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "2.8.2"
versionName "2.8.3"
}
packagingOptions{
doNotStrip '*/mips/*.so'
doNotStrip '*/mips64/*.so'
}

}



dependencies {
compile 'com.github.barteksc:pdfium-android:1.7.1'
compile 'com.android.support:support-compat:28.0.0'
compile 'com.android.support:support-v4:28.0.0'
compile 'com.github.barteksc:pdfium-android:1.9.0'
}

apply from: 'https://github.com/raw/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://github.com/raw/nuuneoi/JCenter/master/bintrayv1.gradle'
//apply from: 'https://github.com/raw/nuuneoi/JCenter/master/installv1.gradle'
//apply from: 'https://github.com/raw/nuuneoi/JCenter/master/bintrayv1.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public void onScrollEnd(MotionEvent event) {

@Override
public void onLongPress(MotionEvent e) {

if(pdfView.getOnLongPressListener() != null){
pdfView.getOnLongPressListener().onLongPress(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
import android.os.HandlerThread;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.RelativeLayout;

import com.github.barteksc.pdfviewer.exception.PageRenderingException;
import com.github.barteksc.pdfviewer.listener.OnDrawListener;
import com.github.barteksc.pdfviewer.listener.OnErrorListener;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnLongPressListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.listener.OnPageErrorListener;
import com.github.barteksc.pdfviewer.listener.OnPageScrollListener;
Expand Down Expand Up @@ -91,6 +93,7 @@ public class PDFView extends RelativeLayout {
private float minZoom = DEFAULT_MIN_SCALE;
private float midZoom = DEFAULT_MID_SCALE;
private float maxZoom = DEFAULT_MAX_SCALE;
private OnLoadCompleteListener globalOnLoadCompleteListener;

/**
* START - scrolling in first page direction
Expand Down Expand Up @@ -223,6 +226,11 @@ enum ScrollDir {
*/
private OnPageScrollListener onPageScrollListener;

/**
* Call back object to call when the user does a long tap gesture
*/
private OnLongPressListener onLongPressListener;

/**
* Call back object to call when the above layer is to drawn
*/
Expand Down Expand Up @@ -531,6 +539,15 @@ OnTapListener getOnTapListener() {
return this.onTapListener;
}

private void setOnLongPressListener(OnLongPressListener onLongPressListener) {
this.onLongPressListener = onLongPressListener;
}

OnLongPressListener getOnLongPressListener() {
return this.onLongPressListener;
}


private void setOnDrawListener(OnDrawListener onDrawListener) {
this.onDrawListener = onDrawListener;
}
Expand Down Expand Up @@ -873,7 +890,9 @@ void loadComplete(PdfDocument pdfDocument, int pageWidth, int pageHeight) {
if (onLoadCompleteListener != null) {
onLoadCompleteListener.loadComplete(documentPageCount);
}

if(globalOnLoadCompleteListener != null){
globalOnLoadCompleteListener.loadComplete(documentPageCount);
}
jumpTo(defaultPage, false);
}

Expand Down Expand Up @@ -1235,6 +1254,14 @@ public float getOptimalPageHeight() {
return optimalPageHeight;
}

public float getPageWidth(){
return pageWidth;
}

public float getPageHeight(){
return pageHeight;
}

private void setDefaultPage(int defaultPage) {
this.defaultPage = defaultPage;
}
Expand Down Expand Up @@ -1364,6 +1391,15 @@ public List<PdfDocument.Bookmark> getTableOfContents() {
return pdfiumCore.getTableOfContents(pdfDocument);
}

public void setGlobalOnLoad(OnLoadCompleteListener onLoadCompleteListener){
this.globalOnLoadCompleteListener = onLoadCompleteListener;
}

public void setAlpha(int alpha){
paint.setAlpha(alpha);
invalidate();
}

/**
* Use an asset file as the pdf source
*/
Expand Down Expand Up @@ -1399,6 +1435,7 @@ public Configurator fromStream(InputStream stream) {
return new Configurator(new InputStreamSource(stream));
}


/**
* Use custom source as pdf source
*/
Expand Down Expand Up @@ -1426,6 +1463,8 @@ public class Configurator {

private OnErrorListener onErrorListener;

private OnLongPressListener onLongPressListener;

private OnPageChangeListener onPageChangeListener;

private OnPageScrollListener onPageScrollListener;
Expand Down Expand Up @@ -1521,6 +1560,11 @@ public Configurator onTap(OnTapListener onTapListener) {
return this;
}

public Configurator onLongPress(OnLongPressListener onLongPressListener) {
this.onLongPressListener = onLongPressListener;
return this;
}

public Configurator defaultPage(int defaultPage) {
this.defaultPage = defaultPage;
return this;
Expand Down Expand Up @@ -1563,6 +1607,7 @@ public void load() {
PDFView.this.setOnPageChangeListener(onPageChangeListener);
PDFView.this.setOnPageScrollListener(onPageScrollListener);
PDFView.this.setOnRenderListener(onRenderListener);
PDFView.this.setOnLongPressListener(onLongPressListener);
PDFView.this.setOnTapListener(onTapListener);
PDFView.this.setOnPageErrorListener(onPageErrorListener);
PDFView.this.enableSwipe(enableSwipe);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2017 Bartosz Schiller
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.barteksc.pdfviewer.listener;

import android.view.MotionEvent;

/**
* Implement this interface to receive events from PDFView
* when view has been long pressed
*/
public interface OnLongPressListener {

/**
* Called when the user has a long tap gesture, before processing scroll handle toggling
*
* @param e MotionEvent that registered as a confirmed long press
*/
void onLongPress(MotionEvent e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ private boolean isPDFViewReady() {
return pdfView != null && pdfView.getPageCount() > 0 && !pdfView.documentFitsView();
}

@Override
public boolean performClick() {
return super.performClick();
}

@Override
public boolean onTouchEvent(MotionEvent event) {

Expand Down
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@

buildscript {
repositories {
google()
maven {
url 'https://maven.google.com'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

allprojects {
repositories {
google()
maven {
url 'https://maven.google.com'
}
jcenter()
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
11 changes: 7 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "26.1.0"

defaultConfig {
minSdkVersion 11
targetSdkVersion 25
versionCode 3
versionName "2.0.0"
}

packagingOptions{
doNotStrip '*/mips/*.so'
doNotStrip '*/mips64/*.so'
}
}

dependencies {
compile project(':android-pdf-viewer')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:26.1.0'
provided 'org.androidannotations:androidannotations:4.0.0'
compile 'org.androidannotations:androidannotations-api:4.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;

import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnLongPressListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.listener.OnPageErrorListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
Expand Down Expand Up @@ -118,6 +120,12 @@ private void displayFromAsset(String assetFileName) {
.onPageChange(this)
.enableAnnotationRendering(true)
.onLoad(this)
.onLongPress(new OnLongPressListener() {
@Override
public void onLongPress(MotionEvent e) {
System.out.println("LONG PRESS FROM ASSET!");
}
})
.scrollHandle(new DefaultScrollHandle(this))
.spacing(10) // in dp
.onPageError(this)
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ':android-pdf-viewer'
include ':sample'
//include ':sample'