From 129a648345aca7e989368f31fc867514208ddd70 Mon Sep 17 00:00:00 2001 From: shaoweishen Date: Wed, 2 Aug 2023 03:36:20 +0000 Subject: [Output Switcher] Improve volume control improve volume control to avoid volume jump when adjustment happened too intensive. 1.When we send two requests to adjust volume, we record second(latest) request volume change value. 2. We receive response from first request -> this will cause volume bar jump, so in this change will ignore this update 3. We receive second response, we'll accept it cause value match. Bug: 291754047 Test: Verify on device by adjust volume twice in very short period, and no volume bar jump situation happened. Change-Id: I6871adad229281076414e02d5002c04d43fc3e32 --- .../systemui/media/dialog/MediaOutputBaseAdapter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java index b88eba9081f7..a3d1d8c6959d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java @@ -157,6 +157,7 @@ public abstract class MediaOutputBaseAdapter extends private String mDeviceId; private ValueAnimator mCornerAnimator; private ValueAnimator mVolumeAnimator; + private int mLatestUpdateVolume = -1; MediaDeviceBaseViewHolder(View view) { super(view); @@ -314,7 +315,11 @@ public abstract class MediaOutputBaseAdapter extends mSeekBar.setMaxVolume(device.getMaxVolume()); final int currentVolume = device.getCurrentVolume(); if (!mIsDragging) { - if (mSeekBar.getVolume() != currentVolume) { + if (mSeekBar.getVolume() != currentVolume && (mLatestUpdateVolume == -1 + || currentVolume == mLatestUpdateVolume)) { + // Update only if volume of device and value of volume bar doesn't match. + // Check if response volume match with the latest request, to ignore obsolete + // response if (isCurrentSeekbarInvisible && !mIsInitVolumeFirstTime) { updateTitleIcon(currentVolume == 0 ? R.drawable.media_output_icon_volume_off : R.drawable.media_output_icon_volume, @@ -330,12 +335,16 @@ public abstract class MediaOutputBaseAdapter extends updateUnmutedVolumeIcon(); } mSeekBar.setVolume(currentVolume); + mLatestUpdateVolume = -1; } } } else if (currentVolume == 0) { mSeekBar.resetVolume(); updateMutedVolumeIcon(); } + if (currentVolume == mLatestUpdateVolume) { + mLatestUpdateVolume = -1; + } } if (mIsInitVolumeFirstTime) { mIsInitVolumeFirstTime = false; @@ -360,6 +369,7 @@ public abstract class MediaOutputBaseAdapter extends mStartFromMute = false; } if (progressToVolume != deviceVolume) { + mLatestUpdateVolume = progressToVolume; mController.adjustVolume(device, progressToVolume); } } -- cgit v1.2.3-59-g8ed1b