Enabling the Annotation Inspector on Android

The annotation inspector is a PSPDFKit UI component that allows editing of annotation properties. It’s integrated with the PdfActivity and it’s displayed when a user selects the annotation properties picker from the annotation creation or editing toolbars.

Controlling Whether or Not the Annotation Inspector Is Enabled

You can control whether or not the annotation inspector is enabled in PdfActivity via the #setAnnotationInspectorEnabled method in PdfActivityConfiguration.Builder. When the annotation inspector is disabled, the annotation picker icon is hidden from toolbars.

Controlling Which Annotation Properties Are Available in the Annotation Inspector

To control the set of properties shown by the annotation inspector for each annotation type, your custom annotation configuration needs to do two things:

  1. Based on the property type, annotation configuration has to implement the respective interface extending AnnotationConfiguration.

  2. The #getSupportedProperties() method from the configuration must return the set of properties that should be shown in the inspector.

For example, to enable editing of the annotation color property, supported properties must be set to AnnotationProperty#COLOR, and the configuration must implement AnnotationColorConfiguration:

fragment.annotationConfiguration().put(
   AnnotationType.FREETEXT,
   FreeTextAnnotationConfiguration(context)
      // Free text annotations support color and text size properties.
      // This will disable the text size property in the annotation inspector.
      .setSupportedProperties(EnumSet.of(AnnotationProperty.COLOR))
      .build()
)
getPdfFragment().getAnnotationConfiguration().put(
   AnnotationType.FREETEXT,
   FreeTextAnnotationConfiguration(context)
      // Free text annotations support color and text size properties.
      // This will disable the text size property in the annotation inspector.
      .setSupportedProperties(EnumSet.of(AnnotationProperty.COLOR))
      .build()
);

Custom Annotation Inspector UI

PdfActivity uses AnnotationCreationInspectorController when creating annotations and AnnotationEditingInspectorController when editing annotations. Replacing the built-in annotation inspector UI with a custom implementation is simple. All you need to do is provide an implementation of both AnnotationCreationInspectorController and AnnotationEditingInspectorController to PdfActivity via #setAnnotationCreationInspectorController() and #setAnnotationEditingInspectorController().

If you don’t need to create the entire UI from scratch, you can extend the ready-to-use inspector controllers, DefaultAnnotationCreationInspectorController and DefaultAnnotationEditingInspectorController.

See CustomAnnotationInspectorExample from the Catalog app for a complete overview of how to create a custom annotation inspector UI.

Using the Annotation Inspector with a Custom Activity or Layout

If you’re using a custom layout in PdfActivity, you need to provide PropertyInspectorCoordinatorLayout with the ID @id/pspdf__inspector_coordinator in order to be able to use the annotation inspector. See the Custom Activity Layouts section of the Extending PdfActivity guide article for more details.

If you’re using a custom activity built around PdfFragment, follow the using property inspectors within fragment guide for information on how to manually integrate the annotation inspector. Alternatively, you can take a look at ToolbarsInFragmentExample from the Catalog app for a complete example of how to integrate contextual toolbars using the default annotation inspector in a custom activity using PdfFragment.