public class

PdfSelectionHandles

extends ZoomableSelectionHandles<PageSelection>

 java.lang.Object

androidx.pdf.widget.ZoomableSelectionHandles<PageSelection>

↳androidx.pdf.viewer.PdfSelectionHandles

Gradle dependencies

compile group: 'androidx.pdf', name: 'pdf-viewer', version: '1.0.0-alpha02'

  • groupId: androidx.pdf
  • artifactId: pdf-viewer
  • version: 1.0.0-alpha02

Artifact androidx.pdf:pdf-viewer:1.0.0-alpha02 it located at Google repository (https://maven.google.com/)

Overview

Implementation of SelectionHandles for PdfViewer.

Summary

Fields
from ZoomableSelectionHandles<S>mOnTouchListener, mSelection, mSelectionObservable, mSelectionObserverKey, mStartHandle, mStopHandle, mZoomView, mZoomViewObserverKey
Constructors
publicPdfSelectionHandles(PdfSelectionModel selectionModel, ZoomView zoomView, PaginatedView pdfView, SelectionActionMode selectionActionMode)

Methods
public ImageViewgetStartHandle()

public ImageViewgetStopHandle()

protected abstract voidonDragHandleDown(boolean isStopHandle)

Handle drag begins.

protected abstract voidonDragHandleMove(int deltaX, int deltaY)

Handle drag continues.

protected abstract voidonDragHandleUp()

Handle drag stops.

protected abstract voidupdateHandles()

Show or hide both handles, according to the current selection.

from ZoomableSelectionHandles<S>calcTranslation, createHandle, createSelectionObserver, createZoomViewObserver, destroy, destroyHandle, hideHandles, showHandle
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public PdfSelectionHandles(PdfSelectionModel selectionModel, ZoomView zoomView, PaginatedView pdfView, SelectionActionMode selectionActionMode)

Methods

protected abstract void updateHandles()

Show or hide both handles, according to the current selection. Should delegate to ZoomableSelectionHandles.hideHandles() or to ZoomableSelectionHandles.showHandle(ImageView, float, float, boolean) - showHandle will take the zoom into account when displaying the handles.

protected abstract void onDragHandleDown(boolean isStopHandle)

Handle drag begins. Implementation should note which handle is being dragged and store the original positions of both handles.

protected abstract void onDragHandleMove(int deltaX, int deltaY)

Handle drag continues. Implementation should update the selection so that it spans between the fixed handle, and the new position of the dragging handle, which is moved by (deltaX, deltaY) from its original position.

protected abstract void onDragHandleUp()

Handle drag stops. The implementation might not need to do anything here.

public ImageView getStartHandle()

public ImageView getStopHandle()

Source

/*
 * Copyright 2024 The Android Open Source Project
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 androidx.pdf.viewer;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.pdf.R;
import androidx.pdf.models.PageSelection;
import androidx.pdf.models.SelectionBoundary;
import androidx.pdf.select.SelectionActionMode;
import androidx.pdf.select.SelectionModel;
import androidx.pdf.util.Preconditions;
import androidx.pdf.widget.ZoomView;
import androidx.pdf.widget.ZoomableSelectionHandles;

/**
 * Implementation of SelectionHandles for PdfViewer.
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class PdfSelectionHandles extends ZoomableSelectionHandles<PageSelection> {

    private final SelectionModel<?> mSelectionModel;
    private final PaginatedView mPdfView;

    private SelectionBoundary mFixed;
    private SelectionBoundary mDragging;

    private SelectionActionMode mSelectionActionMode;

    public PdfSelectionHandles(
            @NonNull PdfSelectionModel selectionModel, @NonNull ZoomView zoomView,
            @NonNull PaginatedView pdfView,
            @NonNull SelectionActionMode selectionActionMode) {
        super(
                zoomView, (ViewGroup) zoomView.findViewById(R.id.zoomed_view),
                selectionModel.selection());
        this.mSelectionModel = Preconditions.checkNotNull(selectionModel);
        this.mPdfView = Preconditions.checkNotNull(pdfView);
        this.mSelectionActionMode = selectionActionMode;
    }

    @Override
    protected void updateHandles() {
        if (mSelection == null || mPdfView.getViewAt(mSelection.getPage()) == null) {
            hideHandles();
        } else {
            View pageView = mPdfView.getViewAt(mSelection.getPage()).asView();
            showHandle(mStartHandle, pageView, mSelection.getStart(), false);
            showHandle(mStopHandle, pageView, mSelection.getStop(), true);
        }
    }

    private void showHandle(
            ImageView handle, View pageView, SelectionBoundary boundary, boolean isStop) {
        float rawX = pageView.getX() + boundary.getX();
        float rawY = pageView.getY() + boundary.getY();
        boolean isRight = isStop ^ boundary.isRtl();
        super.showHandle(handle, rawX, rawY, isRight);
    }

    @Override
    protected void onDragHandleDown(boolean isStopHandle) {
        mDragging = isStopHandle ? mSelection.getStop() : mSelection.getStart();
        mFixed = isStopHandle ? mSelection.getStart() : mSelection.getStop();
    }

    @Override
    protected void onDragHandleMove(int deltaX, int deltaY) {
        mSelectionActionMode.stopActionMode();
        SelectionBoundary updated = SelectionBoundary.atPoint(mDragging.getX() + deltaX,
                mDragging.getY() + deltaY);
        mSelectionModel.updateSelectionAsync(mFixed, updated);
    }

    @Override
    protected void onDragHandleUp() {
        mSelectionActionMode.resume();
    }

    @NonNull
    public ImageView getStartHandle() {
        return mStartHandle;
    }

    @NonNull
    public ImageView getStopHandle() {
        return mStopHandle;
    }
}