public class

PdfActivity

extends AppCompatActivity
implements InternalPdfUi PdfActivityMenu.OnMenuItemsGenerateListener PdfActivityListener
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ androidx.core.app.ComponentActivity
             ↳ androidx.fragment.app.FragmentActivity
               ↳ androidx.appcompat.app.AppCompatActivity
                 ↳ com.pspdfkit.ui.PdfActivity
Known Direct Subclasses

Class Overview

Activity with fully integrated views and behaviour. Can be invoked by the simple helper methods showDocument(Context, Uri, PdfActivityConfiguration) and showDocument(Context, Uri, String, PdfActivityConfiguration). For more advanced customization use PdfActivityIntentBuilder to generate an Intent with proper parameters.

Summary

[Expand]
Inherited Constants
From class android.app.Activity
From class android.content.Context
From interface android.content.ComponentCallbacks2
From interface com.pspdfkit.ui.PdfUi
Fields
public static final int MENU_OPTION_EDIT_ANNOTATIONS Id of the thumbnail grid menu item.
public static final int MENU_OPTION_OUTLINE Id of the thumbnail grid menu item.
public static final int MENU_OPTION_SEARCH Id of the thumbnail grid menu item.
public static final int MENU_OPTION_SETTINGS Id of the settings menu item.
public static final int MENU_OPTION_SHARE Id of the thumbnail grid menu item.
public static final int MENU_OPTION_THUMBNAIL_GRID Id of the thumbnail grid menu item.
[Expand]
Inherited Fields
From class android.app.Activity
Public Constructors
PdfActivity()
Public Methods
abstract void addPropertyInspectorLifecycleListener(PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)
Adds the listener for lifecycle changes of the PropertyInspector as it goes through the PropertyInspectorCoordinatorLayout - preparing, displaying, removing.
boolean dispatchKeyEvent(KeyEvent event)
PdfActivityConfiguration getConfiguration()
Returns the PdfActivityConfiguration that was provided while launching this activity.
AppCompatActivity getHostingActivity()
Bundle getPdfParameters()
abstract PropertyInspectorCoordinatorLayout getPropertyInspectorCoordinator()
Returns property inspector coordinator layout.
void onActivityResult(int requestCode, int resultCode, Intent data)
void onBackPressed()
boolean onCreateOptionsMenu(Menu menu)
boolean onDocumentClick()
Called when the user taps / clicks on the document, not the page itself but on the side (if visible).
void onDocumentLoadFailed(Throwable exception)
Called if document loading has failed.
void onDocumentLoaded(PdfDocument document)
Called when document is successfully loaded and the document view has been laid out.
boolean onDocumentSave(PdfDocument document, DocumentSaveOptions saveOptions)
Called before document will be saved.
void onDocumentSaveCancelled(PdfDocument document)
Called if document saving has been cancelled.
void onDocumentSaveFailed(PdfDocument document, Throwable exception)
Called if document saving has failed.
void onDocumentSaved(PdfDocument document)
Called after the document has been saved.
void onDocumentZoomed(PdfDocument document, int pageIndex, float scaleFactor)
Called when a user zooms a document.
List<Integer> onGenerateMenuItemIds(List<Integer> menuItems)
Called before the main menu items are set to be ordered.
boolean onOptionsItemSelected(MenuItem item)
void onPageChanged(PdfDocument document, int pageIndex)
Called when user scrolled to a new page.
boolean onPageClick(PdfDocument document, int pageIndex, MotionEvent event, PointF pagePosition, Annotation clickedAnnotation)
Called when user taps / clicks on the page.
void onPageUpdated(PdfDocument document, int pageIndex)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated).
boolean onPrepareOptionsMenu(Menu menu)
void onSetActivityTitle(PdfActivityConfiguration configuration, PdfDocument document)
Called when activity title must be set - before and after document was loaded.
void onTrimMemory(int level)
void onUserInteraction()
void onUserInterfaceVisibilityChanged(boolean visible)
Called when user interface visibility have changed.
void onWindowFocusChanged(boolean hasFocus)
void performApplyConfiguration(PdfActivityConfiguration configuration)
abstract void removePropertyInspectorLifecycleListener(PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)
Removes previously registered listener for lifecycle changes of the PropertyInspector as it goes through the PropertyInspectorCoordinatorLayout - preparing, displaying, removing.
abstract void setAnnotationCreationInspectorController(AnnotationCreationInspectorController annotationCreationInspectorController)
Sets controller of the annotation inspector used when creating annotations.
abstract void setAnnotationEditingInspectorController(AnnotationEditingInspectorController annotationEditingInspectorController)
Sets controller of the annotation inspector used when editing annotations.
void setConfiguration(PdfActivityConfiguration configuration)
Replaces activity configuration.
abstract void setDocumentPrintDialogFactory(DocumentPrintDialogFactory factory)
Sets the creator for document print dialogs.
abstract void setDocumentSharingDialogFactory(DocumentSharingDialogFactory factory)
Sets the creator for document sharing dialogs.
abstract void setOnContextualToolbarLifecycleListener(ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener lifecycleListener)
Sets the listener for lifecycle changes of the ContextualToolbar as it goes through the ToolbarCoordinatorLayout - preparing, displaying, removing.
abstract void setOnContextualToolbarMovementListener(ToolbarCoordinatorLayout.OnContextualToolbarMovementListener movementListener)
Sets the listener for ContextualToolbar movements within the layout.
abstract void setOnContextualToolbarPositionListener(ToolbarCoordinatorLayout.OnContextualToolbarPositionListener positionListener)
Sets the listener for ContextualToolbar position changes within the layout.
void setPdfView(View pdfView)
abstract void setPrintOptionsProvider(PrintOptionsProvider provider)
Sets the provider for print options.
abstract void setSharingActionMenuListener(ActionMenuListener listener)
Sets the listener for sharing menu lifecycle and click events.
abstract void setSharingOptionsProvider(SharingOptionsProvider provider)
Sets the provider for sharing options.
static void showDocument(Context context, Uri documentUri, String password, PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed document.
static void showDocument(Context context, Uri documentUri, PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed document.
static void showImage(Context context, Uri imageUri, PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed image document.
Protected Methods
void onCreate(Bundle savedInstanceState)
void onDestroy()
void onPause()
void onPostCreate(Bundle savedInstanceState)
void onResume()
void onSaveInstanceState(Bundle outState)
void onStart()
void onStop()
[Expand]
Inherited Methods
From class androidx.appcompat.app.AppCompatActivity
From class androidx.fragment.app.FragmentActivity
From class androidx.core.app.ComponentActivity
From class android.app.Activity
From class android.view.ContextThemeWrapper
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2
From interface android.view.KeyEvent.Callback
From interface android.view.LayoutInflater.Factory
From interface android.view.LayoutInflater.Factory2
From interface android.view.View.OnCreateContextMenuListener
From interface android.view.Window.Callback
From interface androidx.appcompat.app.ActionBarDrawerToggle.DelegateProvider
From interface androidx.appcompat.app.AppCompatCallback
From interface androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
From interface androidx.core.app.ActivityCompat.RequestPermissionsRequestCodeValidator
From interface androidx.core.app.TaskStackBuilder.SupportParentable
From interface androidx.core.view.KeyEventDispatcher.Component
From interface androidx.lifecycle.LifecycleOwner
From interface androidx.lifecycle.ViewModelStoreOwner
From interface com.pspdfkit.framework.ui.InternalPdfUi
From interface com.pspdfkit.framework.ui.menu.PdfActivityMenu.OnMenuItemsGenerateListener
From interface com.pspdfkit.listeners.DocumentListener
From interface com.pspdfkit.listeners.PdfActivityListener
From interface com.pspdfkit.ui.PdfUi

Fields

public static final int MENU_OPTION_EDIT_ANNOTATIONS

Id of the thumbnail grid menu item.

public static final int MENU_OPTION_OUTLINE

Id of the thumbnail grid menu item.

public static final int MENU_OPTION_SEARCH

Id of the thumbnail grid menu item.

public static final int MENU_OPTION_SETTINGS

Id of the settings menu item.

public static final int MENU_OPTION_SHARE

Id of the thumbnail grid menu item.

public static final int MENU_OPTION_THUMBNAIL_GRID

Id of the thumbnail grid menu item.

Public Constructors

public PdfActivity ()

Public Methods

public abstract void addPropertyInspectorLifecycleListener (PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)

Adds the listener for lifecycle changes of the PropertyInspector as it goes through the PropertyInspectorCoordinatorLayout - preparing, displaying, removing. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
lifecycleListener PropertyInspectorLifecycleListener that should be notified. Must be non-null.

public boolean dispatchKeyEvent (KeyEvent event)

public PdfActivityConfiguration getConfiguration ()

Returns the PdfActivityConfiguration that was provided while launching this activity.

Returns
  • Currently set activity configuration.

public AppCompatActivity getHostingActivity ()

public Bundle getPdfParameters ()

public abstract PropertyInspectorCoordinatorLayout getPropertyInspectorCoordinator ()

Returns property inspector coordinator layout.

Returns
  • Property inspector coordinator.

public void onActivityResult (int requestCode, int resultCode, Intent data)

public void onBackPressed ()

public boolean onCreateOptionsMenu (Menu menu)

public 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 or false if PSPDFKit should execute it's default action.

public void onDocumentLoadFailed (Throwable exception)

Called if document loading has failed.

Parameters
exception Cause of the loading failure.

public void onDocumentLoaded (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.

public boolean onDocumentSave (PdfDocument document, 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. You may change parameters on this object to control how document is saved.
Returns
  • true if the document should be saved, false if saving should be cancelled.

public void onDocumentSaveCancelled (PdfDocument document)

Called if document saving has been cancelled.

Parameters
document Instance of document that was saved.

public void onDocumentSaveFailed (PdfDocument document, Throwable exception)

Called if document saving has failed.

Parameters
exception Cause of the saving failure if applicable.

public void onDocumentSaved (PdfDocument document)

Called after the document has been saved.

Parameters
document Instance of document that was saved.

public void onDocumentZoomed (PdfDocument document, 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.

public List<Integer> onGenerateMenuItemIds (List<Integer> menuItems)

Called before the main menu items are set to be ordered. Override this method to add your custom items to the list. You add just the ids and then in onCreateOptionsMenu(Menu) and onPrepareOptionsMenu(Menu) you can find your items by id and edit them accordingly.

Parameters
menuItems A list of menu item ids, ordered by how they're gonna appear in the main toolbar.
Returns
  • A final list of item ids, declaring how they're gonna be sorted in the toolbar.

public boolean onOptionsItemSelected (MenuItem item)

public void onPageChanged (PdfDocument document, int pageIndex)

Called when user scrolled to a new page.

Parameters
document Currently opened document.
pageIndex Page number of new page.

public boolean onPageClick (PdfDocument document, int pageIndex, MotionEvent event, PointF pagePosition, 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. May be null if this page click was triggered from keyboard or accessibility event.
pagePosition Tapped page position (in PDF page coordinates with origin on bottom left). Coordinates passed here may exceed the page size (which is returned by getPageSize(int)) and can also be negative. If the click was triggered by the keyboard, pagePosition will be null.
clickedAnnotation Annotation that was tapped, or null if no annotation was tapped.
Returns
  • true if tap was handled by this DocumentListener and should not be handled by PSPDFKit anymore. If returning false PSPDFKit will continue executing it's default action.

public void onPageUpdated (PdfDocument document, 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. Page index is 0-based.

public boolean onPrepareOptionsMenu (Menu menu)

public void onSetActivityTitle (PdfActivityConfiguration configuration, PdfDocument document)

Called when activity title must be set - before and after document was loaded.

Parameters
configuration Passed activity configuration instance.
document Loaded document. If document hasn't been loaded yet, this parameter will be null.

public void onTrimMemory (int level)

public void onUserInteraction ()

public void onUserInterfaceVisibilityChanged (boolean visible)

Called when user interface visibility have changed.

Parameters
visible true when UI interface is visible, false when it is hidden.

public void onWindowFocusChanged (boolean hasFocus)

public void performApplyConfiguration (PdfActivityConfiguration configuration)

public abstract void removePropertyInspectorLifecycleListener (PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)

Removes previously registered listener for lifecycle changes of the PropertyInspector as it goes through the PropertyInspectorCoordinatorLayout - preparing, displaying, removing. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
lifecycleListener PropertyInspectorLifecycleListener that should be removed. Must be non-null.

public abstract void setAnnotationCreationInspectorController (AnnotationCreationInspectorController annotationCreationInspectorController)

Sets controller of the annotation inspector used when creating annotations. This replaces default annotation inspector.

Parameters
annotationCreationInspectorController Controller instance to use.

public abstract void setAnnotationEditingInspectorController (AnnotationEditingInspectorController annotationEditingInspectorController)

Sets controller of the annotation inspector used when editing annotations. This replaces default annotation inspector.

Parameters
annotationEditingInspectorController Controller instance to use.

public void setConfiguration (PdfActivityConfiguration configuration)

Replaces activity configuration. This method restarts activity to apply new configuration.

Note: This is a no-op when configuration has not changed.

Parameters
configuration The configuration to restart activity with.

public abstract void setDocumentPrintDialogFactory (DocumentPrintDialogFactory factory)

Sets the creator for document print dialogs.

Parameters
factory Creator to set or null to clear registered creator.

public abstract void setDocumentSharingDialogFactory (DocumentSharingDialogFactory factory)

Sets the creator for document sharing dialogs.

Parameters
factory Creator to set or null to clear registered creator.

public abstract void setOnContextualToolbarLifecycleListener (ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener lifecycleListener)

Sets the listener for lifecycle changes of the ContextualToolbar as it goes through the ToolbarCoordinatorLayout - preparing, displaying, removing. Calling this method will replace any previously set listener. You may provide null to clear the listener.

Parameters
lifecycleListener OnContextualToolbarLifecycleListener that should be notified, or null to clear the listener.

public abstract void setOnContextualToolbarMovementListener (ToolbarCoordinatorLayout.OnContextualToolbarMovementListener movementListener)

Sets the listener for ContextualToolbar movements within the layout. Calling this method will replace any previously set listener. You may provide null to clear the listener.

Parameters
movementListener OnContextualToolbarMovementListener that should be notified, or null to clear the listener.

public abstract void setOnContextualToolbarPositionListener (ToolbarCoordinatorLayout.OnContextualToolbarPositionListener positionListener)

Sets the listener for ContextualToolbar position changes within the layout. Calling this method will replace any previously set listener. You may provide null to clear the listener.

Parameters
positionListener OnContextualToolbarPositionListener that should be notified, or null to clear the listener.

public void setPdfView (View pdfView)

public abstract void setPrintOptionsProvider (PrintOptionsProvider provider)

Sets the provider for print options.

Parameters
provider Provider to set or null to clear registered provider.

public abstract void setSharingActionMenuListener (ActionMenuListener listener)

Sets the listener for sharing menu lifecycle and click events.

Parameters
listener Listener to set or null to clear registered listener.

public abstract void setSharingOptionsProvider (SharingOptionsProvider provider)

Sets the provider for sharing options.

Parameters
provider Provider to set or null to clear registered provider.

public static void showDocument (Context context, Uri documentUri, String password, PdfActivityConfiguration configuration)

Opens a new PdfActivity displaying a passed document. If the document is password protected PSPDFKit will prompt the user to enter the password.

Parameters
context Calling context.
documentUri Uri pointing to the document file.
password Document password, can be null.
configuration Desired activity configuration generated with PdfActivityConfiguration.Builder.

public static void showDocument (Context context, Uri documentUri, PdfActivityConfiguration configuration)

Opens a new PdfActivity displaying a passed document. If the document is password protected PSPDFKit will prompt the user to enter the password.

Parameters
context Calling context
documentUri Uri pointing to the document file
configuration Desired activity configuration generated with PdfActivityConfiguration.Builder

public static void showImage (Context context, Uri imageUri, PdfActivityConfiguration configuration)

Opens a new PdfActivity displaying a passed image document.

Parameters
context Calling context
imageUri Uri pointing to the image document with a supported format (JPG or PNG).
configuration Desired activity configuration generated with PdfActivityConfiguration.Builder, getDefaultImageDocumentActivityConfiguration(PdfActivityConfiguration) or getDefaultImageDocumentActivityConfiguration(Context).

Protected Methods

protected void onCreate (Bundle savedInstanceState)

protected void onDestroy ()

protected void onPause ()

protected void onPostCreate (Bundle savedInstanceState)

protected void onResume ()

protected void onSaveInstanceState (Bundle outState)

protected void onStart ()

protected void onStop ()