For the complete documentation index, see llms.txt. This page is also available as Markdown.

Customize annotation handling

This tutorial only applies to Xamarin.Android. See Xamarin.iOS equivalent here .

By default, the Tools library will respond to user actions such as a click event on a link or form widget, or a property change event on a selected annotation. It is possible to customize such behavior before it is executed within the Tools library, as well as getting notified of an action after it has happened.

Intercept annotation events

If you would like to customize the behavior executed in response to user actions prior to it being handled by the Tools library, it is possible to do so with the BasicAnnotationListener.onInterceptAnnotationHandling(Annot, Bundle, int) API. If this method returns true, then it will intercept executing the default logic.

In BasicAnnotationListener.onInterceptAnnotationHandling(Annot, Bundle, int), the second parameter, Bundle, contains the name of the action intercepted by this function, as well as some extra information. You can get the name of the intercepted action by calling bundle.getString(Tool.METHOD_FROM):

public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
    if (extra != null && extra.containsKey(Tool.METHOD_FROM)) {
        String methodCalling = extra.getString(Tool.METHOD_FROM);
    }
}
override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode): Boolean {
    if (extra != null && extra.containsKey(Tool.METHOD_FROM)) {
        val methodCalling = extra.getString(Tool.METHOD_FROM)
    }
}

To get extra information, first obtain the information keys by calling bundle.getStringArray(Tool.KEYS):

String[] paramKeys = extra.getStringArray(Tool.KEYS)
val paramKeys = extra!!.getStringArray(Tool.KEYS)

Then, you can get the information values by looping on each key obtained above:

public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
    if (extra != null && extra.containsKey(Tool.KEYS)) {
        String[] paramKeys = extra.getStringArray(Tool.KEYS);
        if (paramKeys != null) {
            for (String key : paramKeys) {
                // Gets the information value
                Object param = extra.get(key);
            }
        }
    }
}
override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode): Boolean {
    if (extra != null && extra.containsKey(Tool.KEYS)) {
        val paramKeys = extra.getStringArray(Tool.KEYS)
        if (paramKeys != null) {
            for (key in paramKeys) {
                // Gets the information value
                val param = extra.get(key)
            }
        }
    }
}

Common use cases

Form widgets

Full sample code

For example, the following code demonstrates several scenarios and how you can get notified before each: clicking on a radio button, changing the annotation opacity, and clicking on a link. See the comments in the code for details.

Get notified after an action

If you simply want to get notified after the action has happened, you can do so via the AnnotationModificationListener.onAnnotationsModified(Map<Annot, Integer>) API. This event callback is raised when an annotation change has occurred. For example, in order to get notified when the value of a checkbox has been changed and when annotation opacity has been changed, do the following:

We are always interested in expanding the customization options through APIs, and will be adding more options in the future. If you would like to suggest changes, please don't hesitate to get in touch.

Last updated

Was this helpful?