Annotation style dialog fragment

AnnotStyleDialogFragment is a DialogFragment that shows annotation style properties in a bottom sheet. With this style dialog, users can edit annotation styles easily with style presets as well as choosing their own colors through the advanced color picker. The style dialog also provides a recent and a favorite list for quick access.

To learn about customizing style dialog, see the customize style dialog guide.

Build an annotation style dialog

The AnnotationStyleDialogFragment.Builder class provides APIs that allows you to create an AnnotStyleDialogFragment with a specified AnnotStyle. The AnnotStyle represents the initial annotation style to display.

To build an AnnotStyleDialogFragment:

// 1. Instantiate an AnnotStyle with its constructor
AnnotStyle annotStyle = new AnnotStyle();

// 2. Set annotation type to annot style
annotStyle.setAnnotType(Annot.e_Square);

// 3. Set blue stroke, yellow fill color, thickness 5, opacity 0.8 to the annotation style.
annotStyle.setStyle(Color.BLUE, Color.YELLOW, 5, 0.8);

// 4. Instantiate an AnnotStyleDialogFragment.Builder with its constructor
AnnotStyleDialogFragment.Builder styleDialogBuilder = new AnnotStyleDialogFragment.Builder(annotStyle);

// 5. Set anchor rectangle if you want the `AnnotStyleDialogFragment` be displayed as a popup window in tablet mode
Rect anchor = new Rect(0, 0, 100, 100);
styleDialogBuilder.setAnchor(anchor);

// 6. Build AnnotStyleDialogFragment with the arguments supplied to this builder.
AnnotStyleDialogFragment annotStyleDialog = styleDialogBuilder.build();

Show/dismiss style dialog

To show an annotation style dialog, call show(Activity activity):

annotStyleDialog.show(getActivity());

To dismiss the annotation style dialog programmatically, call dismiss():

annotStyleDialog.dismiss();

Listen to annotation style changes

To listen to annotation style changes, subscribe to setOnAnnotStyleChangeListener(AnnotStyle.OnAnnotStyleChangeListener). It will raise an event when a property change has occurred in the style dialog. Examples include a color change, a thickness change, a text color change, a text size change, an opacity change, an icon change, and a font change. You can define custom behavior when such an event occurs:

annotStyleDialog.setOnAnnotStyleChangeListener(new AnnotStyle.OnAnnotStyleChangeListener() {
            @Override
            public void onChangeAnnotThickness(float thickness) {
                // do something
            }

            @Override
            public void onChangeAnnotTextSize(float textSize) {
                // do something
            }

            @Override
            public void onChangeAnnotTextColor(int textColor) {
                // do something

            }

            @Override
            public void onChangeAnnotOpacity(float opacity) {
                // do something

            }

            @Override
            public void onChangeAnnotStrokeColor(int color) {
                // do something

            }

            @Override
            public void onChangeAnnotFillColor(int color) {
                // do something

            }

            @Override
            public void onChangeAnnotIcon(String icon) {
                // do something

            }

            @Override
            public void onChangeAnnotFont(FontResource font) {
                // do something

            }
        });
To learn about changing annotation style, see the annotation style guide.