public class

PdfActivity

extends AppCompatActivity
implements PdfActivityListener
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ android.support.v4.app.SupportActivity
             ↳ android.support.v4.app.FragmentActivity
               ↳ android.support.v7.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

Constants
String LOG_TAG
long TIMEOUT_DEFAULT Parameter for setScreenTimeout(long) used for restoring screen timeout to its default system value.
long TIMEOUT_INFINITE Parameter for setScreenTimeout(long) used for disabling screen timeout.
[Expand]
Inherited Constants
From class android.app.Activity
From class android.content.Context
From interface android.content.ComponentCallbacks2
Fields
public static final int MENU_OPTION_OUTLINE Outline menu option identifier.
public static final int MENU_OPTION_SEARCH Search menu option identifier.
public static final int MENU_OPTION_THUMBNAIL_GRID Thumbnail grid menu option identifier.
[Expand]
Inherited Fields
From class android.app.Activity
Public Constructors
PdfActivity()
Public Methods
void addPropertyInspectorLifecycleListener(PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)
boolean dispatchKeyEvent(KeyEvent event)
PdfActivityMenuManager getActivityMenuManager()
Returns the menu manager which you can use to change main menu item icons and colors programmatically.
PdfActivityConfiguration getConfiguration()
Returns the PdfActivityConfiguration that was provided while launching this activity.
PdfDocument getDocument()
Returns the PdfDocument that is loaded into this activity, or null if no document has been loaded yet.
DocumentCoordinator getDocumentCoordinator()
Returns the coordinator responsible for displaying documents and switching between multiple loaded documents.
PSPDFKitViews getPSPDFKitViews()
Returns object with inflated PSPDFKit views.
int getPageIndex()
Returns current page index set on the document.
PdfFragment getPdfFragment()
Returns the PdfFragment that is used to show the document.
PropertyInspectorCoordinatorLayout getPropertyInspectorCoordinator()
Returns property inspector coordinator layout.
long getScreenTimeout()
Gets screen timeout in milliseconds that has been added to the predefined system timeout, TIMEOUT_DEFAULT or TIMEOUT_INFINITE.
int getSiblingPageIndex(int pageIndex)
Get page sibling index (usable in double page mode).
UserInterfaceViewMode getUserInterfaceViewMode()
Return current user interface view mode that activity is using.
void hideUserInterface()
Animates user interface controls out of view.
boolean isImageDocument()
Indicates whether the displayed document is an image or not.
boolean isUserInterfaceVisible()
Checks whether user interface controls are currently visible.
void onActivityResult(int requestCode, int resultCode, Intent data)
void onBackPressed()
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.
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 removePropertyInspectorLifecycleListener(PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)
void setAnnotationCreationInspectorController(AnnotationCreationInspectorController annotationCreationInspectorController)
Sets controller of the annotation inspector used when creating annotations.
void setAnnotationEditingInspectorController(AnnotationEditingInspectorController annotationEditingInspectorController)
Sets controller of the annotation inspector used when editing annotations.
void setConfiguration(PdfActivityConfiguration configuration)
Replaces activity configuration.
void setDocumentFromDataProvider(DataProvider dataProvider, String password)
Loads a new document in this activity and replaces the existing one.
void setDocumentFromDataProviders(List<DataProvider> dataProviders, List<String> passwords)
Loads a new document in this activity and replaces the existing one.
void setDocumentFromUri(Uri documentUri, String password)
Loads a new document in this activity and replaces the existing one.
void setDocumentFromUris(List<Uri> documentUris, List<String> passwords)
Loads a new document in this activity and replaces the existing one.
void setDocumentPrintDialogFactory(DocumentPrintDialogFactory factory)
Sets the creator for document print dialogs.
void setDocumentSharingDialogFactory(DocumentSharingDialogFactory factory)
Sets the creator for document sharing dialogs.
void setOnContextualToolbarLifecycleListener(ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener lifecycleListener)
void setOnContextualToolbarMovementListener(ToolbarCoordinatorLayout.OnContextualToolbarMovementListener movementListener)
void setOnContextualToolbarPositionListener(ToolbarCoordinatorLayout.OnContextualToolbarPositionListener positionListener)
void setPageIndex(int pageIndex)
Set page to be displayed in the current document.
void setPageIndex(int pageIndex, boolean animate)
Set page to be displayed in the current document.
void setPrintOptionsProvider(PrintOptionsProvider provider)
void setScreenTimeout(long screenTimeoutMillis)
Sets screen timeout in milliseconds that will be added to the predefined system timeout (that is usually 1 minute).
void setSharingActionMenuListener(ActionMenuListener listener)
Sets the listener for sharing menu lifecycle and click events.
void setSharingOptionsProvider(SharingOptionsProvider provider)
void setUserInterfaceViewMode(UserInterfaceViewMode userInterfaceViewMode)
Sets the activity user interface view mode at a runtime.
void setUserInterfaceVisible(boolean show, boolean animate)
Show or hide user interface controls.
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.
void showUserInterface()
Animates user interface controls into view.
void toggleUserInterface()
Toggles the visibility of user interface controls.
Protected Methods
void onCreate(Bundle savedInstanceState)
void onDestroy()
void onPause()
void onResume()
void onSaveInstanceState(Bundle outState)
void onStart()
void onStop()
[Expand]
Inherited Methods
From class android.support.v7.app.AppCompatActivity
From class android.support.v4.app.FragmentActivity
From class android.support.v4.app.SupportActivity
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.arch.lifecycle.LifecycleOwner
From interface android.arch.lifecycle.ViewModelStoreOwner
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2
From interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
From interface android.support.v4.app.ActivityCompat.RequestPermissionsRequestCodeValidator
From interface android.support.v4.app.TaskStackBuilder.SupportParentable
From interface android.support.v4.view.KeyEventDispatcher.Component
From interface android.support.v7.app.ActionBarDrawerToggle.DelegateProvider
From interface android.support.v7.app.AppCompatCallback
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 com.pspdfkit.listeners.DocumentListener
From interface com.pspdfkit.listeners.PdfActivityListener

Constants

public static final String LOG_TAG

Constant Value: "PSPDFKit.PdfActivity"

public static final long TIMEOUT_DEFAULT

Parameter for setScreenTimeout(long) used for restoring screen timeout to its default system value.

Constant Value: 0 (0x0000000000000000)

public static final long TIMEOUT_INFINITE

Parameter for setScreenTimeout(long) used for disabling screen timeout.

Constant Value: 9223372036854775807 (0x7fffffffffffffff)

Fields

public static final int MENU_OPTION_OUTLINE

Outline menu option identifier.

public static final int MENU_OPTION_SEARCH

Search menu option identifier.

public static final int MENU_OPTION_THUMBNAIL_GRID

Thumbnail grid menu option identifier.

Public Constructors

public PdfActivity ()

Public Methods

public void addPropertyInspectorLifecycleListener (PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)

public boolean dispatchKeyEvent (KeyEvent event)

public PdfActivityMenuManager getActivityMenuManager ()

Returns the menu manager which you can use to change main menu item icons and colors programmatically.

Returns
  • Activity's menu manager.

public PdfActivityConfiguration getConfiguration ()

Returns the PdfActivityConfiguration that was provided while launching this activity.

Returns
  • Currently set activity configuration.

public PdfDocument getDocument ()

Returns the PdfDocument that is loaded into this activity, or null if no document has been loaded yet.

Returns
  • Document loaded into the activity.

public DocumentCoordinator getDocumentCoordinator ()

Returns the coordinator responsible for displaying documents and switching between multiple loaded documents.

Returns

public PSPDFKitViews getPSPDFKitViews ()

Returns object with inflated PSPDFKit views. This is meant to be used when extending this class for easier customization.

Returns

public int getPageIndex ()

Returns current page index set on the document.

Returns
  • Index of the page currently displayed in the document (-1 if document is null).

public PdfFragment getPdfFragment ()

Returns the PdfFragment that is used to show the document.

Returns
  • Current fragment for displaying the document.

public PropertyInspectorCoordinatorLayout getPropertyInspectorCoordinator ()

Returns property inspector coordinator layout.

Returns
  • Property inspector coordinator.

public long getScreenTimeout ()

Gets screen timeout in milliseconds that has been added to the predefined system timeout, TIMEOUT_DEFAULT or TIMEOUT_INFINITE.

Returns

public int getSiblingPageIndex (int pageIndex)

Get page sibling index (usable in double page mode).

Parameters
pageIndex Index of the page for which we look for the sibling.
Returns
  • Provided page sibling, or -1 if there is none.

public UserInterfaceViewMode getUserInterfaceViewMode ()

Return current user interface view mode that activity is using.

public void hideUserInterface ()

Animates user interface controls out of view. Does nothing if already hidden, USER_INTERFACE_VIEW_MODE_VISIBLE is set or when user interface is sticky - inline search is active, toolbar forces user interface to be visible etc.

public boolean isImageDocument ()

Indicates whether the displayed document is an image or not.

Returns
  • true if the displayed document is image, false otherwise.

public boolean isUserInterfaceVisible ()

Checks whether user interface controls are currently visible.

Returns
  • true if visible, false otherwise.

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

public void onBackPressed ()

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.

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 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.

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 removePropertyInspectorLifecycleListener (PropertyInspectorCoordinatorLayoutController.PropertyInspectorLifecycleListener lifecycleListener)

public 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 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 void setDocumentFromDataProvider (DataProvider dataProvider, String password)

Loads a new document in this activity and replaces the existing one. This method may only be called if onSaveInstanceState(Bundle) has not been called or an exception will be thrown, since after that call state loss could occur.

Parameters
dataProvider Data provider for the document.
password Document password. May be null.

public void setDocumentFromDataProviders (List<DataProvider> dataProviders, List<String> passwords)

Loads a new document in this activity and replaces the existing one. This method may only be called if onSaveInstanceState(Bundle) has not been called or an exception will be thrown, since after that call state loss could occur.

Parameters
dataProviders List of data providers for compound document.
passwords List of passwords for compound document, may be null.

public void setDocumentFromUri (Uri documentUri, String password)

Loads a new document in this activity and replaces the existing one. This method may only be called if onSaveInstanceState(Bundle) has not been called or an exception will be thrown, since after that call state loss could occur.

Parameters
documentUri Document URI.
password Document password. May be null.

public void setDocumentFromUris (List<Uri> documentUris, List<String> passwords)

Loads a new document in this activity and replaces the existing one. This method may only be called if onSaveInstanceState(Bundle) has not been called or an exception will be thrown, since after that call state loss could occur.

Parameters
documentUris List of document URIs for compound document.
passwords List of passwords for compound document, may be null.

public void setDocumentPrintDialogFactory (DocumentPrintDialogFactory factory)

Sets the creator for document print dialogs.

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

public void setDocumentSharingDialogFactory (DocumentSharingDialogFactory factory)

Sets the creator for document sharing dialogs.

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

public void setOnContextualToolbarLifecycleListener (ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener lifecycleListener)

public void setOnContextualToolbarMovementListener (ToolbarCoordinatorLayout.OnContextualToolbarMovementListener movementListener)

public void setOnContextualToolbarPositionListener (ToolbarCoordinatorLayout.OnContextualToolbarPositionListener positionListener)

public void setPageIndex (int pageIndex)

Set page to be displayed in the current document.

Parameters
pageIndex Index of the target page (starting at 0).

public void setPageIndex (int pageIndex, boolean animate)

Set page to be displayed in the current document.

Parameters
pageIndex Index of the target page (starting at 0).
animate true if the transition to the specified page should be animated, false otherwise.

public void setPrintOptionsProvider (PrintOptionsProvider provider)

public void setScreenTimeout (long screenTimeoutMillis)

Sets screen timeout in milliseconds that will be added to the predefined system timeout (that is usually 1 minute). I.e. setScreenTimeout(30 * 1000) will turn off the device screen in 90 seconds.

Parameters
screenTimeoutMillis can be a positive number, TIMEOUT_DEFAULT or TIMEOUT_INFINITE.

public void setSharingActionMenuListener (ActionMenuListener listener)

Sets the listener for sharing menu lifecycle and click events. Calling this method will replace any previously set listener. You may provide null to clear the listener.

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

public void setSharingOptionsProvider (SharingOptionsProvider provider)

public void setUserInterfaceViewMode (UserInterfaceViewMode userInterfaceViewMode)

Sets the activity user interface view mode at a runtime. Overriding PdfActivityConfiguration.

public void setUserInterfaceVisible (boolean show, boolean animate)

Show or hide user interface controls. This does not respect currently configured UserInterfaceViewMode.

Parameters
show True to show user interface, False to hide it.
animate True to animate the change.

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, ImageDocumentLoader#getDefaultImageDocumentActivityConfiguration(PdfActivityConfiguration.Builder), or getDefaultImageDocumentActivityConfiguration(Context).

public void showUserInterface ()

Animates user interface controls into view. Does nothing if already showing, USER_INTERFACE_VIEW_MODE_HIDDEN is set or when user interface is forced to be hidden - for example when creating annotations and using vertical toolbar.

public void toggleUserInterface ()

Toggles the visibility of user interface controls.

Protected Methods

protected void onCreate (Bundle savedInstanceState)

protected void onDestroy ()

protected void onPause ()

protected void onResume ()

protected void onSaveInstanceState (Bundle outState)

protected void onStart ()

protected void onStop ()