EditablePdfViewerFragment


@RequiresExtension(extension = 31, version = 18)
open class EditablePdfViewerFragment : PdfViewerFragment


A androidx.fragment.app.Fragment that extends PdfViewerFragment to provide PDF editing capabilities, including annotation and form filling, leveraging the 'androidx.ink' library.

This fragment coordinates the underlying PDF content with editing layers, enabling users to add ink strokes, create annotations, and modify form fields. It manages the interaction logic between viewing the document and performing edits.

Editing Workflow:

  1. Viewing: Behaves exactly like [PdfViewerFragment].
  2. Editing: When [isEditModeEnabled] is set to `true`, user can leverage editing capabilities(such as annotating or filling forms).
  3. Saving: Edits are accumulated as "drafts". To persist changes, the host must call [applyDraftEdits], which asynchronously applies unsaved edits and creates a [PdfWriteHandle] used to write the modified document to a file.

Summary

Public constructors

Protected constructors

Public functions

Unit

Applies all draft edits to the document.

open Unit

Callback invoked when applying draft edits has failed.

open Unit

Callback invoked when draft edits have been successfully applied to the document.

open Unit
onAttach(context: Context)

Called when a fragment is first attached to its context.

open View?
onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
)
open Unit
open Unit

Called when the fragment is no longer attached to its activity.

open Unit

Callback invoked when EditablePdfViewerFragment enters edit mode.

open Unit

Callback invoked when EditablePdfViewerFragment exits edit mode.

open Unit
onViewCreated(view: View, savedInstanceState: Bundle?)

Public properties

Boolean

Returns true if there are any draft edits that have not yet been applied to the document, false otherwise.

Boolean

Returns true if an applyDraftEdits operation is currently in progress.

Boolean

If true, the fragment is in edit mode, allowing for annotating or editing.

Inherited functions

From androidx.fragment.app.Fragment
open Unit
dump(
    prefix: String,
    fd: FileDescriptor?,
    writer: PrintWriter,
    args: Array<String>?
)

Print the Fragments's state into the given stream.

final operator Boolean
equals(other: Any?)

Subclasses can not override equals().

FragmentActivity?

Return the FragmentActivity this fragment is currently associated with.

open Boolean

Returns whether the the exit transition and enter transition overlap or not.

open Boolean

Returns whether the the return transition and reenter transition overlap or not.

Bundle?

Return the arguments supplied when the fragment was instantiated, if any.

FragmentManager

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

open Context?

Return the Context this fragment is currently associated with.

open Any?

Returns the Transition that will be used to move Views into the initial scene.

open Any?

Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

FragmentManager?

This function is deprecated.

This has been removed in favor of getParentFragmentManager() which throws an IllegalStateException if the FragmentManager is null.

Any?

Return the host object of this fragment.

Int

Return the identifier this fragment is known by.

LayoutInflater

Returns the cached LayoutInflater used to inflate Views of this Fragment.

open LoaderManager

This function is deprecated.

Use LoaderManager.getInstance(this).

Fragment?

Returns the parent Fragment containing this Fragment.

FragmentManager

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

open Any?

Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

Resources

Return requireActivity().getResources().

Boolean

This function is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

open Any?

Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

open Any?

Returns the Transition that will be used for shared elements transferred into the content Scene.

open Any?

Return the Transition that will be used for shared elements transferred back during a pop of the back stack.

String

Return a localized string from the application's package's default string table.

String
getString(resId: @StringRes Int, vararg formatArgs: Any?)

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and format.

String?

Get the tag name of the fragment, if specified.

Fragment?

This function is deprecated.

Instead of using a target fragment to pass results, use setFragmentResult to deliver results to FragmentResultListener instances registered by other fragments via setFragmentResultListener.

Int

This function is deprecated.

When using the target fragment replacement of setFragmentResultListener and setFragmentResult, consider using setArguments to pass a requestKey if you need to support dynamic request keys.

CharSequence

Return a localized, styled CharSequence from the application's package's default string table.

open Boolean

This function is deprecated.

Use setMaxLifecycle instead.

open View?

Get the root view for the fragment's layout (the one returned by onCreateView), if provided.

open LifecycleOwner

Get a LifecycleOwner that represents the Fragment's View lifecycle.

open LiveData<LifecycleOwner>

Retrieve a LiveData which allows you to observe the lifecycle of the Fragment's View.

final Int

Subclasses can not override hashCode().

Boolean

Return true if the fragment is currently added to its activity.

Boolean

Return true if the fragment has been explicitly detached from the UI.

Boolean

Return true if the fragment has been hidden.

Boolean

Return true if the layout is included as part of an activity view hierarchy via the tag.

Boolean

Return true if this fragment is currently being removed from its activity.

Boolean

Return true if the fragment is in the resumed state.

Boolean

Returns true if this fragment is added and its state has already been saved by its host.

Boolean

Return true if the fragment is currently visible to the user.

open Unit

This function is deprecated.

use onViewCreated for code touching the view created by onCreateView and onCreate for other initialization.

open Unit
onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

open Unit

This function is deprecated.

See onAttach.

open Unit

This function is deprecated.

The responsibility for listening for fragments being attached has been moved to FragmentManager.

open Unit
open Boolean

This hook is called whenever an item in a context menu is selected.

open Unit
@MainThread
@CallSuper
onCreate(savedInstanceState: Bundle?)

Called to do initial creation of a fragment.

open Animation?
@MainThread
onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int)

Called when a fragment loads an animation.

open Animator?
@MainThread
onCreateAnimator(transit: Int, enter: Boolean, nextAnim: Int)

Called when a fragment loads an animator.

open Unit
@MainThread
onCreateContextMenu(
    menu: ContextMenu,
    v: View,
    menuInfo: ContextMenu.ContextMenuInfo?
)

Called when a context menu for the view is about to be shown.

open Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

open Unit

Called when the fragment is no longer in use.

open Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

open LayoutInflater
onGetLayoutInflater(savedInstanceState: Bundle?)

Returns the LayoutInflater used to inflate Views of this Fragment.

open Unit

Called when the hidden state (as returned by isHidden of the fragment or another fragment in its hierarchy has changed.

open Unit
@UiThread
@CallSuper
onInflate(
    activity: Activity,
    attrs: AttributeSet,
    savedInstanceState: Bundle?
)

This function is deprecated.

See onInflate.

open Unit

This function is deprecated.

open Unit
onMultiWindowModeChanged(isInMultiWindowMode: Boolean)

Called when the Fragment's activity changes from fullscreen mode to multi-window mode and visa-versa.

open Boolean

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

open Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

open Unit

Called when the Fragment is no longer resumed.

open Unit
onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean)

Called by the system when the activity changes to and from picture-in-picture mode.

open Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

open Unit
@MainThread
onPrimaryNavigationFragmentChanged(
    isPrimaryNavigationFragment: Boolean
)

Callback for when the primary navigation state of this Fragment has changed.

open Unit
onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String>,
    grantResults: IntArray
)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

open Unit

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted.

open Unit

Called when the Fragment is visible to the user.

open Unit

Called when the Fragment is no longer started.

open Unit

Called when all saved state has been restored into the view hierarchy of the fragment.

open Unit

Postpone the entering Fragment transition until startPostponedEnterTransition or executePendingTransactions has been called.

Unit
postponeEnterTransition(duration: Long, timeUnit: TimeUnit)

Postpone the entering Fragment transition for a given amount of time and then call startPostponedEnterTransition.

final ActivityResultLauncher<I>
@MainThread
<I : Any, O : Any> registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    callback: ActivityResultCallback<O>
)

Register a request to start an activity for result, designated by the given contract.

final ActivityResultLauncher<I>
@MainThread
<I : Any, O : Any> registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    registry: ActivityResultRegistry,
    callback: ActivityResultCallback<O>
)

Register a request to start an activity for result, designated by the given contract.

open Unit

Registers a context menu to be shown for the given view (multiple views can show the context menu).

Unit
requestPermissions(permissions: Array<String>, requestCode: Int)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

FragmentActivity

Return the FragmentActivity this fragment is currently associated with.

Bundle

Return the arguments supplied when the fragment was instantiated.

Context

Return the Context this fragment is currently associated with.

FragmentManager

This function is deprecated.

This has been renamed to getParentFragmentManager() to make it clear that you are accessing the FragmentManager that contains this Fragment and not the FragmentManager associated with child Fragments.

Any

Return the host object of this fragment.

Fragment

Returns the parent Fragment containing this Fragment.

View

Get the root view for the fragment's layout (the one returned by onCreateView).

open Unit

Sets whether the the exit transition and enter transition overlap or not.

open Unit

Sets whether the the return transition and reenter transition overlap or not.

open Unit

Supply the construction arguments for this fragment.

open Unit

When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.

open Unit
setEnterTransition(transition: Any?)

Sets the Transition that will be used to move Views into the initial scene.

open Unit

When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.

open Unit
setExitTransition(transition: Any?)

Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

open Unit

This function is deprecated.

This method is no longer needed when using a MenuProvider to provide a Menu to your activity, which replaces onCreateOptionsMenu as the recommended way to provide a consistent, optionally Lifecycle-aware, and modular way to handle menu creation and item selection.

open Unit

Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager.saveFragmentInstanceState.

open Unit
setMenuVisibility(menuVisible: Boolean)

Set a hint for whether this fragment's menu should be visible.

open Unit
setReenterTransition(transition: Any?)

Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

open Unit

This function is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

open Unit
setReturnTransition(transition: Any?)

Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

open Unit

Sets the Transition that will be used for shared elements transferred into the content Scene.

open Unit

Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.

open Unit
setTargetFragment(fragment: Fragment?, requestCode: Int)

This function is deprecated.

Instead of using a target fragment to pass results, the fragment requesting a result should use setFragmentResultListener to register a FragmentResultListener with a requestKey using its parent fragment manager.

open Unit
setUserVisibleHint(isVisibleToUser: Boolean)

This function is deprecated.

If you are manually calling this method, use setMaxLifecycle instead.

open Boolean

Gets whether you should show UI with rationale before requesting a permission.

open Unit

Call startActivity from the fragment's containing Activity.

open Unit
startActivity(intent: Intent, options: Bundle?)

Call startActivity from the fragment's containing Activity.

open Unit
startActivityForResult(intent: Intent, requestCode: Int)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

open Unit
startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

open Unit
startIntentSenderForResult(
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle?
)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

open Unit

Begin postponed transitions after postponeEnterTransition was called.

open String
open Unit

Prevents a context menu to be shown for the given view.

From androidx.pdf.viewer.fragment.PdfViewerFragment
open Unit
onInflate(
    context: Context,
    attrs: AttributeSet,
    savedInstanceState: Bundle?
)

Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity.

open Boolean
onLinkClicked(externalLink: ExternalLink)

Called when an external link in the PDF is clicked.

open Unit

Invoked when a problem arises during the loading process of the PDF document.

open Unit

Invoked when the document has been fully loaded, processed, and the initial pages are displayed within the viewing area.

open Unit

Invoked when underlying PdfView implementation has been created.

open Unit

Called when the PDF view wants to enter or exit immersive mode based on user's interaction with the content.

open Unit

Called when the fragment is visible to the user and actively running.

Inherited properties

From androidx.fragment.app.Fragment
open CreationExtras

The Fragment's arguments when this is first called will be used as the defaults to any androidx.lifecycle.SavedStateHandle passed to a view model created using this extra.

open ViewModelProvider.Factory
open Lifecycle

Overriding this method is no longer supported and this method will be made final in a future version of Fragment.

final SavedStateRegistry
open ViewModelStore

Returns the ViewModelStore associated with this Fragment

From androidx.pdf.viewer.fragment.PdfViewerFragment
Uri?

The URI of the PDF document to display defaulting to null.

Boolean

Controls whether text search mode is active.

Boolean

Indicates whether the toolbox should be visible.

Public constructors

EditablePdfViewerFragment

Added in 1.0.0-alpha13
EditablePdfViewerFragment()

Protected constructors

EditablePdfViewerFragment

Added in 1.0.0-alpha13
protected EditablePdfViewerFragment(pdfStylingOptions: PdfStylingOptions)

Public functions

applyDraftEdits

Added in 1.0.0-alpha13
fun applyDraftEdits(): Unit

Applies all draft edits to the document.

This operation executes asynchronously. The operation will be terminated if EditablePdfViewerFragment is removed from the fragment manager while an applyDraftEdits is in progress. EditablePdfViewerFragment internally disallows editing capabilities during complete operation. Upon completion, either onApplyEditsSuccess or onApplyEditsFailed will be invoked with the result.

Throws
ApplyInProgressException

if another apply operation is already in progress.

onApplyEditsFailed

Added in 1.0.0-alpha13
open fun onApplyEditsFailed(error: Throwable): Unit

Callback invoked when applying draft edits has failed.

Parameters
error: Throwable

The Throwable that caused the failure.

See also
applyDraftEdits

onApplyEditsSuccess

Added in 1.0.0-alpha13
open fun onApplyEditsSuccess(handle: PdfWriteHandle): Unit

Callback invoked when draft edits have been successfully applied to the document.

The host should override this method to perform the write operation. The provided PdfWriteHandle allows writing the document changes to a android.os.ParcelFileDescriptor. The handle must be closed after writing to ensure proper resource cleanup.

After the write operation is complete, the host is responsible for exiting the edit mode by setting isEditModeEnabled to false.

Parameters
handle: PdfWriteHandle

A PdfWriteHandle to be used for writing the changes to a file.

See also
applyDraftEdits

onAttach

open fun onAttach(context: Context): Unit

Called when a fragment is first attached to its context. onCreate will be called after this.

onCreateView

open fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View?

onDestroyView

open fun onDestroyView(): Unit

onDetach

open fun onDetach(): Unit

Called when the fragment is no longer attached to its activity. This is called after onDestroy.

onEnterEditMode

Added in 1.0.0-alpha13
open fun onEnterEditMode(): Unit

Callback invoked when EditablePdfViewerFragment enters edit mode. This is triggered when the user begins an edit for example modifying a form field or interaction via toolbox.

This callback can be used by the developers to make any UI changes required when the user enters edit mode, e.g. showing the "Save" button to the user.

onExitEditMode

Added in 1.0.0-alpha13
open fun onExitEditMode(): Unit

Callback invoked when EditablePdfViewerFragment exits edit mode. This is triggered when the the edit mode is disabled and the fragment completes cleaning up it's edit state.

This callback can be used by the developers to make any UI changes required when the user exits edit mode e.g. hiding the "Save" button.

onViewCreated

open fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit

Public properties

hasUnsavedChanges

Added in 1.0.0-alpha13
val hasUnsavedChangesBoolean

Returns true if there are any draft edits that have not yet been applied to the document, false otherwise.

This can be used to prompt the user to save changes before navigating away, as draft edits will be lost if the fragment is removed from the stack or comes out of edit mode.

isApplyEditsInProgress

Added in 1.0.0-alpha13
val isApplyEditsInProgressBoolean

Returns true if an applyDraftEdits operation is currently in progress.

See also
applyDraftEdits

isEditModeEnabled

Added in 1.0.0-alpha13
var isEditModeEnabledBoolean

If true, the fragment is in edit mode, allowing for annotating or editing. If false, the fragment is in viewing mode.

Note: The host is responsible for setting this to false after a write operation is complete.