Annotation events and notifications

In Nutrient Android SDK, annotation events are accessible through the AnnotationManager interface, which is implemented by the PdfFragment. There, you can find the following listeners for subscription:

Listener Description
OnAnnotationCreationModeChangeListener Listener for annotation creation mode enter/exit.
OnAnnotationCreationModeSettingsChangeListener Listener for annotation creation mode settings changes.
OnAnnotationDeselectedListener Listener for annotation deselection.
OnAnnotationEditingModeChangeListener Listener for annotation editing mode enter/exit.
OnAnnotationSelectedListener Listener for annotation selection.

Most use cases should be covered by these listeners, and they can be used as such:

override fun onCreate(savedInstanceState : Bundle?) {
    super.onCreate(savedInstanceState)

    pdfFragment.addOnAnnotationSelectedListener(object :AnnotationManager.OnAnnotationSelectedListener {
        override fun onPrepareAnnotationSelection(controller: AnnotationSelectionController, annotation: Annotation, annotationCreated: Boolean): Boolean {
            // Returning `false` here would prevent the annotation from being selected.
            return true
        }

        override fun onAnnotationSelected(annotation: Annotation, annotationCreated: Boolean) {
            Log.i(TAG, "The annotation was selected.")
        }
    })

    pdfFragment.addOnAnnotationDeselectedListener { annotation, reselected ->
        Log.i(TAG, "The annotation was deselected.")
    }

    pdfFragment.addOnAnnotationUpdatedListener(object: OnAnnotationUpdatedListener {
        override fun onAnnotationCreated(annotation: Annotation) {
            Log.i(TAG, "The annotation was created.")
        }

        override fun onAnnotationUpdated(annotation: Annotation) {
            Log.i(TAG, "The annotation was updated.")
        }

        override fun onAnnotationRemoved(annotation: Annotation) {
            Log.i(TAG, "The annotation was removed.")
        }
    })

    // This will remove all previously registered listeners. Instead, you could unregister them selectively.
    pdfFragment.clearAnnotationListeners()
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getPdfFragment().addOnAnnotationSelectedListener(new AnnotationManager.OnAnnotationSelectedListener() {
        @Override
        public boolean onPrepareAnnotationSelection(@NonNull AnnotationSelectionController controller, @NonNull Annotation annotation, boolean annotationCreated) {
            // Returning `false` here would prevent the annotation from being selected.
            return true;
        }

        @Override public void onAnnotationSelected(@NonNull Annotation annotation, boolean annotationCreated) {
            Log.i(TAG, "The annotation was selected");
        }
    });

    getPdfFragment().addOnAnnotationDeselectedListener(new AnnotationManager.OnAnnotationDeselectedListener() {
        @Override public void onAnnotationDeselected(@NonNull Annotation annotation, boolean reselected) {
            Log.i(TAG, "The annotation was deselected");
        }
    });

    getPdfFragment().addOnAnnotationUpdatedListener(new AnnotationProvider.OnAnnotationUpdatedListener() {
        @Override
        public void onAnnotationCreated(@NonNull Annotation annotation) {
            Log.i(TAG, "The annotation was created.");
        }

        @Override
        public void onAnnotationUpdated(@NonNull Annotation annotation) {
            Log.i(TAG, "The annotation was updated.");
        }

        @Override
        public void onAnnotationRemoved(@NonNull Annotation annotation) {
            Log.i(TAG, "The annotation was removed.");
        }
    });

    // This will remove all previously registered listeners. Instead, you could unregister them selectively.
    getPdfFragment().clearAnnotationListeners();
}

For more information on editing annotations and reacting to changes, please see our how to detect annotation changes guide.