Class PdfActivity
-
- All Implemented Interfaces:
-
android.content.ComponentCallbacks
,android.content.ComponentCallbacks2
,android.view.KeyEvent.Callback
,android.view.LayoutInflater.Factory
,android.view.LayoutInflater.Factory2
,android.view.View.OnCreateContextMenuListener
,android.view.Window.Callback
,androidx.activity.FullyDrawnReporterOwner
,androidx.activity.OnBackPressedDispatcherOwner
,androidx.activity.contextaware.ContextAware
,androidx.activity.result.ActivityResultCaller
,androidx.activity.result.ActivityResultRegistryOwner
,androidx.appcompat.app.ActionBarDrawerToggle.DelegateProvider
,androidx.appcompat.app.AppCompatCallback
,androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
,androidx.core.app.ActivityCompat.RequestPermissionsRequestCodeValidator
,androidx.core.app.OnMultiWindowModeChangedProvider
,androidx.core.app.OnNewIntentProvider
,androidx.core.app.OnPictureInPictureModeChangedProvider
,androidx.core.app.OnUserLeaveHintProvider
,androidx.core.app.TaskStackBuilder.SupportParentable
,androidx.core.content.OnConfigurationChangedProvider
,androidx.core.content.OnTrimMemoryProvider
,androidx.core.view.KeyEventDispatcher.Component
,androidx.core.view.MenuHost
,androidx.lifecycle.HasDefaultViewModelProviderFactory
,androidx.lifecycle.LifecycleOwner
,androidx.lifecycle.ViewModelStoreOwner
,androidx.savedstate.SavedStateRegistryOwner
,com.pspdfkit.internal.ui.menu.PdfActivityMenu.OnPrepareDefaultMenuItemListener
,com.pspdfkit.listeners.DocumentListener
,com.pspdfkit.listeners.OnMenuItemsGenerateListener
,com.pspdfkit.listeners.PdfActivityListener
,com.pspdfkit.ui.PdfActivityComponentsApi
,com.pspdfkit.ui.PdfUi
public class PdfActivity extends AppCompatActivity implements PdfUi, PdfActivityListener, PdfActivityComponentsApi
Activity with fully integrated views and behaviour. Can be invoked by the simple helper methods showDocument and showDocument. For more advanced customization use to generate an Intent with proper parameters.
-
-
Field Summary
Fields Modifier and Type Field Description public final static int
MENU_OPTION_THUMBNAIL_GRID
public final static int
MENU_OPTION_SEARCH
public final static int
MENU_OPTION_OUTLINE
public final static int
MENU_OPTION_EDIT_ANNOTATIONS
public final static int
MENU_OPTION_EDIT_CONTENT
public final static int
MENU_OPTION_SIGNATURE
public final static int
MENU_OPTION_SHARE
public final static int
MENU_OPTION_SETTINGS
public final static int
MENU_OPTION_READER_VIEW
public final static int
MENU_OPTION_DOCUMENT_INFO
public PdfUiImpl
implementation
-
Constructor Summary
Constructors Constructor Description PdfActivity()
-
Method Summary
Modifier and Type Method Description PdfUiImpl
getImplementation()
Gets the PdfUiImpl. static void
showDocument(@NonNull() Context context, @NonNull() Uri documentUri, @Nullable() PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed document. static void
showImage(@NonNull() Context context, @NonNull() Uri imageUri, @Nullable() PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed image document. static void
showDocument(@NonNull() Context context, @NonNull() Uri documentUri, @Nullable() String password, @Nullable() PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed document. void
onTrimMemory(int level)
boolean
dispatchKeyEvent(KeyEvent event)
void
onUserInteraction()
void
onWindowFocusChanged(boolean hasFocus)
List<Integer>
onGenerateMenuItemIds(@NonNull() List<Integer> menuItems)
Called before the main menu items are set to be ordered. boolean
onCreateOptionsMenu(Menu menu)
boolean
onPrepareOptionsMenu(Menu menu)
boolean
onOptionsItemSelected(@NonNull() MenuItem item)
void
onActivityResult(int requestCode, int resultCode, Intent data)
int
onGetShowAsAction(int menuItemId, int defaultShowAsAction)
void
onBackPressed()
PdfActivityConfiguration
getConfiguration()
Returns the PdfActivityConfiguration that was provided while launching this activity. void
setConfiguration(@NonNull() PdfActivityConfiguration configuration)
Replaces activity configuration. void
onSetActivityTitle(@NonNull() PdfActivityConfiguration configuration, @Nullable() PdfDocument document)
Called when activity title must be set - before and after document was loaded. void
onUserInterfaceVisibilityChanged(boolean visible)
Called when user interface visibility have changed. 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
onConfigurationChanged(@NonNull() Configuration newConfig)
-
-
Method Detail
-
getImplementation
@NonNull() PdfUiImpl getImplementation()
Gets the PdfUiImpl. For internal usage only.
-
showDocument
static void showDocument(@NonNull() Context context, @NonNull() Uri documentUri, @Nullable() 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 contextdocumentUri
- android.net.Uri pointing to the document fileconfiguration
- Desired activity configuration generated with
-
showImage
static void showImage(@NonNull() Context context, @NonNull() Uri imageUri, @Nullable() PdfActivityConfiguration configuration)
Opens a new PdfActivity displaying a passed image document.
- Parameters:
context
- Calling contextimageUri
- android.net.Uri pointing to the image document with a supported format (JPG or PNG).configuration
- Desired activity configuration generated with , getDefaultImageDocumentActivityConfiguration or getDefaultImageDocumentActivityConfiguration.
-
showDocument
static void showDocument(@NonNull() Context context, @NonNull() Uri documentUri, @Nullable() String password, @Nullable() 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 benull
.configuration
- Desired activity configuration generated with .
-
onTrimMemory
void onTrimMemory(int level)
-
dispatchKeyEvent
boolean dispatchKeyEvent(KeyEvent event)
-
onUserInteraction
void onUserInteraction()
-
onWindowFocusChanged
void onWindowFocusChanged(boolean hasFocus)
-
onGenerateMenuItemIds
@NonNull() List<Integer> onGenerateMenuItemIds(@NonNull() 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 and onPrepareOptionsMenu 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.
-
onCreateOptionsMenu
boolean onCreateOptionsMenu(Menu menu)
-
onPrepareOptionsMenu
boolean onPrepareOptionsMenu(Menu menu)
-
onOptionsItemSelected
boolean onOptionsItemSelected(@NonNull() MenuItem item)
-
onActivityResult
void onActivityResult(int requestCode, int resultCode, Intent data)
-
onGetShowAsAction
int onGetShowAsAction(int menuItemId, int defaultShowAsAction)
-
onBackPressed
void onBackPressed()
-
getConfiguration
@NonNull() PdfActivityConfiguration getConfiguration()
Returns the PdfActivityConfiguration that was provided while launching this activity.
- Returns:
Currently set activity configuration.
-
setConfiguration
void setConfiguration(@NonNull() 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.
-
onSetActivityTitle
void onSetActivityTitle(@NonNull() PdfActivityConfiguration configuration, @Nullable() PdfDocument document)
Called when activity title must be set - before and after document was loaded.
- Parameters:
configuration
- Passed activity configuration instance.document
- Loaded document.
-
onUserInterfaceVisibilityChanged
void onUserInterfaceVisibilityChanged(boolean visible)
Called when user interface visibility have changed.
- Parameters:
visible
-true
when UI interface is visible,false
when it is hidden.
-
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 this DocumentListener 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.
-
onConfigurationChanged
void onConfigurationChanged(@NonNull() Configuration newConfig)
-
-
-
-