Example usage for android.graphics Canvas drawArc

List of usage examples for android.graphics Canvas drawArc

Introduction

In this page you can find the example usage for android.graphics Canvas drawArc.

Prototype

public void drawArc(@NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter,
        @NonNull Paint paint) 

Source Link

Document

Draw the specified arc, which will be scaled to fit inside the specified oval.

Usage

From source file:com.kadavelil.jossy.mapalarm.SeekArc.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
    }/* w ww. ja va 2  s.  c  om*/

    // Draw the arcs
    final int arcStart = mStartAngle + mAngleOffset + mRotation;
    final int arcSweep = mSweepAngle;
    canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
    canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint);

    // Draw the thumb nail
    canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
    mThumb.draw(canvas);
}

From source file:com.keylesspalace.tusky.view.ProgressImageView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float angle = (progress / 100f) * 360 - 90;
    float halfWidth = canvas.getWidth() / 2;
    float halfHeight = canvas.getHeight() / 2;
    progressRect.set(halfWidth * 0.75f, halfHeight * 0.75f, halfWidth * 1.25f, halfHeight * 1.25f);
    biggerRect.set(progressRect);// ww  w.j av  a 2 s  .c  o m
    int margin = 8;
    biggerRect.set(progressRect.left - margin, progressRect.top - margin, progressRect.right + margin,
            progressRect.bottom + margin);
    canvas.saveLayer(biggerRect, null, Canvas.ALL_SAVE_FLAG);
    if (progress != -1) {
        canvas.drawOval(progressRect, circlePaint);
        canvas.drawArc(biggerRect, angle, 360 - angle - 90, true, clearPaint);
    }
    canvas.restore();

    int circleRadius = Utils.dpToPx(getContext(), 14);
    int circleMargin = Utils.dpToPx(getContext(), 14);

    int circleY = canvas.getHeight() - circleMargin - circleRadius / 2;
    int circleX = canvas.getWidth() - circleMargin - circleRadius / 2;

    canvas.drawCircle(circleX, circleY, circleRadius, markBgPaint);

    captionDrawable.setBounds(canvas.getWidth() - circleMargin - circleRadius,
            canvas.getHeight() - circleMargin - circleRadius, canvas.getWidth() - circleMargin,
            canvas.getHeight() - circleMargin);
    DrawableCompat.setTint(captionDrawable, Color.WHITE);
    captionDrawable.draw(canvas);
}

From source file:fr.francetv.zoom.share.loader.ZoomLoaderView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int sc = canvas.saveLayer(0, 0, mViewWidthPx, mViewHeightPx, null,
            Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
                    | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);

    int mAnimationInValue = (int) mAnimationIn.getAnimatedValue();
    int mAnimationOutValue = mAnimationOut.isRunning() ? (int) mAnimationOut.getAnimatedValue() : 0;

    canvas.drawPaint(mBackgroundPaint);/*from  w ww  .  ja  v a  2  s  .  co  m*/
    canvas.drawArc(mLeftCircleArc, LEFT_START_DEGRE - mAnimationOutValue,
            -mAnimationInValue + mAnimationOutValue, true, mAnimPaint);
    canvas.drawArc(mRightCircleArc, RIGHT_START_DEGRE - mAnimationOutValue,
            -mAnimationInValue + mAnimationOutValue, true, mAnimPaint);
    canvas.drawBitmap(mMaskBitmap, 0, 0, mMaskPaint);
    canvas.restoreToCount(sc);
}

From source file:com.triggertrap.seekarc.SeekArc.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
    }//from   w w  w .  java 2 s  . co  m

    // Draw the arcs
    final int arcStart = mStartAngle + mAngleOffset + mRotation;
    final int arcSweep = mSweepAngle;
    canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
    canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint);

    if (mEnabled) {
        // Draw the thumb nail
        canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
        mThumb.draw(canvas);
    }
}

From source file:ch.berta.fabio.fabprogress.FabProgress.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float startAngle = mCurrentRotationAngle - mCurrentRotationAngleOffset;
    float sweepAngle = mCurrentSweepAngle;
    if (!mIsGrowing) {
        startAngle = startAngle + (360 - sweepAngle);
    }/*from   w  w  w .j  av  a 2 s. c o  m*/

    canvas.drawArc(mArcBounds, startAngle, sweepAngle, false, mPaint);
}

From source file:org.telegram.ui.Cells.FeaturedStickerSetCell.java

public FeaturedStickerSetCell(Context context) {
    super(context);

    setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    setElevation(AndroidUtilities.dp(2));

    if (paint == null) {
        paint = new Paint();
        paint.setColor(ContextCompat.getColor(context, R.color.divider));
    }/*  ww w. ja  va2s .  co  m*/
    if (botProgressPaint == null) {
        botProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        botProgressPaint.setColor(ContextCompat.getColor(context, R.color.primary_text_inverse));
        botProgressPaint.setStrokeCap(Paint.Cap.ROUND);
        botProgressPaint.setStyle(Paint.Style.STROKE);
    }
    botProgressPaint.setStrokeWidth(AndroidUtilities.dp(2));

    textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    addView(textView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 100 : 71,
                    10, LocaleController.isRTL ? 71 : 100, 0));

    valueTextView = new TextView(context);
    //valueTextView.setTextColor(0xff8a8a8a);
    valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    valueTextView.setLines(1);
    valueTextView.setMaxLines(1);
    valueTextView.setSingleLine(true);
    valueTextView.setEllipsize(TextUtils.TruncateAt.END);
    valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    addView(valueTextView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 100 : 71,
                    35, LocaleController.isRTL ? 71 : 100, 0));

    imageView = new BackupImageView(context);
    imageView.setAspectFit(true);
    addView(imageView,
            LayoutHelper.createFrame(48, 48,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));

    addButton = new TextView(context) {
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (drawProgress || !drawProgress && progressAlpha != 0) {
                botProgressPaint.setAlpha(Math.min(255, (int) (progressAlpha * 255)));
                int x = getMeasuredWidth() - AndroidUtilities.dp(11);
                progressRect.set(x, AndroidUtilities.dp(3), x + AndroidUtilities.dp(8),
                        AndroidUtilities.dp(8 + 3));
                canvas.drawArc(progressRect, angle, 220, false, botProgressPaint);
                invalidate((int) progressRect.left - AndroidUtilities.dp(2),
                        (int) progressRect.top - AndroidUtilities.dp(2),
                        (int) progressRect.right + AndroidUtilities.dp(2),
                        (int) progressRect.bottom + AndroidUtilities.dp(2));
                long newTime = System.currentTimeMillis();
                if (Math.abs(lastUpdateTime - System.currentTimeMillis()) < 1000) {
                    long delta = (newTime - lastUpdateTime);
                    float dt = 360 * delta / 2000.0f;
                    angle += dt;
                    angle -= 360 * (angle / 360);
                    if (drawProgress) {
                        if (progressAlpha < 1.0f) {
                            progressAlpha += delta / 200.0f;
                            if (progressAlpha > 1.0f) {
                                progressAlpha = 1.0f;
                            }
                        }
                    } else {
                        if (progressAlpha > 0.0f) {
                            progressAlpha -= delta / 200.0f;
                            if (progressAlpha < 0.0f) {
                                progressAlpha = 0.0f;
                            }
                        }
                    }
                }
                lastUpdateTime = newTime;
                invalidate();
            }
        }
    };
    addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0);
    addButton.setGravity(Gravity.CENTER);
    // TODO
    addButton.setTextColor(0xffffffff);
    addButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    addButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addButton.setBackgroundResource(R.drawable.add_states);
    addButton.setText(LocaleController.getString("Add", R.string.Add).toUpperCase());
    addView(addButton,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 28,
                    Gravity.TOP | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT),
                    LocaleController.isRTL ? 14 : 0, 18, LocaleController.isRTL ? 0 : 14, 0));

    checkImage = new ImageView(context);
    checkImage.setImageResource(R.drawable.sticker_added);
    addView(checkImage, LayoutHelper.createFrame(19, 14));
}

From source file:com.lovejjfg.demo.TouchCircleView.java

@Override
protected void onDraw(Canvas canvas) {
    //// ww w . ja v a 2s .com
    switch (currentState) {
    case STATE_DRAW_IDLE:
        canvas.drawArc(outRectF, 0, 0, false, paint);
        break;
    case STATE_DRAW_ARC:
        canvas.drawArc(outRectF, START_ANGLE, angle, true, paint);
        break;
    case STATE_DRAW_ARROW:
        isDrawTriangle = true;
        mCurrentRectf = outRectF;
        mCurrentRadius = outCirRadius;
        mCurrentPaint = paint;
        resetPoints();
        drawCirclePath(canvas);
        drawArc(canvas);
        break;
    case STATE_DRAW_PROGRESS:
        isDrawTriangle = false;
        mCurrentRectf = outRectF;
        mCurrentPaint = paint;
        mCurrentRadius = outCirRadius;
        resetPoints();
        drawCirclePath(canvas);
        drawArc(canvas);
        break;
    case STATE_DRAW_SUCCESS:
        drawHook(canvas);
        break;
    case STATE_DRAW_ERROR:
        drawError(canvas);
        break;
    case STATE_DRAW_PATH:
        mCurrentRadius = outCirRadius;
        mCurrentRectf = outRectF;
        mCurrentPaint = paint;
        resetPoints();
        drawCirclePath(canvas, paths);
        break;
    case STATE_TRANSLATE_PATH:
        drawCirclePath(canvas);
        break;
    case STATE_DRAW_OUT_PATH:
        mCurrentRadius = secondRadius;
        mCurrentRectf = secondRectf;
        mCurrentPaint = secPaint;
        resetPoints();
        drawCirclePath(canvas, backpaths);
        break;
    case STATE_DRAW_CIRCLE:
        mCurrentRadius = secondRadius;
        mCurrentRectf = secondRectf;
        mCurrentPaint = secPaint;
        resetPoints();
        drawCirclePath(canvas);
        break;
    }
}

From source file:com.microsoft.mimickeralarm.mimics.ProgressButton.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mState == State.ReadyCamera) {
        prepareDrawFill(sYellow);/*from  w w  w .  j  ava  2  s.  co  m*/
        canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush);

        canvas.drawBitmap(mCameraIcon, mCenterX - (mCameraIcon.getWidth() / 2),
                mCenterY - (mCameraIcon.getHeight() / 2), mBrush);
    } else if (mState == State.ReadyAudio) {
        prepareDrawFill(sYellow);
        canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush);

        canvas.drawBitmap(mMicrophoneIcon, mCenterX - (mMicrophoneIcon.getWidth() / 2),
                mCenterY - (mMicrophoneIcon.getHeight() / 2), mBrush);
    } else if (mState == State.Loading) {
        prepareDrawFill(sBlue);
        canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush);

        prepareDrawStroke(sWhite);
        canvas.drawArc(mLoadingAnimationRect, mLoadingAnimationProgress, 300f, false, mBrush);
    } else if (mState == State.Waiting) {
        prepareDrawFill(sGrey);
        canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush);
        prepareDrawFill(sWhite);
        canvas.drawCircle(mCenterX, mCenterY, (float) (mRadius * 0.7), mBrush);
        prepareDrawFill(sGrey);
        float w = (float) (mRadius * 0.3);
        canvas.drawRect(mCenterX - w, mCenterY - w, mCenterX + w, mCenterY + w, mBrush);
    }
}

From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java

@Override
protected void onDraw(Canvas canvas) {
    borderPaint.setColor(borderColor);//from w  w  w  . jav  a 2  s  .  co  m
    colorPaint.setColor(color);
    if (shape == ColorShape.SQUARE) {
        if (borderWidthPx > 0) {
            canvas.drawRect(drawingRect, borderPaint);
        }
        if (alphaPattern != null) {
            alphaPattern.draw(canvas);
        }
        canvas.drawRect(colorRect, colorPaint);
    } else if (shape == ColorShape.CIRCLE) {
        final int outerRadius = getMeasuredWidth() / 2;
        if (borderWidthPx > 0) {
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius, borderPaint);
        }
        if (Color.alpha(color) < 255) {
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius - borderWidthPx,
                    alphaPaint);
        }
        if (showOldColor) {
            canvas.drawArc(centerRect, 90, 180, true, originalPaint);
            canvas.drawArc(centerRect, 270, 180, true, colorPaint);
        } else {
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius - borderWidthPx,
                    colorPaint);
        }
    }
}

From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java

public void drawMoon(Canvas canvas) {
    moonPaint.reset();//from   w w  w .  j  a v a  2  s. co  m
    moonPaint.setColor(Color.WHITE);
    moonPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    moonPaintB.reset();// moon Paint Black
    moonPaintB.setColor(Color.BLACK);
    moonPaintB.setStyle(Paint.Style.FILL_AND_STROKE);
    moonPaintO.reset();// moon Paint for Oval
    moonPaintO.setColor(Color.WHITE);
    moonPaintO.setStyle(Paint.Style.FILL_AND_STROKE);
    moonPaintD.reset();// moon Paint for Diameter
    // draw
    moonPaintD.setColor(Color.GRAY);
    moonPaintD.setStyle(Paint.Style.STROKE);
    double moonPhase = sunMoonPosition.getMoonPhase();
    if (moonPosition.getElevation() > -5) {
        canvas.rotate((float) moonPosition.getAzimuth() - 360, px, py);
        int eOffset = (int) ((moonPosition.getElevation() / 90) * Radius);
        // elevation Offset 0 for 0 degree; r for 90 degree
        moonRect.set(px - r, py + eOffset - Radius - r, px + r, py + eOffset - Radius + r);
        canvas.drawArc(moonRect, 90, 180, false, moonPaint);
        canvas.drawArc(moonRect, 270, 180, false, moonPaintB);
        int arcWidth = (int) ((moonPhase - 0.5) * (4 * r));
        moonPaintO.setColor(arcWidth < 0 ? Color.BLACK : Color.WHITE);
        moonOval.set(px - Math.abs(arcWidth) / 2, py + eOffset - Radius - r, px + Math.abs(arcWidth) / 2,
                py + eOffset - Radius + r);
        canvas.drawArc(moonOval, 0, 360, false, moonPaintO);
        canvas.drawArc(moonRect, 0, 360, false, moonPaintD);
        moonPaintD.setPathEffect(dashPath);
        canvas.drawLine(px, py - Radius, px, py + Radius, moonPaintD);
        moonPaintD.setPathEffect(null);
        canvas.restore();

    }

}