public class

HtcPaintingView

extends RelativeLayout
implements IStrokeNotifyPaintingView
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.RelativeLayout
         ↳ com.htc.painting.engine.HtcPaintingView

Class Overview

This class is an implementation of IStrokeNotifyPaintingView. It implements all functionalities of the IPaintingView and IStrokeNotifyPaintingView. Besides the features defined in IPaintingView and IStrokeNotifyPaintingView, HtcPaintingView also provides basic mechanism to save/load stroke information.

Summary

Nested Classes
interface HtcPaintingView.OnCacheListener Interface definition for a callback to be invoked when an Cache events occur. 
Constants
int NO_SEPARATOR
[Expand]
Inherited Constants
From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View
Fields
protected boolean mEnableEditMode
protected List<IPaintingView.OnPaintingViewListener> mPaintingViewListener
[Expand]
Inherited Fields
From class android.view.ViewGroup
From class android.view.View
Public Constructors
HtcPaintingView(Context context)
same as FrameLayout's constructor
HtcPaintingView(Context context, AttributeSet attrs)
same as FrameLayout's constructor
HtcPaintingView(Context context, AttributeSet attrs, int defStyle)
same as FrameLayout's constructor
Public Methods
boolean canRedo()
Indicates whether redo operation can be performed on this HtcPaintingView.
boolean canUndo()
Indicates whether undo operation can be performed on this HtcPaintingView.
void clearAll()
Clear all strokes from this HtcPaitingView.
void clearInkDrawingCache()
void clearStrokeGroup(int groupId)
clear all strokes in a stroke group
void clearStrokeGroups(int[] groupIds)
clear all strokes in the specified StrokeGroups
void clearUndoRedoHistory()
clear undo/redo history.
void deleteStrokeGroup(int groupId)
Delete aStrokeGroup from this HtcPaintingView
void destroy()
This function release all resources within the HtcPainting.
boolean dispatchPenEvent(MotionEvent event)
boolean dispatchTouchEvent(MotionEvent event)
void drawOnBitmap(Bitmap bitmap, int groupId, int strokeId, ViewPort viewport)
Draws a specific Stroke and Viewport of a specific StrokeGroup on the input bitmap.
void drawOnBitmap(Bitmap bitmap, int groupId, int strokeId)
Draws a specific Stroke of a specific StrokeGroup on the input bitmap.
void drawOnBitmap(Bitmap bitmap, int groupId, ViewPort viewport)
Draw a specific StrokeGroups onto a bitmap with respect to the given viewport
void drawOnBitmap(Bitmap bitmap, int[] groupIds)
Draw a specific StrokeGroups onto a bitmap
void drawOnCanvas(Canvas canvas)
Draw requested groups on targes canvas
void drawStroke(Canvas canvas, int groupId, int strokeId, int startPoint, int endPoint, ViewPort viewport)
This function will draw a specific segment of a stroke on the input canvas The startPoint and endPoint together specify the segment in the Stroke to be drawn.
void drawStroke(Canvas canvas, int groupId, int strokeId, int startPoint, int endPoint)
This function will draw a specific segment of a stroke on the input canvas The startPoint and endPoint together specify the segment in the Stroke to be drawn.
void enableEditMode(boolean value)
void enableEraseMode(boolean enable)
Enable/disable erase mode
void enablePainting(boolean enable)
enable/disable HtcPainting This function is originally designed to show/hide strokes and is no longer needed
void enableTouchPainting(boolean enable)
Enable/disable painting strokes by touch event.
RectF getBoundingRectF(int groupId)
Returns the minimal rectangle that contains all strokes of a StrokeGroup.
int getRequestedStrokeGroupCount()
This function returns the number of requested StrokeGroups.
int[] getRequestedStrokeGroupIds()
returns the StrokeGroup Id of current requested StrokeGroups
WeakReference<Stroke> getStroke(int groupId, int strokeID)
Get a specific Stroke instance
long getStrokeGroupMemorySize(int groupId)
StrokeProperties getStrokeProperties()
Get current StrokeProperties
List<Stroke> getStrokesFromReqGroup(int groupId)
Get Strokes from Requested Stroke Group.
List<Stroke> getStrokesFromReqGroup(int groupId, boolean containIneffectiveStroke)
Get Strokes from Requested Stroke Group.
ViewPort getViewPort(int groupId)
This method returns the ViewPort of a StrokeGroup.
void init(AbsSerializeDAO serializeDAO)
This init() must called before using the HtcPaintingView.
void interceptPenEvent(boolean intercept)
This method can be used to configure whether the HtcPainting should consume the PenEvent.
boolean isEraseModeOn()
Inidicates whether erase mode is on
boolean isInitialized()
Indicates whether this HtcPaintingView has been initialized.
boolean isPainting()
boolean isPaintingEnable()
true if HtcPainting is enabled
boolean isStrokeGroupClean(int groupId)
Indicates whether this stroke group has stroke or not
boolean isStrokeGroupModified(int groupId)
void onConfigurationChanged(Configuration newConfig)
void onDraw(Canvas canvas)
void onWindowFocusChanged(boolean hasWindowFocus)
void redo()
redo previous undo action
void removeOnCacheListener(HtcPaintingView.OnCacheListener list)
void removeOnPaintingViewListener(IPaintingView.OnPaintingViewListener listener)
removes a registered OnPaintingViewListener from further event callbacks.
void removeOnStrokeListener(IStrokeNotifyPaintingView.OnStrokeListener listener)
removes a registered OnStrokeListener from further event callbacks.
void requestSaveStrokeGroup(int id)
requests the HtcPaitingView to save a specified StrokeGroup.
void requestSaveStrokeGroup(int id, boolean saveIneffectiveStrokes)
void requestSaveStrokeGroups(int[] ids, boolean saveIneffectiveStrokes)
void requestSaveStrokeGroups(int[] ids)
requests the HtcPaitingView to save some specified StrokeGroups.
void requestSaveStrokeGroupsAsync(int[] groupIds, int key, IPaintingCallBack.IActionCallback callback, boolean saveIneffectiveStrokes)
void requestSaveStrokeGroupsAsync(int[] groupIds, int key, IPaintingCallBack.IActionCallback callback)
boolean[] requestStrokeGroups(int[] groupIds, ViewPort[] viewports)
This method will change current stroke groups.
void requestStrokeGroupsAsync(int[] groupIds, ViewPort[] viewports, int key, IPaintingCallBack.IActionCallback callback)
void setDisplayAlpha(int alpha)
Apply specified alpha value on strokes
void setDocViewPort(ViewPort docViewport)
void setDrawingPartialInvalidate(boolean value)
Enable/disable partial invalidate dirty rectangle when drawing stroke
void setEnabled(boolean enabled)
void setInkDrawingCacheRatio(float xRatio, float yRatio)
sets the ink drawing cache ratio of this HtcPaintingView.
void setOnCacheListener(HtcPaintingView.OnCacheListener list)
void setOnPaintingViewListener(IPaintingView.OnPaintingViewListener listener)
Register a callback to be invoked when an PaintingView event occurs.
void setOnStrokeListener(IStrokeNotifyPaintingView.OnStrokeListener listener)
Register a callback to be invoked when an Stroke event occurs.
void setPen(Pen p, StrokeProperties defaultProperties)
void setSeparatorDist(int dist)
void setShowProcessingIndicator(boolean show)
Set whether this HtcPaintingView should show processing indicator to user.
void setStrokeProperties(StrokeProperties p)
Set as current HtcPainting StrokeProperties.
boolean setViewPortForStrokeGroup(int groupId, ViewPort viewPort)
Sets a ViewPort to a StrokeGroup
void undo()
undo previous drawing action
Protected Methods
void onDetachedFromWindow()
void onLayout(boolean changed, int left, int top, int right, int bottom)
[Expand]
Inherited Methods
From class android.widget.RelativeLayout
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.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource
From interface com.htc.painting.engine.IPaintingView
From interface com.htc.painting.engine.IStrokeNotifyPaintingView

Constants

public static final int NO_SEPARATOR

Constant Value: -1 (0xffffffff)

Fields

protected boolean mEnableEditMode

protected List<IPaintingView.OnPaintingViewListener> mPaintingViewListener

Public Constructors

public HtcPaintingView (Context context)

same as FrameLayout's constructor

public HtcPaintingView (Context context, AttributeSet attrs)

same as FrameLayout's constructor

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

same as FrameLayout's constructor

Public Methods

public boolean canRedo ()

Indicates whether redo operation can be performed on this HtcPaintingView.

Returns
  • true if it is a valid redo state

public boolean canUndo ()

Indicates whether undo operation can be performed on this HtcPaintingView.

Returns
  • true if it is a valid undo state

public void clearAll ()

Clear all strokes from this HtcPaitingView.

public void clearInkDrawingCache ()

public void clearStrokeGroup (int groupId)

clear all strokes in a stroke group

Parameters
groupId which stroke group

public void clearStrokeGroups (int[] groupIds)

clear all strokes in the specified StrokeGroups

Parameters
groupIds which stroke groups to clear

public void clearUndoRedoHistory ()

clear undo/redo history. This should be called in onDestroy() but before destroyHtcPainting() is called

public void deleteStrokeGroup (int groupId)

Delete aStrokeGroup from this HtcPaintingView

Parameters
groupId which stroke group

public void destroy ()

This function release all resources within the HtcPainting. This should be call in onDestroy()

public boolean dispatchPenEvent (MotionEvent event)

public boolean dispatchTouchEvent (MotionEvent event)

public void drawOnBitmap (Bitmap bitmap, int groupId, int strokeId, ViewPort viewport)

Draws a specific Stroke and Viewport of a specific StrokeGroup on the input bitmap.

Parameters
bitmap bitmap to be drawn
groupId the StrokeGroup id of the stroke to be drawn
strokeId the Stroke Id of the stroke to be drawn
viewport the view port of the stroke to be drawn

public void drawOnBitmap (Bitmap bitmap, int groupId, int strokeId)

Draws a specific Stroke of a specific StrokeGroup on the input bitmap.

Parameters
bitmap bitmap to be drawn
groupId the StrokeGroup id of the stroke to be drawn
strokeId the Stroke Id of the stroke to be drawn

public void drawOnBitmap (Bitmap bitmap, int groupId, ViewPort viewport)

Draw a specific StrokeGroups onto a bitmap with respect to the given viewport

Parameters
bitmap the bitmap to be drawn
groupId which stroke group to draw
viewport the viewport to be applied to the strokes

public void drawOnBitmap (Bitmap bitmap, int[] groupIds)

Draw a specific StrokeGroups onto a bitmap

Parameters
bitmap the bitmap to be drawn
groupIds which stroke groups to draw

public void drawOnCanvas (Canvas canvas)

Draw requested groups on targes canvas

Parameters
canvas target canvas

public void drawStroke (Canvas canvas, int groupId, int strokeId, int startPoint, int endPoint, ViewPort viewport)

This function will draw a specific segment of a stroke on the input canvas The startPoint and endPoint together specify the segment in the Stroke to be drawn.

Parameters
canvas the canvas to draw on
groupId the StrokeGroup id of the stroke to be drawn
strokeId the stroke id of the stroke to be drawn
startPoint starting point of the segment
endPoint end point of the segment.
viewport the viewport to be applied to the strokes

public void drawStroke (Canvas canvas, int groupId, int strokeId, int startPoint, int endPoint)

This function will draw a specific segment of a stroke on the input canvas The startPoint and endPoint together specify the segment in the Stroke to be drawn.

Parameters
canvas the canvas to draw on
groupId the StrokeGroup id of the stroke to be drawn
strokeId the stroke id of the stroke to be drawn
startPoint starting point of the segment
endPoint end point of the segment.

public void enableEditMode (boolean value)

public void enableEraseMode (boolean enable)

Enable/disable erase mode

Parameters
enable If true, next stroke will be an eraser. If false, next stroke will be a pen

public void enablePainting (boolean enable)

enable/disable HtcPainting This function is originally designed to show/hide strokes and is no longer needed

public void enableTouchPainting (boolean enable)

Enable/disable painting strokes by touch event.

Parameters
enable true to enable painting by touch event, false to disable.

public RectF getBoundingRectF (int groupId)

Returns the minimal rectangle that contains all strokes of a StrokeGroup.

Parameters
groupId which stroke group
Returns
  • bounding rectangle of specified stroke group

public int getRequestedStrokeGroupCount ()

This function returns the number of requested StrokeGroups.

Returns
  • number of stroke group ids that has been requested

public int[] getRequestedStrokeGroupIds ()

returns the StrokeGroup Id of current requested StrokeGroups

Returns
  • current stroke groups' ids

public WeakReference<Stroke> getStroke (int groupId, int strokeID)

Get a specific Stroke instance

Parameters
groupId the group Id of the desired Stroke
strokeID the Stroke Id of the desired Stroke
Returns
  • the Stroke instance of the desired Stroke

public long getStrokeGroupMemorySize (int groupId)

public StrokeProperties getStrokeProperties ()

Get current StrokeProperties

Returns
  • the currentStrokeProperties

public List<Stroke> getStrokesFromReqGroup (int groupId)

Get Strokes from Requested Stroke Group. Only effective stroke will be included.

public List<Stroke> getStrokesFromReqGroup (int groupId, boolean containIneffectiveStroke)

Get Strokes from Requested Stroke Group.

Parameters
containIneffectiveStroke true: Include Ineffective strokes

public ViewPort getViewPort (int groupId)

This method returns the ViewPort of a StrokeGroup.

Parameters
groupId which stroke group
Returns
  • the AbsHtcPaintingViewPort of the specified StrokeGroup; null if such ViewPort cannot be found.

public void init (AbsSerializeDAO serializeDAO)

This init() must called before using the HtcPaintingView. It will create HtcPainting and set up HtcPainting default settings.

Parameters
serializeDAO The DAO callback used load/save/delete strokes

public void interceptPenEvent (boolean intercept)

This method can be used to configure whether the HtcPainting should consume the PenEvent.

Parameters
intercept the HtcPaintingView will consume the PenEvent if this value is set to true and will not consume the PenEvent if the value is set to false.

public boolean isEraseModeOn ()

Inidicates whether erase mode is on

Returns
  • true if next stroke is an eraser

public boolean isInitialized ()

Indicates whether this HtcPaintingView has been initialized.

Returns
  • true if this HtcPaintingView has been initialized, and false otherwise

public boolean isPainting ()

public boolean isPaintingEnable ()

true if HtcPainting is enabled

Returns
  • true if HtcPainting is enabled

public boolean isStrokeGroupClean (int groupId)

Indicates whether this stroke group has stroke or not

Parameters
groupId which stroke group
Returns
  • true if it has no strokes

public boolean isStrokeGroupModified (int groupId)

public void onConfigurationChanged (Configuration newConfig)

public void onDraw (Canvas canvas)

public void onWindowFocusChanged (boolean hasWindowFocus)

public void redo ()

redo previous undo action

public void removeOnCacheListener (HtcPaintingView.OnCacheListener list)

public void removeOnPaintingViewListener (IPaintingView.OnPaintingViewListener listener)

removes a registered OnPaintingViewListener from further event callbacks.

Parameters
listener the callback to be removed

public void removeOnStrokeListener (IStrokeNotifyPaintingView.OnStrokeListener listener)

removes a registered OnStrokeListener from further event callbacks.

Parameters
listener the callback to be removed

public void requestSaveStrokeGroup (int id)

requests the HtcPaitingView to save a specified StrokeGroup. When upon saving the StrokeGroup, the designated AbsSerializeDAO.save will be called to perform the actual saving.

Parameters
id the StrokeGroup id of that StrokeGroup that is to be saved

public void requestSaveStrokeGroup (int id, boolean saveIneffectiveStrokes)

public void requestSaveStrokeGroups (int[] ids, boolean saveIneffectiveStrokes)

public void requestSaveStrokeGroups (int[] ids)

requests the HtcPaitingView to save some specified StrokeGroups. When upon saving the StrokeGroup, the designated AbsSerializeDAO.save will be called to perform the actual saving.

Parameters
ids the StrokeGroup id of that StrokeGroups that are to be saved

public void requestSaveStrokeGroupsAsync (int[] groupIds, int key, IPaintingCallBack.IActionCallback callback, boolean saveIneffectiveStrokes)

public void requestSaveStrokeGroupsAsync (int[] groupIds, int key, IPaintingCallBack.IActionCallback callback)

public boolean[] requestStrokeGroups (int[] groupIds, ViewPort[] viewports)

This method will change current stroke groups. If the specified stroke groups are not in memory, painting framework will request them by serializeDAO. If serializeDAO returns null, it will create empty new stroke groups with specified stroke group ids.

Parameters
groupIds which stroke groups
Returns
  • true(s) if success

public void requestStrokeGroupsAsync (int[] groupIds, ViewPort[] viewports, int key, IPaintingCallBack.IActionCallback callback)

Parameters
groupIds which stroke group
key action key
callback callback when operation completed

public void setDisplayAlpha (int alpha)

Apply specified alpha value on strokes

public void setDocViewPort (ViewPort docViewport)

public void setDrawingPartialInvalidate (boolean value)

Enable/disable partial invalidate dirty rectangle when drawing stroke

Parameters
value if true, only invalidate the rectangle that stroke do partial render. if false, invalidate stroke's bounding rectangle.

public void setEnabled (boolean enabled)

public void setInkDrawingCacheRatio (float xRatio, float yRatio)

sets the ink drawing cache ratio of this HtcPaintingView. Note that the ratio must be greater or equal to 1.0f

Parameters
xRatio ink cache size to display size ratio in x-axis
yRatio ink cache size to display size ratio in y-axis

public void setOnCacheListener (HtcPaintingView.OnCacheListener list)

public void setOnPaintingViewListener (IPaintingView.OnPaintingViewListener listener)

Register a callback to be invoked when an PaintingView event occurs.

Parameters
listener the callback to be run on

public void setOnStrokeListener (IStrokeNotifyPaintingView.OnStrokeListener listener)

Register a callback to be invoked when an Stroke event occurs.

Parameters
listener the callback to be run on

public void setPen (Pen p, StrokeProperties defaultProperties)

public void setSeparatorDist (int dist)

public void setShowProcessingIndicator (boolean show)

Set whether this HtcPaintingView should show processing indicator to user. If set to true, the HtcPaintingView will show indicator when performing loading process. The default value is set to true.

Parameters
show true to show indicator

public void setStrokeProperties (StrokeProperties p)

Set as current HtcPainting StrokeProperties. These properties will determine how the pen stroke is drawn.

Parameters
p the StrokeProperties to be used when drawing a stroke

public boolean setViewPortForStrokeGroup (int groupId, ViewPort viewPort)

Sets a ViewPort to a StrokeGroup

Parameters
groupId which stroke group
viewPort the view port assigned to the stroke group
Returns
  • true if the operation was done successfully; false otherwise.

public void undo ()

undo previous drawing action

Protected Methods

protected void onDetachedFromWindow ()

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