Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package at.sapps.utils;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.view.View;
- import android.widget.ProgressBar;
- import android.widget.ViewSwitcher;
- public class ProgressBarSwitcher extends ViewSwitcher {
- private ProgressBar mProgressBar;
- public ProgressBarSwitcher(Context context) {
- super(context);
- }
- public ProgressBarSwitcher(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public ProgressBar getProgressBar() {
- return mProgressBar;
- }
- /**
- * Recursively calling showNext() to at some point show the progressbar
- */
- public void showProgressBar() {
- if (mProgressBar == null || getCurrentView() == mProgressBar) {
- return;
- }
- showNext();
- showProgressBar();// recursive call to show progressbar at some point
- }
- /**
- * Goes to the next view if the progress bar is the current View
- */
- public void hideProgressBar() {
- if (getCurrentView() == mProgressBar) {
- showNext();
- }
- }
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- lookForProgressBar();
- }
- private void lookForProgressBar() {
- for (int i = 0; i < getChildCount(); i++) {
- View child = getChildAt(i);
- if (child instanceof ProgressBar) {
- mProgressBar = (ProgressBar) child;
- return;
- }
- }
- throw new IllegalStateException(
- "A ProgressBarSwitcher needs to contain a ProgressBar!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement