Esempio n. 1
0
  /** @hide */
  protected int setProgress() {
    if (mPlayer == null || mDragging) {
      return 0;
    }
    int position = mPlayer.getCurrentPosition();
    int duration = mPlayer.getDuration();
    /// M: add log for seldom ALPS01020394. @{
    MmsLog.d(
        "MmsMediaController", "setProgress, position: " + position + ", duration: " + duration);
    /// @}
    if (mProgress != null) {
      if (duration > 0) {
        // use long to avoid overflow
        long pos = 1000L * position / duration;
        mProgress.setProgress((int) pos);
      }
      int percent = mPlayer.getBufferPercentage();
      mProgress.setSecondaryProgress(percent * 10);
    }

    if (mEndTime != null) mEndTime.setText(stringForTime(duration));
    if (mCurrentTime != null) mCurrentTime.setText(stringForTime(position));

    // If duration is short, refresh every 100ms
    if (duration < 10000) {
      return 900;
    }
    return position;
  }
  @Override
  public void onRestoreInstanceState(Parcelable state) {
    SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    setProgress(ss.progress);
    setSecondaryProgress(ss.secondaryProgress);
  }
  private void reset() {
    progressBar.setProgress(0);
    progressBar.setSecondaryProgress(0);
    progressBar.setVisibility(ProgressBar.INVISIBLE);

    btnCancel.setVisibility(Button.INVISIBLE);
    btnConnect.setVisibility(Button.VISIBLE);
  }
  public void setProgressBarProgress(int numCorrect, int numFaulty, int numTotal) {

    int percentCorrect = (int) Math.round(((float) numCorrect / (float) numTotal) * 100);
    int percentFaulty =
        (int) Math.round(((float) numFaulty / (float) numTotal) * 100) + percentCorrect;

    mProgressBar.setProgress(percentCorrect);
    mProgressBar.setSecondaryProgress(percentFaulty);
  }
  public ProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mUiThreadId = Thread.currentThread().getId();
    initProgressBar();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressBar, defStyle, 0);

    mNoInvalidate = true;

    Drawable drawable = a.getDrawable(R.styleable.ProgressBar_progressDrawable);
    if (drawable != null) {
      drawable = tileify(drawable, false);
      // Calling this method can set mMaxHeight, make sure the corresponding
      // XML attribute for mMaxHeight is read after calling this method
      setProgressDrawable(drawable);
    }

    mDuration = a.getInt(R.styleable.ProgressBar_indeterminateDuration, mDuration);

    mMinWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_minWidth, mMinWidth);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_maxWidth, mMaxWidth);
    mMinHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_minHeight, mMinHeight);
    mMaxHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_maxHeight, mMaxHeight);

    mBehavior = a.getInt(R.styleable.ProgressBar_indeterminateBehavior, mBehavior);

    final int resID =
        a.getResourceId(
            com.android.internal.R.styleable.ProgressBar_interpolator,
            android.R.anim.linear_interpolator); // default to linear interpolator
    if (resID > 0) {
      setInterpolator(context, resID);
    }

    setMax(a.getInt(R.styleable.ProgressBar_max, mMax));

    setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress));

    setSecondaryProgress(a.getInt(R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress));

    drawable = a.getDrawable(R.styleable.ProgressBar_indeterminateDrawable);
    if (drawable != null) {
      drawable = tileifyIndeterminate(drawable);
      setIndeterminateDrawable(drawable);
    }

    mOnlyIndeterminate =
        a.getBoolean(R.styleable.ProgressBar_indeterminateOnly, mOnlyIndeterminate);

    mNoInvalidate = false;

    setIndeterminate(
        mOnlyIndeterminate || a.getBoolean(R.styleable.ProgressBar_indeterminate, mIndeterminate));

    a.recycle();
  }
  private int setProgress() {
    if (mPlayer == null || mDragging) {
      return 0;
    }
    int position = mPlayer.getCurrentPosition();
    int duration = mPlayer.getDuration();
    if (mProgress != null) {
      if (duration > 0) {
        // use long to avoid overflow
        long pos = 1000L * position / duration;
        mProgress.setProgress((int) pos);
      }
      int percent = mPlayer.getBufferPercentage();
      mProgress.setSecondaryProgress(percent * 10);
    }

    if (mEndTime != null) mEndTime.setText(stringForTime(duration));
    if (mCurrentTime != null) mCurrentTime.setText(stringForTime(position));

    return position;
  }
  private long setProgress() {
    if (mPlayer == null || mDragging) return 0;

    long position = mPlayer.getCurrentPosition();
    long duration = mPlayer.getDuration();
    if (mProgress != null) {
      if (duration > 0) {
        long pos = 1000L * position / duration;
        mProgress.setProgress((int) pos);
      }
      int percent = mPlayer.getBufferPercentage();
      mProgress.setSecondaryProgress(percent * 10);
    }

    mDuration = duration;

    if (mEndTime != null) mEndTime.setText(generateTime(mDuration));
    if (mCurrentTime != null) mCurrentTime.setText(generateTime(position));

    return position;
  }
 /**
  * Increase the progress bar's secondary progress by the specified amount.
  *
  * @param diff the amount by which the secondary progress must be increased
  * @see #setSecondaryProgress(int)
  */
 public final synchronized void incrementSecondaryProgressBy(int diff) {
   setSecondaryProgress(mSecondaryProgress + diff);
 }