Commit cdb01a48 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Commit Bot

[Autofill Assistant] Fix progress animations.

Before this CL, progress animations worked on debug builds but not on
release builds. I suspect that it was because of ProGuard or some other
mechanism that stripped away some classes/reflection information
previously used by the ObjectAnimators (which only knew about the name
of the property to set during the animation).

This CL fixes progress animations by defining progress and color
properties to use in the ObjectAnimators.

Change-Id: Idcfe71e63547672d42bf50274fd838b9efcd48ad
Reviewed-on: https://chromium-review.googlesource.com/c/1312477Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604554}
parent 07b192ba
...@@ -9,6 +9,7 @@ import android.animation.AnimatorListenerAdapter; ...@@ -9,6 +9,7 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator; import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.util.Property;
import android.view.View; import android.view.View;
import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation; import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation;
...@@ -22,8 +23,36 @@ import java.util.Queue; ...@@ -22,8 +23,36 @@ import java.util.Queue;
* pulsing. * pulsing.
*/ */
public class AnimatedProgressBar { public class AnimatedProgressBar {
private static final String PROGRESS_PROPERTY_NAME = "progress"; // TODO(806868): Move these properties into MaterialProgressBar.java.
private static final String PROGRESS_COLOR_PROPERTY_NAME = "progressColor"; private static final Property<MaterialProgressBar, Integer> PROGRESS_PROPERTY =
new Property<MaterialProgressBar, Integer>(Integer.class, "progress") {
@Override
public Integer get(MaterialProgressBar progressBar) {
// TODO(806868): Implement get once this property is moved into
// MaterialProgressBar.java.
throw new UnsupportedOperationException();
}
@Override
public void set(MaterialProgressBar progressBar, Integer progress) {
progressBar.setProgress(progress);
}
};
private static final Property<MaterialProgressBar, Integer> COLOR_PROPERTY =
new Property<MaterialProgressBar, Integer>(Integer.class, "progressColor") {
@Override
public Integer get(MaterialProgressBar progressBar) {
// TODO(806868): Implement get once this property is moved into
// MaterialProgressBar.java.
throw new UnsupportedOperationException();
}
@Override
public void set(MaterialProgressBar progressBar, Integer progressColor) {
progressBar.setProgressColor(progressColor);
}
};
// The number of ms the progress bar would take to go from 0 to 100%. // The number of ms the progress bar would take to go from 0 to 100%.
private static final int PROGRESS_BAR_SPEED_MS = 3_000; private static final int PROGRESS_BAR_SPEED_MS = 3_000;
...@@ -54,8 +83,8 @@ public class AnimatedProgressBar { ...@@ -54,8 +83,8 @@ public class AnimatedProgressBar {
public void setProgress(int progress) { public void setProgress(int progress) {
if (progress > mLastProgress) { if (progress > mLastProgress) {
ObjectAnimator progressAnimation = ObjectAnimator.ofInt( ObjectAnimator progressAnimation =
mProgressBar, PROGRESS_PROPERTY_NAME, mLastProgress, progress); ObjectAnimator.ofInt(mProgressBar, PROGRESS_PROPERTY, mLastProgress, progress);
progressAnimation.setDuration(PROGRESS_BAR_SPEED_MS * (progress - mLastProgress) / 100); progressAnimation.setDuration(PROGRESS_BAR_SPEED_MS * (progress - mLastProgress) / 100);
progressAnimation.setInterpolator(ChromeAnimation.getAccelerateInterpolator()); progressAnimation.setInterpolator(ChromeAnimation.getAccelerateInterpolator());
progressAnimation.addListener(new AnimatorListenerAdapter() { progressAnimation.addListener(new AnimatorListenerAdapter() {
...@@ -82,8 +111,8 @@ public class AnimatedProgressBar { ...@@ -82,8 +111,8 @@ public class AnimatedProgressBar {
public void enablePulsing() { public void enablePulsing() {
if (mPulseAnimation == null) { if (mPulseAnimation == null) {
mPulseAnimation = ObjectAnimator.ofInt( mPulseAnimation =
mProgressBar, PROGRESS_COLOR_PROPERTY_NAME, mNormalColor, mPulsedColor); ObjectAnimator.ofInt(mProgressBar, COLOR_PROPERTY, mNormalColor, mPulsedColor);
mPulseAnimation.setDuration(PROGRESS_BAR_PULSING_DURATION_MS); mPulseAnimation.setDuration(PROGRESS_BAR_PULSING_DURATION_MS);
mPulseAnimation.setEvaluator(new ArgbEvaluator()); mPulseAnimation.setEvaluator(new ArgbEvaluator());
mPulseAnimation.setRepeatCount(ValueAnimator.INFINITE); mPulseAnimation.setRepeatCount(ValueAnimator.INFINITE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment