@Override
  protected synchronized void onDraw(Canvas canvas) {
    canvas.drawArc(mCircleBounds, 0, 360, false, mBackgroundColorPaint);

    int prog = getProgress();
    float scale = getMax() > 0 ? (float) prog / getMax() * 360 : 0;

    if (mHasShadow) mProgressColorPaint.setShadowLayer(3, 0, 1, mShadowColor);
    canvas.drawArc(mCircleBounds, 270, scale, false, mProgressColorPaint);

    if (!TextUtils.isEmpty(mTitle)) {
      int xPos = (int) (getMeasuredWidth() / 2 - mTitlePaint.measureText(mTitle) / 2);
      int yPos = (int) (getMeasuredHeight() / 2);

      float titleHeight = Math.abs(mTitlePaint.descent() + mTitlePaint.ascent());
      if (TextUtils.isEmpty(mSubTitle)) {
        yPos += titleHeight / 2;
      }
      canvas.drawText(mTitle, xPos, yPos, mTitlePaint);

      yPos += titleHeight;
      xPos = (int) (getMeasuredWidth() / 2 - mSubtitlePaint.measureText(mSubTitle) / 2);

      canvas.drawText(mSubTitle, xPos, yPos, mSubtitlePaint);
    }

    super.onDraw(canvas);
  }
예제 #2
0
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // Draw the inner circle
    canvas.drawArc(innerCircleBounds, 360, 360, false, circlePaint);
    // Draw the rim
    canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
    canvas.drawArc(circleOuterContour, 360, 360, false, contourPaint);
    // canvas.drawArc(circleInnerContour, 360, 360, false, contourPaint);
    // Draw the bar
    if (isSpinning) {
      canvas.drawArc(circleBounds, progress - 90, barLength, false, barPaint);
    } else {
      canvas.drawArc(circleBounds, -90, progress, false, barPaint);
    }
    // Draw the text (attempts to center it horizontally and vertically)
    float textHeight = textPaint.descent() - textPaint.ascent();
    float verticalTextOffset = (textHeight / 2) - textPaint.descent();

    for (String line : splitText) {
      float horizontalTextOffset = textPaint.measureText(line) / 2;
      canvas.drawText(
          line,
          this.getWidth() / 2 - horizontalTextOffset,
          this.getHeight() / 2 + verticalTextOffset,
          textPaint);
    }
    if (isSpinning) {
      scheduleRedraw();
    }
  }
예제 #3
0
  @Override
  protected void onDraw(Canvas canvas) {
    // All of our positions are using our internal coordinate system.
    // Instead of translating
    // them we let Canvas do the work for us.
    canvas.translate(mTranslationOffset, mTranslationOffset);

    // Draw the color wheel.
    canvas.drawOval(mColorWheelRectangle, mColorWheelPaint);

    float[] pointerPosition = calculatePointerPosition(mAngle);

    // Draw the pointer's "halo"
    canvas.drawCircle(
        pointerPosition[0], pointerPosition[1], mColorPointerHaloRadius, mPointerHaloPaint);

    // Draw the pointer (the currently selected color) slightly smaller on
    // top.
    canvas.drawCircle(pointerPosition[0], pointerPosition[1], mColorPointerRadius, mPointerColor);

    // Draw the halo of the center colors.
    canvas.drawCircle(0, 0, mColorCenterHaloRadius, mCenterHaloPaint);

    // Draw the old selected color in the center.
    canvas.drawArc(mCenterRectangle, 90, 180, true, mCenterOldPaint);

    // Draw the new selected color in the center.
    canvas.drawArc(mCenterRectangle, 270, 180, true, mCenterNewPaint);
  }
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   // Draw the rim
   canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
   // Draw the bar
   if (isSpinning) {
     canvas.drawArc(circleBounds, progress - 90, barLength, false, barPaint);
   } else {
     canvas.drawArc(circleBounds, -90, progress, false, barPaint);
   }
   // Draw the inner circle
   canvas.drawCircle(
       (circleBounds.width() / 2) + rimWidth + paddingLeft,
       (circleBounds.height() / 2) + rimWidth + paddingTop,
       circleRadius,
       circlePaint);
   // Draw the text (attempts to center it horizontally and vertically)
   int offsetNum = 0;
   for (String s : splitText) {
     float offset = textPaint.measureText(s) / 2;
     canvas.drawText(
         s,
         this.getWidth() / 2 - offset,
         this.getHeight() / 2
             + (textSize * (offsetNum))
             - ((splitText.length - 1) * (textSize / 2)),
         textPaint);
     offsetNum++;
   }
 }
  @Override
  public void draw(Canvas canvas) {
    mBounds.set(getBounds());

    if (mMode == MODE_RATING) {
      float arcAngle = mCurrentValue * 360f;
      final float arcStart = -90f;
      canvas.drawArc(mBounds, arcStart + arcAngle, 360f - arcAngle, true, mBackgroundArcPaint);
      canvas.drawArc(mBounds, arcStart, arcAngle, true, mArcPaint);
    } else if (mMode == MODE_PROMPT) {
      canvas.drawCircle(
          mBounds.centerX(),
          mBounds.centerY(),
          mBounds.height() * BACKGROUND_CIRCLE_RADIUS_RATIO,
          mBackgroundArcPaint);
    }

    canvas.drawCircle(
        mBounds.centerX(),
        mBounds.centerY(),
        mBounds.height() * FOREGROUND_CIRCLE_RADIUS_RATIO,
        mForegroundCirclePaint);

    if (mText != null) {
      canvas.drawText(
          mText,
          mBounds.centerX() - (mTextWidth / 2f),
          mBounds.centerY() + (mTextHeight / 2f),
          mTextPaint);
    }
  }
 void drawRipple(Canvas canvas) {
   // TODO precise problem
   mRipplePaint.setAlpha(mRippleAlpha);
   float mRippleRadius = mLineRadius + mRippleWidth;
   canvas.drawArc(
       new RectF(
           cxLeft - mRippleRadius,
           cyLeft - mRippleRadius,
           cxLeft + mRippleRadius,
           cyLeft + mRippleRadius),
       90,
       180,
       false,
       mRipplePaint);
   canvas.drawRect(
       cxLeft,
       cyLeft - mLineRadius - mRippleWidth,
       cxRight,
       cyRight + mLineRadius + mRippleWidth,
       mRipplePaint);
   canvas.drawArc(
       new RectF(
           cxRight - mRippleRadius,
           cyRight - mRippleRadius,
           cxRight + mRippleRadius,
           cyRight + mRippleRadius),
       -90,
       180,
       false,
       mRipplePaint);
 }
예제 #7
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.save();
    canvas.translate(0, mWidth / signalSize);
    mPaint.setStrokeWidth(mWidth / signalSize / 2 / 2 / 2);
    int scale =
        (int) ((mAnimatedValue * signalSize - (int) (mAnimatedValue * signalSize)) * signalSize)
            + 1;
    RectF rect = null;
    float signalRadius = mWidth / 2 / signalSize;
    for (int i = 0; i < signalSize; i++) {

      if (i >= signalSize - scale) {
        float radius = signalRadius * i;
        rect = new RectF(radius, radius, mWidth - radius, mWidth - radius);
        if (i < signalSize - 1) {
          mPaint.setStyle(Paint.Style.STROKE);
          canvas.drawArc(rect, -135, 90, false, mPaint);
        } else {
          mPaint.setStyle(Paint.Style.FILL);
          canvas.drawArc(rect, -135, 90, true, mPaint);
        }
      }
    }
    canvas.restore();
  }
예제 #8
0
 private void drawYMotion(Canvas canvas) {
   canvas.drawArc(mOval, 0, -180, true, mFstHalfPaint);
   canvas.drawArc(mOval, -180, -180, true, mScndHalfPaint);
   mPath.reset();
   mPath.moveTo(0, mHalf);
   mPath.cubicTo(0, mAxisValue, mDiameter, mAxisValue, mDiameter, mHalf);
 }
예제 #9
0
 public Bitmap getCircleBitmap(Bitmap paramBitmap, int paramInt) {
   if (paramBitmap == null) {
     paramBitmap = null;
     return paramBitmap;
   }
   if (paramInt == 0) paramInt = Math.min(paramBitmap.getWidth(), paramBitmap.getHeight());
   while (true) {
     Bitmap localBitmap = Bitmap.createBitmap(paramInt, paramInt, Bitmap.Config.ARGB_8888);
     Canvas localCanvas = new Canvas(localBitmap);
     Paint localPaint = new Paint();
     Rect localRect =
         new Rect(
             this.mStrokeWidth,
             this.mStrokeWidth,
             paramInt - this.mStrokeWidth,
             paramInt - this.mStrokeWidth);
     RectF localRectF = new RectF(localRect);
     localPaint.setAntiAlias(true);
     localCanvas.drawArc(localRectF, 0.0F, 360.0F, true, localPaint);
     localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
     localCanvas.drawBitmap(paramBitmap, localRect, localRect, localPaint);
     paramBitmap = localBitmap;
     if (this.mStrokeWidth <= 0) break;
     paramBitmap = new RectF(new Rect(0, 0, paramInt, paramInt));
     localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
     localPaint.setColor(this.mStrokeColor);
     localCanvas.drawArc(paramBitmap, 0.0F, 360.0F, false, localPaint);
     return localBitmap;
   }
 }
예제 #10
0
    private void drawRightTopArc(Canvas canvas) {
      canvas.save();

      canvas.translate(0, -radius * 3); // the center of the circle in the rightTop
      canvas.drawArc(oval, -22.5f, -135, true, arcPaint);

      arcPaint.setStyle(Paint.Style.STROKE);
      arcPaint.setColor(Color.WHITE);
      canvas.drawArc(
          oval, -22.5f, -135, false,
          arcPaint); // @param useCenter: useCenter If true, include the center of the oval in the
                     // arc, and close it if it is being stroked. This will draw a wedge

      // ======== draw arc text ==========
      canvas.save();
      canvas.rotate(-135 / 2); // 到正中间

      for (int i = 0; i < 135; i += 33.75) { // 33.75 * 4 = 135;
        canvas.save();
        canvas.rotate(i);
        canvas.drawText("Item", 0, -width * 5 / 32, textPaint);
        canvas.restore();
      }

      canvas.restore();
      // ======== draw arc text ==========

      canvas.restore();
    }
예제 #11
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.save();
    mPaint.setStrokeWidth(2);
    canvas.drawCircle(mWidth / 2, mWidth / 2, mWidth / 2 - mPadding, mPaint);
    mPaint.setStrokeWidth(3);
    canvas.drawCircle(mWidth / 2, mWidth / 2, mPadding, mPaint);

    mPaint.setStrokeWidth(2);
    rectF =
        new RectF(
            mWidth / 2 - mWidth / 3,
            mWidth / 2 - mWidth / 3,
            mWidth / 2 + mWidth / 3,
            mWidth / 2 + mWidth / 3);
    canvas.drawArc(rectF, 0, 80, false, mPaint);

    canvas.drawArc(rectF, 180, 80, false, mPaint);

    rectF2 =
        new RectF(
            mWidth / 2 - mWidth / 4,
            mWidth / 2 - mWidth / 4,
            mWidth / 2 + mWidth / 4,
            mWidth / 2 + mWidth / 4);
    canvas.drawArc(rectF2, 0, 80, false, mPaint);
    canvas.drawArc(rectF2, 180, 80, false, mPaint);
    canvas.restore();
  }
예제 #12
0
 @Override
 public void draw(Canvas mCanvas) {
   // TODO 自動產生的方法 Stub
   Paint paint = new Paint();
   paint.setAntiAlias(true);
   paint.setStyle(Paint.Style.STROKE);
   paint.setStrokeWidth(5);
   paint.setColor(color);
   float r = (stopY - startY) / 4;
   /* 心两半圆结点处 */
   float topX = startX + 100;
   float topY = startY - r + 100;
   /* 左上半圆 */
   RectF leftOval = new RectF(topX - 2 * r, topY - r, topX, topY + r);
   mCanvas.drawArc(leftOval, 180f, 180f, false, paint);
   /* 右上半圆 */
   RectF rightOval = new RectF(topX, topY - r, topX + 2 * r, topY + r);
   mCanvas.drawArc(rightOval, 180f, 180f, false, paint);
   /* 下半两sin曲线 */
   float base = 3 * r;
   double argu = Math.PI / 2 / base;
   float y = base, value;
   while (y >= 0) {
     value = (float) (2 * r * Math.sin(argu * (base - y)));
     mCanvas.drawPoint(topX - value, topY + y, paint);
     mCanvas.drawPoint(topX + value, topY + y, paint);
     y -= 1;
   }
 }
예제 #13
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    /** 画最外层的大圆环 */
    int centre = getWidth() / 2; // 获取圆心的x坐标
    int radius = (int) (centre - roundWidth / 2); // 圆环的半径
    paint.setColor(roundColor); // 设置圆环的颜色
    paint.setStyle(Paint.Style.STROKE); // 设置空心
    paint.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
    paint.setStrokeWidth(roundWidth); // 设置圆环的宽度
    paint.setAntiAlias(true); // 消除锯齿
    canvas.drawCircle(centre, centre, radius - SHADOW_WIDTH_HALF, paint); // 画出圆环

    Log.e("log", centre + "");

    /** 画进度百分比 */
    paint.setStrokeWidth(0);
    paint.setColor(textColor);
    paint.setTextSize(textSize);
    paint.setTypeface(Typeface.DEFAULT_BOLD); // 设置字体
    int percent = (int) (((float) progress / (float) max) * 100); // 中间的进度百分比,先转换成float在进行除法运算,不然都为0
    float textWidth = paint.measureText(percent + "%"); // 测量字体宽度,我们需要根据字体的宽度设置在圆环中间

    if (textIsDisplayable && percent != 0 && style == STROKE) {
      canvas.drawText(
          percent + "%", centre - textWidth / 2, centre + textSize / 2, paint); // 画出进度百分比
    }

    /** 画圆弧 ,画圆环的进度 */

    // 设置进度是实心还是空心
    paint.setStrokeWidth(roundWidth); // 设置圆环的宽度
    paint.setColor(roundProgressColor); // 设置进度的颜色
    paint.setShadowLayer(SHADOW_WIDTH, 0, 0, roundProgressColor);
    this.setLayerType(View.LAYER_TYPE_SOFTWARE, paint);
    RectF oval =
        new RectF(
            centre - radius + SHADOW_WIDTH_HALF,
            centre - radius + SHADOW_WIDTH_HALF,
            centre + radius - SHADOW_WIDTH_HALF,
            centre + radius - SHADOW_WIDTH_HALF); // 用于定义的圆弧的形状和大小的界限

    switch (style) {
      case STROKE:
        {
          paint.setStyle(Paint.Style.STROKE);
          canvas.drawArc(oval, 270, 360 * progress / max, false, paint); // 根据进度画圆弧
          break;
        }
      case FILL:
        {
          paint.setStyle(Paint.Style.FILL_AND_STROKE);
          if (progress != 0)
            canvas.drawArc(oval, 270, 360 * progress / max, true, paint); // 根据进度画圆弧
          break;
        }
    }
  }
예제 #14
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   paint.setColor(doneColor);
   canvas.drawArc(rect, 270, 360 * percentage / 100, true, paint);
   paint.setColor(leftColor);
   canvas.drawArc(rect, 270 + 360 * percentage / 100, 360 - 360 * percentage / 100, true, paint);
 }
예제 #15
0
 // ----------------------------------
 // Animation stuff
 // ----------------------------------
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
   boolean mustInvalidate = false;
   if (!shouldAnimate) {
     return;
   }
   if (isSpinning) {
     // Draw the spinning bar
     mustInvalidate = true;
     long deltaTime = (SystemClock.uptimeMillis() - lastTimeAnimated);
     float deltaNormalized = deltaTime * spinSpeed / 1000.0f;
     updateBarLength(deltaTime);
     mProgress += deltaNormalized;
     if (mProgress > 360) {
       mProgress -= 360f;
       // A full turn has been completed
       // we run the callback with -1 in case we want to
       // do something, like changing the color
       runCallback(-1.0f);
     }
     lastTimeAnimated = SystemClock.uptimeMillis();
     float from = mProgress - 90;
     float length = barLength + barExtraLength;
     if (isInEditMode()) {
       from = 0;
       length = 135;
     }
     canvas.drawArc(circleBounds, from, length, false, barPaint);
   } else {
     float oldProgress = mProgress;
     if (mProgress != mTargetProgress) {
       // We smoothly increase the progress bar
       mustInvalidate = true;
       float deltaTime = (float) (SystemClock.uptimeMillis() - lastTimeAnimated) / 1000;
       float deltaNormalized = deltaTime * spinSpeed;
       mProgress = Math.min(mProgress + deltaNormalized, mTargetProgress);
       lastTimeAnimated = SystemClock.uptimeMillis();
     }
     if (oldProgress != mProgress) {
       runCallback();
     }
     float offset = 0.0f;
     float progress = mProgress;
     if (!linearProgress) {
       float factor = 2.0f;
       offset = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, 2.0f * factor)) * 360.0f;
       progress = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, factor)) * 360.0f;
     }
     if (isInEditMode()) {
       progress = 360;
     }
     canvas.drawArc(circleBounds, offset - 90, progress, false, barPaint);
   }
   if (mustInvalidate) {
     invalidate();
   }
 }
    private void drawCircle(Canvas canvas, BatteryTracker tracker, float textX, RectF drawRect) {
      boolean unknownStatus = tracker.status == BatteryManager.BATTERY_STATUS_UNKNOWN;
      int animOffset = tracker.shouldIndicateCharging() ? mAnimOffset : 0;
      int level = tracker.level;
      Paint paint;

      if (unknownStatus) {
        paint = mBackPaint;
        level = 100; // Draw all the circle;
      } else {
        paint = mFrontPaint;
        paint.setColor(getColorForLevel(level));
        if (tracker.status == BatteryManager.BATTERY_STATUS_FULL) {
          level = 100;
        }
      }

      // draw thin gray ring first
      canvas.drawArc(drawRect, 270, 360, false, mBackPaint);
      // draw colored arc representing charge level
      canvas.drawArc(drawRect, 270 + animOffset, 3.6f * level, false, paint);
      // if chosen by options, draw percentage text in the middle
      // always skip percentage when 100, so layout doesnt break
      if (unknownStatus) {
        mTextPaint.setColor(paint.getColor());
        canvas.drawText("?", textX, mTextY, mTextPaint);

      } else if (tracker.shouldIndicateCharging() && (!mShowPercent || level == 100)) {
        // draw the bolt
        final float bl = (int) (drawRect.left + drawRect.width() / 3.2f);
        final float bt = (int) (drawRect.top + drawRect.height() / 4f);
        final float br = (int) (drawRect.right - drawRect.width() / 5.2f);
        final float bb = (int) (drawRect.bottom - drawRect.height() / 8f);
        if (mBoltFrame.left != bl
            || mBoltFrame.top != bt
            || mBoltFrame.right != br
            || mBoltFrame.bottom != bb) {
          mBoltFrame.set(bl, bt, br, bb);
          mBoltPath.reset();
          mBoltPath.moveTo(
              mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(),
              mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height());
          for (int i = 2; i < mBoltPoints.length; i += 2) {
            mBoltPath.lineTo(
                mBoltFrame.left + mBoltPoints[i] * mBoltFrame.width(),
                mBoltFrame.top + mBoltPoints[i + 1] * mBoltFrame.height());
          }
          mBoltPath.lineTo(
              mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(),
              mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height());
        }
        canvas.drawPath(mBoltPath, mBoltPaint);

      } else if (level < 100 && mShowPercent) {
        mTextPaint.setColor(paint.getColor());
        canvas.drawText(Integer.toString(level), textX, mTextY, mTextPaint);
      }
    }
예제 #17
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    /** 画最外层的大圆环 */
    int centre = getWidth() / 2; // 获取圆心的x坐标
    int radius = (int) (centre - roundWidth / 2); // 圆环的半径
    paint.setColor(roundColor); // 设置圆环的颜色
    paint.setStyle(Paint.Style.STROKE); // 设置空心
    paint.setStrokeWidth(roundWidth); // 设置圆环的宽度
    paint.setAntiAlias(true); // 消除锯齿
    canvas.drawCircle(centre, centre, radius, paint); // 画出圆环

    Log.e("log", centre + "");

    /** 画进度百分比 */
    paint.setStrokeWidth(0);
    paint.setColor(textColor);
    paint.setTextSize(textSize);
    paint.setTypeface(Typeface.DEFAULT_BOLD); // 设置字体
    int percent = (int) (((float) progress / (float) max) * 100); // 中间的进度百分比,先转换成float在进行除法运算,不然都为0
    float textWidth = paint.measureText(percent + "%"); // 测量字体宽度,我们需要根据字体的宽度设置在圆环中间

    if (textIsDisplayable && percent != 0 && style == STROKE) {
      canvas.drawText(
          percent + "%", centre - textWidth / 2, centre + textSize / 2, paint); // 画出进度百分比
    }

    /** 画圆弧 ,画圆环的进度 */

    // 设置进度是实心还是空心
    paint.setStrokeWidth(roundWidth); // 设置圆环的宽度
    paint.setColor(roundProgressColor); // 设置进度的颜色
    RectF oval =
        new RectF(
            centre - radius, centre - radius, centre + radius, centre + radius); // 用于定义的圆弧的形状和大小的界限

    switch (style) {
      case STROKE:
        {
          paint.setStyle(Paint.Style.STROKE);
          canvas.drawArc(oval, 0, 360 * progress / max, false, paint); // 根据进度画圆弧
          break;
        }
      case FILL:
        {
          paint.setStyle(Paint.Style.FILL_AND_STROKE);
          if (progress != 0) canvas.drawArc(oval, 0, 360 * progress / max, true, paint); // 根据进度画圆弧
          break;
        }
    }

    /** 进度条达到满的时候触发事件 */
    if (progress == max && null != onLoadFinish) {
      onLoadFinish.onLoadFinished();
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mProgressBarEnabled) {
      if (mShowProgressBackground) {
        canvas.drawArc(mProgressCircleBounds, 360, 360, false, mBackgroundPaint);
      }

      boolean shouldInvalidate = false;

      if (mProgressIndeterminate) {
        shouldInvalidate = true;

        long deltaTime = SystemClock.uptimeMillis() - mLastTimeAnimated;
        float deltaNormalized = deltaTime * mSpinSpeed / 1000.0f;

        updateProgressLength(deltaTime);

        mCurrentProgress += deltaNormalized;
        if (mCurrentProgress > 360f) {
          mCurrentProgress -= 360f;
        }

        mLastTimeAnimated = SystemClock.uptimeMillis();
        float from = mCurrentProgress - 90;
        float to = mBarLength + mBarExtraLength;

        if (isInEditMode()) {
          from = 0;
          to = 135;
        }

        canvas.drawArc(mProgressCircleBounds, from, to, false, mProgressPaint);
      } else {
        if (mCurrentProgress != mTargetProgress) {
          shouldInvalidate = true;
          float deltaTime = (float) (SystemClock.uptimeMillis() - mLastTimeAnimated) / 1000;
          float deltaNormalized = deltaTime * mSpinSpeed;

          if (mCurrentProgress > mTargetProgress) {
            mCurrentProgress = Math.max(mCurrentProgress - deltaNormalized, mTargetProgress);
          } else {
            mCurrentProgress = Math.min(mCurrentProgress + deltaNormalized, mTargetProgress);
          }
          mLastTimeAnimated = SystemClock.uptimeMillis();
        }

        canvas.drawArc(mProgressCircleBounds, -90, mCurrentProgress, false, mProgressPaint);
      }

      if (shouldInvalidate) {
        invalidate();
      }
    }
  }
예제 #19
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawCircle(centerX, centerY, radiusCircle, drawPaintCircle);
   if (isDrawingRing) {
     canvas.drawArc(rectRingBound, INITIAL_ANGLE, finiteSweepAngle, false, drawPaintFirstRing);
   }
   canvas.drawArc(
       rectRingBound, progressActualAngle, progressSweepAngle, false, drawPaintSecondRing);
 }
예제 #20
0
  private void drawArc(Canvas canvas) {

    mPaint.setColor(Color.CYAN);

    RectF rect = new RectF(100, 100, 300, 200);
    canvas.drawArc(rect, 30, 120, true, mPaint);

    rect = new RectF(100, 300, 300, 400);
    canvas.drawArc(rect, 30, 120, false, mPaint);
  }
예제 #21
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mInnerRectF.set(0, 0, canvas.getWidth(), canvas.getHeight());
    final int halfBorder = (int) (mStrokePaint.getStrokeWidth() / 2f + 0.5f);
    mInnerRectF.inset(halfBorder, halfBorder);

    canvas.drawArc(mInnerRectF, 0, 360, true, mBackgroundPaint);

    switch (mProgressFillType) {
      case FILL_TYPE_RADIAL:
        float sweepAngle = 360 * mProgress / mMax;
        canvas.drawArc(mInnerRectF, mStartAngle, sweepAngle, true, mProgressPaint);
        break;
      case FILL_TYPE_CENTER:
        float centerX = canvas.getWidth() / 2;
        float centerY = canvas.getHeight() / 2;
        float radius = (canvas.getWidth() / 2) * ((float) mProgress / mMax);
        canvas.drawCircle(
            centerX, centerY, radius + 0.5f - mStrokePaint.getStrokeWidth(), mProgressPaint);
        break;
      default:
        throw new IllegalArgumentException("Invalid Progress Fill = " + mProgressFillType);
    }

    if (!TextUtils.isEmpty(mText) && mShowText) {
      if (!TextUtils.isEmpty(mTypeface)) {
        Typeface typeface = sTypefaceCache.get(mTypeface);
        if (null == typeface && null != getResources()) {
          AssetManager assets = getResources().getAssets();
          if (null != assets) {
            typeface = Typeface.createFromAsset(assets, mTypeface);
            sTypefaceCache.put(mTypeface, typeface);
          }
        }
        mTextPaint.setTypeface(typeface);
      }
      int xPos = canvas.getWidth() / 2;
      int yPos =
          (int) ((canvas.getHeight() / 2) - ((mTextPaint.descent() + mTextPaint.ascent()) / 2));
      canvas.drawText(mText, xPos, yPos, mTextPaint);
    }

    if (null != mImage && mShowImage) {
      int drawableSize = mImage.getIntrinsicWidth();
      mImageRect.set(0, 0, drawableSize, drawableSize);
      mImageRect.offset((getWidth() - drawableSize) / 2, (getHeight() - drawableSize) / 2);
      mImage.setBounds(mImageRect);
      mImage.draw(canvas);
    }

    if (mShowStroke) {
      canvas.drawOval(mInnerRectF, mStrokePaint);
    }
  }
예제 #22
0
  @Override
  public void draw(Canvas canvas) {
    // Draw the bounding boxes
    drawBoundingBoxes(canvas);

    // Set the right values for the paint
    operatorPaint.setColor(getColor());
    operatorPaint.setTextSize(findTextSize());

    // Get our operator bounding boxes
    Rect[] operatorBounding = this.getOperatorBoundingBoxes();

    // Draws the operator
    canvas.save();
    Rect textBounding = new Rect();
    operatorPaint.getTextBounds(type.getName(), 0, type.getName().length(), textBounding);
    canvas.translate(
        (operatorBounding[0].width() - textBounding.width()) / 2,
        (operatorBounding[0].height() - textBounding.height()) / 2);
    canvas.drawText(
        type.getName(),
        operatorBounding[0].left - textBounding.left,
        operatorBounding[0].top - textBounding.top,
        operatorPaint);
    canvas.restore();

    // Use stroke style for the parentheses
    operatorPaint.setStyle(Paint.Style.STROKE);

    // Draw the left bracket
    canvas.save();
    canvas.clipRect(operatorBounding[1], Region.Op.INTERSECT);
    RectF bracket = new RectF(operatorBounding[1]);
    bracket.inset(0, -operatorPaint.getStrokeWidth());
    bracket.offset(bracket.width() / 4, 0);
    canvas.drawArc(bracket, 100.0f, 160.0f, false, operatorPaint);
    canvas.restore();

    // Draw the right bracket
    canvas.save();
    canvas.clipRect(operatorBounding[2], Region.Op.INTERSECT);
    bracket = new RectF(operatorBounding[2]);
    bracket.inset(0, -operatorPaint.getStrokeWidth());
    bracket.offset(-bracket.width() / 4, 0);
    canvas.drawArc(bracket, -80.0f, 160.0f, false, operatorPaint);
    canvas.restore();

    // Set the paint back to fill style
    operatorPaint.setStyle(Paint.Style.FILL);

    // Draw the children
    drawChildren(canvas);
  }
  private void drawOval(Canvas canvas, int center, int radius) {
    float itemSize = (360 * 1.0f - mCount * mSplitSize) / mCount;
    RectF oval = new RectF(center - radius, center - radius, center + radius, center + radius);
    mPaint.setColor(mFirstColor);
    for (int i = 0; i < mCount; i++) {
      canvas.drawArc(oval, i * (itemSize + mSplitSize), itemSize, false, mPaint);
    }

    mPaint.setColor(mSecondColor); // 设置圆环的颜色
    for (int i = 0; i < mCurrentCount; i++) {
      canvas.drawArc(oval, i * (itemSize + mSplitSize), itemSize, false, mPaint); // 根据进度画圆弧
    }
  }
예제 #24
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    mCirclePaint.setColor(mCurProperty.mCircleColor);
    canvas.drawCircle(mCenterX, mCenterY, mAttributes.getCircleRadius(), mCirclePaint);

    if (mOval != null) {
      mRingPaint.setColor(mUnCheckedPaintColor);
      canvas.drawArc(mOval, 225, 360, false, mRingPaint);
      mRingPaint.setColor(mCheckedPaintColor);
      canvas.drawArc(mOval, 225, mCurProperty.mSweepAngle, false, mRingPaint);
    }
  }
예제 #25
0
 @Override
 protected void onDraw(Canvas canvas) {
   int w = getWidth();
   int h = getHeight();
   int centerX = w / 2;
   int centerY = h / 2;
   if (mShape == SHAPE_RING) {
     int radius = (centerX < centerY ? centerX : centerY) - mProgressWidth / 2;
     mPaint.reset();
     mPaint.setAntiAlias(true);
     mPaint.setStrokeCap(mCap);
     mPaint.setStrokeWidth(mProgressWidth);
     mPaint.setColor(mSolidColor);
     mPaint.setStyle(Paint.Style.FILL);
     canvas.drawCircle(centerX, centerY, radius, mPaint);
     mRectF.set(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
     mPaint.setColor(mProgressBgColor);
     mPaint.setStyle(Paint.Style.STROKE);
     canvas.drawArc(mRectF, mStartAngle, 360 * (mRatio - 1), false, mPaint);
     mPaint.setColor(mProgressColor);
     mPaint.setStyle(Paint.Style.STROKE);
     canvas.drawArc(mRectF, mStartAngle, 360 * mRatio, false, mPaint);
   } else {
     int stokePadding = mProgressWidth / 2;
     w = w - mProgressWidth;
     mPaint.reset();
     mPaint.setAntiAlias(true);
     mPaint.setStrokeCap(mCap);
     mPaint.setStrokeWidth(mProgressWidth);
     mPaint.setColor(mProgressBgColor);
     mPaint.setStyle(Paint.Style.STROKE);
     canvas.drawLine(stokePadding, centerY, stokePadding + w, centerY, mPaint);
     mPaint.setColor(mProgressColor);
     mPaint.setStyle(Paint.Style.STROKE);
     float progressLineWidth = w * mRatio;
     canvas.drawLine(stokePadding, centerY, stokePadding + progressLineWidth, centerY, mPaint);
     if (mTextVisible) {
       String text = Math.round(mRatio * 100) + "%";
       mPaint.reset();
       mPaint.setAntiAlias(true);
       mPaint.setColor(mTextColor);
       mPaint.setTextSize(mTextSize);
       float textWidth = mPaint.measureText(text);
       float textX =
           stokePadding + (textWidth >= progressLineWidth ? 0 : (progressLineWidth - textWidth));
       canvas.drawText(text, textX, AppUtil.getYOfDrawText(mPaint, centerY), mPaint);
     }
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see android.view.View#onDraw(android.graphics.Canvas)
   */
  @Override
  protected void onDraw(final Canvas canvas) {

    // All of our positions are using our internal coordinate system.
    // Instead of translating
    // them we let Canvas do the work for us.
    canvas.translate(mTranslationOffsetX, mTranslationOffsetY);

    final float progressRotation = getCurrentRotation();

    // draw the background
    if (!mOverrdraw) {
      canvas.drawArc(mCircleBounds, 270, -(360 - progressRotation), false, mBackgroundColorPaint);
    }

    // draw the progress or a full circle if overdraw is true
    canvas.drawArc(
        mCircleBounds, 270, mOverrdraw ? 360 : progressRotation, false, mProgressColorPaint);

    // draw the marker at the correct rotated position
    if (mIsMarkerEnabled) {
      final float markerRotation = getMarkerRotation();

      canvas.save();
      canvas.rotate(markerRotation - 90);
      canvas.drawLine(
          (float) (mThumbPosX + mThumbRadius / 2 * 1.4),
          mThumbPosY,
          (float) (mThumbPosX - mThumbRadius / 2 * 1.4),
          mThumbPosY,
          mMarkerColorPaint);
      canvas.restore();
    }

    if (isThumbEnabled()) {
      // draw the thumb square at the correct rotated position
      canvas.save();
      canvas.rotate(progressRotation - 90);
      // rotate the square by 45 degrees
      canvas.rotate(45, mThumbPosX, mThumbPosY);
      mSquareRect.left = mThumbPosX - mThumbRadius / 3;
      mSquareRect.right = mThumbPosX + mThumbRadius / 3;
      mSquareRect.top = mThumbPosY - mThumbRadius / 3;
      mSquareRect.bottom = mThumbPosY + mThumbRadius / 3;
      canvas.drawRect(mSquareRect, mThumbColorPaint);
      canvas.restore();
    }
  }
  @Override
  public void draw(Canvas canvas, Paint paint) {
    float circleSpacing = 12;
    float x = getWidth() / 2;
    float y = getHeight() / 2;

    // draw fill circle
    canvas.save();
    canvas.translate(x, y);
    canvas.scale(scaleFloat1, scaleFloat1);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(0, 0, x / 2.5f, paint);

    canvas.restore();

    canvas.translate(x, y);
    canvas.scale(scaleFloat2, scaleFloat2);
    canvas.rotate(degrees);

    paint.setStrokeWidth(3);
    paint.setStyle(Paint.Style.STROKE);

    // draw two arc
    float[] startAngles = new float[] {225, 45};
    for (int i = 0; i < 2; i++) {
      RectF rectF =
          new RectF(-x + circleSpacing, -y + circleSpacing, x - circleSpacing, y - circleSpacing);
      canvas.drawArc(rectF, startAngles[i], 90, false, paint);
    }
  }
예제 #28
0
  @Override
  protected void onDraw(Canvas canvas) {
    float left = getPaddingLeft() + mUnreachedWidth / 2;
    float top = getPaddingTop() + mUnreachedWidth / 2;
    float right = canvas.getWidth() - getPaddingRight() - mUnreachedWidth / 2;
    float bottom = canvas.getHeight() - getPaddingBottom() - mUnreachedWidth / 2;
    float centerX = (left + right) / 2;
    float centerY = (top + bottom) / 2;

    float wheelRadius =
        (canvas.getWidth() - getPaddingLeft() - getPaddingRight()) / 2 - mUnreachedWidth / 2;

    if (isHasCache) {
      if (mCacheCanvas == null) {
        buildCache(centerX, centerY, wheelRadius);
      }
      canvas.drawBitmap(mCacheBitmap, 0, 0, null);
    } else {
      canvas.drawCircle(centerX, centerY, wheelRadius, mWheelPaint);
    }

    // 画选中区域
    canvas.drawArc(
        new RectF(left, top, right, bottom), -90, (float) mCurAngle, false, mReachedPaint);

    // 画锚点
    canvas.drawCircle(mWheelCurX, mWheelCurY, mPointerRadius, mPointerPaint);
  }
예제 #29
0
  Bitmap drawpicture() {
    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#F2E16C"));
    Paint paint_jacket = new Paint();
    paint_jacket.setColor(Color.parseColor("#2D71A1"));

    Bitmap bg = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bg);
    canvas.drawArc(new RectF(100, 100, 350, 350), 180, 180, true, paint);
    canvas.drawRect(new RectF(100, 210, 350, 350), paint);
    Canvas canvas1 = new Canvas(bg);
    canvas1.drawArc(new RectF(100, 200, 350, 500), 360, 180, false, paint_jacket);

    return bg;
  }
예제 #30
0
  @Override
  protected void onDraw(Canvas canvas) {

    if (channelmark) {
      backPaint.setStrokeWidth(coverWidth);
      backPaint.setColor(0xffa8a8a8);
      canvas.drawArc(backBound, 50, 260, false, backPaint);
    } else {
      backPaint.setStrokeWidth(backWidth);
      backPaint.setColor(backColor);
      canvas.drawOval(backBound, backPaint);
      canvas.drawArc(coverBound, -90, 360 * (currValue / maxValue), false, coverPaint);
    }

    super.onDraw(canvas);
  }