Class PdfThumbnailGrid
-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback
,android.view.KeyEvent.Callback
,android.view.ViewManager
,android.view.ViewParent
,android.view.accessibility.AccessibilityEventSource
,com.pspdfkit.internal.document.editor.OnFileWriteCompleteListener
,com.pspdfkit.listeners.DocumentListener
,com.pspdfkit.ui.PSPDFKitViews.PSPDFView
,com.pspdfkit.ui.drawable.PdfDrawableManager
public class PdfThumbnailGrid extends RelativeLayout implements PSPDFKitViews.PSPDFView, DocumentListener, PdfDrawableManager, OnFileWriteCompleteListener
Scrollable grid view of document pages.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
PdfThumbnailGrid.OnPageClickListener
Listener for observing a PdfThumbnailGrid page click.
public interface
PdfThumbnailGrid.OnDocumentSavedListener
Listener for document saving inside PdfThumbnailGrid. Document is being saved after clicking on the "Save" or "Save As" buttons inside DocumentEditingToolbar when document editing mode is active.
-
Field Summary
Fields Modifier and Type Field Description public DocumentEditorSavingToolbarHandler
documentEditorSavingToolbarHandler
public boolean
isDisplayed
public int
backgroundColor
public int
itemLabelTextStyle
public FilePicker
filePicker
public boolean
isRedactionAnnotationPreviewEnabled
-
Constructor Summary
Constructors Constructor Description PdfThumbnailGrid(Context context)
PdfThumbnailGrid(Context context, AttributeSet attrs)
PdfThumbnailGrid(Context context, AttributeSet attrs, int defStyleAttr)
PdfThumbnailGrid(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
-
Method Summary
Modifier and Type Method Description DocumentEditorSavingToolbarHandler
getDocumentEditorSavingToolbarHandler()
Returns document editor saving toolbar handler, may return null
if document has not been set.boolean
isDisplayed()
Called when the activity needs to know the visibility of this view. int
getBackgroundColor()
Returns the background color of the thumbnail grid. void
setBackgroundColor(@ColorInt() int backgroundColor)
Sets the background color of the thumbnail grid. int
getItemLabelTextStyle()
Returns the thumbnail grid item's label text style. void
setItemLabelTextStyle(@StyleRes() int itemLabelTextStyle)
Sets the thumbnail grid item's label text style. FilePicker
getFilePicker()
Returns a file picker to use during a saving process. void
setFilePicker(@Nullable() FilePicker filePicker)
Sets a file picker to use during a saving process. boolean
isRedactionAnnotationPreviewEnabled()
Returns redaction annotation preview mode, false
by default.void
setRedactionAnnotationPreviewEnabled(boolean enable)
Sets redaction annotations preview as redacted. int
getItemLabelBackground()
Returns the thumbnail grid background label background. void
setItemLabelBackground(@DrawableRes() int itemLabelBackgroundDrawableRes)
Sets the thumbnail grid background label background. NewPageDialog.Callback
getDefaultNewPageDialogCallback()
Returns The default NewPageDialog.Callback that is used by default by the . void
setOnPageClickListener(@Nullable() PdfThumbnailGrid.OnPageClickListener onPageClickListener)
Sets the OnPageClickListener, replacing any previously set listener. void
addOnPageClickListener(PdfThumbnailGrid.OnPageClickListener onPageClickListener)
Adds a listener that will be notified when a page on the ThumbnailGrid was clicked. boolean
removeOnDocumentSavedListener(PdfThumbnailGrid.OnPageClickListener onPageClickListener)
Removes a listener from the list of registered onPageClick listeners void
addOnDocumentSavedListener(PdfThumbnailGrid.OnDocumentSavedListener onDocumentSavedListener)
Adds a listener that will be notified about document saves inside the thumbnail grid. boolean
removeOnDocumentSavedListener(@Nullable() PdfThumbnailGrid.OnDocumentSavedListener onDocumentSavedListener)
Removes a listener from the list of registered onDocumentSaved listeners PdfDocumentEditor
getDocumentEditor()
Returns document editor to perform operations such as page manipulation, reordering and importing documents. boolean
isDocumentEditorEnabled()
void
setDocumentEditorSaveAsEnabled(boolean saveAsEnabled)
Enables/Disables document editor "Save As" option in action bar. void
setDocumentEditorExportEnabled(boolean exportEnabled)
Enables/Disables document editor "Export pages" option in action bar. void
onDocumentLoaded(@NonNull() PdfDocument document)
Called when document is successfully loaded and the document view has been laid out. void
onDocumentLoadFailed(@NonNull() Throwable exception)
Called if document loading has failed. boolean
onDocumentSave(@NonNull() PdfDocument document, @NonNull() DocumentSaveOptions saveOptions)
Called before document will be saved. void
onDocumentSaved(@NonNull() PdfDocument document)
Called after the document has been saved. void
onDocumentSaveFailed(@NonNull() PdfDocument document, @NonNull() Throwable exception)
Called if document saving has failed. void
onDocumentSaveCancelled(PdfDocument document)
Called if document saving has been cancelled. boolean
onPageClick(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @Nullable() MotionEvent event, @Nullable() PointF pagePosition, @Nullable() Annotation clickedAnnotation)
Called when user taps / clicks on the page. boolean
onDocumentClick()
Called when the user taps / clicks on the document, not the page itself but on the side (if visible). void
onPageChanged(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when user scrolled to a new page. void
onDocumentZoomed(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, float scaleFactor)
Called when a user zooms a document. void
onPageUpdated(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated). void
setDocument(@Nullable() PdfDocument document, @NonNull() PdfConfiguration configuration)
Called when the document
has been loaded and is going to be displayed.void
addOnVisibilityChangedListener(@NonNull() OnVisibilityChangedListener listener)
Register a listener
that would like to receive visibility change events.void
removeOnVisibilityChangedListener(@NonNull() OnVisibilityChangedListener listener)
Unregister a previously registered listener
that no longer wants to receive visibility change events.void
show()
Called by the activity when the view should make itself visible. void
hide()
Called by the activity when the view should hide itself. void
clearDocument()
Called by the activity when the view should unbind the previously set document. PSPDFKitViews.Type
getPSPDFViewType()
Returns the current type of this view. void
enterDocumentEditingMode()
Enters document editing mode. void
exitDocumentEditingMode()
Exits document editing mode. boolean
isShowPageLabels()
Returns true
if page labels are shown,false
otherwise.void
addDrawableProvider(@NonNull() PdfDrawableProvider drawableProvider)
Adds a PdfDrawableProvider to be managed by this object. void
removeDrawableProvider(@NonNull() PdfDrawableProvider drawableProvider)
Removes a previously added PdfDrawableProvider. void
onDocumentSaved()
Called when saving a document in place is complete. void
onDocumentExported(@NonNull() Uri destinationUri)
Called when saving a document or exporting pages to a given destination is complete. Set<Integer>
getSelectedPages()
Retrieves the currently selected pages of the thumbnail grid. View
focusSearch(@NonNull() View focused, int direction)
final void
setNewPageFactory(@Nullable() NewPageFactory newPageFactory)
Sets a NewPageFactory that will be used by the document editor. void
setDocumentEditorEnabled(boolean documentEditorEnabled)
Enables/Disables document editor. void
setShowPageLabels(boolean showPageLabels)
Sets whether the page labels will be shown or just the page number. -
-
Constructor Detail
-
PdfThumbnailGrid
PdfThumbnailGrid(Context context)
-
PdfThumbnailGrid
PdfThumbnailGrid(Context context, AttributeSet attrs)
-
PdfThumbnailGrid
PdfThumbnailGrid(Context context, AttributeSet attrs, int defStyleAttr)
-
PdfThumbnailGrid
PdfThumbnailGrid(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
-
-
Method Detail
-
getDocumentEditorSavingToolbarHandler
@Nullable() DocumentEditorSavingToolbarHandler getDocumentEditorSavingToolbarHandler()
Returns document editor saving toolbar handler, may return
null
if document has not been set.- Returns:
document editor saving toolbar handler.
-
isDisplayed
boolean isDisplayed()
Called when the activity needs to know the visibility of this view. Returns
true
if this view is visible, otherwise returnsfalse
.
-
getBackgroundColor
@ColorInt() int getBackgroundColor()
Returns the background color of the thumbnail grid.
- Returns:
Thumbnail grid background color.
-
setBackgroundColor
void setBackgroundColor(@ColorInt() int backgroundColor)
Sets the background color of the thumbnail grid.
- Parameters:
backgroundColor
- Thumbnail grid background color.
-
getItemLabelTextStyle
@StyleRes() int getItemLabelTextStyle()
Returns the thumbnail grid item's label text style.
- Returns:
Style resource for the item label.
-
setItemLabelTextStyle
void setItemLabelTextStyle(@StyleRes() int itemLabelTextStyle)
Sets the thumbnail grid item's label text style.
- Parameters:
itemLabelTextStyle
- Style resource for the item label.
-
getFilePicker
@NonNull() FilePicker getFilePicker()
Returns a file picker to use during a saving process. If not provided, a default implementation relying on Android Storage Access Framework will be returned. For more info about Android Storage Access Framework see Open files using storage access framework.
- Returns:
File picker to use during a saving process.
-
setFilePicker
void setFilePicker(@Nullable() FilePicker filePicker)
Sets a file picker to use during a saving process. If not provided, a default implementation relying on Android Storage Access Framework will be used. For more info about Android Storage Access Framework see Open files using storage access framework.
- Parameters:
filePicker
- File picker to use during a saving process.
-
isRedactionAnnotationPreviewEnabled
boolean isRedactionAnnotationPreviewEnabled()
Returns redaction annotation preview mode,
false
by default.- Returns:
true
if redaction annotation preview mode is enabled,false
otherwise.
-
setRedactionAnnotationPreviewEnabled
void setRedactionAnnotationPreviewEnabled(boolean enable)
Sets redaction annotations preview as redacted.
- Parameters:
enable
-true
to show redaction annotations as redacted,false
to show them as marks.
-
getItemLabelBackground
@DrawableRes() int getItemLabelBackground()
Returns the thumbnail grid background label background.
- Returns:
Thumbnail grid background label background resource drawable.
-
setItemLabelBackground
void setItemLabelBackground(@DrawableRes() int itemLabelBackgroundDrawableRes)
Sets the thumbnail grid background label background.
- Parameters:
itemLabelBackgroundDrawableRes
- Thumbnail grid background label background resource drawable.
-
getDefaultNewPageDialogCallback
@NonNull() NewPageDialog.Callback getDefaultNewPageDialogCallback()
Returns The default NewPageDialog.Callback that is used by default by the . Can be used to manually restore the NewPageDialog when using a custom DialogNewPageFactory.
-
setOnPageClickListener
void setOnPageClickListener(@Nullable() PdfThumbnailGrid.OnPageClickListener onPageClickListener)
Sets the OnPageClickListener, replacing any previously set listener.
- Parameters:
onPageClickListener
- OnPageClickListener for receiving events of this view.
-
addOnPageClickListener
void addOnPageClickListener(PdfThumbnailGrid.OnPageClickListener onPageClickListener)
Adds a listener that will be notified when a page on the ThumbnailGrid was clicked.
- Parameters:
onPageClickListener
- Listener to add.
-
removeOnDocumentSavedListener
boolean removeOnDocumentSavedListener(PdfThumbnailGrid.OnPageClickListener onPageClickListener)
Removes a listener from the list of registered onPageClick listeners
- Parameters:
onPageClickListener
- Listener to remove- Returns:
true if the listener was removed, otherwise false
-
addOnDocumentSavedListener
void addOnDocumentSavedListener(PdfThumbnailGrid.OnDocumentSavedListener onDocumentSavedListener)
Adds a listener that will be notified about document saves inside the thumbnail grid.
- Parameters:
onDocumentSavedListener
- Listener for document saves after clicking on the "Save" and "Save As" button in the document editing toolbar.
-
removeOnDocumentSavedListener
boolean removeOnDocumentSavedListener(@Nullable() PdfThumbnailGrid.OnDocumentSavedListener onDocumentSavedListener)
Removes a listener from the list of registered onDocumentSaved listeners
- Parameters:
onDocumentSavedListener
- Listener to remove- Returns:
true if the listener was removed
-
getDocumentEditor
@Nullable() PdfDocumentEditor getDocumentEditor()
Returns document editor to perform operations such as page manipulation, reordering and importing documents.
- Returns:
document editor to perform operations on the current PDF document.
-
isDocumentEditorEnabled
boolean isDocumentEditorEnabled()
-
setDocumentEditorSaveAsEnabled
void setDocumentEditorSaveAsEnabled(boolean saveAsEnabled)
Enables/Disables document editor "Save As" option in action bar. If disabled, clicking on Done button will overwrite the document automatically.
- Parameters:
saveAsEnabled
-true
to enable document editing "Save As" option,false
to disable it.
-
setDocumentEditorExportEnabled
void setDocumentEditorExportEnabled(boolean exportEnabled)
Enables/Disables document editor "Export pages" option in action bar.
- Parameters:
exportEnabled
-true
to enable document editing page export option,false
to disable it.
-
onDocumentLoaded
@UiThread() void onDocumentLoaded(@NonNull() PdfDocument document)
Called when document is successfully loaded and the document view has been laid out. This has to be called on the main thread.
- Parameters:
document
- Loaded document instance.
-
onDocumentLoadFailed
void onDocumentLoadFailed(@NonNull() Throwable exception)
Called if document loading has failed.
- Parameters:
exception
- Cause of the loading failure.
-
onDocumentSave
boolean onDocumentSave(@NonNull() PdfDocument document, @NonNull() DocumentSaveOptions saveOptions)
Called before document will be saved. This callback allows cancellation of the save process.
- Parameters:
document
- Instance of document to be saved.saveOptions
- Save options to be applied to the document.- Returns:
true
if the document should be saved,false
if saving should be cancelled.
-
onDocumentSaved
void onDocumentSaved(@NonNull() PdfDocument document)
Called after the document has been saved.
- Parameters:
document
- Instance of document that was saved.
-
onDocumentSaveFailed
void onDocumentSaveFailed(@NonNull() PdfDocument document, @NonNull() Throwable exception)
Called if document saving has failed.
- Parameters:
exception
- Cause of the saving failure if applicable.
-
onDocumentSaveCancelled
void onDocumentSaveCancelled(PdfDocument document)
Called if document saving has been cancelled.
- Parameters:
document
- Instance of document that was saved.
-
onPageClick
boolean onPageClick(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @Nullable() MotionEvent event, @Nullable() PointF pagePosition, @Nullable() Annotation clickedAnnotation)
Called when user taps / clicks on the page.
- Parameters:
document
- Currently opened document.pageIndex
- Page number of the page being tapped.event
- MotionEvent that triggered this page click.pagePosition
- Tapped page position (in PDF page coordinates with origin on bottom left).clickedAnnotation
- Annotation that was tapped, ornull
if no annotation was tapped.- Returns:
true
if tap was handled by thisDocumentListener
and should not be handled by PSPDFKit anymore. If returningfalse
PSPDFKit will continue executing it's default action.
-
onDocumentClick
boolean onDocumentClick()
Called when the user taps / clicks on the document, not the page itself but on the side (if visible).
- Returns:
true
if tap is handled orfalse
if PSPDFKit should execute it's default action.
-
onPageChanged
void onPageChanged(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when user scrolled to a new page.
- Parameters:
document
- Currently opened document.pageIndex
- Page number of new page.
-
onDocumentZoomed
void onDocumentZoomed(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, float scaleFactor)
Called when a user zooms a document.
- Parameters:
document
- Current document.pageIndex
- The number of the page that the was zoomed.scaleFactor
- The current scale factor.
-
onPageUpdated
void onPageUpdated(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated). All views displaying this page need to refresh.
- Parameters:
pageIndex
- Page index of the updated page.
-
setDocument
@UiThread() void setDocument(@Nullable() PdfDocument document, @NonNull() PdfConfiguration configuration)
Called when the
document
has been loaded and is going to be displayed. This has to be called on the main thread.- Parameters:
document
- Loaded PdfDocument.configuration
- Containing document and presentation settings.
-
addOnVisibilityChangedListener
void addOnVisibilityChangedListener(@NonNull() OnVisibilityChangedListener listener)
Register a
listener
that would like to receive visibility change events. Whenever the visibility of a managed PSPDFView changes, all registered listeners will be notified.- Parameters:
listener
- Listener to be added.
-
removeOnVisibilityChangedListener
void removeOnVisibilityChangedListener(@NonNull() OnVisibilityChangedListener listener)
Unregister a previously registered
listener
that no longer wants to receive visibility change events.- Parameters:
listener
- Listener to be removed.
-
show
void show()
Called by the activity when the view should make itself visible.
-
hide
void hide()
Called by the activity when the view should hide itself.
-
clearDocument
void clearDocument()
Called by the activity when the view should unbind the previously set document. This may be called in low-memory situations or prior to re-binding another document.
-
getPSPDFViewType
@NonNull() PSPDFKitViews.Type getPSPDFViewType()
Returns the current type of this view.
- Returns:
Any of Type.
-
enterDocumentEditingMode
void enterDocumentEditingMode()
Enters document editing mode.
-
exitDocumentEditingMode
void exitDocumentEditingMode()
Exits document editing mode.
-
isShowPageLabels
boolean isShowPageLabels()
Returns
true
if page labels are shown,false
otherwise.- Returns:
true
if page labels are shown,false
otherwise.
-
addDrawableProvider
void addDrawableProvider(@NonNull() PdfDrawableProvider drawableProvider)
Adds a PdfDrawableProvider to be managed by this object. If the provider has been added previously, this method will be a no-op. Adding
null
is not allowed, and will result in an exception.- Parameters:
drawableProvider
- PdfDrawableProvider whose drawable instances should be managed (e.g.
-
removeDrawableProvider
void removeDrawableProvider(@NonNull() PdfDrawableProvider drawableProvider)
Removes a previously added PdfDrawableProvider. If the provider hasn't been added previously, this method will be a no-op.
- Parameters:
drawableProvider
- PdfDrawableProvider that should be removed.
-
onDocumentSaved
void onDocumentSaved()
Called when saving a document in place is complete.
-
onDocumentExported
void onDocumentExported(@NonNull() Uri destinationUri)
Called when saving a document or exporting pages to a given destination is complete.
- Parameters:
destinationUri
- Destination Uri where the document is saved.
-
getSelectedPages
@NonNull() Set<Integer> getSelectedPages()
Retrieves the currently selected pages of the thumbnail grid.
- Returns:
A set containing the indices of the selected pages or an empty set otherwise
-
focusSearch
View focusSearch(@NonNull() View focused, int direction)
-
setNewPageFactory
final void setNewPageFactory(@Nullable() NewPageFactory newPageFactory)
Sets a NewPageFactory that will be used by the document editor. The factory will be called every time the user wants to add a new page to the edited document. Setting it to
null
will tell the document editor to use the default factory (which is using a page creation dialog).Note: When setting a factory this must be done each time the activity is recreated, since it won't be retained.
- Parameters:
newPageFactory
- Factory that will return instances for the document editor.
-
setDocumentEditorEnabled
void setDocumentEditorEnabled(boolean documentEditorEnabled)
Enables/Disables document editor. This should be set before displaying . If enabled, a floating action button will be displayed, through which a document editing mode can be entered.
- Parameters:
documentEditorEnabled
-true
to enable document editing mode,false
to disable it.
-
setShowPageLabels
void setShowPageLabels(boolean showPageLabels)
Sets whether the page labels will be shown or just the page number.
- Parameters:
showPageLabels
- whether to show page labels or just the page number.
-
-
-
-