@Override public void onInitPath(Path outPath) { final float startX = this.startX.getAnimatedValue(); final float startY = this.startY.getAnimatedValue(); final float endX = this.endX.getAnimatedValue(); final float endY = this.endY.getAnimatedValue(); outPath.moveTo(startX, startY); outPath.lineTo(endX, endY); } }
@Override public void onInitPath(Path outPath) { final float l = x.getAnimatedValue(); final float t = y.getAnimatedValue(); final float r = l + width.getAnimatedValue(); final float b = t + height.getAnimatedValue(); final float rx = cornerRadiusX.getAnimatedValue(); final float ry = cornerRadiusY.getAnimatedValue(); tempRect.set(l, t, r, b); outPath.addRoundRect(tempRect, rx, ry, Path.Direction.CW); } }
@Override public void onInitPath(Path outPath) { final float cx = centerX.getAnimatedValue(); final float cy = centerY.getAnimatedValue(); final float rx = radiusX.getAnimatedValue(); final float ry = radiusY.getAnimatedValue(); tempRect.set(cx - rx, cy - ry, cx + rx, cy + ry); outPath.addOval(tempRect, Path.Direction.CW); } }
@Override public void onInitPath(Path outPath) { final float cx = centerX.getAnimatedValue(); final float cy = centerY.getAnimatedValue(); final float r = radius.getAnimatedValue(); tempRect.set(cx - r, cy - r, cx + r, cy + r); outPath.addOval(tempRect, Path.Direction.CW); } }
@Override public void onInitPath(Path outPath) { PathData.toPath(pathData.getAnimatedValue(), outPath); } }
@Nullable private DashPathEffect getDashPathEffect(float strokeScaleFactor) { final float[] strokeDashArray = this.strokeDashArray.getAnimatedValue(); if (strokeDashArray.length == 0) { return null; } // DashPathEffect throws an exception if the dash array is odd in length, // so double the size of the array if this is the case. final int initialSize = strokeDashArray.length; final int expansionFactor = initialSize % 2 == 0 ? 1 : 2; final int requiredSize = initialSize * expansionFactor; if (tempStrokeDashArray == null || tempStrokeDashArray.length != requiredSize) { tempStrokeDashArray = new float[requiredSize]; } for (int i = 0; i < initialSize; i++) { tempStrokeDashArray[i] = strokeDashArray[i] * strokeScaleFactor; } System.arraycopy( tempStrokeDashArray, 0, tempStrokeDashArray, initialSize, requiredSize - initialSize); final float strokeDashOffset = this.strokeDashOffset.getAnimatedValue(); return new DashPathEffect(tempStrokeDashArray, strokeDashOffset); }
@Override public final void draw(Canvas canvas, Matrix parentMatrix, PointF viewportScale) { final float pivotX = this.pivotX.getAnimatedValue(); final float pivotY = this.pivotY.getAnimatedValue(); final float rotation = this.rotation.getAnimatedValue(); final float scaleX = this.scaleX.getAnimatedValue(); final float scaleY = this.scaleY.getAnimatedValue(); final float translateX = this.translateX.getAnimatedValue(); final float translateY = this.translateY.getAnimatedValue(); tempMatrix.set(parentMatrix); if (translateX + pivotX != 0f || translateY + pivotY != 0f) { tempMatrix.preTranslate(translateX + pivotX, translateY + pivotY); } if (rotation != 0f) { tempMatrix.preRotate(rotation, 0, 0); } if (scaleX != 1f || scaleY != 1f) { tempMatrix.preScale(scaleX, scaleY); } if (pivotX != 0f || pivotY != 0f) { tempMatrix.preTranslate(-pivotX, -pivotY); } onDraw(canvas, tempMatrix, viewportScale); }
private void drawFillIfNeeded(Canvas canvas, Path path) { final int fillColor = this.fillColor.getAnimatedValue(); final float fillAlpha = this.fillAlpha.getAnimatedValue(); if (fillColor == Color.TRANSPARENT) { return; } if (tempFillPaint == null) { tempFillPaint = new Paint(); tempFillPaint.setStyle(Paint.Style.FILL); tempFillPaint.setAntiAlias(true); } final Paint paint = tempFillPaint; paint.setColor(applyAlpha(fillColor, fillAlpha)); path.setFillType(getPaintFillType(fillType)); canvas.drawPath(path, paint); }
private void drawStrokeIfNeeded(Canvas canvas, Path path, float strokeScaleFactor) { final int strokeColor = this.strokeColor.getAnimatedValue(); final float strokeAlpha = this.strokeAlpha.getAnimatedValue(); final float strokeWidth = this.strokeWidth.getAnimatedValue(); if (strokeColor == Color.TRANSPARENT || strokeWidth == 0) { return; } if (tempStrokePaint == null) { tempStrokePaint = new Paint(); tempStrokePaint.setStyle(Paint.Style.STROKE); tempStrokePaint.setAntiAlias(true); } final Paint paint = tempStrokePaint; paint.setStrokeCap(getPaintStrokeLineCap(strokeLineCap)); paint.setStrokeJoin(getPaintStrokeLineJoin(strokeLineJoin)); paint.setStrokeMiter(strokeMiterLimit.getAnimatedValue()); paint.setColor(applyAlpha(strokeColor, strokeAlpha)); paint.setStrokeWidth(strokeWidth * strokeScaleFactor); // TODO: can/should we cache path effects? paint.setPathEffect(getDashPathEffect(strokeScaleFactor)); canvas.drawPath(path, paint); }
private void applyTrimPathIfNeeded(Path outPath) { final float trimPathStart = this.trimPathStart.getAnimatedValue(); final float trimPathEnd = this.trimPathEnd.getAnimatedValue(); final float trimPathOffset = this.trimPathOffset.getAnimatedValue(); if (trimPathStart == 0f && trimPathEnd == 1f) { return; } float start = (trimPathStart + trimPathOffset) % 1f; float end = (trimPathEnd + trimPathOffset) % 1f; if (tempPathMeasure == null) { tempPathMeasure = new PathMeasure(); } tempPathMeasure.setPath(outPath, false); final float len = tempPathMeasure.getLength(); start = start * len; end = end * len; outPath.reset(); if (start > end) { tempPathMeasure.getSegment(start, len, outPath, true); tempPathMeasure.getSegment(0f, end, outPath, true); } else { tempPathMeasure.getSegment(start, end, outPath, true); } // Required for Android 4.4 and earlier. outPath.rLineTo(0f, 0f); }
final float alphaFloat = (this.alpha / 255f) * alphaProperty.getAnimatedValue(); final int alphaInt = Math.round(alphaFloat * 255f); if (alphaInt < 0xff || cf != null) {
@Override public void onDraw(Canvas canvas, Matrix parentMatrix, PointF viewportScale) { final float matrixScale = getMatrixScale(parentMatrix); if (matrixScale == 0) { return; } final float scaleX = viewportScale.x; final float scaleY = viewportScale.y; tempMatrix.set(parentMatrix); if (scaleX != 1f || scaleY != 1f) { tempMatrix.postScale(scaleX, scaleY); } tempRenderPath.reset(); tempPath.reset(); PathData.toPath(pathData.getAnimatedValue(), tempPath); tempRenderPath.addPath(tempPath, tempMatrix); tempRenderPath.setFillType(getPaintFillType(fillType)); if (clipType == ClipType.INTERSECT) { canvas.clipPath(tempRenderPath); } else { canvas.clipPath(tempRenderPath, Region.Op.DIFFERENCE); } }