use of android.graphics.DashPathEffect in project muzei by romannurik.
the class AnimatedMuzeiLogoView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mState == STATE_NOT_STARTED || mGlyphData == null) {
return;
}
long t = System.currentTimeMillis() - mStartTime;
// Draw outlines (starts as traced)
for (int i = 0; i < mGlyphData.length; i++) {
float phase = MathUtil.constrain(0, 1, (t - (TRACE_TIME - TRACE_TIME_PER_GLYPH) * i * 1f / mGlyphData.length) * 1f / TRACE_TIME_PER_GLYPH);
float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length;
mGlyphData[i].paint.setColor(TRACE_RESIDUE_COLOR);
mGlyphData[i].paint.setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0));
canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint);
mGlyphData[i].paint.setColor(TRACE_COLOR);
mGlyphData[i].paint.setPathEffect(new DashPathEffect(new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0));
canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint);
}
if (t > FILL_START) {
if (mState < STATE_FILL_STARTED) {
changeState(STATE_FILL_STARTED);
}
// If after fill start, draw fill
float phase = MathUtil.constrain(0, 1, (t - FILL_START) * 1f / FILL_TIME);
mFillPaint.setARGB((int) (phase * 255), 255, 255, 255);
for (GlyphData glyphData : mGlyphData) {
canvas.drawPath(glyphData.path, mFillPaint);
}
}
if (t < FILL_START + FILL_TIME) {
// draw next frame if animation isn't finished
postInvalidateOnAnimation();
} else {
changeState(STATE_FINISHED);
}
}
use of android.graphics.DashPathEffect in project lottie-android by airbnb.
the class StrokeContent method applyDashPatternIfNeeded.
private void applyDashPatternIfNeeded() {
if (dashPatternAnimations.isEmpty()) {
return;
}
float scale = lottieDrawable.getScale();
for (int i = 0; i < dashPatternAnimations.size(); i++) {
dashPatternValues[i] = dashPatternAnimations.get(i).getValue();
// and a minimum gap size of 0.01.
if (i % 2 == 0) {
if (dashPatternValues[i] < 1f) {
dashPatternValues[i] = 1f;
}
} else {
if (dashPatternValues[i] < 0.1f) {
dashPatternValues[i] = 0.1f;
}
}
dashPatternValues[i] *= scale;
}
float offset = dashPatternOffsetAnimation == null ? 0f : dashPatternOffsetAnimation.getValue();
paint.setPathEffect(new DashPathEffect(dashPatternValues, offset));
}
use of android.graphics.DashPathEffect in project android_frameworks_base by ParanoidAndroid.
the class GradientDrawable method setStroke.
/**
* <p>Set the stroke width and color for the drawable. If width is zero,
* then no stroke is drawn. This method can also be used to dash the stroke.</p>
* <p><strong>Note</strong>: changing this property will affect all instances
* of a drawable loaded from a resource. It is recommended to invoke
* {@link #mutate()} before changing this property.</p>
*
* @param width The width in pixels of the stroke
* @param color The color of the stroke
* @param dashWidth The length in pixels of the dashes, set to 0 to disable dashes
* @param dashGap The gap in pixels between dashes
*
* @see #mutate()
* @see #setStroke(int, int)
*/
public void setStroke(int width, int color, float dashWidth, float dashGap) {
mGradientState.setStroke(width, color, dashWidth, dashGap);
if (mStrokePaint == null) {
mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint.setStyle(Paint.Style.STROKE);
}
mStrokePaint.setStrokeWidth(width);
mStrokePaint.setColor(color);
DashPathEffect e = null;
if (dashWidth > 0) {
e = new DashPathEffect(new float[] { dashWidth, dashGap }, 0);
}
mStrokePaint.setPathEffect(e);
invalidateSelf();
}
use of android.graphics.DashPathEffect in project WoWoViewPager by Nightonke.
the class WoWoPathView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
PathEffect pathEffect = new DashPathEffect(new float[] { mPathLength, mPathLength }, (mPathLength - mPathLength * mProgress));
mPaint.setPathEffect(pathEffect);
canvas.save();
canvas.translate(getPaddingLeft(), getPaddingTop());
canvas.drawPath(mPath, mPaint);
if (headImageId != 0) {
mPathMeasure.getPosTan(mPathLength * mProgress, mBitmapPosition, mBitmapTan);
mMatrix.reset();
float degrees = (float) (Math.atan2(mBitmapTan[1], mBitmapTan[0]) * 180.0 / Math.PI);
mMatrix.postRotate(degrees, mBitmapOffsetX, mBitmapOffsetY);
mMatrix.postTranslate(mBitmapPosition[0] - mBitmapOffsetX, mBitmapPosition[1] - mBitmapOffsetY);
canvas.drawBitmap(mBitmap, mMatrix, null);
}
canvas.restore();
}
use of android.graphics.DashPathEffect in project XobotOS by xamarin.
the class GradientDrawable method setStroke.
public void setStroke(int width, int color, float dashWidth, float dashGap) {
mGradientState.setStroke(width, color, dashWidth, dashGap);
if (mStrokePaint == null) {
mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint.setStyle(Paint.Style.STROKE);
}
mStrokePaint.setStrokeWidth(width);
mStrokePaint.setColor(color);
DashPathEffect e = null;
if (dashWidth > 0) {
e = new DashPathEffect(new float[] { dashWidth, dashGap }, 0);
}
mStrokePaint.setPathEffect(e);
invalidateSelf();
}
Aggregations