Class ContextualToolbar

  • All Implemented Interfaces:
    android.graphics.drawable.Drawable.Callback , android.view.KeyEvent.Callback , android.view.View.OnClickListener , android.view.View.OnLongClickListener , android.view.ViewManager , android.view.ViewParent , android.view.accessibility.AccessibilityEventSource

    
    public abstract class ContextualToolbar<T extends SpecialModeController>
    extends ViewGroup implements View.OnClickListener, View.OnLongClickListener
                        

    Base class of all contextual toolbars.

    • Constructor Detail

    • Method Detail

      • setDragButton

         void setDragButton(ContextualToolbarMenuItem dragButton)

        Sets the button used to drag the toolbar (if detachable).

        Parameters:
        dragButton - Button to be set as a drag button.
      • getMenuItems

        @NonNull() List<ContextualToolbarMenuItem> getMenuItems()

        Gets the list of originally set menu items. Note that the shown menu items in the toolbar could differ from structure because they could be altered by MenuItemGroupingRule that regroups items depending on the available space.

        Returns:

        List of originally set toolbar menu items.

      • isDraggable

         boolean isDraggable()

        Returns true when toolbar is draggable.

      • setDraggable

         void setDraggable(boolean draggable)

        Sets whether the toolbar is draggable or not.

        Parameters:
        draggable - If true, the toolbar can be dragged.
      • isAttached

         final boolean isAttached()

        Indicates whether the toolbar is attached or detached.

        Returns:

        true if the toolbar is attached and can't be dragged around, false otherwise.

      • setAttached

         final void setAttached(boolean isAttached)

        Sets whether the toolbar is attached or detached from the layout. Being detached means that it can be moved around (used for annotation editor toolbar). In the scope of this view, what it affects is coloring of the view - the toolbar is highlighted when detached. This is usually called from the outside (toolbar coordinator layout).

        Parameters:
        isAttached - true to set toolbar as attached, false as detached.
      • bindController

         abstract void bindController(T specialModeController)

        Binds the special mode controller to this toolbar.

        Parameters:
        specialModeController - Controller to bind to a toolbar.
      • unbindController

         abstract void unbindController()

        Unbinds the bound controller (if any).

      • isControllerBound

         abstract boolean isControllerBound()

        Returns true if the controller is bound.

      • getSubmenuSizePx

         int getSubmenuSizePx()

        Returns the submenu's size in pixels, or the amount of space needed for the submenu.

      • getToolbarSizeInPx

        @Deprecated(forRemoval = true) int getToolbarSizeInPx()

        Returns the toolbar's size in pixels (height in horizontal mode, width in vertical mode) This method has been deprecated and will be removed in a later version. Use getHeight of this class instead

      • onBackPressed

         boolean onBackPressed()

        Called when onBackPressed() to wire up back press with back and close buttons.

        Returns:

        true if the back press was handled, false otherwise.

      • findItemById

        @Nullable() ContextualToolbarMenuItem findItemById(@IdRes() int menuItemId)

        Finds a menu item with specific ID in a list of currently displayed menu items.

        Returns:

        A menu item currently displayed in the toolbar with the provided ID, or null if no menu item with the given identifier was found.

      • setMenuItemVisibility

         boolean setMenuItemVisibility(@IdRes() int menuItemId, int visibility)

        Shows or hides a menu item if that menu item currently exists.

        Parameters:
        menuItemId - ID of the menu item.
        visibility - One of VISIBLE, INVISIBLE, or GONE.
        Returns:

        true if the menu item exists and it's visibility was changed.

      • setMenuItemEnabled

         boolean setMenuItemEnabled(@IdRes() int menuItemId, boolean enabled)

        Enables or disables a menu item if that menu item currently exists.

        Parameters:
        menuItemId - ID of the menu item.
        enabled - true if the item should be enabled, false otherwise.
        Returns:

        true if the menu item exists and it's enabled status was applied.

      • onLongClick

         boolean onLongClick(View v)

        Called when a view has been clicked and held.

        Parameters:
        v - The view that was clicked and held.
        Returns:

        true if the callback consumed the long click, false otherwise.

      • hasOpenedSubmenu

         boolean hasOpenedSubmenu()

        Returns true if this contextual toolbar have currently opened submenu.

      • setUseBackButtonForCloseWhenHorizontal

         void setUseBackButtonForCloseWhenHorizontal(boolean useBackButtonForCloseWhenHorizontal)

        Sets whether to use back button for closing the toolbar when the toolbar is placed horizontally. Defaults to true. If false the 'X' button will be used and it will be placed on the end of the toolbar.

        Parameters:
        useBackButtonForCloseWhenHorizontal - true to use back button, false to use 'X' button