@Override
  protected void onDraw(Canvas canvas) {
    int width = getWidth() - getPaddingLeft() - getPaddingRight();
    int height = getHeight() - getPaddingTop() - getPaddingBottom();

    if (backgroundDrawable != null) {
      int dw = backgroundDrawable.getIntrinsicWidth();
      int left = getPaddingLeft() + (width - dw) / 2;
      int top = getPaddingTop();
      int right = left + dw;
      int bottom = height + getPaddingTop();
      backgroundDrawable.setBounds(left, top, right, bottom);
      backgroundDrawable.draw(canvas);
    }

    if (progressDrawable != null) {
      int dw = progressDrawable.getIntrinsicWidth();
      int left = getPaddingLeft() + (width - dw) / 2;
      int top = getPaddingTop();
      int right = left + dw;
      int bottom = height + getPaddingTop();
      progressDrawable.setBounds(left, top, right, bottom);
      progressDrawable.setLevel((int) (10000 * progress.percentage()));
      progressDrawable.draw(canvas);
    }

    int textWidth = (int) paint.measureText(progress.toString());
    int x = (width - textWidth) / 2 + getPaddingLeft();
    int y = height / 2 + getPaddingTop() - (int) (paint.getTextSize() / 2);
    canvas.drawText(progress.toString(), x, y, paint);
  }
예제 #2
0
  public static void setProgress(double value) {
    ClipDrawable drawable = (ClipDrawable) progressDrawableImageView.getBackground();
    double percent = (double) value / (double) max;
    int level = (int) Math.floor(percent * 10000);

    drawable.setLevel(level);
  }
예제 #3
0
 @SuppressWarnings("unused")
 @CalledByNative
 private void onLoadProgressChanged(double progress) {
   removeCallbacks(mClearProgressRunnable);
   mProgressDrawable.setLevel((int) (10000.0 * progress));
   if (progress == 1.0) postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS);
 }
 private void onLoadProgressChanged(int progress) {
   removeCallbacks(mClearProgressRunnable);
   mProgressDrawable.setLevel((int) (100.0 * progress));
   if (progress == 100) postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS);
 }