Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Support bitmap with opacity animation on Android (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
renyu-io authored Jun 15, 2017
1 parent 6acda2f commit d6ae643
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,23 @@ public void draw(Canvas canvas) {
continue;
}

// We need paint for drawing (opacity animated) bitmaps and paths
mDrawingPaint.setShader(null);
mDrawingPaint.setAlpha(featureState.getAlpha());

// Drawing bitmap
final Bitmap backedImage = featureState.getBackedImageBitmap();
final Matrix uniqueFeatureMatrix = featureState.getUniqueFeatureMatrix();
if (backedImage != null && uniqueFeatureMatrix != null) {
// This block is for the experimental bitmap supporting
canvas.save();
canvas.concat(mScaleMatrix);
canvas.drawBitmap(backedImage, uniqueFeatureMatrix, null);

canvas.drawBitmap(backedImage, uniqueFeatureMatrix, mDrawingPaint);
canvas.restore();
continue;
}

// Drawing path
pathToDraw = featureState.getCurrentPathForDrawing();
if (pathToDraw == null || pathToDraw.isEmpty()) {
continue;
Expand All @@ -209,7 +214,6 @@ public void draw(Canvas canvas) {
canvas.save();
applyScaleAndClipCanvas(canvas, featureState.getCurrentMaskPath(), Region.Op.INTERSECT);
}
mDrawingPaint.setShader(null);
mDrawingPaint.setStrokeCap(featureState.getStrokeLineCap());
if (featureState.getFillColor() != Color.TRANSPARENT) {
mDrawingPaint.setStyle(Paint.Style.FILL);
Expand All @@ -224,7 +228,6 @@ public void draw(Canvas canvas) {
}
if (featureState.getStrokeColor() != Color.TRANSPARENT && featureState.getStrokeWidth() > 0) {
mDrawingPaint.setColor(featureState.getStrokeColor());
mDrawingPaint.setAlpha(featureState.getAlpha());
mDrawingPaint.setStyle(Paint.Style.STROKE);
mDrawingPaint.setStrokeWidth(
featureState.getStrokeWidth() * mScale * mScaleFromCenter * mScaleFromEnd);
Expand Down Expand Up @@ -484,6 +487,7 @@ public void setupFeatureStateForProgress(float frameProgress) {
if (layerTransformMatrix != null && !layerTransformMatrix.isIdentity()) {
mFeatureMatrix.postConcat(layerTransformMatrix);
}
mFeature.setOpacity(mOpacity, frameProgress);
KeyFramedPath path = mFeature.getPath();
if (hasCustomDrawable() || path == null) {
return; // skip all the path stuff
Expand All @@ -494,8 +498,8 @@ public void setupFeatureStateForProgress(float frameProgress) {

mFeature.setStrokeWidth(mStrokeWidth, frameProgress);
mFeature.setStrokeColor(mStrokeColor, frameProgress);
mFeature.setFillColor(mFillColor, frameProgress);
mStrokeWidth.adjustScale(extractScaleFromMatrix(mFeatureMatrix));
mFeature.setOpacity(mOpacity, frameProgress);
if (mFeature.getEffect() != null) {
prepareShadersForFeature(mFeature);
}
Expand Down

0 comments on commit d6ae643

Please sign in to comment.