Example usage for android.graphics Canvas drawPath

List of usage examples for android.graphics Canvas drawPath

Introduction

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

Prototype

public void drawPath(@NonNull Path path, @NonNull Paint paint) 

Source Link

Document

Draw the specified path using the specified paint.

Usage

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java

@Override
void doDraw(Canvas canvas, Paint paint) {
    if (!mPath.isEmpty()) {
        paint.setStyle(Paint.Style.FILL);
        int color = blendColors(mStartColor, mEndColor, mCurrentScale);
        paint.setColor(color);//from ww  w . j a v a 2 s. c o m
        canvas.drawPath(mPath, paint);
    }
}

From source file:com.frapim.windwatch.Notifier.java

public Bitmap createIcon(Context context, Wind wind) {
    Paint paint = new Paint();
    int color = wind.scale.getColor(context);
    paint.setColor(color);//from   ww w  .j  a v a  2s.c  o m
    paint.setStyle(Style.FILL_AND_STROKE);
    Bitmap bitmap = Bitmap.createBitmap(mBigIconSize, mBigIconSize, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Bitmap backgroundBmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.turbine);
    Bitmap backgroundScaled = Bitmap.createScaledBitmap(backgroundBmp, mBigIconSize, mBigIconSize, false);
    canvas.drawBitmap(backgroundScaled, new Matrix(), new Paint());
    canvas.drawPath(getArrowPath(wind.degrees), paint);
    return bitmap;
}

From source file:Main.java

public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX, float spotY,
        Paint p, Paint shadowPaint) {
    float sx = cropBounds.width() * spotX;
    float sy = cropBounds.height() * spotY;
    float cx = cropBounds.centerX();
    float cy = cropBounds.centerY();
    RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    float temp = sx;
    sx = sy;/*from  w  w  w . j a  v a 2s  .c om*/
    sy = temp;
    RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    canvas.save();
    canvas.clipRect(cropBounds);
    canvas.clipRect(r1, Region.Op.DIFFERENCE);
    canvas.clipRect(r2, Region.Op.DIFFERENCE);
    canvas.drawPaint(shadowPaint);
    canvas.restore();
    Path path = new Path();
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.right, r1.top);
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.left, r1.bottom);
    path.moveTo(r1.left, r1.bottom);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r1.right, r1.top);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.right, r2.top);
    path.moveTo(r2.right, r2.top);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.bottom);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.left, r2.bottom);
    canvas.drawPath(path, p);
}

From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java

@Override
public void draw(Canvas canvas) {
    canvas.save();//from   ww  w.  j  ava  2 s  . co m
    canvas.rotate(mGlobalAngle, mBounds.centerX(), mBounds.centerY());
    for (int i = 0; i < mSpinnerCount; i++) {
        canvas.drawPath(mSpinners[i].path, mSpinners[i].paint);
    }
    canvas.restore();
}

From source file:com.github.czy1121.view.CornerLabelView.java

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

    float xy = mHeight / SQRT2;
    canvas.save();//from   ww  w .ja v a2s  .  c o m
    canvas.translate(xy, xy);
    canvas.rotate((mIsTop ? 1 : -1) * (mIsLeft ? -45 : 45));
    canvas.drawPath(calcPath(), mPaint);

    mText1.draw(canvas, mPaddingBottom, mIsTop);
    if (mIsTriangle) {
        mText2.draw(canvas, mPaddingBottom + mPaddingCenter + mText1.height, mIsTop);
    }
    canvas.restore();
}

From source file:com.cooltechworks.views.ScratchImageView.java

@Override
protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);
    canvas.drawBitmap(mScratchBitmap, 0, 0, mBitmapPaint);
    canvas.drawPath(mErasePath, mErasePaint);

}

From source file:com.miris.ui.view.WaveView.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawPath(mWavePath, mShadowPaint);
    canvas.drawPath(mWavePath, mPaint);/*w  ww  . j av  a  2s .  c  om*/
    mWavePath.rewind();

    mDropTangentPath.rewind();
    mDropCirclePath.rewind();
    float circleCenterY = (Float) mDropCircleAnimator.getAnimatedValue();
    float circleCenterX = mWidth / 2.f;
    mDropRect.setEmpty();
    float scale = (Float) mDisappearCircleAnimator.getAnimatedValue();
    float vertical = (Float) mDropBounceVerticalAnimator.getAnimatedValue();
    float horizontal = (Float) mDropBounceHorizontalAnimator.getAnimatedValue();
    mDropRect.set(
            circleCenterX - mDropCircleRadius * (1 + vertical) * scale + mDropCircleRadius * horizontal / 2,
            circleCenterY + mDropCircleRadius * (1 + horizontal) * scale - mDropCircleRadius * vertical / 2,
            circleCenterX + mDropCircleRadius * (1 + vertical) * scale - mDropCircleRadius * horizontal / 2,
            circleCenterY - mDropCircleRadius * (1 + horizontal) * scale + mDropCircleRadius * vertical / 2);
    float vertex = (Float) mDropVertexAnimator.getAnimatedValue();
    mDropTangentPath.moveTo(circleCenterX, vertex);
    double q = (Math.pow(mDropCircleRadius, 2) + circleCenterY * vertex - Math.pow(circleCenterY, 2))
            / (vertex - circleCenterY);
    double b = -2.0 * mWidth / 2;
    double c = Math.pow(q - circleCenterY, 2) + Math.pow(circleCenterX, 2) - Math.pow(mDropCircleRadius, 2);
    double p1 = (-b + Math.sqrt(b * b - 4 * c)) / 2;
    double p2 = (-b - Math.sqrt(b * b - 4 * c)) / 2;
    mDropTangentPath.lineTo((float) p1, (float) q);
    mDropTangentPath.lineTo((float) p2, (float) q);
    mDropTangentPath.close();
    mShadowPath.set(mDropTangentPath);
    mShadowPath.addOval(mDropRect, Path.Direction.CCW);
    mDropCirclePath.addOval(mDropRect, Path.Direction.CCW);
    if (mDropVertexAnimator.isRunning()) {
        canvas.drawPath(mShadowPath, mShadowPaint);
    } else {
        canvas.drawPath(mDropCirclePath, mShadowPaint);
    }
    canvas.drawPath(mDropTangentPath, mPaint);
    canvas.drawPath(mDropCirclePath, mPaint);
}

From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java

/**
 * /*w w w.j  ava2s .  co m*/
 */
@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.save();
    // ?
    canvas.translate(mInitTranslationX + mTranslationX, getHeight() + 5);
    canvas.drawPath(mPath, mPaint);
    canvas.restore();

    // tab
    canvas.drawLine(mTranslationX, getHeight() - 3, mTranslationX + mHalfScreenWidth, getHeight() - 3,
            mLinePaint);
    // 
    canvas.drawLine(0, getHeight() - 1, 2 * mHalfScreenWidth, getHeight() - 1, mDividerLinePaint);
    super.dispatchDraw(canvas);
}

From source file:pl.rmakowiecki.simplemusicplayer.ui.widget.MusicCoverView.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.clipPath(mClipPath);/* w w w.  j  a v a2 s.  co m*/
    super.onDraw(canvas);
    canvas.drawPath(mTrackPath, mTrackPaint);
}

From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*w ww  .j a  va2  s. c  o m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
            generateMaskPath(mCachedWidth, mCachedHeight);
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        int sc = cacheCanvas.save();
        mDesaturatePaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
        cacheCanvas.saveLayer(mBoundsF, mDesaturatePaint,
                Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
        super.onDraw(cacheCanvas);
        cacheCanvas.drawPath(this.mMaskedPath, this.mMaskedPaint);
        cacheCanvas.restoreToCount(sc);
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}