FileDocCategorySizeDatePackage
ContentLoadingProgressBar.javaAPI DocAndroid 5.1 API4013Thu Mar 12 22:22:56 GMT 2015android.support.v4.widget

ContentLoadingProgressBar

public class ContentLoadingProgressBar extends android.widget.ProgressBar
ContentLoadingProgressBar implements a ProgressBar that waits a minimum time to be dismissed before showing. Once visible, the progress bar will be visible for a minimum amount of time to avoid "flashes" in the UI when an event could take a largely variable time to complete (from none, to a user perceivable amount)

Fields Summary
private static final int
MIN_SHOW_TIME
private static final int
MIN_DELAY
private long
mStartTime
private boolean
mPostedHide
private boolean
mPostedShow
private boolean
mDismissed
private final Runnable
mDelayedHide
private final Runnable
mDelayedShow
Constructors Summary
public ContentLoadingProgressBar(android.content.Context context)


       
        this(context, null);
    
public ContentLoadingProgressBar(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs, 0);
    
Methods Summary
public voidhide()
Hide the progress view if it is visible. The progress view will not be hidden until it has been shown for at least a minimum show time. If the progress view was not yet visible, cancels showing the progress view.

        mDismissed = true;
        removeCallbacks(mDelayedShow);
        long diff = System.currentTimeMillis() - mStartTime;
        if (diff >= MIN_SHOW_TIME || mStartTime == -1) {
            // The progress spinner has been shown long enough
            // OR was not shown yet. If it wasn't shown yet,
            // it will just never be shown.
            setVisibility(View.GONE);
        } else {
            // The progress spinner is shown, but not long enough,
            // so put a delayed message in to hide it when its been
            // shown long enough.
            if (!mPostedHide) {
                postDelayed(mDelayedHide, MIN_SHOW_TIME - diff);
                mPostedHide = true;
            }
        }
    
public voidonAttachedToWindow()

        super.onAttachedToWindow();
        removeCallbacks();
    
public voidonDetachedFromWindow()

        super.onDetachedFromWindow();
        removeCallbacks();
    
private voidremoveCallbacks()

        removeCallbacks(mDelayedHide);
        removeCallbacks(mDelayedShow);
    
public voidshow()
Show the progress view after waiting for a minimum delay. If during that time, hide() is called, the view is never made visible.

        // Reset the start time.
        mStartTime = -1;
        mDismissed = false;
        removeCallbacks(mDelayedHide);
        if (!mPostedShow) {
            postDelayed(mDelayedShow, MIN_DELAY);
            mPostedShow = true;
        }