Java Code Examples for android.graphics.Canvas#drawPath()

The following examples show how to use android.graphics.Canvas#drawPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XAxisRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
public void renderLimitLineLine(Canvas c, LimitLine limitLine, float[] position)
{
    mLimitLineSegmentsBuffer[0] = position[0];
    mLimitLineSegmentsBuffer[1] = mViewPortHandler.contentTop();
    mLimitLineSegmentsBuffer[2] = position[0];
    mLimitLineSegmentsBuffer[3] = mViewPortHandler.contentBottom();

    mLimitLinePath.reset();
    mLimitLinePath.moveTo(mLimitLineSegmentsBuffer[0], mLimitLineSegmentsBuffer[1]);
    mLimitLinePath.lineTo(mLimitLineSegmentsBuffer[2], mLimitLineSegmentsBuffer[3]);

    mLimitLinePaint.setStyle(Paint.Style.STROKE);
    mLimitLinePaint.setColor(limitLine.getLineColor());
    mLimitLinePaint.setStrokeWidth(limitLine.getLineWidth());
    mLimitLinePaint.setPathEffect(limitLine.getDashPathEffect());

    c.drawPath(mLimitLinePath, mLimitLinePaint);
}
 
Example 2
Source File: DynamicPageIndicator.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
private void drawUnselected(Canvas canvas) {
    combinedUnselectedPath.rewind();

    // draw any settled, revealing or joining dots
    for (int page = 0; page < pageCount; page++) {
        int nextXIndex = page == pageCount - 1 ? page : page + 1;
        Path unselectedPath = getUnselectedPath(page,
                dotCenterX[page],
                dotCenterX[nextXIndex],
                page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                dotRevealFractions[page]);
        unselectedPath.addPath(combinedUnselectedPath);
        combinedUnselectedPath.addPath(unselectedPath);
    }
    // draw any retreating joins
    if (retreatingJoinX1 != INVALID_FRACTION) {
        Path retreatingJoinPath = getRetreatingJoinPath();
        combinedUnselectedPath.addPath(retreatingJoinPath);
    }

    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}
 
Example 3
Source File: AddDeleteDrawable.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    float canvasRotate;
    if (mVerticalMirror) {
        canvasRotate = MathUtils.lerp(270, 135f, mProgress);
    } else {
        canvasRotate = MathUtils.lerp(0f, 135f, mProgress);
    }

    canvas.save();
    canvas.translate(bounds.centerX(), bounds.centerY());
    canvas.rotate(canvasRotate);
    canvas.drawPath(mPath, mPaint);
    canvas.restore();
}
 
Example 4
Source File: DividerDrawable.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
       if(mHeight == 0)
           return;

	Rect bounds = getBounds();
	float y = bounds.bottom - mHeight / 2;

	if(!isRunning()){
		mPath.reset();
		mPath.moveTo(bounds.left + mPaddingLeft, y);
		mPath.lineTo(bounds.right - mPaddingRight, y);
		mPaint.setPathEffect(mEnable ? null : getPathEffect());
		mPaint.setColor(mCurColor);
		canvas.drawPath(mPath, mPaint);
	}
	else{
           float centerX = (bounds.right + bounds.left - mPaddingRight + mPaddingLeft) / 2f;
		float start = centerX * (1f - mAnimProgress) + (bounds.left + mPaddingLeft) * mAnimProgress;
		float end = centerX * (1f - mAnimProgress) + (bounds.right + mPaddingRight) * mAnimProgress;
		
		mPaint.setPathEffect(null);
		
		if(mAnimProgress < 1f){
			mPaint.setColor(mPrevColor);				
			mPath.reset();
			mPath.moveTo(bounds.left + mPaddingLeft, y);
			mPath.lineTo(start, y);
			mPath.moveTo(bounds.right - mPaddingRight, y);
			mPath.lineTo(end, y);				
			canvas.drawPath(mPath, mPaint);
		}
		
		mPaint.setColor(mCurColor);
		mPath.reset();
		mPath.moveTo(start, y);
		mPath.lineTo(end, y);
		canvas.drawPath(mPath, mPaint);
	}
}
 
Example 5
Source File: LandscapeBezierCurveView.java    From property-animation-bessel with Apache License 2.0 5 votes vote down vote up
public void onDraw(Canvas canvas) {
    canvas.drawColor(Color.TRANSPARENT);
    mPath.reset();
    mPath.moveTo(mWidth, mHeight);        //开始起点
    mPath.quadTo(mWidth / 2 + 600, mHeight / 2 - 300, mWidth / 2, mHeight / 2);    // 控制点、终点
    canvas.drawPath(mPath, mPaint);
}
 
Example 6
Source File: Wave.java    From X-Alarm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawPath(mBlowWavePath, mBlowWavePaint);
    canvas.drawPath(mAboveWavePath, mAboveWavePaint);
}
 
Example 7
Source File: BookPageView.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
private void drawPathBContentBitmap(Bitmap bitmap, Paint pathPaint) {
    Canvas mCanvas = new Canvas(bitmap);
    //下面开始绘制区域内的内容...
    mCanvas.drawPath(getPathDefault(), pathPaint);
    mCanvas.drawText("这是在B区域的内容...BBBB", viewWidth - 260, viewHeight - 100, textPaint);

    //结束绘制区域内的内容...
}
 
Example 8
Source File: BotHelpCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    int x = (getWidth() - width) / 2;
    int y = AndroidUtilities.dp(2);
    Drawable shadowDrawable = Theme.chat_msgInMediaDrawable.getShadowDrawable();
    if (shadowDrawable != null) {
        shadowDrawable.setBounds(x, y, width + x, height + y);
        shadowDrawable.draw(canvas);
    }
    int h = AndroidUtilities.displaySize.y;
    if (getParent() instanceof View) {
        View view = (View) getParent();
        h = view.getMeasuredHeight();
    }
    Theme.chat_msgInMediaDrawable.setTop((int) getY(), h, false, false);
    Theme.chat_msgInMediaDrawable.setBounds(x, y, width + x, height + y);
    Theme.chat_msgInMediaDrawable.draw(canvas);
    Theme.chat_msgTextPaint.setColor(Theme.getColor(Theme.key_chat_messageTextIn));
    Theme.chat_msgTextPaint.linkColor = Theme.getColor(Theme.key_chat_messageLinkIn);
    canvas.save();
    canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y);
    if (pressedLink != null) {
        canvas.drawPath(urlPath, Theme.chat_urlPaint);
    }
    if (textLayout != null) {
        textLayout.draw(canvas);
    }
    canvas.restore();
    wasDraw = true;
}
 
Example 9
Source File: CircularProgressBarDrawable.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    if (!ensureValidRect()) {
        // nothing to draw
        return;
    }

    // remember the alpha values, in case we temporarily overwrite them
    // when we modulate them with mAlpha
    final int prevFillAlpha = mFillPaint.getAlpha();

    // compute the modulate alpha values
    final int currFillAlpha = modulateAlpha(prevFillAlpha);

    final CircularProgressBarState st = mCircularProgressBarState;

    /*  Drawing with a layer is slower than direct drawing, but it
        allows us to apply paint effects like alpha and colorfilter to
        the result of multiple separate draws. In our case, if the user
        asks for a non-opaque alpha value (via setAlpha), and we're
        stroking, then we need to apply the alpha AFTER we've drawn
        both the fill and the stroke.
    */
    /*  since we're not using a layer, apply the dither/filter to our
        individual paints
    */

    mFillPaint.setAlpha(currFillAlpha);
    mFillPaint.setColorFilter(mColorFilter);
    if (mColorFilter != null && !mCircularProgressBarState.mHasSolidColor) {
        mFillPaint.setColor(mAlpha << 24);
    }

    Path path = buildRing(st);
    canvas.drawPath(path, mFillPaint);

    mFillPaint.setAlpha(prevFillAlpha);
}
 
Example 10
Source File: XfermodeView2.java    From zone-sdk with MIT License 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Canvas canvas2 = new Canvas();
    //画黄色的圆 满屏幕那种 bitmap
    Bitmap bt = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_4444);
    canvas2.setBitmap(bt);
    //1:绘制红色的矩形
    paint.setColor(Color.RED);
    canvas2.drawRect(getWidth() / 2 - 200, getHeight() / 2 - 200, getWidth() / 2 + 200, getHeight() / 2 + 300, paint);
    //2:saveLayer
    canvas2.saveLayer(0, 0, getWidth(), getHeight(), paint,
            Canvas.ALL_SAVE_FLAG);
    //3:绘制黄色的圆
    paint.setColor(Color.YELLOW);
    canvas2.drawCircle(getWidth() / 2, getHeight() / 2, 200, paint);

    //4:用我的工具类进行 matte
    Matrix mar = new Matrix();
    mar.postTranslate(-100, 0);
    paint.setColor(Color.BLUE);
    MatteUtils.setMatte(canvas2, new Circle(getWidth() / 2 + 200, getHeight() / 2 + 200, 200F).getPath()
            , mar, paint, PorterDuff.Mode.SRC_OUT);

    //5:绘制个浅蓝色的圆看看 上面的工具类对此有影响不
    Circle topCircle = new Circle(getWidth() / 2 + 200, getHeight() / 2 + 200, 100F);
    paint.setColor(Color.CYAN);
    canvas2.drawPath(topCircle.getPath(), paint);
    canvas2.restore();//画布提交  对应上面的 保存图层,不然会显示不出来 saveLayer的那层画面;

    canvas.drawBitmap(bt, 0, 0, paint);
}
 
Example 11
Source File: RoundedUI.java    From RoundedUI with Apache License 2.0 5 votes vote down vote up
private void clipRightUp(Canvas canvas) {
    int width = getWidth();

    Path path = new Path();
    path.moveTo(width, roundHeight);
    path.lineTo(width, 0);
    path.lineTo(width-roundWidth, 0);
    RectF arc = new RectF(width - roundWidth * 2, 0, width, roundHeight * 2);
    float startAngle=-90;
    float sweepAngle=90;
    path.arcTo(arc, startAngle, sweepAngle);
    path.close();
    canvas.drawPath(path, paint);
}
 
Example 12
Source File: HorizontalExpandMenu.java    From ExpandMenu with MIT License 5 votes vote down vote up
/**
 * 绘制右边的按钮
 * @param canvas
 */
private void drawRightIcon(Canvas canvas){
    path.reset();
    path.moveTo(rightButtonCenter.x- buttonIconSize, rightButtonCenter.y);
    path.lineTo(rightButtonCenter.x+ buttonIconSize, rightButtonCenter.y);
    canvas.drawPath(path, buttonIconPaint);//划横线

    canvas.save();
    canvas.rotate(buttonIconDegrees, rightButtonCenter.x, rightButtonCenter.y);//旋转画布,让竖线可以随角度旋转
    path.reset();
    path.moveTo(rightButtonCenter.x, rightButtonCenter.y- buttonIconSize);
    path.lineTo(rightButtonCenter.x, rightButtonCenter.y+ buttonIconSize);
    canvas.drawPath(path, buttonIconPaint);//画竖线
    canvas.restore();
}
 
Example 13
Source File: AnimationLayout.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void drawLeftBottomElevation(Canvas canvas) {
    canvas.save();
    canvas.translate(mBound.left + mCornerRadius, mBound.bottom - mCornerRadius);
    canvas.rotate(90);
    mPaint.setShader(mElevationCornerShader);
    canvas.drawPath(mElevationCorner, mPaint);
    canvas.restore();
}
 
Example 14
Source File: prevBtnImg.java    From Android-Music-Player with MIT License 4 votes vote down vote up
public void draw(Canvas canvas) {
    canvas.drawPath(S0, P0);
    canvas.drawPath(S1, P1);
    canvas.drawPath(S2, P2);
}
 
Example 15
Source File: Bar3D.java    From XCL-Charts with Apache License 2.0 4 votes vote down vote up
/**
  * 横向3D柱形图
  * @param barLeft	左边X坐标
  * @param barTop	顶部Y坐标
  * @param barRight	右边X坐标
  * @param barBottom	底部Y坐标
  * @param color	柱形颜色
  * @param canvas	画布
  */
 public void renderHorizontal3DBar(float barLeft,float barTop,
		  float barRight,float barBottom,
		  int color,
		  Canvas canvas)
{
	 if(Float.compare(barTop, barBottom) == 0)return;		 
	 
	//浅色
	int lightColor =  DrawHelper.getInstance().getLightColor(color,mAlpha);
	
	getBarPaint().setColor(color);		
	mPaint3D.setColor(lightColor);
	
	//水平偏移量
	float offsetX = (float) getOffsetX();
	//垂直偏移量
	float offsetY= (float) getOffsetY();
	
	//Shadow
	float barLeft2 = MathHelper.getInstance().sub(barLeft , offsetX);
	float barTop2 = MathHelper.getInstance().add(barTop , offsetY);
	float barRight2 = MathHelper.getInstance().sub(barRight , offsetX) ;
	float barBottom2 = MathHelper.getInstance().add(barBottom, offsetY) ;	
	
	//右侧边 浅色
	mPathRectangle2D.reset();
	mPathRectangle2D.moveTo(barRight, barTop); 
	mPathRectangle2D.lineTo(barRight, barBottom); 
	mPathRectangle2D.lineTo(barRight2, barBottom2); 
	mPathRectangle2D.lineTo(barRight2, barTop2); 					
	mPathRectangle2D.close();		
	canvas.drawPath(mPathRectangle2D,mPaint3D); 	
	
	//正面	
	canvas.drawRect(barLeft2, barTop2, barRight2, barBottom2, mPaint3D);
	
	//顶
	mPathRectangle2D.reset();		
	mPathRectangle2D.moveTo(barLeft, barTop); 
	mPathRectangle2D.lineTo(barLeft2, barTop2); 
	mPathRectangle2D.lineTo(barRight2, barTop2 );
	mPathRectangle2D.lineTo(barRight, barTop );
	mPathRectangle2D.close();
	canvas.drawPath(mPathRectangle2D,getBarPaint()); 		

	//轮廓线
	mPaintLine.reset();
	mPaintLine.setColor(Color.WHITE);
	mPaintLine.setStyle(Style.STROKE);		
	canvas.drawLine( barLeft2,  barTop2, barRight2, barTop2, mPaintLine);
	canvas.drawLine( barRight2, barTop2, barRight2, barBottom2,mPaintLine);		
	canvas.drawLine( barRight, barTop, barRight2,barTop2,mPaintLine);   	
}
 
Example 16
Source File: RoundSideRectDrawable.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    canvas.drawPath(mPath, mPaint);
}
 
Example 17
Source File: YAxisRender.java    From LChart with Apache License 2.0 4 votes vote down vote up
@Override
public void renderWarnLine(Canvas canvas) {
    super.renderWarnLine(canvas);

    List<WarnLine> warnLines = _Axis.getListWarnLins();
    if (warnLines == null) {
        return;
    }

    canvas.save();
    canvas.clipRect(_rectMain);

    for (WarnLine warnLine : warnLines) {
        if (warnLine.isEnable()) {
            double value = warnLine.getValue();

            SingleF_XY xy = _MappingManager.getPxByValue(0, value);
            float y = xy.getY();

            if (y < _rectMain.top || y > _rectMain.bottom) {
                continue;
            }

            _PaintWarnText.setColor(warnLine.getWarnColor());
            _PaintWarnText.setStrokeWidth(warnLine.getWarnLineWidth());
            _PaintWarnText.setTextSize(warnLine.getTxtSize());

            _PaintWarnPath.setColor(warnLine.getWarnColor());
            _PaintWarnPath.setStrokeWidth(warnLine.getWarnLineWidth());

            _PathWarn.reset();
            _PathWarn.moveTo(_rectMain.left, y);
            _PathWarn.lineTo(_rectMain.right, y);

            canvas.drawPath(_PathWarn, _PaintWarnPath);

            float txtHeight = Utils.textHeight(_PaintWarnText);
            canvas.drawText(value + "", _rectMain.left + 10, y - txtHeight, _PaintWarnText);
        }
    }

    canvas.restore();
}
 
Example 18
Source File: MotionLayout.java    From Carbon with Apache License 2.0 4 votes vote down vote up
private void drawStroke(Canvas canvas) {
    strokePaint.setStrokeWidth(strokeWidth * 2);
    strokePaint.setColor(stroke.getColorForState(getDrawableState(), stroke.getDefaultColor()));
    cornersMask.setFillType(Path.FillType.WINDING);
    canvas.drawPath(cornersMask, strokePaint);
}
 
Example 19
Source File: CloudRainView.java    From MaterialCalendar with Apache License 2.0 4 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // set canvas background color
    canvas.drawColor(bgColor);
    if (count > 360) {
        count = count % 360;
    } else {
        count += 15;
    }


    dRain += 5;
    dRain %= 100;

    dy = centerY + 20;

    if (drop1) {
        dx = centerX - 20;
        if (dRain == 95) {
            drop2 = true;
            drop1 = false;
        }
    } else if (drop2) {
        dx = centerX;
        if (dRain == 95) {
            drop3 = true;
            drop2 = false;
        }
    } else if (drop3) {
        dx = centerX + 20;
        if (dRain == 95) {
            drop1 = true;
            drop3 = false;
        }
    }

    mRainPath.reset();
    mRainPath.moveTo(dx, dy);
    mRainPath.addArc(new RectF(dx - 5, dy - 5 + dRain, dx + 5, dy + 5 + dRain), 180, -180);
    mRainPath.lineTo(dx, dy - 10 + dRain);
    mRainPath.close();

    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    canvas.drawPath(mRainPath, mPaint);


    // drawing cloud with fill
    mPaint.setColor(bgColor);
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(cloud.getCloud(centerX, centerY, (int) width, count), mPaint);

    // mPaint cloud with stroke
    mPaint.setColor(strokeColor);
    mPaint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(cloud.getCloud(centerX, centerY, (int) width, count), mPaint);

    if (!isStatic) {
        postInvalidateDelayed(33);
    }

}
 
Example 20
Source File: itemMenu.java    From Android-Music-Player with MIT License votes vote down vote up
public void draw(Canvas canvas) {
 			if(drawing){
				canvas.drawPath(S0, P0);
				canvas.drawPath(S1, P1);
				canvas.drawPath(S2, P2);
				canvas.drawPath(S3, P3);
				canvas.drawPath(S4, P4);
			}
		}