public class

PenMenu

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.htc.painting.penmenu.PenMenu

Class Overview

Provide UI widget to select pen setting for drawing on painting view and to execute functions such as undo, redo, clear, set visible of painting view (through IStrokeNotifyPaintingView interface).

Summary

Constants
int CLEAR_ACTION_ID The ID of action button: Clear All.
int COLOR_MENU_ID The ID of menu item: Color.
int PENSET_ALL The supported pen set on Pen Menu: All.
int PENSET_SIMPLE The supported pen set on Pen Menu: Only simple pen (the default stroke type supported by Android) and eraser pen are supported.
int PENSET_SINGLE The supported pen set on Pen Menu: Single pen.
int REDO_ACTION_ID The ID of action button: Redo the previous stroke if any.
int SIZE_MENU_ID The ID of menu item: Size.
int STROKE_INVISIBLE Constants for IPaintingView stroke visibility.
int STROKE_VISIBLE Constants for IPaintingView stroke visibility.
int TYPE_MENU_ID The ID of menu item: Stroke type.
int UNDO_ACTION_ID The ID of action button: Undo the previous stroke if any.
int VISIBLE_ACTION_ID The ID of action button: Show/Hide All.
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
Public Constructors
PenMenu(Context context)
same as FrameLayout's constructor
PenMenu(Context context, AttributeSet attrs)
same as FrameLayout's constructor
PenMenu(Context context, AttributeSet attrs, int defStyle)
same as FrameLayout's constructor
Public Methods
void OnRestoreInstanceState(Bundle bundle)
Called to let PenMenu retrieve the previous saved state and settings.
void OnSaveInstanceState(Bundle bundle)
Called to let PenMenu have chance to save current show/hide state and settings before being killed so that the state and settings can be restored later.
void changeState()
Called to switch the show/hide state of the PenMenu alternately.
boolean dispatchTouchEvent(MotionEvent ev)
int forceHideStroke(boolean forceHide)
Force to hide the strokes (lower the opacity to the predefined value) on painting view when the value of forceHide is set to true or restore the original state of strokes when the value of forceHide is set to false.
boolean handleKeyEvent(int keyCode, KeyEvent event)
Receive the key event passed by applications.
void hide(boolean playAnimation, boolean turnOffStickyState)
Hide PenMenu.
void onDestroy()
void onMenuClosed()
Callback for invoke on Activity#onOptionsMenuClosed or whatever hide the PenMenu by previous onMenuOpened() call.
void onMenuOpened()
Callback for invoke on Activity#onMenuOpened or whatever would overlay with PenMenu to hide the PenMenu.
void restoreSetting()
Restore current pen settings and history pens settings if any.
void saveSetting()
Save current pen settings and history pens settings if any.
void setActionActive(int actionId, boolean active)
When the applications implement their own painting view and integrate with Pen Menu with different behaviors, they can disable action buttons by calling this function.
void setEraserMode(boolean isEraserMode)
Called to enable/disable the Eraser mode.
void setLayoutParams(ViewGroup.LayoutParams params)
void setOnActionPerformListener(OnActionPerformListener listener)
Used for registering one listener to Pen Menu.
void setPaintingView(IStrokeNotifyPaintingView paintingView)
Associate HtcPaintingView with PenMenu.
void setPenSetType(int penSetType)
When applications implement their own painting view and integrate with HTC Pen Menu with limited pen set, call this function to grey out the predefined pens enabled on the device.
void setStrokeVisibleState(int visibility)
void show()
This method is deprecated. Replaced by show(boolean, boolean) since HC.
void show(boolean playAnimation, boolean turnOnStickyState)
Show PenMenu.
Protected Methods
void dispatchDraw(Canvas canvas)
boolean drawChild(Canvas canvas, View child, long drawingTime)
void onAttachedToWindow()
void onDetachedFromWindow()
void onLayout(boolean changed, int left, int top, int right, int bottom)
[Expand]
Inherited Methods
From class android.widget.FrameLayout
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.graphics.drawable.Drawable.Callback2
From interface android.view.HtcIfViewGroup
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int CLEAR_ACTION_ID

Since: API Level 4.0

The ID of action button: Clear All. Clear all strokes on the painting view when this action button is tapped.

Constant Value: 300 (0x0000012c)

public static final int COLOR_MENU_ID

Since: API Level 4.0

The ID of menu item: Color. Tap this menu to select the color of current stroke.

Constant Value: 3 (0x00000003)

public static final int PENSET_ALL

Since: API Level 4.0

The supported pen set on Pen Menu: All. It will enable all pens to users excepts simple pen.

Constant Value: 0 (0x00000000)

public static final int PENSET_SIMPLE

Since: API Level 4.0

The supported pen set on Pen Menu: Only simple pen (the default stroke type supported by Android) and eraser pen are supported.

Constant Value: 1 (0x00000001)

public static final int PENSET_SINGLE

Since: API Level 4.0

The supported pen set on Pen Menu: Single pen. Only support the default stroke type of Android. In this case, the eraser pen is also not supported. The menu item for selecting brush type will be greyed out.

Constant Value: 2 (0x00000002)

public static final int REDO_ACTION_ID

Since: API Level 4.0

The ID of action button: Redo the previous stroke if any. When there is no stroke to redo on the painting view, this button will be greyed out.

Constant Value: 400 (0x00000190)

public static final int SIZE_MENU_ID

Since: API Level 4.0

The ID of menu item: Size. Tap this menu to select the size (width) of current stroke.

Constant Value: 1 (0x00000001)

public static final int STROKE_INVISIBLE

Since: API Level 4.0

Constants for IPaintingView stroke visibility. The ID of stroke visibility: STROKE_INVISIBLE. Set stroke to lower opacity value.

Constant Value: 0 (0x00000000)

public static final int STROKE_VISIBLE

Since: API Level 4.0

Constants for IPaintingView stroke visibility. The ID of stroke visibility: STROKE_VISIBLE. Set stroke to original opacity value.

Constant Value: 1 (0x00000001)

public static final int TYPE_MENU_ID

Since: API Level 4.0

The ID of menu item: Stroke type. Tap this menu to select pen (stroke) to draw.

Constant Value: 2 (0x00000002)

public static final int UNDO_ACTION_ID

Since: API Level 4.0

The ID of action button: Undo the previous stroke if any. When there is no stroke to undo on the painting view, this button will be greyed out.

Constant Value: 100 (0x00000064)

public static final int VISIBLE_ACTION_ID

Since: API Level 4.0

The ID of action button: Show/Hide All. Set the opacity of all strokes on the painting view to lower value when hiding them. (The final value is still under discussion and not decided yet). Reset to the original opacity value by tapping this button again.

Constant Value: 200 (0x000000c8)

Public Constructors

public PenMenu (Context context)

Since: API Level 4.0

same as FrameLayout's constructor

public PenMenu (Context context, AttributeSet attrs)

Since: API Level 4.0

same as FrameLayout's constructor

public PenMenu (Context context, AttributeSet attrs, int defStyle)

Since: API Level 4.0

same as FrameLayout's constructor

Public Methods

public void OnRestoreInstanceState (Bundle bundle)

Since: API Level 4.0

Called to let PenMenu retrieve the previous saved state and settings. PenMenu will restore its state and settings after device orientation is changed.

Parameters
bundle Bundle in which to place your saved state.

public void OnSaveInstanceState (Bundle bundle)

Since: API Level 4.0

Called to let PenMenu have chance to save current show/hide state and settings before being killed so that the state and settings can be restored later. PenMenu will keep its state and setting while device orientation is changed.

Parameters
bundle Bundle in which to place your saved state.

public void changeState ()

Since: API Level 4.0

Called to switch the show/hide state of the PenMenu alternately.

public boolean dispatchTouchEvent (MotionEvent ev)

Since: API Level

public int forceHideStroke (boolean forceHide)

Since: API Level 4.0

Force to hide the strokes (lower the opacity to the predefined value) on painting view when the value of forceHide is set to true or restore the original state of strokes when the value of forceHide is set to false. This function is provided for integrated APPs when users want to interact with the contents behind the painting view. For example, users may press the lower hardware button of Pen to enable Text Selection function. The integrated APPs can call this function to hide on-screen strokes. It will provide a clear view to let users do Text Selection.

Parameters
forceHide true to hide the strokes, false to restore the original state of strokes.
Returns
  • The original stroke state: PenMenu.STROKE_VISIBLE or PenMenu.STROKE_INVISIBLE

public boolean handleKeyEvent (int keyCode, KeyEvent event)

Since: API Level 4.0

Receive the key event passed by applications. If the Hardware Pen Button is pressed, PenMenu will then switch the show/hide state alternately.

Parameters
keyCode the key code.
event the key event.
Returns
  • true if PenMune recognized this key code and processed it.

public void hide (boolean playAnimation, boolean turnOffStickyState)

Since: API Level 4.0

Hide PenMenu. Client app can control whether to play animation by playAnimation parameter. And the turnOffStickyState parameter can control whether the sticky state should be forced to turn off. The sticky state is for controlling the behavior to restore PenMenu's previous show/hide state when it is hidden. If this flag is turned off, the PenMenu couldn't show itself.

Parameters
playAnimation true to play hiding animation, false to hide directly without animation.
turnOffStickyState true to turn off stick state, false to keep sticky state unchanged.
See Also
  • {@link #show(boolean, boolean)}

public void onDestroy ()

Since: API Level 4.0

public void onMenuClosed ()

Since: API Level 4.0

Callback for invoke on Activity#onOptionsMenuClosed or whatever hide the PenMenu by previous onMenuOpened() call. Client app should always call this method on its Activity#onOptionsMenuClosed. Note. The method should be called in pair with onMenuOpened()

See Also
  • {@link #onMenuOpened}

public void onMenuOpened ()

Since: API Level 4.0

Callback for invoke on Activity#onMenuOpened or whatever would overlay with PenMenu to hide the PenMenu. Client app should always call this method on its Activity#onMenuOpened. Note. The method should be called in pair with onMenuClosed()

See Also
  • {@link #onMenuClosed}

public void restoreSetting ()

Since: API Level 4.0

Restore current pen settings and history pens settings if any. This function is designed for the feature of global pens settings (share the same preferences between all pen integrated APPs). When the setting, using the same pen settings among all pen integrated APPs, is set to true. The integrated APPs is responsible to call this function before activities are back to foreground. Once this is called, PenMune module will then restore pen settings by using the global preferences. If the setting is set to false, called this function will restore pen settings by using the local preferences. The pen integrated activities should call this method at their Activity#onResume() method.

public void saveSetting ()

Since: API Level 4.0

Save current pen settings and history pens settings if any. This function is designed for the feature of global pens settings (share the same preferences between all pen integrated APPs). When the setting, using the same pen settings among all pen integrated APPs, is set to true. The integrated APPs is responsible to call this function before activities switch to background. Once this is called, PenMune module will then save current pen preferences for the next foreground pen-integrated activity. If the setting is set to false, called this function will save pen settings in the local preference. The pen integrated activities should call this method at their Activity#onPause() method.

public void setActionActive (int actionId, boolean active)

Since: API Level 4.0

When the applications implement their own painting view and integrate with Pen Menu with different behaviors, they can disable action buttons by calling this function. For example, when the customized painting view doesn't support Clear All function, call this function to grey out Clear All button. Simply, pass the identification of action button and its new state.

Parameters
actionId the identification of action button to set.
active the state of this button. True means to enable and False to grey out this button.

public void setEraserMode (boolean isEraserMode)

Since: API Level 4.0

Called to enable/disable the Eraser mode. When pressing the upper buttons on the H/W Pen and the its corresponding function is configured to Eraser, applications can call this function to enable Eraser mode and the size of Eraser mode will be the same as the current size of Eraser Pen. Once the button is released, call this function with false parameter to disable Eraser mode and restore pen to previous setting.

Parameters
isEraserMode true to enable eraser mode. false to disable eraser mode.

public void setLayoutParams (ViewGroup.LayoutParams params)

Since: API Level

public void setOnActionPerformListener (OnActionPerformListener listener)

Since: API Level 4.0

Used for registering one listener to Pen Menu. Once registered, when the action buttons on Pen Menu are tapped by pen, the application will receive notification. The current action buttons are listed below.

The application can handle these buttons and override the behavior defined by Htc Painging View.

Parameters
listener The OnActionPerformListener object to register

public void setPaintingView (IStrokeNotifyPaintingView paintingView)

Since: API Level 4.0

Associate HtcPaintingView with PenMenu. Once the association is created, any user actions made on PenMenu will apply to Painting Engine, including Pen settings (stroke, size and color) and actions (redo, undo, clear all and set ink opacity)

Parameters
paintingView the painting view to be associated with PenMenu.

public void setPenSetType (int penSetType)

Since: API Level 4.0

When applications implement their own painting view and integrate with HTC Pen Menu with limited pen set, call this function to grey out the predefined pens enabled on the device. Currently, only following pen set are supported for Pen Menu.

Parameters
penSetType the pen set to be set.

public void setStrokeVisibleState (int visibility)

Since: API Level 4.0

public void show ()

Since: API Level 4.0

This method is deprecated.
Replaced by show(boolean, boolean) since HC.

Called to show PenMenu on the screen. It's equivalent to call show(true, false).

public void show (boolean playAnimation, boolean turnOnStickyState)

Since: API Level 4.0

Show PenMenu. Client app can control whether to play animation by playAnimation parameter. And the turnOnStickyState parameter can control whether the sticky state should be forced to turn on. The sticky state is for controlling the behavior to restore PenMenu's previous state when it is hidden. If this flag is turned off, the method has no effect.

Parameters
playAnimation playAnimation true to play showing animation, false to show directly without animation.
turnOnStickyState true to turn on stick state, false to keep sticky state unchanged.
See Also
  • {@link #hide(boolean, boolean)}

Protected Methods

protected void dispatchDraw (Canvas canvas)

Since: API Level

protected boolean drawChild (Canvas canvas, View child, long drawingTime)

Since: API Level

protected void onAttachedToWindow ()

Since: API Level

protected void onDetachedFromWindow ()

Since: API Level

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

Since: API Level