public class

ColorPickerPanel

extends View
java.lang.Object
   ↳ android.view.View
     ↳ com.droidux.pack.commons.widget.color.ColorPickerPanel

Class Overview

Custom view for selecting color.

Summary

XML Attributes
Attribute Name Related Method Description
dux_border_color Color of the border of the panels. 
dux_border_width Specifies the width of the border. 
dux_orientation Specifies the orientation of the widget. 
dux_showAlphaPanel Controls whether the alpha slider/panel should be shown/hidden. 
dux_showSelectionPanel Controls whether the color selection panels should be shown/hidden. 
dux_sliderHandle_color Color of the slider's handle. 
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ColorPickerPanel(Context context)
ColorPickerPanel(Context context, AttributeSet attrs)
ColorPickerPanel(Context context, AttributeSet attrs, int defStyle)
Public Methods
int getBorderColor()
Gets the color of the border.
int getColor()
Gets the currently selected color.
ColorPickerInterfaces.Listeners.OnColorChangedListener getOnColorChangedListener()
Gets the color changed listener registered for this view.
ColorPickerInterfaces.Listeners.OnColorSelectedListener getOnColorSelectedListener()
Gets the color selected listener registered for this view.
int getSliderHandleColor()
Gets the color of the slider's handles.
boolean isPortrait()
Checks whether the color panels are layout in a portrait orientation.
boolean onTouchEvent(MotionEvent event)
Implement this method to handle touch screen motion events.
boolean onTrackballEvent(MotionEvent event)
Implement this method to handle trackball motion events.
void setBorderColor(int color)
Sets the color of panels' border.
void setColor(int color)
Sets the currently selected color.
void setOnColorChangedListener(ColorPickerInterfaces.Listeners.OnColorChangedListener listener)
Register a listener to be notified when the color is changed.
void setOnColorSelectedListener(ColorPickerInterfaces.Listeners.OnColorSelectedListener listener)
Register a listener to be notified when a new color is selected.
void setSliderHandleColor(int color)
Sets the color of the slider's handles.
void showAlphaPanel(boolean show)
Sets whether to show/hide the alpha panel/slider.
void showSelectionPanel(boolean show)
Sets whether to show the color selection panels.
Protected Methods
void onDraw(Canvas canvas)
Implement this to do your drawing.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

void onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().
Parcelable onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.
void onSizeChanged(int w, int h, int oldw, int oldh)
This is called during layout when the size of this view has changed.
[Expand]
Inherited Methods
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.accessibility.AccessibilityEventSource

XML Attributes

dux_border_color

Since: API Level

Color of the border of the panels. If the border width is greater than 0, a border with the specified color will be drawn around every panels.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related Methods

dux_border_width

Since: API Level

Specifies the width of the border. Its value should be a dimension type (such as "2dip"). If the width is greater than 0, a border will be drawn around the panel.

Related Methods

dux_orientation

Since: API Level

Specifies the orientation of the widget.

Must be one of the following constant values.

ConstantValueDescription
auto0 The orientation will be determined automatically.
portrait1 The widget should have a "portrait" orientation.
landscape2 The widget should have a "landscape" orientation.

Related Methods

dux_showAlphaPanel

Since: API Level

Controls whether the alpha slider/panel should be shown/hidden. Default is true.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

Related Methods

dux_showSelectionPanel

Since: API Level

Controls whether the color selection panels should be shown/hidden. A color selection panels are panels that shows the initial color and the currently selected color with an arrow in the middle of them. Normally you would like to show the selection panel, but there are some cases where you might prefer to hide it. By default, the selection panel is displayed. Default is true.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

Related Methods

dux_sliderHandle_color

Since: API Level

Color of the slider's handle. Certain panels/sliders have handle. This attribute defines the color of those handles.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related Methods

Public Constructors

public ColorPickerPanel (Context context)

Since: API Level 2.5

public ColorPickerPanel (Context context, AttributeSet attrs)

Since: API Level 2.5

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

Since: API Level 2.5

Public Methods

public int getBorderColor ()

Since: API Level 2.5

Gets the color of the border.

Returns
  • The border color.

public int getColor ()

Since: API Level 2.5

Gets the currently selected color.

Returns
  • The selected color.

public ColorPickerInterfaces.Listeners.OnColorChangedListener getOnColorChangedListener ()

Since: API Level 2.5

Gets the color changed listener registered for this view.

Returns
  • The listener.

public ColorPickerInterfaces.Listeners.OnColorSelectedListener getOnColorSelectedListener ()

Since: API Level 2.5

Gets the color selected listener registered for this view.

Returns
  • The listener.

public int getSliderHandleColor ()

Since: API Level 2.5

Gets the color of the slider's handles. Certain panels function as a slider (like the alpha panel/slider). These sliders have a handle to adjust the value. The color of the handles can be specified using the setSliderHandleColor(int) method.

Returns
  • The slider's handle color.

public boolean isPortrait ()

Since: API Level 2.5

Checks whether the color panels are layout in a portrait orientation.

Returns
  • If true, the panels are layout in a portrait orientation. Otherwise, it's landscape.

public boolean onTouchEvent (MotionEvent event)

Since: API Level

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling ACTION_CLICK when accessibility features are enabled

Parameters
event The motion event.
Returns
  • True if the event was handled, false otherwise.

public boolean onTrackballEvent (MotionEvent event)

Since: API Level

Implement this method to handle trackball motion events. The relative movement of the trackball since the last event can be retrieve with MotionEvent.getX() and MotionEvent.getY(). These are normalized so that a movement of 1 corresponds to the user pressing one DPAD key (so they will often be fractional values, representing the more fine-grained movement information available from a trackball).

Parameters
event The motion event.
Returns
  • True if the event was handled, false otherwise.

public void setBorderColor (int color)

Since: API Level 2.5

Sets the color of panels' border. If the border color is set, all panels in this view will have a border with the specified color.

public void setColor (int color)

Since: API Level 2.5

Sets the currently selected color.

Parameters
color The selected color.

public void setOnColorChangedListener (ColorPickerInterfaces.Listeners.OnColorChangedListener listener)

Since: API Level 2.5

Register a listener to be notified when the color is changed.

Parameters
listener The listener to be notified.

public void setOnColorSelectedListener (ColorPickerInterfaces.Listeners.OnColorSelectedListener listener)

Since: API Level 2.5

Register a listener to be notified when a new color is selected.

Parameters
listener The listener to be notified.

public void setSliderHandleColor (int color)

Since: API Level 2.5

Sets the color of the slider's handles. Certain panels function as a slider (like the alpha panel/slider). These sliders have a handle to adjust the value.

Parameters
color The slider's handle color.

public void showAlphaPanel (boolean show)

Since: API Level 2.5

Sets whether to show/hide the alpha panel/slider.

Parameters
show If true, the alpha panel/slider will be shown which can be used to adjust the color's alpha value. Otherwise, it will be hidden.

public void showSelectionPanel (boolean show)

Since: API Level 2.5

Sets whether to show the color selection panels. The color selection panels are the panels/boxes that show the original color and the new/selected color with an arrow in the middle of it. If the user press on the "original color" panel/box, the color selection will be reset to the original color. If the user press on the "new/selected color" panel/box, the new color will be accepted, and the "original color" box will show the accepted color.

Parameters
show If true, the color selection panels will be shown, otherwise it will be hidden.

Protected Methods

protected void onDraw (Canvas canvas)

Since: API Level

Implement this to do your drawing.

Parameters
canvas the canvas on which the background will be drawn

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Since: API Level

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

protected void onRestoreInstanceState (Parcelable state)

Since: API Level

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

Parameters
state The frozen state that had previously been returned by onSaveInstanceState().

protected Parcelable onSaveInstanceState ()

Since: API Level

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.

Returns
  • Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.

protected void onSizeChanged (int w, int h, int oldw, int oldh)

Since: API Level

This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Parameters
w Current width of this view.
h Current height of this view.
oldw Old width of this view.
oldh Old height of this view.