Merge "[Catalyst] Fix restriction issue on sound settings" into main

This commit is contained in:
Treehugger Robot
2025-02-10 21:29:48 -08:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 10 deletions

View File

@@ -47,7 +47,6 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
private final InteractionJankMonitor mJankMonitor = InteractionJankMonitor.getInstance(); private final InteractionJankMonitor mJankMonitor = InteractionJankMonitor.getInstance();
protected SeekBar mSeekBar;
private int mStream; private int mStream;
private SeekBarVolumizer mVolumizer; private SeekBarVolumizer mVolumizer;
@VisibleForTesting @VisibleForTesting
@@ -115,17 +114,20 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
@Override @Override
public void onDetached() { public void onDetached() {
destroyVolumizer();
super.onDetached();
}
private void destroyVolumizer() {
if (mVolumizer != null) { if (mVolumizer != null) {
mVolumizer.stop(); mVolumizer.stop();
mVolumizer = null; mVolumizer = null;
} }
super.onDetached();
} }
@Override @Override
public void onBindViewHolder(PreferenceViewHolder view) { public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view); super.onBindViewHolder(view);
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon); mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text); mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
mTitle = (TextView) view.findViewById(com.android.internal.R.id.title); mTitle = (TextView) view.findViewById(com.android.internal.R.id.title);
@@ -133,15 +135,20 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
} }
protected void onBindViewHolder() { protected void onBindViewHolder() {
boolean isEnabled = isEnabled(); if (isEnabled()) {
mSeekBar.setEnabled(isEnabled);
if (mVolumizer == null) { if (mVolumizer == null) {
createSeekBarVolumizer(); createSeekBarVolumizer();
} }
// note that setSeekBar will update enabled state!
mVolumizer.setSeekBar(mSeekBar); mVolumizer.setSeekBar(mSeekBar);
} else {
// destroy volumizer to avoid updateSeekBar reset enabled state
destroyVolumizer();
mSeekBar.setEnabled(false);
}
updateIconView(); updateIconView();
updateSuppressionText(); updateSuppressionText();
if (isEnabled && mListener != null) { if (mListener != null) {
mListener.onUpdateMuteState(); mListener.onUpdateMuteState();
} }
} }

View File

@@ -33,6 +33,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.SeekBar.OnSeekBarChangeListener;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.res.TypedArrayUtils; import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
@@ -59,7 +60,8 @@ public class SeekBarPreference extends RestrictedPreference
private int mHapticFeedbackMode = HAPTIC_FEEDBACK_MODE_NONE; private int mHapticFeedbackMode = HAPTIC_FEEDBACK_MODE_NONE;
private int mDefaultProgress = -1; private int mDefaultProgress = -1;
private SeekBar mSeekBar; @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public SeekBar mSeekBar;
private boolean mShouldBlink; private boolean mShouldBlink;
private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT; private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
private CharSequence mOverrideSeekBarStateDescription; private CharSequence mOverrideSeekBarStateDescription;