public abstract class

ContextualToolbar

extends ViewGroup
implements View.OnClickListener View.OnLongClickListener
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ com.pspdfkit.ui.toolbar.ContextualToolbar<T extends com.pspdfkit.ui.special_mode.controller.base.SpecialModeController>
Known Direct Subclasses

Class Overview

Base class of all contextual toolbars.

Summary

Nested Classes
interface ContextualToolbar.OnMenuItemClickListener Listener for menu items clicks. 
interface ContextualToolbar.OnMenuItemLongClickListener Listener for long clicks on menu items with submenu. 
Constants
int CONTEXTUAL_TOOLBAR_PADDING_DP
int DEFAULT_TOOLBAR_HEIGHT The default toolbar height in DP (in horizontal mode, otherwise it's the toolbar width)
int DRAG_BUTTON_ALPHA Alpha value of the drag button (if visible).
int MIN_TOOLBAR_CAPACITY Minimal number of spaces left on the toolbar for menu icons.
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
Fields
protected ContextualToolbarMenuItem closeButton A button for closing the contextual toolbar.
protected ToolbarCoordinatorLayoutController coordinatorController Controller for ContextualToolbar -> ToolbarCoordinatorLayout communication.
protected List<ContextualToolbarMenuItem> originalMenuItems Items originally set on the toolbar before the grouping rule is applied, see setMenuItems(List).
[Expand]
Inherited Fields
From class android.view.View
Protected Constructors
ContextualToolbar(Context context)
ContextualToolbar(Context context, AttributeSet attrs)
ContextualToolbar(Context context, AttributeSet attrs, int defStyleAttr)
Public Methods
abstract void bindController(T specialModeController)
Binds the special mode controller to this toolbar.
ContextualToolbarMenuItem findItemById(int menuItemId)
Finds a menu item with specific ID in a list of currently displayed menu items.
ContextualToolbarMenuItem getCloseButton()
Returns the button used to close the toolbar.
ContextualToolbarMenuItem getDragButton()
Returns the button used to drag the toolbar (if detachable).
List<ContextualToolbarMenuItem> getMenuItems()
Gets the list of originally set menu items.
int getParentMenuId(int childMenuId)
ToolbarCoordinatorLayout.LayoutParams.Position getPosition()
Gets position of the toolbar.
int getSubmenuSizePx()
Returns the submenu's size in pixels, or the amount of space needed for the submenu.
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.
boolean hasOpenedSubmenu()
Returns true if this contextual toolbar have currently opened submenu.
final boolean isAttached()
Indicates whether the toolbar is attached or detached.
abstract boolean isControllerBound()
Returns true if the controller is bound.
boolean isDraggable()
Returns true when toolbar is draggable.
boolean onBackPressed()
Called when onBackPressed() to wire up back press with back and close buttons.
void onClick(View v)
boolean onLongClick(View v)
Called when a view has been clicked and held.
List<ContextualToolbarMenuItem> onMenuItemsGrouped(List<ContextualToolbarMenuItem> menuItems)
A method called once the flat items provided through setMenuItems(List) have been grouped by the MenuItemGroupingRule that can be set with setMenuItemGroupingRule(MenuItemGroupingRule) and with DefaultMenuItemGroupingRule as the default one.
boolean onTouchEvent(MotionEvent event)
final void setAttached(boolean isAttached)
Sets whether the toolbar is attached or detached from the layout.
void setCloseButton(ContextualToolbarMenuItem closeButton)
Sets the button used to close the toolbar.
void setDragButton(ContextualToolbarMenuItem dragButton)
Sets the button used to drag the toolbar (if detachable).
void setDraggable(boolean draggable)
Sets whether the toolbar is draggable or not.
boolean setMenuItemEnabled(int menuItemId, boolean enabled)
Enables or disables a menu item if that menu item currently exists.
void setMenuItemGroupingRule(MenuItemGroupingRule groupingRule)
Sets the rule for grouping menu items.
boolean setMenuItemVisibility(int menuItemId, int visibility)
Shows or hides a menu item if that menu item currently exists.
void setMenuItems(List<ContextualToolbarMenuItem> menuItems)
Sets contextual toolbar menu items.
void setOnMenuItemClickListener(ContextualToolbar.OnMenuItemClickListener listener)
Sets a listener for menu item clicks on the toolbar.
void setOnMenuItemLongClickListener(ContextualToolbar.OnMenuItemLongClickListener listener)
Sets a listener for menu item long clicks.
void setPosition(ToolbarCoordinatorLayout.LayoutParams.Position position)
Sets position of the toolbar.
void setToolbarCoordinatorController(ToolbarCoordinatorLayoutController coordinatorController)
Sets the toolbar coordinator controller for communication with ToolbarCoordinatorLayout.
void setUseBackButtonForCloseWhenHorizontal(boolean useBackButtonForCloseWhenHorizontal)
Sets whether to use back button for closing the toolbar when the toolbar is placed horizontally.
abstract void unbindController()
Unbinds the bound controller (if any).
Protected Methods
Completable closeSubmenuForItem(ContextualToolbarMenuItem menuItem)
void deselectCurrentMenuItem()
ContextualToolbarMenuItem findItemById(int menuItemId, List<ContextualToolbarMenuItem> listToSearch)
ContextualToolbarMenuItem getCurrentlySelectedMenuItem()
boolean getUseAlternateBackground()
Toolbars in vertical mode may show a different background color for their items positioned at END (usually the "close", "undo/redo" and "drag" items) Also see getUseAlternateBackground()
abstract void handleMenuItemClick(ContextualToolbarMenuItem item)
void notifyToolbarChanged()
Notifies ToolbarCoordinatorLayoutController about toolbar menu items change made by the toolbar implementation.
void onAttachedToWindow()
void onDetachedFromWindow()
void onDraw(Canvas canvas)
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
boolean onMenuItemClick(ContextualToolbarMenuItem clickedMenuItem)
This method handles menu item clicks, in respect to the menu item listener, which can mark click as handled and suppress further click handling.
boolean onMenuItemLongClick(ContextualToolbarMenuItem clickedMenuItem)
Completable openSubmenuForItem(ContextualToolbarMenuItem menuItem)
boolean selectMenuItem(ContextualToolbarMenuItem menuItem)
void setDragButtonColor(int color)
[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnClickListener
From interface android.view.View.OnLongClickListener
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int CONTEXTUAL_TOOLBAR_PADDING_DP

Constant Value: 5 (0x00000005)

public static final int DEFAULT_TOOLBAR_HEIGHT

The default toolbar height in DP (in horizontal mode, otherwise it's the toolbar width)

Constant Value: 58 (0x0000003a)

public static final int DRAG_BUTTON_ALPHA

Alpha value of the drag button (if visible).

Constant Value: 186 (0x000000ba)

public static final int MIN_TOOLBAR_CAPACITY

Minimal number of spaces left on the toolbar for menu icons.

Constant Value: 4 (0x00000004)

Fields

protected ContextualToolbarMenuItem closeButton

A button for closing the contextual toolbar.

protected ToolbarCoordinatorLayoutController coordinatorController

Controller for ContextualToolbar -> ToolbarCoordinatorLayout communication. ContextualToolbar needs a way to invoke its own detaching and attaching. ToolbarCoordinatorLayout is the one that handles movements once ContextualToolbar is detached.

protected List<ContextualToolbarMenuItem> originalMenuItems

Items originally set on the toolbar before the grouping rule is applied, see setMenuItems(List).

Protected Constructors

protected ContextualToolbar (Context context)

protected ContextualToolbar (Context context, AttributeSet attrs)

protected ContextualToolbar (Context context, AttributeSet attrs, int defStyleAttr)

Public Methods

public abstract void bindController (T specialModeController)

Binds the special mode controller to this toolbar.

Parameters
specialModeController Controller to bind to a toolbar.

public ContextualToolbarMenuItem findItemById (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.

public ContextualToolbarMenuItem getCloseButton ()

Returns the button used to close the toolbar.

Returns
  • Contextual toolbar's close button.

public ContextualToolbarMenuItem getDragButton ()

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

Returns
  • Contextual toolbar's drag button.

public 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.

public int getParentMenuId (int childMenuId)

public ToolbarCoordinatorLayout.LayoutParams.Position getPosition ()

Gets position of the toolbar.

Returns

public int getSubmenuSizePx ()

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

public 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

public boolean hasOpenedSubmenu ()

Returns true if this contextual toolbar have currently opened submenu.

public 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.

public abstract boolean isControllerBound ()

Returns true if the controller is bound.

public boolean isDraggable ()

Returns true when toolbar is draggable.

public 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.

public void onClick (View v)

public 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.

public List<ContextualToolbarMenuItem> onMenuItemsGrouped (List<ContextualToolbarMenuItem> menuItems)

A method called once the flat items provided through setMenuItems(List) have been grouped by the MenuItemGroupingRule that can be set with setMenuItemGroupingRule(MenuItemGroupingRule) and with DefaultMenuItemGroupingRule as the default one.

By overriding this method you can do final editing before items are added to the toolbar.

Parameters
menuItems Grouped menu items.
Returns
  • Menu items to be set on the toolbar.

public boolean onTouchEvent (MotionEvent event)

public 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.

public void setCloseButton (ContextualToolbarMenuItem closeButton)

Sets the button used to close the toolbar.

Parameters
closeButton Button to be set as a close button.

public void setDragButton (ContextualToolbarMenuItem dragButton)

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

Parameters
dragButton Button to be set as a drag button.

public void setDraggable (boolean draggable)

Sets whether the toolbar is draggable or not.

Parameters
draggable If true, the toolbar can be dragged. If false, it's pinned to the top.

public boolean setMenuItemEnabled (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.

public void setMenuItemGroupingRule (MenuItemGroupingRule groupingRule)

Sets the rule for grouping menu items. Default one is DefaultMenuItemGroupingRule.

Parameters
groupingRule Menu items grouping rule to be set.

public boolean setMenuItemVisibility (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.

public void setMenuItems (List<ContextualToolbarMenuItem> menuItems)

Sets contextual toolbar menu items.

Parameters
menuItems Menu items to populate the toolbar.

public void setOnMenuItemClickListener (ContextualToolbar.OnMenuItemClickListener listener)

Sets a listener for menu item clicks on the toolbar. Calling this method will replace any previously set listener. You may provide null to clear the listener.

Parameters
listener ContextualToolbar.OnMenuItemClickListener that should be notified, or null to clear the listener.

public void setOnMenuItemLongClickListener (ContextualToolbar.OnMenuItemLongClickListener listener)

Sets a listener for menu item long clicks. Calling this method will replace any previously set listener. You may provide null to clear the listener.

Parameters
listener ContextualToolbar.OnMenuItemLongClickListener that should be notified, or null to clear the listener.

public void setPosition (ToolbarCoordinatorLayout.LayoutParams.Position position)

Sets position of the toolbar.

Parameters
position Position for the toolbar in the ToolbarCoordinatorLayout.

public void setToolbarCoordinatorController (ToolbarCoordinatorLayoutController coordinatorController)

Sets the toolbar coordinator controller for communication with ToolbarCoordinatorLayout. Calling this method will replace any previously set controller. You may provide null to clear the controller.

Parameters
coordinatorController ToolbarCoordinatorLayoutController that should be notified, or null to clear the controller.

public 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

public abstract void unbindController ()

Unbinds the bound controller (if any).

Protected Methods

protected Completable closeSubmenuForItem (ContextualToolbarMenuItem menuItem)

protected void deselectCurrentMenuItem ()

protected ContextualToolbarMenuItem findItemById (int menuItemId, List<ContextualToolbarMenuItem> listToSearch)

protected ContextualToolbarMenuItem getCurrentlySelectedMenuItem ()

protected boolean getUseAlternateBackground ()

Toolbars in vertical mode may show a different background color for their items positioned at END (usually the "close", "undo/redo" and "drag" items) Also see getUseAlternateBackground()

Returns
  • true if this toolbar supports alternate background colors for the end-items.

protected abstract void handleMenuItemClick (ContextualToolbarMenuItem item)

protected void notifyToolbarChanged ()

Notifies ToolbarCoordinatorLayoutController about toolbar menu items change made by the toolbar implementation. Coordinator controller is not notified about the change when using public method setMenuItems(List).

This will trigger a call to onPrepareContextualToolbar(ContextualToolbar), giving users the chance to modify the toolbar - e.g. to apply a custom grouping rule or hide toolbar items.

protected void onAttachedToWindow ()

protected void onDetachedFromWindow ()

protected void onDraw (Canvas canvas)

protected void onLayout (boolean changed, int l, int t, int r, int b)

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

protected boolean onMenuItemClick (ContextualToolbarMenuItem clickedMenuItem)

This method handles menu item clicks, in respect to the menu item listener, which can mark click as handled and suppress further click handling.

Parameters
clickedMenuItem Menu item that was clicked.
Returns
  • true if the click was handled, and should not be processed further on.

protected boolean onMenuItemLongClick (ContextualToolbarMenuItem clickedMenuItem)

protected Completable openSubmenuForItem (ContextualToolbarMenuItem menuItem)

protected boolean selectMenuItem (ContextualToolbarMenuItem menuItem)

protected void setDragButtonColor (int color)