Skip to content

Commit

Permalink
blend colors between animation phases
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed May 13, 2019
1 parent 422307b commit 9fab6bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions stepview/src/main/java/com/shuhart/stepview/StepView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.view.ViewCompat;
import android.text.Layout;
import android.text.StaticLayout;
Expand Down Expand Up @@ -637,8 +638,19 @@ private void drawStep(Canvas canvas, int step, int circleCenterX, int circleCent
paint.setColor(selectedCircleColor);
int radius;
if (state == ANIMATE_STEP_TRANSITION && (animationType == ANIMATION_CIRCLE || animationType == ANIMATION_ALL)
&& nextAnimatedStep < currentStep && (!nextStepCircleEnabled || nextStepCircleColor == 0)) {
radius = (int) (selectedCircleRadius - selectedCircleRadius * animatedFraction);
&& nextAnimatedStep < currentStep) {
if (!nextStepCircleEnabled || nextStepCircleColor == 0) {
radius = (int) (selectedCircleRadius - selectedCircleRadius * animatedFraction);
} else {
radius = selectedCircleRadius;
}
if (nextStepCircleEnabled && nextStepCircleColor != 0) {
paint.setColor(ColorUtils.blendARGB(
selectedCircleColor,
nextStepCircleColor,
animatedFraction)
);
}
} else {
radius = selectedCircleRadius;
}
Expand Down Expand Up @@ -671,7 +683,11 @@ private void drawStep(Canvas canvas, int step, int circleCenterX, int circleCent
if (state == ANIMATE_STEP_TRANSITION && step == nextAnimatedStep && nextAnimatedStep > currentStep) {
if (animationType == ANIMATION_CIRCLE || animationType == ANIMATION_ALL) {
if (nextStepCircleEnabled && nextStepCircleColor != 0) {
paint.setColor(nextStepCircleColor);
paint.setColor(ColorUtils.blendARGB(
nextStepCircleColor,
selectedCircleColor,
animatedFraction)
);
canvas.drawCircle(circleCenterX, circleCenterY, selectedCircleRadius, paint);
} else {
int animatedRadius = (int) (selectedCircleRadius * animatedFraction);
Expand Down
2 changes: 1 addition & 1 deletion stepview/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item name="sv_stepPadding">12dp</item>
<item name="sv_textPadding">12dp</item>
<item name="sv_stepLineWidth">0.5dp</item>
<item name="sv_animationDuration">200</item>
<item name="sv_animationDuration">2000</item>
<item name="sv_textSize">14sp</item>
<item name="sv_animationType">Line</item>
</style>
Expand Down

0 comments on commit 9fab6bf

Please sign in to comment.