Advertisement
Guest User

ProgressBarSwitcher

a guest
Jul 25th, 2013
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package at.sapps.utils;
  2.  
  3. import android.content.Context;
  4. import android.util.AttributeSet;
  5. import android.view.View;
  6. import android.widget.ProgressBar;
  7. import android.widget.ViewSwitcher;
  8.  
  9. public class ProgressBarSwitcher extends ViewSwitcher {
  10.  
  11.     private ProgressBar mProgressBar;
  12.  
  13.     public ProgressBarSwitcher(Context context) {
  14.         super(context);
  15.     }
  16.  
  17.     public ProgressBarSwitcher(Context context, AttributeSet attrs) {
  18.         super(context, attrs);
  19.     }
  20.  
  21.     public ProgressBar getProgressBar() {
  22.         return mProgressBar;
  23.     }
  24.  
  25.     /**
  26.      * Recursively calling showNext() to at some point show the progressbar
  27.      */
  28.     public void showProgressBar() {
  29.         if (mProgressBar == null || getCurrentView() == mProgressBar) {
  30.             return;
  31.         }
  32.  
  33.         showNext();
  34.         showProgressBar();// recursive call to show progressbar at some point
  35.     }
  36.  
  37.     /**
  38.      * Goes to the next view if the progress bar is the current View
  39.      */
  40.     public void hideProgressBar() {
  41.         if (getCurrentView() == mProgressBar) {
  42.             showNext();
  43.         }
  44.     }
  45.  
  46.     @Override
  47.     protected void onFinishInflate() {
  48.         super.onFinishInflate();
  49.         lookForProgressBar();
  50.     }
  51.  
  52.     private void lookForProgressBar() {
  53.         for (int i = 0; i < getChildCount(); i++) {
  54.             View child = getChildAt(i);
  55.             if (child instanceof ProgressBar) {
  56.                 mProgressBar = (ProgressBar) child;
  57.                 return;
  58.             }
  59.         }
  60.  
  61.         throw new IllegalStateException(
  62.                 "A ProgressBarSwitcher needs to contain a ProgressBar!");
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement