Android Open Source - PullToRefresh Content Loading Smooth Progress Bar






From Project

Back to project page PullToRefresh.

License

The source code is released under:

Apache License

If you think the Android project PullToRefresh listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.castorflex.android.smoothprogressbar;
//from   w  w  w  . j ava  2 s . com
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

/**
 * This is a copy of the ContentLoadingProgressBar from the support library, but extends
 * SmoothProgressBar.
 */
public class ContentLoadingSmoothProgressBar extends SmoothProgressBar {

  private static final int MIN_SHOW_TIME = 500; // ms
  private static final int MIN_DELAY = 500; // ms

  private long mStartTime = -1;

  private boolean mPostedHide = false;

  private boolean mPostedShow = false;

  private boolean mDismissed = false;

  private final Runnable mDelayedHide = new Runnable() {

    @Override
    public void run() {
      mPostedHide = false;
      mStartTime = -1;
      setVisibility(View.GONE);
    }
  };

  private final Runnable mDelayedShow = new Runnable() {

    @Override
    public void run() {
      mPostedShow = false;
      if (!mDismissed) {
        mStartTime = System.currentTimeMillis();
        setVisibility(View.VISIBLE);
      }
    }
  };

  public ContentLoadingSmoothProgressBar(Context context) {
    this(context, null);
  }

  public ContentLoadingSmoothProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs, 0);
  }

  @Override
  public void onAttachedToWindow() {
    super.onAttachedToWindow();
    removeCallbacks();
  }

  @Override
  public void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    removeCallbacks();
  }

  private void removeCallbacks() {
    removeCallbacks(mDelayedHide);
    removeCallbacks(mDelayedShow);
  }

  /**
   * 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.
   */
  public void hide() {
    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;
      }
    }
  }

  /**
   * Show the progress view after waiting for a minimum delay. If
   * during that time, hide() is called, the view is never made visible.
   */
  public void show() {
    // Reset the start time.
    mStartTime = -1;
    mDismissed = false;
    removeCallbacks(mDelayedHide);
    if (!mPostedShow) {
      postDelayed(mDelayedShow, MIN_DELAY);
      mPostedShow = true;
    }
  }
}




Java Source Code List

android.support.v7.appcompat.BuildConfig.java
android.support.v7.appcompat.BuildConfig.java
android.support.v7.gridlayout.BuildConfig.java
android.support.v7.gridlayout.BuildConfig.java
fr.castorflex.android.smoothprogressbar.BuildConfig.java
fr.castorflex.android.smoothprogressbar.BuildConfig.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.AbcDefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.AbcPullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.BuildConfig.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.AbsDefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.AbsPullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh.java
uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh.java
uk.co.senab.actionbarpulltorefresh.library.BuildConfig.java
uk.co.senab.actionbarpulltorefresh.library.BuildConfig.java
uk.co.senab.actionbarpulltorefresh.library.DefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.DefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.EnvironmentDelegate.java
uk.co.senab.actionbarpulltorefresh.library.EnvironmentDelegate.java
uk.co.senab.actionbarpulltorefresh.library.HeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.HeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.InstanceCreationUtils.java
uk.co.senab.actionbarpulltorefresh.library.InstanceCreationUtils.java
uk.co.senab.actionbarpulltorefresh.library.Options.java
uk.co.senab.actionbarpulltorefresh.library.Options.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.library.listeners.HeaderViewListener.java
uk.co.senab.actionbarpulltorefresh.library.listeners.HeaderViewListener.java
uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener.java
uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatBase.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatBase.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV11.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV11.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV16.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV16.java
uk.co.senab.actionbarpulltorefresh.library.sdk.Compat.java
uk.co.senab.actionbarpulltorefresh.library.sdk.Compat.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.AbsListViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.AbsListViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ScrollYDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ScrollYDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.WebViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.WebViewDelegate.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.BaseSampleActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.Constants.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.FragmentTabPager.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.FragmentTabsActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.FragmentTabsViewPagerActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.GridViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.ListViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.MainActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.ScrollViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.WebViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.BaseSampleActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.Constants.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.FragmentTabPager.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.FragmentTabsActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.FragmentTabsViewPagerActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.GridViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.ListViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.MainActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.ScrollViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.WebViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.BaseSampleActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.Constants.java
uk.co.senab.actionbarpulltorefresh.samples.stock.FragmentTabsActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.GridViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.ListViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.MainActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.ScrollViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.WebViewActivity.java