java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ com.droidux.pack.wheel.widget.WheelSpinner

Class Overview

A custom view that presents a list of items on a wheel-like control and lets the user pick among them. The items in the wheel spinner come from the WheelInterfaces.Adapters.WheelAdapterInterface associated with this view.

Summary

XML Attributes
Attribute Name Related Method Description
dux_drawSelectorOnTop When set to true, the selector will be drawn over the selected item. 
dux_embossEffect When set to true and the items of a wheel widget is represented by a TextView, an emboss effect will be applied to the text widget. 
dux_faceColor Specifies the face color of a wheel. 
dux_frameColor Specifies the frame color of a wheel. 
dux_leftStaticView A reference to a layout resource containing view to be displayed on the left of the selected item in a wheel widget. 
dux_leftStaticView A reference to a layout resource containing view to be displayed on the right of the selected item in a wheel widget. 
dux_selectorDrawable Reference to a drawable resource to use for a selector. 
dux_selectorDrawable_tint Specifies a color to overlay/tint the selector drawable. 
dux_visibleItems Specifies the number of visible items in a wheel widget. 
[Expand]
Inherited XML Attributes
From interface com.droidux.pack.wheel.interfaces.WheelInterfaces.Views.WheelSpinnerInterface
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
WheelSpinner(Context context)
WheelSpinner(Context context, AttributeSet attrs)
WheelSpinner(Context context, AttributeSet attrs, int defStyle)
Public Methods
View asView()
Convert this interface to its corresponding View.
WheelInterfaces.Adapters.WheelAdapterInterface getAdapter()
Returns the adapter currently associated with this widget.
int getFaceColor()
Gets the color of the frame of the wheel.
int getFrameColor()
Gets the color of the face of the wheel.
View getLeftStaticView()
Gets the static view to be displayed on the left of the selected value, if any.
WheelInterfaces.Listeners.OnWheelItemSelectedListener getOnWheelItemSelectedListener()
Gets the item-selected listener registered for this view.
WheelInterfaces.Listeners.OnWheelScrollListener getOnWheelScrollListener()
Gets the scroll listener registered for this view.
View getRightStaticView()
Gets the static view to be displayed on the right of the selected value, if any.
Object getSelectedItem()
Gets the currently selected item in the data set.
View getSelectedView()
Gets the currently selected view.
int getSelection()
Gets the position of the currently selected item in the data set.
boolean onDown(MotionEvent e)
Notified when a tap occurs with the down MotionEvent that triggered it.
boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
Notified of a fling event when it occurs with the initial on down MotionEvent and the matching up MotionEvent.
void onLongPress(MotionEvent e)
Notified when a long press occurs with the initial on down MotionEvent that trigged it.
boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
Notified when a scroll occurs with the initial on down MotionEvent and the current move MotionEvent.
void onShowPress(MotionEvent e)
The user has performed a down MotionEvent and not performed a move or up yet.
boolean onSingleTapUp(MotionEvent e)
Notified when a tap occurs with the up MotionEvent that triggered it.
boolean onTouchEvent(MotionEvent event)
Implement this method to handle touch screen motion events.
void requestLayout()
Call this when something has changed which has invalidated the layout of this view.
void setAdapter(WheelInterfaces.Adapters.WheelAdapterInterface adapter)
The Adapter is used to provide the data which backs this Spinner.
void setCallbackDuringFling(boolean shouldCallback)
Whether or not to callback on any listener while the items are being flinged.
void setColors(int frameColor, int faceColor)
Sets the colors of the wheel.
void setFaceColor(int color)
Sets the color of the wheel.
void setFrameColor(int color)
Sets the frame color of the wheel.
void setInterpolator(Interpolator interp)
Sets the interpolator for use by the internal scroller.
void setLeftStaticView(View view)
Sets a static view to be displayed on the left of the selected value.
void setOnWheelItemSelectedListener(WheelInterfaces.Listeners.OnWheelItemSelectedListener listener)
Registers a listener to be notified when an item is selected.
void setOnWheelScrollListener(WheelInterfaces.Listeners.OnWheelScrollListener listener)
Registers a listener to be notified when the wheel is scrolled.
void setRightStaticView(View view)
Sets a static view to be displayed on the right of the selected value.
void setSelection(int position, int animationDuration)
Sets the currently selected item, with option to animate the change.
void setSelection(int position)
Sets the currently selected item.
void setSelection(int position, boolean animated)
Sets the currently selected item, with option to animate the change.
void setVisibleItems(int count)
Sets the maximum number of items visible in this spinner.
Protected Methods
void dispatchDraw(Canvas canvas)
Called by draw to draw the child views.
boolean drawChild(Canvas canvas, View child, long drawingTime)
Draw one child of this View Group.
void onAttachedToWindow()
This is called when the view is attached to a window.
void onDetachedFromWindow()
This is called when the view is detached from a window.
void onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children.
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.
boolean verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.
[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.GestureDetector.OnGestureListener
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.droidux.pack.wheel.interfaces.WheelInterfaces.Views.WheelSpinnerInterface
From interface com.droidux.pack.wheel.interfaces.WheelInterfaces.Views.WheelViewInterface

XML Attributes

dux_drawSelectorOnTop

Since: API Level

When set to true, the selector will be drawn over the selected item. Otherwise the selector is drawn behind the selected item. The default value 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_embossEffect

Since: API Level

When set to true and the items of a wheel widget is represented by a TextView, an emboss effect will be applied to the text widget. Default value 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_faceColor

Since: API Level

Specifies the face color of a wheel.

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_frameColor

Since: API Level

Specifies the frame color of a wheel.

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_leftStaticView

Since: API Level

A reference to a layout resource containing view to be displayed on the left of the selected item in a wheel widget. Can be used to show a static label, icon, button, or other appropriate views.

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

Related Methods

dux_leftStaticView

Since: API Level

A reference to a layout resource containing view to be displayed on the right of the selected item in a wheel widget. Can be used to show a static label, icon, button, or other appropriate views.

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

Related Methods

dux_selectorDrawable

Since: API Level

Reference to a drawable resource to use for a selector.

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

Related Methods

dux_selectorDrawable_tint

Since: API Level

Specifies a color to overlay/tint the selector drawable.

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_visibleItems

Since: API Level

Specifies the number of visible items in a wheel widget. Default is 5.

Must be an integer value, such as "5".

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

Public Constructors

public WheelSpinner (Context context)

Since: API Level 2.5

public WheelSpinner (Context context, AttributeSet attrs)

Since: API Level 2.5

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

Since: API Level 2.5

Public Methods

public View asView ()

Since: API Level 2.5

Convert this interface to its corresponding View.

Returns
  • A view object that corresponds to this interface.

public WheelInterfaces.Adapters.WheelAdapterInterface getAdapter ()

Since: API Level 2.5

Returns the adapter currently associated with this widget.

Returns
  • The adapter used to provide this view's content.

public int getFaceColor ()

Since: API Level 2.5

Gets the color of the frame of the wheel.

Returns
  • The frame color.

public int getFrameColor ()

Since: API Level 2.5

Gets the color of the face of the wheel.

Returns
  • The face color.

public View getLeftStaticView ()

Since: API Level 2.5

Gets the static view to be displayed on the left of the selected value, if any.

Returns
  • The left static view, or null.

public WheelInterfaces.Listeners.OnWheelItemSelectedListener getOnWheelItemSelectedListener ()

Since: API Level 2.5

Gets the item-selected listener registered for this view.

Returns
  • The listener.

public WheelInterfaces.Listeners.OnWheelScrollListener getOnWheelScrollListener ()

Since: API Level 2.5

Gets the scroll listener registered for this view.

Returns
  • The listener.

public View getRightStaticView ()

Since: API Level 2.5

Gets the static view to be displayed on the right of the selected value, if any.

Returns
  • The right static view, or null.

public Object getSelectedItem ()

Since: API Level 2.5

Gets the currently selected item in the data set.

Returns
  • The selected item.

public View getSelectedView ()

Since: API Level 2.5

Gets the currently selected view.

Returns
  • The view corresponding to the currently selected item, or null if nothing is selected.

public int getSelection ()

Since: API Level 2.5

Gets the position of the currently selected item in the data set.

Returns
  • The position of the currently selected item in the data set.

public boolean onDown (MotionEvent e)

Since: API Level 2.5

Notified when a tap occurs with the down MotionEvent that triggered it. This will be triggered immediately for every down event. All other events should be preceded by this.

Parameters
e The down motion event.

public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)

Since: API Level 2.5

Notified of a fling event when it occurs with the initial on down MotionEvent and the matching up MotionEvent. The calculated velocity is supplied along the x and y axis in pixels per second.

Parameters
e1 The first down motion event that started the fling.
e2 The move motion event that triggered the current onFling.
velocityX The velocity of this fling measured in pixels per second along the x axis.
velocityY The velocity of this fling measured in pixels per second along the y axis.
Returns
  • true if the event is consumed, else false

public void onLongPress (MotionEvent e)

Since: API Level 2.5

Notified when a long press occurs with the initial on down MotionEvent that trigged it.

Parameters
e The initial on down motion event that started the longpress.

public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)

Since: API Level 2.5

Notified when a scroll occurs with the initial on down MotionEvent and the current move MotionEvent. The distance in x and y is also supplied for convenience.

Parameters
e1 The first down motion event that started the scrolling.
e2 The move motion event that triggered the current onScroll.
distanceX The distance along the X axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.
distanceY The distance along the Y axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.
Returns
  • true if the event is consumed, else false

public void onShowPress (MotionEvent e)

Since: API Level 2.5

The user has performed a down MotionEvent and not performed a move or up yet. This event is commonly used to provide visual feedback to the user to let them know that their action has been recognized i.e. highlight an element.

Parameters
e The down motion event

public boolean onSingleTapUp (MotionEvent e)

Since: API Level 2.5

Notified when a tap occurs with the up MotionEvent that triggered it.

Parameters
e The up motion event that completed the first tap
Returns
  • true if the event is consumed, else false

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 void requestLayout ()

Since: API Level

Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.

Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.

public void setAdapter (WheelInterfaces.Adapters.WheelAdapterInterface adapter)

Since: API Level 2.5

The Adapter is used to provide the data which backs this Spinner. It also provides methods to transform spinner items based on their position relative to the selected item.

Parameters
adapter The adapter to use for this spinner.

public void setCallbackDuringFling (boolean shouldCallback)

Since: API Level 2.5

Whether or not to callback on any listener while the items are being flinged. If false only the final selected item will cause the callback. If true, all items between the first and the final will cause callbacks.

Parameters
shouldCallback Whether or not to callback on the listener while the items are being flinged.

public void setColors (int frameColor, int faceColor)

Since: API Level 2.5

Sets the colors of the wheel. The wheel colors has 2 parts, the frame/edge of the wheel, and the face/main color of the wheel.

Parameters
frameColor The frame color.
faceColor The face color.

public void setFaceColor (int color)

Since: API Level 2.5

Sets the color of the wheel. The face color is the main color of the wheel.

Parameters
color The color of the wheel.

public void setFrameColor (int color)

Since: API Level 2.5

Sets the frame color of the wheel. The frame color is the color of the edges/frame of the wheel.

Parameters
color The frame color.

public void setInterpolator (Interpolator interp)

Since: API Level 2.5

Sets the interpolator for use by the internal scroller.

Parameters
interp The interpolator.

public void setLeftStaticView (View view)

Since: API Level 2.5

Sets a static view to be displayed on the left of the selected value. The static view can be used, for example, to display label, reset button, etc.

Parameters
view The view to be displayed on the left of the selected value. Or null.

public void setOnWheelItemSelectedListener (WheelInterfaces.Listeners.OnWheelItemSelectedListener listener)

Since: API Level 2.5

Registers a listener to be notified when an item is selected.

Parameters
listener The listener to be notified.

public void setOnWheelScrollListener (WheelInterfaces.Listeners.OnWheelScrollListener listener)

Since: API Level 2.5

Registers a listener to be notified when the wheel is scrolled.

Parameters
listener The listener to be notified.

public void setRightStaticView (View view)

Since: API Level 2.5

Sets a static view to be displayed on the right of the selected value. The static view can be used, for example, to display label, reset button, etc.

Parameters
view The view to be displayed on the right of the selected value. Or null.

public void setSelection (int position, int animationDuration)

Since: API Level 2.5

Sets the currently selected item, with option to animate the change. If the position is less than 0, then the item at position 0 will be selected.

Parameters
position Index (starting at 0) of the data item to be selected.
animationDuration If greater than 0, the change will be animated for the duration (by spinning the wheel).

public void setSelection (int position)

Since: API Level 2.5

Sets the currently selected item. If the position is less than 0, then the item at position 0 will be selected.

Parameters
position Index (starting at 0) of the data item to be selected.

public void setSelection (int position, boolean animated)

Since: API Level 2.5

Sets the currently selected item, with option to animate the change. If the position is less than 0, then the item at position 0 will be selected.

Parameters
position Index (starting at 0) of the data item to be selected.
animated If true, the change will be animated (by spinning the wheel).

public void setVisibleItems (int count)

Since: API Level 2.5

Sets the maximum number of items visible in this spinner.

Parameters
count The maximum number of visible items.

Protected Methods

protected void dispatchDraw (Canvas canvas)

Since: API Level

Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).

Parameters
canvas the canvas on which to draw the view

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

Since: API Level

Draw one child of this View Group. This method is responsible for getting the canvas in the right state. This includes clipping, translating so that the child's scrolled origin is at 0, 0, and applying any animation transformations.

Parameters
canvas The canvas on which to draw the child
child Who to draw
drawingTime The time at which draw is occurring
Returns
  • True if an invalidate() was issued

protected void onAttachedToWindow ()

Since: API Level

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

protected void onDetachedFromWindow ()

Since: API Level

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

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

Since: API Level 2.5

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent

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 boolean verifyDrawable (Drawable who)

Since: API Level

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
who The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
  • boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.