/**
   * Change the indeterminate mode for the progress bar. In indeterminate mode, the progress is
   * ignored and the progress bar shows an infinite animation instead.
   *
   * @param indeterminate true to enable the indeterminate mode
   */
  public synchronized void setIndeterminate(boolean indeterminate) {
    if (!indeterminate) {
      mCurrentProgress = 0.0f;
    }

    mProgressBarEnabled = indeterminate;
    mShouldUpdateButtonPosition = true;
    mProgressIndeterminate = indeterminate;
    mLastTimeAnimated = SystemClock.uptimeMillis();
    setupProgressBounds();
    saveButtonOriginalPosition();
    updateBackground();
  }
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    saveButtonOriginalPosition();

    if (mShouldProgressIndeterminate) {
      setIndeterminate(true);
      mShouldProgressIndeterminate = false;
    } else if (mShouldSetProgress) {
      setProgress(mProgress, mAnimateProgress);
      mShouldSetProgress = false;
    } else if (mShouldUpdateButtonPosition) {
      updateButtonPosition();
      mShouldUpdateButtonPosition = false;
    }
    super.onSizeChanged(w, h, oldw, oldh);

    setupProgressBounds();
    setupProgressBarPaints();
    updateBackground();
  }
  public synchronized void setProgress(int progress, boolean animate) {
    if (mProgressIndeterminate) return;

    mProgress = progress;
    mAnimateProgress = animate;

    if (!mButtonPositionSaved) {
      mShouldSetProgress = true;
      return;
    }

    mProgressBarEnabled = true;
    mShouldUpdateButtonPosition = true;
    setupProgressBounds();
    saveButtonOriginalPosition();
    updateBackground();

    if (progress < 0) {
      progress = 0;
    } else if (progress > mProgressMax) {
      progress = mProgressMax;
    }

    if (progress == mTargetProgress) {
      return;
    }

    mTargetProgress = mProgressMax > 0 ? (progress / (float) mProgressMax) * 360 : 0;
    mLastTimeAnimated = SystemClock.uptimeMillis();

    if (!animate) {
      mCurrentProgress = mTargetProgress;
    }

    invalidate();
  }