@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); viewWidth = w; viewHeight = h; buildPathData(); }
public void start() { checkRequirements(); initialTime = System.currentTimeMillis(); changeState(State.STROKE_STARTED); ViewCompat.postInvalidateOnAnimation(this); }
private void checkRequirements() { checkOriginalDimensions(); checkPath(); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!hasToDraw()) { return; } long elapsedTime = System.currentTimeMillis() - initialTime; drawStroke(canvas, elapsedTime); if (isStrokeTotallyDrawn(elapsedTime)) { if (drawingState < State.FILL_STARTED) { changeState(State.FILL_STARTED); previousFramePercentageTime = System.currentTimeMillis() - initialTime; } float fillPhase; if (percentageEnabled) { fillPhase = getFillPhaseForPercentage(elapsedTime); } else { fillPhase = getFillPhaseWithoutPercentage(elapsedTime); } clippingTransform.transform(canvas, fillPhase, this); canvas.drawPath(pathData.path, fillPaint); } if (hasToKeepDrawing(elapsedTime)) { ViewCompat.postInvalidateOnAnimation(this); } else { changeState(State.FINISHED); } }
public void setToFinishedFrame() { initialTime = 1; changeState(State.FINISHED); ViewCompat.postInvalidateOnAnimation(this); }
private void drawStroke(Canvas canvas, long elapsedTime) { float phase = MathUtil.constrain(0, 1, elapsedTime * 1f / strokeDrawingDuration); float distance = animInterpolator.getInterpolation(phase) * pathData.length; dashPaint.setPathEffect(getDashPathForDistance(distance)); canvas.drawPath(pathData.path, dashPaint); }
public FillableLoader build() { Resources res = parent.getContext().getResources(); strokeColor = strokeColor == -1 ? res.getColor(R.color.strokeColor) : strokeColor; fillColor = fillColor == -1 ? res.getColor(R.color.fillColor) : fillColor; strokeWidth = strokeWidth < 0 ? res.getDimensionPixelSize(R.dimen.strokeWidth) : strokeWidth; strokeDrawingDuration = strokeDrawingDuration < 0 ? res.getInteger(R.integer.strokeDrawingDuration) : strokeDrawingDuration; fillDuration = fillDuration < 0 ? res.getInteger(R.integer.fillDuration) : fillDuration; clippingTransform = clippingTransform == null ? new PlainClippingTransform() : clippingTransform; if (params == null) { throwArgumentException("layout params"); } if (svgPath == null) { throwArgumentException("an svg path"); } return new FillableLoader(parent, params, strokeColor, fillColor, strokeWidth, originalWidth, originalHeight, strokeDrawingDuration, fillDuration, clippingTransform, svgPath, percentageEnabled, percentage); }
private void initAttrs(AttributeSet attrs) { AttributeExtractorImpl.Builder extractorBuilder = new AttributeExtractorImpl.Builder(); AttributeExtractorImpl extractor = extractorBuilder.with(getContext()).with(attrs).build(); fillColor = extractor.getFillColor(); strokeColor = extractor.getStrokeColor(); strokeWidth = extractor.getStrokeWidth(); originalWidth = extractor.getOriginalWidth(); originalHeight = extractor.getOriginalHeight(); strokeDrawingDuration = extractor.getStrokeDrawingDuration(); fillDuration = extractor.getFillDuration(); clippingTransform = extractor.getClippingTransform(); percentage = extractor.getFillPercentage(); if (percentage != 100) { percentageEnabled = true; } extractor.recycleAttributes(); }
/** * Resets the fillable loader. Means that the whole loader stroke + fill disappears. */ public void reset() { initialTime = 0; previousFramePercentage = 0; changeState(State.NOT_STARTED); ViewCompat.postInvalidateOnAnimation(this); }
public void setSvgPath(String svgPath) { if (svgPath == null || svgPath.length() == 0) { throw new IllegalArgumentException( "You must provide a not empty path in order to draw the view properly."); } this.svgPath = svgPath; buildPathData(); }