Android Open Source - RssReader Content Loading Smooth Progress Bar






From Project

Back to project page RssReader.

License

The source code is released under:

MIT License

If you think the Android project RssReader 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  www . j  a  v a2 s .c o m
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

com.vicmns.rssreader.activities.MainActivity.java
com.vicmns.rssreader.activities.RssItemDetailsActivity.java
com.vicmns.rssreader.adapters.RssItemsAdapter.java
com.vicmns.rssreader.app.RssReaderApplication.java
com.vicmns.rssreader.http.GetRssItems.java
com.vicmns.rssreader.http.GetWidgetRssItems.java
com.vicmns.rssreader.http.SimpleXmlRequest.java
com.vicmns.rssreader.interfaces.GetRssItemsCallbacks.java
com.vicmns.rssreader.interfaces.HttpConsumerCallbacks.java
com.vicmns.rssreader.interfaces.ListOverlayLayoutCallbacks.java
com.vicmns.rssreader.models.RssItem.java
com.vicmns.rssreader.models.RssItems.java
com.vicmns.rssreader.services.GetRssItemsService.java
com.vicmns.rssreader.views.ListOverlayLayoutView.java
com.vicmns.rssreader.views.SquareImageView.java
com.vicmns.rssreader.widget.WidgetListProvider.java
com.vicmns.rssreader.widget.WidgetProvider.java
com.vicmns.rssreader.widget.WidgetService.java
fr.castorflex.android.smoothprogressbar.ColorsShape.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBarUtils.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
org.robolectric.shadows.ShadowSupportMenuInflater.java