FileDocCategorySizeDatePackage
AdapterViewFlipper.javaAPI DocAndroid 5.1 API10287Thu Mar 12 22:22:10 GMT 2015android.widget

AdapterViewFlipper

public class AdapterViewFlipper extends AdapterViewAnimator
Simple {@link ViewAnimator} that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.
attr
ref android.R.styleable#AdapterViewFlipper_flipInterval
attr
ref android.R.styleable#AdapterViewFlipper_autoStart

Fields Summary
private static final String
TAG
private static final boolean
LOGD
private static final int
DEFAULT_INTERVAL
private int
mFlipInterval
private boolean
mAutoStart
private boolean
mRunning
private boolean
mStarted
private boolean
mVisible
private boolean
mUserPresent
private boolean
mAdvancedByHost
private final android.content.BroadcastReceiver
mReceiver
private final int
FLIP_MSG
private final android.os.Handler
mHandler
Constructors Summary
public AdapterViewFlipper(android.content.Context context)


       
        super(context);
    
public AdapterViewFlipper(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, 0);
    
public AdapterViewFlipper(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public AdapterViewFlipper(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);

        final TypedArray a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.AdapterViewFlipper, defStyleAttr, defStyleRes);
        mFlipInterval = a.getInt(
                com.android.internal.R.styleable.AdapterViewFlipper_flipInterval, DEFAULT_INTERVAL);
        mAutoStart = a.getBoolean(
                com.android.internal.R.styleable.AdapterViewFlipper_autoStart, false);

        // A view flipper should cycle through the views
        mLoopViews = true;

        a.recycle();
    
Methods Summary
public voidfyiWillBeAdvancedByHostKThx()
Called by an {@link android.appwidget.AppWidgetHost} to indicate that it will be automatically advancing the views of this {@link AdapterViewFlipper} by calling {@link AdapterViewFlipper#advance()} at some point in the future. This allows {@link AdapterViewFlipper} to prepare by no longer Advancing its children.


                                                  
    
       
        mAdvancedByHost = true;
        updateRunning(false);
    
public intgetFlipInterval()
Returns the flip interval, in milliseconds.

return
the flip interval in milliseconds
see
#setFlipInterval(int)
attr
ref android.R.styleable#AdapterViewFlipper_flipInterval

        return mFlipInterval;
    
public booleanisAutoStart()
Returns true if this view automatically calls {@link #startFlipping()} when it becomes attached to a window.

        return mAutoStart;
    
public booleanisFlipping()
Returns true if the child views are flipping.

        return mStarted;
    
protected voidonAttachedToWindow()


    
       
        super.onAttachedToWindow();

        // Listen for broadcasts related to user-presence
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_USER_PRESENT);

        // OK, this is gross but needed. This class is supported by the
        // remote views machanism and as a part of that the remote views
        // can be inflated by a context for another user without the app
        // having interact users permission - just for loading resources.
        // For exmaple, when adding widgets from a user profile to the
        // home screen. Therefore, we register the receiver as the current
        // user not the one the context is for.
        getContext().registerReceiverAsUser(mReceiver, android.os.Process.myUserHandle(),
                filter, null, mHandler);


        if (mAutoStart) {
            // Automatically start when requested
            startFlipping();
        }
    
protected voidonDetachedFromWindow()

        super.onDetachedFromWindow();
        mVisible = false;

        getContext().unregisterReceiver(mReceiver);
        updateRunning();
    
public voidonInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        super.onInitializeAccessibilityEvent(event);
        event.setClassName(AdapterViewFlipper.class.getName());
    
public voidonInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)

        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(AdapterViewFlipper.class.getName());
    
protected voidonWindowVisibilityChanged(int visibility)

        super.onWindowVisibilityChanged(visibility);
        mVisible = (visibility == VISIBLE);
        updateRunning(false);
    
public voidsetAdapter(Adapter adapter)

        super.setAdapter(adapter);
        updateRunning();
    
public voidsetAutoStart(boolean autoStart)
Set if this view automatically calls {@link #startFlipping()} when it becomes attached to a window.

        mAutoStart = autoStart;
    
public voidsetFlipInterval(int flipInterval)
How long to wait before flipping to the next view.

param
flipInterval flip interval in milliseconds
see
#getFlipInterval()
attr
ref android.R.styleable#AdapterViewFlipper_flipInterval

        mFlipInterval = flipInterval;
    
public voidshowNext()
{@inheritDoc}

       // if the flipper is currently flipping automatically, and showNext() is called
       // we should we should make sure to reset the timer
       if (mRunning) {
           mHandler.removeMessages(FLIP_MSG);
           Message msg = mHandler.obtainMessage(FLIP_MSG);
           mHandler.sendMessageDelayed(msg, mFlipInterval);
       }
       super.showNext();
   
public voidshowPrevious()
{@inheritDoc}

       // if the flipper is currently flipping automatically, and showPrevious() is called
       // we should we should make sure to reset the timer
       if (mRunning) {
           mHandler.removeMessages(FLIP_MSG);
           Message msg = mHandler.obtainMessage(FLIP_MSG);
           mHandler.sendMessageDelayed(msg, mFlipInterval);
       }
       super.showPrevious();
   
public voidstartFlipping()
Start a timer to cycle through child views

        mStarted = true;
        updateRunning();
    
public voidstopFlipping()
No more flips

        mStarted = false;
        updateRunning();
    
private voidupdateRunning()
Internal method to start or stop dispatching flip {@link Message} based on {@link #mRunning} and {@link #mVisible} state.

        // by default when we update running, we want the
        // current view to animate in
        updateRunning(true);
    
private voidupdateRunning(boolean flipNow)
Internal method to start or stop dispatching flip {@link Message} based on {@link #mRunning} and {@link #mVisible} state.

param
flipNow Determines whether or not to execute the animation now, in addition to queuing future flips. If omitted, defaults to true.

        boolean running = !mAdvancedByHost && mVisible && mStarted && mUserPresent
                && mAdapter != null;
        if (running != mRunning) {
            if (running) {
                showOnly(mWhichChild, flipNow);
                Message msg = mHandler.obtainMessage(FLIP_MSG);
                mHandler.sendMessageDelayed(msg, mFlipInterval);
            } else {
                mHandler.removeMessages(FLIP_MSG);
            }
            mRunning = running;
        }
        if (LOGD) {
            Log.d(TAG, "updateRunning() mVisible=" + mVisible + ", mStarted=" + mStarted
                    + ", mUserPresent=" + mUserPresent + ", mRunning=" + mRunning);
        }