public abstract class

GalleryFlowView

extends DuxAdapterView<T extends Adapter>
implements GestureDetector.OnGestureListener
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ com.droidux.ui.widgets.gallery.DuxAdapterView<T extends android.widget.Adapter>
         ↳ com.droidux.ui.widgets.gallery.GalleryFlowView
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

An abstract base class for GalleryFlow widgets. You will probably not need to use this class.

Summary

[Expand]
Inherited Constants
From class com.droidux.ui.widgets.gallery.DuxAdapterView
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
GalleryFlowView(Context context)
GalleryFlowView(Context context, AttributeSet attrs)
GalleryFlowView(Context context, AttributeSet attrs, int defStyle)
Public Methods
boolean dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
void dispatchSetSelected(boolean selected)
Dispatch setSelected to all of this View's children.
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
SpinnerAdapter getAdapter()
Returns the adapter currently associated with this widget.
int getCount()
ViewEffectLayout.ViewEffect getCustomViewEffect()
float getDistanceOfMaxEffect()
Gets the factor to calculate the distance from the center of the gallery, where all effects should reach the maximum values.
View getSelectedView()
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 onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
boolean onKeyDown(int keyCode, KeyEvent event)
Handles left, right, and clicking
boolean onKeyUp(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released.
void onLongPress(MotionEvent e)
Notified when a long press occurs with the initial on down MotionEvent that trigged it.
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 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.
boolean performAccessibilityAction(int action, Bundle arguments)
Performs the specified accessibility action on the view.
int pointToPosition(int x, int y)
Maps a point to a position in the list.
void requestLayout()
Override to prevent spamming ourselves with layout requests as we place views
void setAdapter(SpinnerAdapter adapter)
The Adapter is used to provide the data which backs this Spinner.
void setAnimationDuration(int animationDurationMillis)
Sets how long the transition animation should run when a child view changes position.
void setCallbackDuringFling(boolean shouldCallback)
Whether or not to callback on any getOnItemSelectedListener() while the items are being flinged.
void setCustomViewEffect(ViewEffectLayout.ViewEffect effect)
Provide an implementation of a ViewEffectLayout.ViewEffect that will be applied to the item views of a GalleryFlow widget.
void setDistanceOfMaxEffect(float factor)
Specifies the factor to calculate the distance from the center of the gallery, where all effects start to reach the maximum values.
void setGravity(int gravity)
Describes how the child views are aligned.
void setMaxFlingVelocity(float maxFlingVelocity)
Caps the maximum velocity of the fling gesture.
void setScrollingEnabled(boolean enabled)
Enable/disable scrolling.
void setSelection(int position)
Sets the currently selected item.
void setSelection(int position, boolean animate)
Jump directly to a specific item in the adapter data.
void setSpacing(int spacing)
Sets the spacing between items in a Gallery
void setUnselectedAlpha(float unselectedAlpha)
Sets the alpha of items that are not selected in the Gallery.
boolean showContextMenu()
Bring up the context menu for this view.
boolean showContextMenuForChild(View originalView)
Bring up a context menu for the specified view or its ancestors.
Protected Methods
boolean checkLayoutParams(ViewGroup.LayoutParams p)
int computeHorizontalScrollExtent()

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range.

int computeHorizontalScrollOffset()

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

int computeHorizontalScrollRange()

Compute the horizontal range that the horizontal scrollbar represents.

void dispatchSetPressed(boolean pressed)
Dispatch setPressed to all of this View's children.
ViewGroup.LayoutParams generateDefaultLayoutParams()
Returns a set of default layout parameters.
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
int getChildDrawingOrder(int childCount, int i)
Returns the index of the child to draw for this iteration.
boolean getChildStaticTransformation(View child, Transformation t)
Sets t to be the static transformation of the child, if set, returning a boolean to indicate whether a static transform was set.
ContextMenu.ContextMenuInfo getContextMenuInfo()
Views should implement this if they have extra information to associate with the context menu.
void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.
void onLayout(boolean changed, int l, int t, int r, int b)
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.

[Expand]
Inherited Methods
From class com.droidux.ui.widgets.gallery.DuxAdapterView
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

Public Constructors

public GalleryFlowView (Context context)

Since: API Level 3.0

public GalleryFlowView (Context context, AttributeSet attrs)

Since: API Level 3.0

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

Since: API Level 3.0

Public Methods

public boolean dispatchKeyEvent (KeyEvent event)

Since: API Level

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled, false otherwise.

public void dispatchSetSelected (boolean selected)

Since: API Level

Dispatch setSelected to all of this View's children.

Parameters
selected The new selected state

public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

Since: API Level

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs the attributes to build the layout parameters from
Returns

public SpinnerAdapter getAdapter ()

Since: API Level

Returns the adapter currently associated with this widget.

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

public int getCount ()

Since: API Level

Returns
  • The number of items owned by the Adapter associated with this DuxAdapterView. (This is the number of data items, which may be larger than the number of visible views.)

public float getDistanceOfMaxEffect ()

Since: API Level 3.0

Gets the factor to calculate the distance from the center of the gallery, where all effects should reach the maximum values. See the dux_effectDistanceFactor attribute for more information.

Returns
  • The ratio between the distance of the view to the center of the gallery, and the distance of the center of the gallery to the outermost x coordinate, where all effects start to reach the maximum values. Between 0.0 - 1.0.

public View getSelectedView ()

Since: API Level

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

public boolean onDown (MotionEvent e)

Since: API Level

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

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 onInitializeAccessibilityEvent (AccessibilityEvent event)

Since: API Level

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Since: API Level

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

public boolean onKeyDown (int keyCode, KeyEvent event)

Since: API Level

Handles left, right, and clicking

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyUp (int keyCode, KeyEvent event)

Since: API Level

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public void onLongPress (MotionEvent e)

Since: API Level

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 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().

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

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

Since: API Level

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

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

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 boolean performAccessibilityAction (int action, Bundle arguments)

Since: API Level

Performs the specified accessibility action on the view. For possible accessibility actions look at AccessibilityNodeInfo.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its performAccessibilityAction(View, int, Bundle) is responsible for handling this call.

Parameters
action The action to perform.
arguments Optional action arguments.
Returns
  • Whether the action was performed.

public int pointToPosition (int x, int y)

Since: API Level

Maps a point to a position in the list.

Parameters
x X in local coordinate
y Y in local coordinate
Returns
  • The position of the item which contains the specified point, or INVALID_POSITION if the point does not intersect an item.

public void requestLayout ()

Since: API Level

Override to prevent spamming ourselves with layout requests as we place views

See Also

public void setAdapter (SpinnerAdapter adapter)

Since: API Level

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 SpinnerAdapter to use for this Spinner

public void setAnimationDuration (int animationDurationMillis)

Since: API Level

Sets how long the transition animation should run when a child view changes position. Only relevant if animation is turned on.

Parameters
animationDurationMillis The duration of the transition, in milliseconds.

public void setCallbackDuringFling (boolean shouldCallback)

Since: API Level

Whether or not to callback on any getOnItemSelectedListener() 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 setCustomViewEffect (ViewEffectLayout.ViewEffect effect)

Since: API Level 3.0

Provide an implementation of a ViewEffectLayout.ViewEffect that will be applied to the item views of a GalleryFlow widget.
Note:You must also set the duxglr_viewEffect_type to custom for the custom effect to work. Otherwise it will be ignored.

Parameters
effect The custom effect to be applied to the item views.

public void setDistanceOfMaxEffect (float factor)

Since: API Level 3.0

Specifies the factor to calculate the distance from the center of the gallery, where all effects start to reach the maximum values. Must be between 0.0 - 1.0.

The selected (center-locked) view is the frontmost view, where all distance-related effects will have the minimum value/strength. The further the view from the center, the greater the strength of the effect will be, like the rotation angle, opacity/alpha, scale, zoom, etc. The maximum effect will be reached when the absolute distance of the view from the center of the gallery reached a certain distance as calculated using the value of this attribute.

Example: In a gallery with a horizontal (x-axis) width of 320 px, and the dux_effectDistanceFactor set to 0.5, a view will have a maximum effect at a distance of 0.5 x (320/2), which is 80px from the center of the gallery. So, a view which have an x-coordinate less than (160-80) and more than (160+80) will have a maximum effect.

public void setGravity (int gravity)

Since: API Level

Describes how the child views are aligned.

public void setMaxFlingVelocity (float maxFlingVelocity)

Since: API Level 3.0

Caps the maximum velocity of the fling gesture.

Parameters
maxFlingVelocity The maximum fling velocity.

public void setScrollingEnabled (boolean enabled)

Since: API Level 3.0

Enable/disable scrolling.

Parameters
enabled If true the scrolling is enabled. Otherwise, it will be disabled.

public void setSelection (int position)

Since: API Level

Sets the currently selected item. To support accessibility subclasses that override this method must invoke the overriden super method first.

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

public void setSelection (int position, boolean animate)

Since: API Level

Jump directly to a specific item in the adapter data.

public void setSpacing (int spacing)

Since: API Level

Sets the spacing between items in a Gallery

Parameters
spacing The spacing in pixels between items in the Gallery

public void setUnselectedAlpha (float unselectedAlpha)

Since: API Level

Sets the alpha of items that are not selected in the Gallery.

Parameters
unselectedAlpha the alpha for the items that are not selected.

public boolean showContextMenu ()

Since: API Level

Bring up the context menu for this view.

Returns
  • Whether a context menu was displayed.

public boolean showContextMenuForChild (View originalView)

Since: API Level

Bring up a context menu for the specified view or its ancestors.

In most cases, a subclass does not need to override this. However, if the subclass is added directly to the window manager (for example, addView(View, android.view.ViewGroup.LayoutParams)) then it should override this and show the context menu.

Parameters
originalView The source view where the context menu was first invoked
Returns
  • true if a context menu was displayed

Protected Methods

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

Since: API Level

protected int computeHorizontalScrollExtent ()

Since: API Level

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollRange() and computeHorizontalScrollOffset().

The default extent is the drawing width of this view.

Returns
  • the horizontal extent of the scrollbar's thumb

protected int computeHorizontalScrollOffset ()

Since: API Level

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollRange() and computeHorizontalScrollExtent().

The default offset is the scroll offset of this view.

Returns
  • the horizontal offset of the scrollbar's thumb

protected int computeHorizontalScrollRange ()

Since: API Level

Compute the horizontal range that the horizontal scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollExtent() and computeHorizontalScrollOffset().

The default range is the drawing width of this view.

Returns
  • the total horizontal range represented by the horizontal scrollbar

protected void dispatchSetPressed (boolean pressed)

Since: API Level

Dispatch setPressed to all of this View's children.

Parameters
pressed The new pressed state

protected ViewGroup.LayoutParams generateDefaultLayoutParams ()

Since: API Level

Returns a set of default layout parameters. These parameters are requested when the View passed to addView(View) has no layout parameters already set. If null is returned, an exception is thrown from addView.

Returns
  • a set of default layout parameters or null

protected ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Since: API Level

Returns a safe set of layout parameters based on the supplied layout params. When a ViewGroup is passed a View whose layout params do not pass the test of checkLayoutParams(android.view.ViewGroup.LayoutParams), this method is invoked. This method should return a new set of layout params suitable for this ViewGroup, possibly by copying the appropriate attributes from the specified set of layout params.

Parameters
p The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Returns

protected int getChildDrawingOrder (int childCount, int i)

Since: API Level

Returns the index of the child to draw for this iteration. Override this if you want to change the drawing order of children. By default, it returns i.

NOTE: In order for this method to be called, you must enable child ordering first by calling setChildrenDrawingOrderEnabled(boolean).

Parameters
i The current iteration.
Returns
  • The index of the child to draw this iteration.

protected boolean getChildStaticTransformation (View child, Transformation t)

Since: API Level

Sets t to be the static transformation of the child, if set, returning a boolean to indicate whether a static transform was set. The default implementation simply returns false; subclasses may override this method for different behavior. setStaticTransformationsEnabled(boolean) must be set to true for this method to be called.

Parameters
child The child view whose static transform is being requested
t The Transformation which will hold the result
Returns
  • true if the transformation was set, false otherwise

protected ContextMenu.ContextMenuInfo getContextMenuInfo ()

Since: API Level

Views should implement this if they have extra information to associate with the context menu. The return result is supplied as a parameter to the onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback.

Returns
  • Extra information about the item for which the context menu should be shown. This information will vary across different subclasses of View.

protected void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)

Since: API Level

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.

Parameters
gainFocus True if the View has focus; false otherwise.
direction The direction focus has moved when requestFocus() is called to give this view focus. Values are FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, or FOCUS_BACKWARD. It may not always apply, in which case use the default.
previouslyFocusedRect The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.

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

Since: API Level

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
l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b 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.