// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/model/LinkTapEvent.java
// public class LinkTapEvent {
//     private float originalX;
//     private float originalY;
//     private float documentX;
//     private float documentY;
//     private RectF mappedLinkRect;
//     private PdfDocument.Link link;
// 
//     public LinkTapEvent(float originalX, float originalY, float documentX, float documentY, RectF mappedLinkRect, PdfDocument.Link link) {
//         this.originalX = originalX;
//         this.originalY = originalY;
//         this.documentX = documentX;
//         this.documentY = documentY;
//         this.mappedLinkRect = mappedLinkRect;
//         this.link = link;
//     }
// 
//     public float getOriginalX() {
//         return originalX;
//     }
// 
//     public float getOriginalY() {
//         return originalY;
//     }
// 
//     public float getDocumentX() {
//         return documentX;
//     }
// 
//     public float getDocumentY() {
//         return documentY;
//     }
// 
//     public RectF getMappedLinkRect() {
//         return mappedLinkRect;
//     }
// 
//     public PdfDocument.Link getLink() {
//         return link;
//     }
// }
// 
// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/SnapEdge.java
// public enum SnapEdge {
//     START, CENTER, END, NONE
// }
// 
// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/Constants.java
// public static float MAXIMUM_ZOOM = 10;
// 
// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/Constants.java
// public static float MINIMUM_ZOOM = 1;


import android.graphics.PointF;
import android.graphics.RectF;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import com.github.barteksc.pdfviewer.model.LinkTapEvent;
import com.github.barteksc.pdfviewer.scroll.ScrollHandle;
import com.github.barteksc.pdfviewer.util.SnapEdge;
import com.shockwave.pdfium.PdfDocument;
import com.shockwave.pdfium.util.SizeF;
import static com.github.barteksc.pdfviewer.util.Constants.Pinch.MAXIMUM_ZOOM;
import static com.github.barteksc.pdfviewer.util.Constants.Pinch.MINIMUM_ZOOM;

        for (PdfDocument.Link link : pdfFile.getPageLinks(page)) {
            RectF mapped = pdfFile.mapRectToDevice(page, pageX, pageY, (int) pageSize.getWidth(),
                    (int) pageSize.getHeight(), link.getBounds());
            mapped.sort();
            if (mapped.contains(mappedX, mappedY)) {
                pdfView.callbacks.callLinkHandler(new LinkTapEvent(x, y, mappedX, mappedY, mapped, link));
                return true;
            }
        }
        return false;
    }

    private void startPageFling(MotionEvent downEvent, MotionEvent ev, float velocityX, float velocityY) {
        if (!checkDoPageFling(velocityX, velocityY)) {
            return;
        }

        int direction;
        if (pdfView.isSwipeVertical()) {
            direction = velocityY > 0 ? -1 : 1;
        } else {
            direction = velocityX > 0 ? -1 : 1;
        }
        // get the focused page during the down event to ensure only a single page is changed
        float delta = pdfView.isSwipeVertical() ? ev.getY() - downEvent.getY() : ev.getX() - downEvent.getX();
        float offsetX = pdfView.getCurrentXOffset() - delta * pdfView.getZoom();
        float offsetY = pdfView.getCurrentYOffset() - delta * pdfView.getZoom();
        int startingPage = pdfView.findFocusPage(offsetX, offsetY);
        int targetPage = Math.max(0, Math.min(pdfView.getPageCount() - 1, startingPage + direction));


// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/model/LinkTapEvent.java
// public class LinkTapEvent {
//     private float originalX;
//     private float originalY;
//     private float documentX;
//     private float documentY;
//     private RectF mappedLinkRect;
//     private PdfDocument.Link link;
// 
//     public LinkTapEvent(float originalX, float originalY, float documentX, float documentY, RectF mappedLinkRect, PdfDocument.Link link) {
//         this.originalX = originalX;
//         this.originalY = originalY;
//         this.documentX = documentX;
//         this.documentY = documentY;
//         this.mappedLinkRect = mappedLinkRect;
//         this.link = link;
//     }
// 
//     public float getOriginalX() {
//         return originalX;
//     }
// 
//     public float getOriginalY() {
//         return originalY;
//     }
// 
//     public float getDocumentX() {
//         return documentX;
//     }
// 
//     public float getDocumentY() {
//         return documentY;
//     }
// 
//     public RectF getMappedLinkRect() {
//         return mappedLinkRect;
//     }
// 
//     public PdfDocument.Link getLink() {
//         return link;
//     }
// }
// 
// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/SnapEdge.java
// public enum SnapEdge {
//     START, CENTER, END, NONE
// }
// 
// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/Constants.java
// public static float MAXIMUM_ZOOM = 10;
// 
// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/Constants.java
// public static float MINIMUM_ZOOM = 1;


// Path: android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DragPinchManager.java
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import com.github.barteksc.pdfviewer.model.LinkTapEvent;
import com.github.barteksc.pdfviewer.scroll.ScrollHandle;
import com.github.barteksc.pdfviewer.util.SnapEdge;
import com.shockwave.pdfium.PdfDocument;
import com.shockwave.pdfium.util.SizeF;
import static com.github.barteksc.pdfviewer.util.Constants.Pinch.MAXIMUM_ZOOM;
import static com.github.barteksc.pdfviewer.util.Constants.Pinch.MINIMUM_ZOOM;

        for (PdfDocument.Link link : pdfFile.getPageLinks(page)) {
            RectF mapped = pdfFile.mapRectToDevice(page, pageX, pageY, (int) pageSize.getWidth(),
                    (int) pageSize.getHeight(), link.getBounds());
            mapped.sort();
            if (mapped.contains(mappedX, mappedY)) {
                pdfView.callbacks.callLinkHandler(new LinkTapEvent(x, y, mappedX, mappedY, mapped, link));
                return true;
            }
        }
        return false;
    }

    private void startPageFling(MotionEvent downEvent, MotionEvent ev, float velocityX, float velocityY) {
        if (!checkDoPageFling(velocityX, velocityY)) {
            return;
        }

        int direction;
        if (pdfView.isSwipeVertical()) {
            direction = velocityY > 0 ? -1 : 1;
        } else {
            direction = velocityX > 0 ? -1 : 1;
        }
        // get the focused page during the down event to ensure only a single page is changed
        float delta = pdfView.isSwipeVertical() ? ev.getY() - downEvent.getY() : ev.getX() - downEvent.getX();
        float offsetX = pdfView.getCurrentXOffset() - delta * pdfView.getZoom();
        float offsetY = pdfView.getCurrentYOffset() - delta * pdfView.getZoom();
        int startingPage = pdfView.findFocusPage(offsetX, offsetY);
        int targetPage = Math.max(0, Math.min(pdfView.getPageCount() - 1, startingPage + direction));


        SnapEdge edge = pdfView.findSnapEdge(targetPage);
