PdfView
public class PdfView extends ViewGroup
A View for presenting PDF content, represented by PdfDocument.
This View supports zooming, scrolling, and flinging. Zooming is supported via pinch gesture, quick scale gesture, and double tap to zoom in or snap back to fitting the page width inside its bounds. Zoom can be changed using the zoom property, which is notably distinct from View.getScaleX / View.getScaleY. Scroll position is based on the View.getScrollX / View.getScrollY properties.
This inherits ViewGroup but does not support adding arbitrary children via addView or in a layout.
Summary
Nested types |
|---|
public interface PdfView.LinkClickListenerListener interface for handling clicks on links in a PDF document. |
public interface PdfView.OnGestureStateChangedListenerListener interface to receive callbacks when the PdfView starts and stops being affected by an external input like user touch. |
public interface PdfView.OnSelectionChangedListenerListener interface to receive updates when the |
public interface PdfView.OnViewportChangedListenerListener interface to receive changes to the viewport, i.e. the window of visible PDF content |
public interface PdfView.SelectionMenuItemPreparerInterface to customize the set of actions in the selection menu |
Constants |
|
|---|---|
static final int |
The PdfView is not currently being affected by an outside input, e.g. user touch |
static final int |
The PdfView is currently being affected by an outside input, e.g. user touch |
static final int |
The PdfView is currently animating to a final position while not under outside control, e.g. settling on a final position following a fling gesture. |
static final int |
Vertically aligns the page to the center of the PdfView. |
static final int |
Vertically aligns the page to the top of the PdfView. |
Public constructors |
|---|
PdfView(@NonNull Context context, AttributeSet attrs, int defStyle) |
Public methods |
|
|---|---|
final void |
Adds the specified listener to the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch. |
final void |
Adds the specified listener to the list of listeners that will be notified of selection change events. |
final void |
Adds the specified listener to the list of listeners that will be notified of viewport change events. |
final void |
addSelectionMenuItemPreparer(Adds the specified listener to the chain of |
void |
|
void |
|
void |
addView(View child, ViewGroup.LayoutParams params) |
void |
addView(View child, int index, ViewGroup.LayoutParams params) |
void |
|
final void |
Clears the current selection, if one exists. |
void |
|
boolean |
dispatchKeyEvent(KeyEvent event)Prioritizes standard keyboard shortcuts over accessibility-specific handling of certain keys. |
final Selection |
The currently selected PDF content, as |
final @NonNull Drawable |
|
final int |
|
final @NonNull Drawable |
|
final int |
|
final int |
The first page in the viewport, including partially-visible pages. |
final int |
The current state of the PDF view with respect to external inputs, e.g. user touch. |
final float |
The maximum scaling factor that can be applied to this View using the |
final float |
The minimum scaling factor that can be applied to this View using the |
final PdfDocument |
Supply a |
final int |
Controls the vertical alignment of a page within the |
final int |
The number of pages visible in the viewport, including partially visible pages |
final float |
getZoom()The zoom level of this view, as a factor of the content's natural size with when 1 pixel is equal to 1 PDF point. |
boolean |
onGenericMotionEvent(MotionEvent event) |
boolean |
onTouchEvent(MotionEvent event) |
final PointF |
pdfToViewPoint(@NonNull PdfPoint pdfPoint)Returns the View coordinate location of |
final void |
Removes the specified listener from the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch. |
final void |
Removes the specified listener from the list of listeners that will be notified of selection change events. |
final void |
Removes the specified listener from the list of listeners that will be notified of viewport change events. |
final void |
removeSelectionMenuItemPreparer(Removes the specified listener from the chain of |
void |
scrollBy(int x, int y) |
void |
scrollTo(int x, int y) |
final void |
scrollToPage(int pageNum)Scrolls to the 0-indexed |
final void |
scrollToPosition(@NonNull PdfPoint position)Scrolls to |
final void |
setFastScrollPageIndicatorBackgroundDrawable( |
final void |
setFastScrollPageIndicatorMarginEnd( |
final void |
setFastScrollVerticalThumbDrawable( |
final void |
setFastScrollVerticalThumbMarginEnd( |
final void |
setHighlights(@NonNull List<@NonNull Highlight> highlights)Applies a set of |
final void |
Registers |
final void |
setMaxZoom(float maxZoom)The maximum scaling factor that can be applied to this View using the |
final void |
setMinZoom(float minZoom)The minimum scaling factor that can be applied to this View using the |
final void |
setPdfDocument(PdfDocument pdfDocument)Supply a |
final void |
setVerticalAlignment(int verticalAlignment)Controls the vertical alignment of a page within the |
final void |
setZoom(float zoom)The zoom level of this view, as a factor of the content's natural size with when 1 pixel is equal to 1 PDF point. |
final PdfPoint |
viewToPdfPoint(@NonNull PointF viewPoint)Returns the |
final PdfPoint |
viewToPdfPoint(float x, float y)Returns the |
Protected methods |
|
|---|---|
int |
|
int |
|
boolean |
dispatchHoverEvent(MotionEvent event) |
void |
|
void |
onConfigurationChanged(Configuration newConfig) |
void |
|
void |
|
void |
onFocusChanged( |
void |
onLayout(boolean changed, int left, int top, int right, int bottom) |
void |
onRestoreInstanceState(Parcelable state) |
Parcelable |
|
void |
onScrollChanged(int l, int t, int oldl, int oldt) |
void |
onSizeChanged(int w, int h, int oldw, int oldh) |
void |
onWindowVisibilityChanged(int visibility) |
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constants
GESTURE_STATE_IDLE
public static final int GESTURE_STATE_IDLE = 0
The PdfView is not currently being affected by an outside input, e.g. user touch
GESTURE_STATE_INTERACTING
public static final int GESTURE_STATE_INTERACTING = 1
The PdfView is currently being affected by an outside input, e.g. user touch
GESTURE_STATE_SETTLING
public static final int GESTURE_STATE_SETTLING = 2
The PdfView is currently animating to a final position while not under outside control, e.g. settling on a final position following a fling gesture.
VERTICAL_ALIGNMENT_CENTER
public static final int VERTICAL_ALIGNMENT_CENTER = 1
Vertically aligns the page to the center of the PdfView.
This alignment is used when the page is scaled to fit the view's width, and the resulting page height is less than the view's height. The top of the page will be positioned at the center of the PdfView. If the scaled page height is greater than the height of PdfView, the top of the first page is always at the top of the view by default, and this alignment will have no effect.
VERTICAL_ALIGNMENT_TOP
public static final int VERTICAL_ALIGNMENT_TOP = 0
Vertically aligns the page to the top of the PdfView.
This alignment is used when the page is scaled to fit the view's width, and the resulting page height is less than the view's height. The top of the page will be positioned at the top of the PdfView. If the scaled page height is greater than the height of PdfView, the top of the first page is always at the top of the view by default, and this alignment will have no effect.
Public constructors
PdfView
public PdfView(@NonNull Context context, AttributeSet attrs, int defStyle)
Public methods
addOnGestureStateChangedListener
public final void addOnGestureStateChangedListener(
@NonNull PdfView.OnGestureStateChangedListener listener
)
Adds the specified listener to the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch.
| Parameters | |
|---|---|
@NonNull PdfView.OnGestureStateChangedListener listener |
listener to notify when interaction state change events occur |
| See also | |
|---|---|
removeOnGestureStateChangedListener |
addOnSelectionChangedListener
public final void addOnSelectionChangedListener(
@NonNull PdfView.OnSelectionChangedListener listener
)
Adds the specified listener to the list of listeners that will be notified of selection change events.
| Parameters | |
|---|---|
@NonNull PdfView.OnSelectionChangedListener listener |
listener to notify when selection change events occur |
| See also | |
|---|---|
removeOnSelectionChangedListener |
addOnViewportChangedListener
public final void addOnViewportChangedListener(
@NonNull PdfView.OnViewportChangedListener listener
)
Adds the specified listener to the list of listeners that will be notified of viewport change events.
| Parameters | |
|---|---|
@NonNull PdfView.OnViewportChangedListener listener |
listener to add |
addSelectionMenuItemPreparer
public final void addSelectionMenuItemPreparer(
@NonNull PdfView.SelectionMenuItemPreparer selectionMenuItemPreparer
)
Adds the specified listener to the chain of SelectionMenuItemPreparer. The listener will be invoked in the order they've been added.
| Parameters | |
|---|---|
@NonNull PdfView.SelectionMenuItemPreparer selectionMenuItemPreparer |
: The |
| See also | |
|---|---|
removeSelectionMenuItemPreparer |
clearSelection
public final void clearSelection()
Clears the current selection, if one exists. No-op if there is no current Selection
dispatchKeyEvent
public boolean dispatchKeyEvent(KeyEvent event)
Prioritizes standard keyboard shortcuts over accessibility-specific handling of certain keys. This ensures a consistent experience for all users, where shortcuts like D-pad scrolling work irrespective of whether accessibility is enabled or not, as both externalInputManager and pdfViewAccessibilityManager are capable of handling certain key events.
getCurrentSelection
public final Selection getCurrentSelection()
The currently selected PDF content, as Selection
getFastScrollPageIndicatorBackgroundDrawable
public final @NonNull Drawable getFastScrollPageIndicatorBackgroundDrawable()
getFastScrollPageIndicatorMarginEnd
public final int getFastScrollPageIndicatorMarginEnd()
getFastScrollVerticalThumbDrawable
public final @NonNull Drawable getFastScrollVerticalThumbDrawable()
getFastScrollVerticalThumbMarginEnd
public final int getFastScrollVerticalThumbMarginEnd()
getFirstVisiblePage
public final int getFirstVisiblePage()
The first page in the viewport, including partially-visible pages. 0-indexed.
getGestureState
public final int getGestureState()
The current state of the PDF view with respect to external inputs, e.g. user touch. Returns one of GESTURE_STATE_IDLE, GESTURE_STATE_INTERACTING, or GESTURE_STATE_SETTLING
getMaxZoom
public final float getMaxZoom()
The maximum scaling factor that can be applied to this View using the zoom property
getMinZoom
public final float getMinZoom()
The minimum scaling factor that can be applied to this View using the zoom property
getPdfDocument
public final PdfDocument getPdfDocument()
Supply a PdfDocument to process the PDF content for rendering
getVerticalAlignment
public final int getVerticalAlignment()
Controls the vertical alignment of a page within the PdfView.
This attribute aligns a page within the view when the page's height is smaller than the view's height. In this state, scrolling and panning are disabled as the entire page is visible. However, zooming in will re-enable scrolling and panning, aligning page to the top.
| See also | |
|---|---|
PdfView.VerticalAlignment |
getVisiblePagesCount
public final int getVisiblePagesCount()
The number of pages visible in the viewport, including partially visible pages
getZoom
public final float getZoom()
The zoom level of this view, as a factor of the content's natural size with when 1 pixel is equal to 1 PDF point. Will always be clamped within (minZoom, maxZoom)
pdfToViewPoint
public final PointF pdfToViewPoint(@NonNull PdfPoint pdfPoint)
Returns the View coordinate location of pdfPoint, or null if that PDF content has not been laid out yet.
removeOnGestureStateChangedListener
public final void removeOnGestureStateChangedListener(
@NonNull PdfView.OnGestureStateChangedListener listener
)
Removes the specified listener from the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch.
| Parameters | |
|---|---|
@NonNull PdfView.OnGestureStateChangedListener listener |
listener to remove |
removeOnSelectionChangedListener
public final void removeOnSelectionChangedListener(
@NonNull PdfView.OnSelectionChangedListener listener
)
Removes the specified listener from the list of listeners that will be notified of selection change events.
| Parameters | |
|---|---|
@NonNull PdfView.OnSelectionChangedListener listener |
listener to remove |
removeOnViewportChangedListener
public final void removeOnViewportChangedListener(
@NonNull PdfView.OnViewportChangedListener listener
)
Removes the specified listener from the list of listeners that will be notified of viewport change events.
| Parameters | |
|---|---|
@NonNull PdfView.OnViewportChangedListener listener |
listener to remove |
removeSelectionMenuItemPreparer
public final void removeSelectionMenuItemPreparer(
@NonNull PdfView.SelectionMenuItemPreparer selectionMenuItemPreparer
)
Removes the specified listener from the chain of SelectionMenuItemPreparer.
| Parameters | |
|---|---|
@NonNull PdfView.SelectionMenuItemPreparer selectionMenuItemPreparer |
: The |
scrollToPage
public final void scrollToPage(int pageNum)
Scrolls to the 0-indexed pageNum, optionally animating the scroll
This View cannot scroll to a page until it knows its dimensions. If pageNum is distant from the currently-visible page in a large PDF, there may be some delay while dimensions are being loaded from the PDF.
scrollToPosition
public final void scrollToPosition(@NonNull PdfPoint position)
Scrolls to position, aligns vertically to center, optionally animating the scroll
This View cannot scroll to a page until it knows its dimensions. If position is distant from the currently-visible page in a large PDF, there may be some delay while dimensions are being loaded from the PDF.
setFastScrollPageIndicatorBackgroundDrawable
public final void setFastScrollPageIndicatorBackgroundDrawable(
@NonNull Drawable fastScrollPageIndicatorBackgroundDrawable
)
setFastScrollPageIndicatorMarginEnd
public final void setFastScrollPageIndicatorMarginEnd(
int fastScrollPageIndicatorMarginEnd
)
setFastScrollVerticalThumbDrawable
public final void setFastScrollVerticalThumbDrawable(
@NonNull Drawable fastScrollVerticalThumbDrawable
)
setFastScrollVerticalThumbMarginEnd
public final void setFastScrollVerticalThumbMarginEnd(
int fastScrollVerticalThumbMarginEnd
)
setHighlights
public final void setHighlights(@NonNull List<@NonNull Highlight> highlights)
Applies a set of Highlight to be drawn over this PDF. Each Highlight may be a different color. This overrides any previous highlights, there is no merging of new and previous values. highlights are defensively copied and the list or its contents may be modified after providing it here.
setLinkClickListener
public final void setLinkClickListener(PdfView.LinkClickListener listener)
Registers listener as the callback to be invoked when an external link in the PDF is clicked. Supply null to clear any current listener.
setMaxZoom
public final void setMaxZoom(float maxZoom)
The maximum scaling factor that can be applied to this View using the zoom property
setMinZoom
public final void setMinZoom(float minZoom)
The minimum scaling factor that can be applied to this View using the zoom property
setPdfDocument
public final void setPdfDocument(PdfDocument pdfDocument)
Supply a PdfDocument to process the PDF content for rendering
setVerticalAlignment
public final void setVerticalAlignment(int verticalAlignment)
Controls the vertical alignment of a page within the PdfView.
This attribute aligns a page within the view when the page's height is smaller than the view's height. In this state, scrolling and panning are disabled as the entire page is visible. However, zooming in will re-enable scrolling and panning, aligning page to the top.
| See also | |
|---|---|
PdfView.VerticalAlignment |
setZoom
public final void setZoom(float zoom)
The zoom level of this view, as a factor of the content's natural size with when 1 pixel is equal to 1 PDF point. Will always be clamped within (minZoom, maxZoom)
viewToPdfPoint
public final PdfPoint viewToPdfPoint(@NonNull PointF viewPoint)
Returns the PdfPoint corresponding to viewPoint in View coordinates, or null if no PDF content has been laid out at viewPoint
viewToPdfPoint
public final PdfPoint viewToPdfPoint(float x, float y)
Returns the PdfPoint corresponding to (x, y)in View coordinates, or null if no PDF content has been laid out at that point.
Protected methods
onFocusChanged
protected void onFocusChanged(
boolean gainFocus,
int direction,
Rect previouslyFocusedRect
)