Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit c0ff292

Browse files
committed
add longtaplistener
1 parent af4d4b2 commit c0ff292

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DragPinchManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void onScrollEnd(MotionEvent event) {
184184

185185
@Override
186186
public void onLongPress(MotionEvent e) {
187-
187+
boolean onLongTapHandled = pdfView.callbacks.callOnLongTap(e);
188188
}
189189

190190
@Override

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.github.barteksc.pdfviewer.listener.OnPageScrollListener;
4646
import com.github.barteksc.pdfviewer.listener.OnRenderListener;
4747
import com.github.barteksc.pdfviewer.listener.OnTapListener;
48+
import com.github.barteksc.pdfviewer.listener.OnLongTapListener;
4849
import com.github.barteksc.pdfviewer.model.PagePart;
4950
import com.github.barteksc.pdfviewer.scroll.ScrollHandle;
5051
import com.github.barteksc.pdfviewer.source.AssetSource;
@@ -1163,6 +1164,8 @@ public class Configurator {
11631164

11641165
private OnTapListener onTapListener;
11651166

1167+
private OnLongTapListener onLongTapListener;
1168+
11661169
private OnPageErrorListener onPageErrorListener;
11671170

11681171
private LinkHandler linkHandler = new DefaultLinkHandler(PDFView.this);
@@ -1252,6 +1255,11 @@ public Configurator onTap(OnTapListener onTapListener) {
12521255
return this;
12531256
}
12541257

1258+
public Configurator onLongTap(OnLongTapListener onLongTapListener) {
1259+
this.onLongTapListener = onLongTapListener;
1260+
return this;
1261+
}
1262+
12551263
public Configurator linkHandler(LinkHandler linkHandler) {
12561264
this.linkHandler = linkHandler;
12571265
return this;
@@ -1306,6 +1314,7 @@ public void load() {
13061314
PDFView.this.callbacks.setOnPageScroll(onPageScrollListener);
13071315
PDFView.this.callbacks.setOnRender(onRenderListener);
13081316
PDFView.this.callbacks.setOnTap(onTapListener);
1317+
PDFView.this.callbacks.setOnLongTap(onLongTapListener);
13091318
PDFView.this.callbacks.setOnPageError(onPageErrorListener);
13101319
PDFView.this.callbacks.setLinkHandler(linkHandler);
13111320
PDFView.this.setSwipeEnabled(enableSwipe);

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/Callbacks.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public class Callbacks {
6464
*/
6565
private OnTapListener onTapListener;
6666

67+
/**
68+
* Call back object to call when the user does a long tap gesture
69+
*/
70+
private OnLongTapListener onLongTapListener;
71+
6772
/**
6873
* Call back object to call when clicking link
6974
*/
@@ -153,6 +158,14 @@ public boolean callOnTap(MotionEvent event) {
153158
return onTapListener != null && onTapListener.onTap(event);
154159
}
155160

161+
public void setOnLongTap(OnLongTapListener onLongTapListener) {
162+
this.onLongTapListener = onLongTapListener;
163+
}
164+
165+
public boolean callOnLongTap(MotionEvent event) {
166+
return onLongTapListener != null && onLongTapListener.onLongTap(event);
167+
}
168+
156169
public void setLinkHandler(LinkHandler linkHandler) {
157170
this.linkHandler = linkHandler;
158171
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2017 Bartosz Schiller
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.barteksc.pdfviewer.listener;
17+
18+
import android.view.MotionEvent;
19+
20+
/**
21+
* Implement this interface to receive events from PDFView
22+
* when view has been touched
23+
*/
24+
public interface OnLongTapListener {
25+
26+
/**
27+
* Called when the user has a long tap gesture, before processing scroll handle toggling
28+
*
29+
* @param e MotionEvent that registered as a confirmed long tap
30+
* @return true if the long tap was handled, false to toggle scroll handle
31+
*/
32+
boolean onLongTap(MotionEvent e);
33+
}

0 commit comments

Comments
 (0)