List of usage examples for android.graphics Path Path
public Path()
From source file:com.android.camera.HighlightView.java
void draw(Canvas canvas) { if (mHidden) { return;//from w w w . ja va 2 s . c o m } canvas.save(); Path path = new Path(); if (!hasFocus()) { mOutlinePaint.setColor(0xFF000000); canvas.drawRect(mDrawRect, mOutlinePaint); } else { Rect viewDrawingRect = new Rect(); mContext.getDrawingRect(viewDrawingRect); if (mCircle) { float width = mDrawRect.width(); float height = mDrawRect.height(); path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW); mOutlinePaint.setColor(mOutlineCircleColor); } else { path.addRect(new RectF(mDrawRect), Path.Direction.CW); mOutlinePaint.setColor(mOutlineColor); } canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint); canvas.restore(); canvas.drawPath(path, mOutlinePaint); if (mMode == ModifyMode.Grow) { if (mCircle) { int width = mResizeDrawableDiagonal.getIntrinsicWidth(); int height = mResizeDrawableDiagonal.getIntrinsicHeight(); int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D)); int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2; int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2; mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y + mResizeDrawableDiagonal.getIntrinsicHeight()); mResizeDrawableDiagonal.draw(canvas); } else { int left = mDrawRect.left + 1; int right = mDrawRect.right + 1; int top = mDrawRect.top + 4; int bottom = mDrawRect.bottom + 3; int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2; int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2; int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2; int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2; int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2); int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2); mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight); mResizeDrawableHeight.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom + heightHeight); mResizeDrawableHeight.draw(canvas); } } } }
From source file:android.support.wear.widget.util.ArcSwipe.java
private float[][] interpolate(float[] start, float[] end, int steps, boolean isClockwise) { float startAngle = getAngle(start[0], start[1]); float endAngle = getAngle(end[0], end[1]); Path path = new Path(); PathMeasure pathMeasure = new PathMeasure(); path.moveTo(start[0], start[1]);// ww w.j a v a 2s . com path.arcTo(mBounds, startAngle, getSweepAngle(startAngle, endAngle, isClockwise)); pathMeasure.setPath(path, false); float pathLength = pathMeasure.getLength(); float[][] res = new float[steps][2]; float[] mPathTangent = new float[2]; for (int i = 1; i < steps + 1; i++) { pathMeasure.getPosTan((pathLength * i) / (steps + 2f), res[i - 1], mPathTangent); } return res; }
From source file:com.cooltechworks.views.ScratchTextView.java
/** * Initialises the paint drawing elements. *//* w ww .j a v a2s .c o m*/ private void init() { mTouchPath = new Path(); mErasePaint = new Paint(); mErasePaint.setAntiAlias(true); mErasePaint.setDither(true); mErasePaint.setColor(0xFFFF0000); mErasePaint.setStyle(Paint.Style.STROKE); mErasePaint.setStrokeJoin(Paint.Join.BEVEL); mErasePaint.setStrokeCap(Paint.Cap.ROUND); mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); setStrokeWidth(6); mGradientBgPaint = new Paint(); mErasePath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); Bitmap scratchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_scratch_pattern); mDrawable = new BitmapDrawable(getResources(), scratchBitmap); mDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); }
From source file:com.example.nouri.playground.drawable.ArrowDrawable.java
public ArrowDrawable(Resources resources, boolean rounded) { this.rounded = rounded; float density = resources.getDisplayMetrics().density; float strokeWidthPixel = STROKE_WIDTH_DP * density; halfStrokeWidthPixel = strokeWidthPixel / 2; linePaint = new Paint(SUBPIXEL_TEXT_FLAG | ANTI_ALIAS_FLAG); linePaint.setStrokeCap(rounded ? ROUND : BUTT); linePaint.setColor(BLACK);// ww w . j a va 2 s .c om linePaint.setStyle(STROKE); linePaint.setStrokeWidth(strokeWidthPixel); int dimen = (int) (DIMEN_DP * density); bounds = new Rect(0, 0, dimen, dimen); Path first, second; JoinedPath joinedA, joinedB; // Top first = new Path(); first.moveTo(5.042f, 20f); first.rCubicTo(8.125f, -16.317f, 39.753f, -27.851f, 55.49f, -2.765f); second = new Path(); second.moveTo(60.531f, 17.235f); second.rCubicTo(11.301f, 18.015f, -3.699f, 46.083f, -23.725f, 43.456f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 20f); first.rCubicTo(4.457f, 16.75f, 1.512f, 37.982f, -22.557f, 42.699f); second = new Path(); second.moveTo(42.402f, 62.699f); second.cubicTo(18.333f, 67.418f, 8.807f, 45.646f, 8.807f, 32.823f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); topLine = new BridgingLine(joinedA, joinedB); // Middle first = new Path(); first.moveTo(5.042f, 35f); first.cubicTo(5.042f, 20.333f, 18.625f, 6.791f, 35f, 6.791f); second = new Path(); second.moveTo(35f, 6.791f); second.rCubicTo(16.083f, 0f, 26.853f, 16.702f, 26.853f, 28.209f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 35f); first.rCubicTo(0f, 10.926f, -8.709f, 26.416f, -29.958f, 26.416f); second = new Path(); second.moveTo(35f, 61.416f); second.rCubicTo(-7.5f, 0f, -23.946f, -8.211f, -23.946f, -26.416f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); middleLine = new BridgingLine(joinedA, joinedB); // Bottom first = new Path(); first.moveTo(5.042f, 50f); first.cubicTo(2.5f, 43.312f, 0.013f, 26.546f, 9.475f, 17.346f); second = new Path(); second.moveTo(9.475f, 17.346f); second.rCubicTo(9.462f, -9.2f, 24.188f, -10.353f, 27.326f, -8.245f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 50f); first.rCubicTo(-7.021f, 10.08f, -20.584f, 19.699f, -37.361f, 12.74f); second = new Path(); second.moveTo(27.598f, 62.699f); second.rCubicTo(-15.723f, -6.521f, -18.8f, -23.543f, -18.8f, -25.642f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); bottomLine = new BridgingLine(joinedA, joinedB); }
From source file:com.example.scratchview.ScratchImageView.java
/** * Initialises the paint drawing elements. */// ww w . ja v a 2 s .c o m private void init() { mTouchPath = new Path(); mErasePaint = new Paint(); mErasePaint.setAntiAlias(true); mErasePaint.setDither(true); mErasePaint.setColor(0xFFFF0000); mErasePaint.setStyle(Paint.Style.STROKE); mErasePaint.setStrokeJoin(Paint.Join.BEVEL); mErasePaint.setStrokeCap(Paint.Cap.ROUND); setStrokeWidth(6); mGradientBgPaint = new Paint(); mErasePath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); Bitmap scratchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_scratch_pattern); mDrawable = new BitmapDrawable(getResources(), scratchBitmap); mDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); setEraserMode(); }
From source file:com.ickphum.android.isoview.IsoCanvas.java
public IsoCanvas(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IsoCanvas, defStyle, defStyle); try {/* w w w . j av a 2 s.c om*/ mBackgroundLineColor = a.getColor(R.styleable.IsoCanvas_backgroundLineColor, mBackgroundLineColor); } finally { a.recycle(); } mPaints[0] = new Paint(); mPaints[0].setColor(Color.CYAN); mPaints[0].setStyle(Paint.Style.FILL); float mHalfWidth = (float) 4.9; float mHalfHeight = (float) 5.6; float quarter_height = mHalfHeight / 2; for (int i = 0; i < 3; i++) { mPaths[i] = new Path(); } mPaths[0].moveTo(0, 0); mPaths[0].lineTo(-mHalfWidth, -quarter_height); mPaths[0].lineTo(-mHalfWidth, quarter_height); mPaths[0].lineTo(0, quarter_height * 2); mPaths[0].setFillType(Path.FillType.WINDING); mPaths[1].moveTo(0, 0); mPaths[1].lineTo(10, 0); mPaths[1].lineTo(10, 10); mPaths[1].lineTo(0, 10); mPaths[1].lineTo(0, 0); mPaths[1].setFillType(Path.FillType.WINDING); initPaints(); // Sets up interactions if (!this.isInEditMode()) { mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener); mGestureDetector = new GestureDetectorCompat(context, mGestureListener); } }
From source file:com.ichi2.anki.Whiteboard.java
public Whiteboard(AnkiActivity context, boolean inverted, boolean monochrome) { super(context, null); mActivity = new WeakReference<>(context); mInvertedColors = inverted;/*from ww w. jav a 2s .c om*/ mMonochrome = monochrome; int foregroundColor; if (!mInvertedColors) { if (mMonochrome) { foregroundColor = Color.BLACK; } else { foregroundColor = ContextCompat.getColor(context, R.color.wb_fg_color); } } else { if (mMonochrome) { foregroundColor = Color.WHITE; } else { foregroundColor = ContextCompat.getColor(context, R.color.wb_fg_color_inv); } } mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(foregroundColor); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); int wbStrokeWidth = AnkiDroidApp.getSharedPrefs(context).getInt("whiteBoardStrokeWidth", 6); mPaint.setStrokeWidth((float) wbStrokeWidth); createBitmap(); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); }
From source file:jp.co.recruit_lifestyle.android.widget.ColoringLoadingView.java
private void initPath() { mColoringPath = new Path(); mLoadingPath = new Path(); mCharacterPath = new Path(); mPencilPath = new PencilPath(); mPencilPath.setWidth(mViewWidth / 6); Path loadingPath = LoadingPath.getPath(mViewWidth); mLoadingPathMeasure = new PathMeasure(loadingPath, false); mBackgroundPath = new BackgroundPath(); mBackgroundPath.setWidth(mViewWidth); }
From source file:com.android.tabletcustomui.views.LeftCircleContainer.java
private void addCircle(int position, final int value, float diff, double ratio) { final int radius = value / 2; final RectF mOval = new RectF(); mOval.set(0 + diff, 0 + diff, value - diff, value - diff); final Paint mPaintClip = new Paint(); mPaintClip.setStyle(Paint.Style.FILL); mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY)); mPaintClip.setAntiAlias(true);//from w w w.jav a2s . co m final PointF pointF = new PointF(mOval.centerX(), mOval.centerY()); final Path clipPath = new Path(); clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW); View circleView; if (position == 0) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 10, true, mPaintClip); canvas.drawArc(mOval, 342, 20, true, mPaintClip); canvas.drawArc(mOval, 4, 10, true, mPaintClip); canvas.drawArc(mOval, 240, 10, true, mPaintClip); canvas.drawArc(mOval, 252, 20, true, mPaintClip); canvas.drawArc(mOval, 275, 10, true, mPaintClip); canvas.drawArc(mOval, 150, 10, true, mPaintClip); canvas.drawArc(mOval, 162, 20, true, mPaintClip); canvas.drawArc(mOval, 185, 10, true, mPaintClip); canvas.drawArc(mOval, 60, 10, true, mPaintClip); canvas.drawArc(mOval, 72, 20, true, mPaintClip); canvas.drawArc(mOval, 95, 10, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 1) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 2) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 55, 190, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 3) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 240, 190, true, mPaintClip); canvas.drawArc(mOval, 80, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 4) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 335, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 180, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 5) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 6) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 290, 5, true, mPaintClip); canvas.drawArc(mOval, 297, 20, true, mPaintClip); canvas.drawArc(mOval, 319, 20, true, mPaintClip); canvas.drawArc(mOval, 60, 15, true, mPaintClip); canvas.drawArc(mOval, 77, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 7) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 160, 10, true, mPaintClip); canvas.drawArc(mOval, 172, 30, true, mPaintClip); canvas.drawArc(mOval, 204, 30, true, mPaintClip); canvas.drawArc(mOval, 236, 10, true, mPaintClip); canvas.drawArc(mOval, 20, 20, true, mPaintClip); canvas.drawArc(mOval, 42, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateAntiClockWise(circleView); } }
From source file:com.github.shareme.gwsmaterialuikit.library.material.drawable.LineMorphingDrawable.java
private LineMorphingDrawable(State[] states, int curState, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom, int animDuration, Interpolator interpolator, int strokeSize, int strokeColor, Paint.Cap strokeCap, Paint.Join strokeJoin, boolean clockwise, boolean isRtl) { mStates = states;/*from w w w. j a va 2 s. c o m*/ mPaddingLeft = paddingLeft; mPaddingTop = paddingTop; mPaddingRight = paddingRight; mPaddingBottom = paddingBottom; mAnimDuration = animDuration; mInterpolator = interpolator; mStrokeSize = strokeSize; mStrokeColor = strokeColor; mStrokeCap = strokeCap; mStrokeJoin = strokeJoin; mClockwise = clockwise; mIsRtl = isRtl; mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeCap(mStrokeCap); mPaint.setStrokeJoin(mStrokeJoin); mPaint.setColor(mStrokeColor); mPaint.setStrokeWidth(mStrokeSize); mDrawBound = new RectF(); mPath = new Path(); switchLineState(curState, false); }