Most visited

Recently visited

Added in API level 11

AdapterViewAnimator

public abstract class AdapterViewAnimator
extends AdapterView<Adapter> implements Advanceable

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<android.widget.Adapter>
         ↳ android.widget.AdapterViewAnimator
Known Direct Subclasses


Base class for a AdapterView that will perform animations when switching between its views.

Summary

XML attributes

android:animateFirstView Defines whether to animate the current View when the ViewAnimation is first displayed. 
android:inAnimation Identifier for the animation to use when a view is shown. 
android:loopViews Defines whether the animator loops to the first view once it has reached the end of the list. 
android:outAnimation Identifier for the animation to use when a view is hidden. 

Inherited XML attributes

From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

AdapterViewAnimator(Context context)
AdapterViewAnimator(Context context, AttributeSet attrs)
AdapterViewAnimator(Context context, AttributeSet attrs, int defStyleAttr)
AdapterViewAnimator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

void advance()

Called by an AppWidgetHost in order to advance the current view when it is being used within an app widget.

void deferNotifyDataSetChanged()

This defers a notifyDataSetChanged on the pending RemoteViewsAdapter if it has not connected yet.

void fyiWillBeAdvancedByHostKThx()

Called by an AppWidgetHost to indicate that it will be automatically advancing the views of this AdapterViewAnimator by calling advance() at some point in the future.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

Adapter getAdapter()

Returns the adapter currently associated with this widget.

int getBaseline()

Return the offset of the widget's text baseline from the widget's top boundary.

View getCurrentView()

Returns the View corresponding to the currently displayed child.

int getDisplayedChild()

Returns the index of the currently displayed child view.

ObjectAnimator getInAnimation()

Returns the current animation used to animate a View that enters the screen.

ObjectAnimator getOutAnimation()

Returns the current animation used to animate a View that exits the screen.

View getSelectedView()
boolean onRemoteAdapterConnected()

Called back when the adapter connects to the RemoteViewsService.

void onRemoteAdapterDisconnected()

Called back when the adapter disconnects from the RemoteViewsService.

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 onTouchEvent(MotionEvent ev)

Implement this method to handle touch screen motion events.

void setAdapter(Adapter adapter)

Sets the adapter that provides the data and the views to represent the data in this widget.

void setAnimateFirstView(boolean animate)

Indicates whether the current View should be animated the first time the ViewAnimation is displayed.

void setDisplayedChild(int whichChild)

Sets which child view will be displayed.

void setInAnimation(ObjectAnimator inAnimation)

Specifies the animation used to animate a View that enters the screen.

void setInAnimation(Context context, int resourceID)

Specifies the animation used to animate a View that enters the screen.

void setOutAnimation(ObjectAnimator outAnimation)

Specifies the animation used to animate a View that exit the screen.

void setOutAnimation(Context context, int resourceID)

Specifies the animation used to animate a View that exit the screen.

void setRemoteViewsAdapter(Intent intent)

Sets up this AdapterViewAnimator to use a remote views adapter which connects to a RemoteViewsService through the specified intent.

void setSelection(int position)

Sets the currently selected item.

void showNext()

Manually shows the next child.

void showPrevious()

Manually shows the previous child.

Protected methods

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.

Inherited methods

From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.widget.Advanceable

XML attributes

android:animateFirstView

Defines whether to animate the current View when the ViewAnimation is first displayed.

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.

This corresponds to the global attribute resource symbol animateFirstView.

android:inAnimation

Identifier for the animation to use when a view is shown.

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

This corresponds to the global attribute resource symbol inAnimation.

android:loopViews

Defines whether the animator loops to the first view once it has reached the end of the list.

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.

This corresponds to the global attribute resource symbol loopViews.

android:outAnimation

Identifier for the animation to use when a view is hidden.

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

This corresponds to the global attribute resource symbol outAnimation.

Public constructors

AdapterViewAnimator

Added in API level 11
AdapterViewAnimator (Context context)

Parameters
context Context

AdapterViewAnimator

Added in API level 11
AdapterViewAnimator (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

AdapterViewAnimator

Added in API level 14
AdapterViewAnimator (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

AdapterViewAnimator

Added in API level 21
AdapterViewAnimator (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

advance

Added in API level 11
void advance ()

Called by an AppWidgetHost in order to advance the current view when it is being used within an app widget.

deferNotifyDataSetChanged

Added in API level 14
void deferNotifyDataSetChanged ()

This defers a notifyDataSetChanged on the pending RemoteViewsAdapter if it has not connected yet.

fyiWillBeAdvancedByHostKThx

Added in API level 11
void fyiWillBeAdvancedByHostKThx ()

Called by an AppWidgetHost to indicate that it will be automatically advancing the views of this AdapterViewAnimator by calling advance() at some point in the future. This allows subclasses to perform any required setup, for example, to stop automatically advancing their children.

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getAdapter

Added in API level 11
Adapter getAdapter ()

Returns the adapter currently associated with this widget.

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

getBaseline

Added in API level 11
int getBaseline ()

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

Returns
int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

getCurrentView

Added in API level 11
View getCurrentView ()

Returns the View corresponding to the currently displayed child.

Returns
View The View currently displayed.

See also:

getDisplayedChild

Added in API level 11
int getDisplayedChild ()

Returns the index of the currently displayed child view.

Returns
int

getInAnimation

Added in API level 11
ObjectAnimator getInAnimation ()

Returns the current animation used to animate a View that enters the screen.

Returns
ObjectAnimator An Animation or null if none is set.

See also:

getOutAnimation

Added in API level 11
ObjectAnimator getOutAnimation ()

Returns the current animation used to animate a View that exits the screen.

Returns
ObjectAnimator An Animation or null if none is set.

See also:

getSelectedView

Added in API level 11
View getSelectedView ()

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

onRemoteAdapterConnected

Added in API level 11
boolean onRemoteAdapterConnected ()

Called back when the adapter connects to the RemoteViewsService.

Returns
boolean

onRemoteAdapterDisconnected

Added in API level 11
void onRemoteAdapterDisconnected ()

Called back when the adapter disconnects from the RemoteViewsService.

onRestoreInstanceState

Added in API level 11
void onRestoreInstanceState (Parcelable state)

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 Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onSaveInstanceState

Added in API level 11
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. 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
Parcelable 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.

onTouchEvent

Added in API level 11
boolean onTouchEvent (MotionEvent ev)

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
ev MotionEvent: The motion event.
Returns
boolean True if the event was handled, false otherwise.

setAdapter

Added in API level 11
void setAdapter (Adapter adapter)

Sets the adapter that provides the data and the views to represent the data in this widget.

Parameters
adapter Adapter: The adapter to use to create this view's content.

setAnimateFirstView

Added in API level 11
void setAnimateFirstView (boolean animate)

Indicates whether the current View should be animated the first time the ViewAnimation is displayed.

Parameters
animate boolean: True to animate the current View the first time it is displayed, false otherwise.

setDisplayedChild

Added in API level 11
void setDisplayedChild (int whichChild)

Sets which child view will be displayed.

Parameters
whichChild int: the index of the child view to display

setInAnimation

Added in API level 11
void setInAnimation (ObjectAnimator inAnimation)

Specifies the animation used to animate a View that enters the screen.

Parameters
inAnimation ObjectAnimator: The animation started when a View enters the screen.

See also:

setInAnimation

Added in API level 11
void setInAnimation (Context context, 
                int resourceID)

Specifies the animation used to animate a View that enters the screen.

Parameters
context Context: The application's environment.
resourceID int: The resource id of the animation.

See also:

setOutAnimation

Added in API level 11
void setOutAnimation (ObjectAnimator outAnimation)

Specifies the animation used to animate a View that exit the screen.

Parameters
outAnimation ObjectAnimator: The animation started when a View exit the screen.

See also:

setOutAnimation

Added in API level 11
void setOutAnimation (Context context, 
                int resourceID)

Specifies the animation used to animate a View that exit the screen.

Parameters
context Context: The application's environment.
resourceID int: The resource id of the animation.

See also:

setRemoteViewsAdapter

Added in API level 11
void setRemoteViewsAdapter (Intent intent)

Sets up this AdapterViewAnimator to use a remote views adapter which connects to a RemoteViewsService through the specified intent.

Parameters
intent Intent: the intent used to identify the RemoteViewsService for the adapter to connect to.

setSelection

Added in API level 11
void setSelection (int position)

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

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

showNext

Added in API level 11
void showNext ()

Manually shows the next child.

showPrevious

Added in API level 11
void showPrevious ()

Manually shows the previous child.

Protected methods

onLayout

Added in API level 11
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. Derived classes with children should override this method and call layout on each of their children.

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

onMeasure

Added in API level 11
void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

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 overridden 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 int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

Hooray!