[ProgressBar] Fix: Media volume bar indicates a wrong value

Symptom:
Media volume bar shows non-zero value even during the mute state.

Root cause:
A request for updating progress of ProgressBar has 2 kind of updating
ways, animated and non-animated. If a non-animated request is invoked
before completing an animated request, the visual progress can be
overwritten by the old animated request. As a result, the visual
progress value becomes different from the actual value.

Solution:
A running animation on the primary progress should be canceled
before handling a new non-animated request.

Bug: 148759348
Test: atest CtsWidgetTestCases:ProgressBarTest
Merged-In: I569dbea4c6346ecfff8141d8378b4952fb1fa530
Change-Id: I569dbea4c6346ecfff8141d8378b4952fb1fa530
(cherry picked from commit 589552766c)
This commit is contained in:
Tetsutoki Shiozawa
2020-01-27 15:37:10 +09:00
committed by Alan Viverette
parent 89724759c7
commit 18a6c10e71

View File

@@ -16,6 +16,8 @@
package android.widget;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.annotation.InterpolatorRes;
import android.annotation.NonNull;
@@ -245,6 +247,8 @@ public class ProgressBar extends View {
private final ArrayList<RefreshData> mRefreshData = new ArrayList<RefreshData>();
private ObjectAnimator mLastProgressAnimator;
/**
* Create a new progress bar with range 0...100 and initial progress of 0.
* @param context the application environment
@@ -1546,8 +1550,19 @@ public class ProgressBar extends View {
animator.setAutoCancel(true);
animator.setDuration(PROGRESS_ANIM_DURATION);
animator.setInterpolator(PROGRESS_ANIM_INTERPOLATOR);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mLastProgressAnimator = null;
}
});
animator.start();
mLastProgressAnimator = animator;
} else {
if (isPrimary && mLastProgressAnimator != null) {
mLastProgressAnimator.cancel();
mLastProgressAnimator = null;
}
setVisualProgress(id, scale);
}