Annotation toolbar

In this document
chevron_rightUndo/Redo
chevron_rightListeners
chevron_rightUndo/Redo listener
chevron_rightAppearance styling
chevron_rightXML attributes

AnnotationToolbar is a FrameLayout consisting of various annotation creation tools. With the annotation toolbar, users are able to conveniently create and switch between different tools.

To learn about each icon, see the icon cheat sheet.
Due to space limitations, only a limited number of tools will show on portrait mode of smaller devices.
ScenarioAnnotation Toolbar
Small devices in landscape mode + Tablet devices
Small devices in portrait mode

Show/hide annotation toolbar

The annotation toolbar allows the user to easily switch tools when adding annotations to the document. To set up your layout with annotation toolbar, add a <AnnotationToolbar> element to your XML layout. For example, your layout may look like this:

<com.pdftron.pdf.controls.AnnotationToolbar
    android:id="@+id/annotationToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:elevation="@dimen/actionbar_elevation"/>

Then, you need to attach a ToolManager to the annotation toolbar:

final AnnotationToolbar annotationToolbar = view.findViewById(R.id.annotationToolbar);
annotationToolbar.setup(mToolManager);
annotationToolbar.show();

To close the annotation toolbar programmatically call:

annotationToolbar.close();

Handle rotation:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    annotationToolbar.onConfigurationChanged(newConfig);
}

Hide annotation toolbar items

If there are tools that you would like to remove from the annotation toolbar, you can disable them via ToolManager.disableToolMode API. For example:

// disable TextHighlightCreate tool, TextUnderlineCreate tool
// TextSquigglyCreate tool and TextStrikeoutCreate tool
mToolManager.disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.TEXT_HIGHLIGHT,
    ToolManager.ToolMode.TEXT_UNDERLINE,
    ToolManager.ToolMode.TEXT_SQUIGGLY,
    ToolManager.ToolMode.TEXT_STRIKEOUT}
);

Then, when open the annotation toolbar, you will see:

Portrait:

Landscape:

Undo/Redo

If undo/redo is enabled in the PDFViewCtrl then the buttons for undo/redo will also be provided as popup windows when the user clicks on the three vertical dots at the right end of the toolbar.

Listeners

Annotation toolbar listener

You can set a listener via setAnnotationToolbarListener(AnnotationToolbarListener) to be notified when the annotation toolbar is displayed or hidden. In addition, the listener should implement onShowAnnotationToolbarByShortcut(int) in order to show the annotation toolbar starting in a given tool mode. The method is invoked when the user presses a shortcut that would bring up the annotation toolbar. This listener is useful, for example, in order to keep the annotation toolbar hidden if the document has read-only access.

Example

annotationToolbar.setAnnotationToolbarListener(new AnnotationToolbar.AnnotationToolbarListener() {
    @Override
    public void onShowAnnotationToolbarByShortcut(final int mode) {
        boolean writeAccess = ...
        // check for write access

        if (writeAccess) {
            annotationToolbar.show(mode);
        }
    }

    @Override
    public void onAnnotationToolbarShown() {
        // annotation toolbar was shown
    }

    @Override
    public void onAnnotationToolbarClosed() {
        // annotation toolbar was closed
    }
});

Undo/Redo listener

To be notified when undo/redo buttons are clicked you should call AnnotationToolbar.setOnUndoRedoListener(OnUndoRedoListener).

Example

mAnnotationToolbar.setOnUndoRedoListener(new UndoRedoPopupWindow.OnUndoRedoListener() {
    @Override
    public void onUndoRedoCalled() {
        // refresh the current page number and the total number of pages if they are shown over the viewer
    }
});

Continuous annotation edit

By default the annotation toolbar returns to the pan tool after an annotation is created. If you prefer to keep the same tool mode after an annotation is created you should call

annotationToolbar.setButtonStayDown(true);

Appearance styling

In order to customize the appearance of UI elements in annotation toolbar, you can define annotation_toolbar style inside your style.xml file:

<style name="YourAppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="colorPrimary">@color/app_color_primary_day</item>
    <item name="colorPrimaryDark">@color/app_color_primary_dark_day</item>
    <item name="colorAccent">@color/app_color_accent</item>

    <item name="annotation_toolbar">@style/CustomAnnotationToolbarStyle</item>
</style>

<style name="CustomAnnotationToolbarStyle" parent="AnnotationToolbarStyle">
    <item name="colorBackground">@android:color/black</item>
</style>

Alternatively, you can change the attributes inside your xml layout:

<com.pdftron.pdf.controls.AnnotationToolbar
  android:id="@+id/annotationToolbar"
    app:colorBackground="@android:color/black"
    ... 
/>

XML attributes

app:colorBackground

Specifies the annotation toolbar background color

Format: color

Default value: ?attr/colorPrimary

app:colorToolBackground

Specifies the background color of each tool in annotation toolbar

Format: color

Default value: ?attr/colorPrimaryDark

app:colorToolIcon

Specifies the icon color of each tool (except the close button) in annotation toolbar

Format: color

Default value: @android:color/white

app:colorCloseIcon

Specifies the icon color of the close button in annotation toolbar

Format: color

Default value: @android:color/white