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

[Autofill Assistant] Use ValueAnimator instead of ObjectAnimator.

This CL replaces ObjectAnimators by ValueAnimators for the progress bar
animations, allowing us to remove the properties introduced in
http://crrev/c/1312477.

Change-Id: I45565b4aa863880e8a16522b9160dc2c8d0c4559
Reviewed-on: https://chromium-review.googlesource.com/c/1314630Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605290}
parent 02b4622b
...@@ -7,9 +7,7 @@ package org.chromium.chrome.browser.autofill_assistant; ...@@ -7,9 +7,7 @@ package org.chromium.chrome.browser.autofill_assistant;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator; import android.animation.ArgbEvaluator;
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;
...@@ -23,37 +21,6 @@ import java.util.Queue; ...@@ -23,37 +21,6 @@ import java.util.Queue;
* pulsing. * pulsing.
*/ */
public class AnimatedProgressBar { public class AnimatedProgressBar {
// TODO(806868): Move these properties into MaterialProgressBar.java.
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;
private static final int PROGRESS_BAR_PULSING_DURATION_MS = 1_000; private static final int PROGRESS_BAR_PULSING_DURATION_MS = 1_000;
...@@ -64,8 +31,8 @@ public class AnimatedProgressBar { ...@@ -64,8 +31,8 @@ public class AnimatedProgressBar {
private boolean mIsRunningProgressAnimation = false; private boolean mIsRunningProgressAnimation = false;
private int mLastProgress = 0; private int mLastProgress = 0;
private Queue<ObjectAnimator> mPendingIncreaseAnimations = new ArrayDeque<>(); private Queue<ValueAnimator> mPendingIncreaseAnimations = new ArrayDeque<>();
private ObjectAnimator mPulseAnimation = null; private ValueAnimator mPulseAnimation = null;
public AnimatedProgressBar(MaterialProgressBar progressBar, int normalColor, int pulsedColor) { public AnimatedProgressBar(MaterialProgressBar progressBar, int normalColor, int pulsedColor) {
mProgressBar = progressBar; mProgressBar = progressBar;
...@@ -87,8 +54,7 @@ public class AnimatedProgressBar { ...@@ -87,8 +54,7 @@ public class AnimatedProgressBar {
*/ */
public void maybeIncreaseProgress(int progress) { public void maybeIncreaseProgress(int progress) {
if (progress > mLastProgress) { if (progress > mLastProgress) {
ObjectAnimator progressAnimation = ValueAnimator progressAnimation = ValueAnimator.ofInt(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() {
...@@ -102,6 +68,8 @@ public class AnimatedProgressBar { ...@@ -102,6 +68,8 @@ public class AnimatedProgressBar {
} }
} }
}); });
progressAnimation.addUpdateListener(
animation -> mProgressBar.setProgress((int) animation.getAnimatedValue()));
mLastProgress = progress; mLastProgress = progress;
if (mIsRunningProgressAnimation) { if (mIsRunningProgressAnimation) {
...@@ -115,8 +83,7 @@ public class AnimatedProgressBar { ...@@ -115,8 +83,7 @@ public class AnimatedProgressBar {
public void enablePulsing() { public void enablePulsing() {
if (mPulseAnimation == null) { if (mPulseAnimation == null) {
mPulseAnimation = mPulseAnimation = ValueAnimator.ofInt(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);
...@@ -128,6 +95,8 @@ public class AnimatedProgressBar { ...@@ -128,6 +95,8 @@ public class AnimatedProgressBar {
mProgressBar.setProgressColor(mNormalColor); mProgressBar.setProgressColor(mNormalColor);
} }
}); });
mPulseAnimation.addUpdateListener(
animation -> mProgressBar.setProgressColor((int) animation.getAnimatedValue()));
mPulseAnimation.start(); mPulseAnimation.start();
} }
} }
......
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