| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings.notification; |
| 18 | |
| Chaohui Wang | f311566 | 2022-04-26 20:04:39 +0800 | [diff] [blame] | 19 | import static com.android.internal.jank.InteractionJankMonitor.CUJ_SETTINGS_SLIDER; |
| 20 | |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 21 | import android.content.ContentResolver; |
| 22 | import android.content.Context; |
| 23 | import android.media.AudioManager; |
| 24 | import android.net.Uri; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 25 | import android.preference.SeekBarVolumizer; |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 26 | import android.text.TextUtils; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 27 | import android.util.AttributeSet; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 28 | import android.view.View; |
| Dan Sandler | cb9f351 | 2014-09-02 01:05:27 +0200 | [diff] [blame] | 29 | import android.widget.ImageView; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 30 | import android.widget.SeekBar; |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 31 | import android.widget.TextView; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 32 | |
| Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 33 | import androidx.annotation.VisibleForTesting; |
| 34 | import androidx.preference.PreferenceViewHolder; |
| 35 | |
| Chaohui Wang | f311566 | 2022-04-26 20:04:39 +0800 | [diff] [blame] | 36 | import com.android.internal.jank.InteractionJankMonitor; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 37 | import com.android.settings.R; |
| Edgar Wang | cdff5c6 | 2021-06-08 09:10:41 +0000 | [diff] [blame] | 38 | import com.android.settings.widget.SeekBarPreference; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 39 | |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 40 | import java.text.NumberFormat; |
| 41 | import java.util.Locale; |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 42 | import java.util.Objects; |
| 43 | |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 44 | /** A slider preference that directly controls an audio stream volume (no dialog) **/ |
| Edgar Wang | cdff5c6 | 2021-06-08 09:10:41 +0000 | [diff] [blame] | 45 | public class VolumeSeekBarPreference extends SeekBarPreference { |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 46 | private static final String TAG = "VolumeSeekBarPreference"; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 47 | |
| Chaohui Wang | f311566 | 2022-04-26 20:04:39 +0800 | [diff] [blame] | 48 | private final InteractionJankMonitor mJankMonitor = InteractionJankMonitor.getInstance(); |
| 49 | |
| jackqdyulei | f25c9b0 | 2019-02-27 10:05:56 -0800 | [diff] [blame] | 50 | protected SeekBar mSeekBar; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 51 | private int mStream; |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 52 | private SeekBarVolumizer mVolumizer; |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 53 | @VisibleForTesting |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 54 | SeekBarVolumizerFactory mSeekBarVolumizerFactory; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 55 | private Callback mCallback; |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 56 | private Listener mListener; |
| Dan Sandler | cb9f351 | 2014-09-02 01:05:27 +0200 | [diff] [blame] | 57 | private ImageView mIconView; |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 58 | private TextView mSuppressionTextView; |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 59 | private TextView mTitle; |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 60 | private String mSuppressionText; |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 61 | private boolean mMuted; |
| John Spurlock | f82154d | 2015-06-10 17:46:58 -0400 | [diff] [blame] | 62 | private boolean mZenMuted; |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 63 | private int mIconResId; |
| 64 | private int mMuteIconResId; |
| John Spurlock | aaaa54e | 2014-12-08 15:20:33 -0500 | [diff] [blame] | 65 | private boolean mStopped; |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 66 | @VisibleForTesting |
| 67 | AudioManager mAudioManager; |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 68 | private Locale mLocale; |
| 69 | private NumberFormat mNumberFormat; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 70 | |
| Fabrice Di Meglio | dbaf080 | 2014-06-17 11:37:55 -0700 | [diff] [blame] | 71 | public VolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, |
| 72 | int defStyleRes) { |
| 73 | super(context, attrs, defStyleAttr, defStyleRes); |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 74 | setLayoutResource(R.layout.preference_volume_slider); |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 75 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 76 | mSeekBarVolumizerFactory = new SeekBarVolumizerFactory(context); |
| Fabrice Di Meglio | dbaf080 | 2014-06-17 11:37:55 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | public VolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) { |
| Fan Zhang | bfb006a | 2017-01-25 15:32:17 -0800 | [diff] [blame] | 80 | super(context, attrs, defStyleAttr); |
| 81 | setLayoutResource(R.layout.preference_volume_slider); |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 82 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 83 | mSeekBarVolumizerFactory = new SeekBarVolumizerFactory(context); |
| Fabrice Di Meglio | dbaf080 | 2014-06-17 11:37:55 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 86 | public VolumeSeekBarPreference(Context context, AttributeSet attrs) { |
| Fan Zhang | bfb006a | 2017-01-25 15:32:17 -0800 | [diff] [blame] | 87 | super(context, attrs); |
| 88 | setLayoutResource(R.layout.preference_volume_slider); |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 89 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 90 | mSeekBarVolumizerFactory = new SeekBarVolumizerFactory(context); |
| Fabrice Di Meglio | dbaf080 | 2014-06-17 11:37:55 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | public VolumeSeekBarPreference(Context context) { |
| Fan Zhang | bfb006a | 2017-01-25 15:32:17 -0800 | [diff] [blame] | 94 | super(context); |
| 95 | setLayoutResource(R.layout.preference_volume_slider); |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 96 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 97 | mSeekBarVolumizerFactory = new SeekBarVolumizerFactory(context); |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | public void setStream(int stream) { |
| 101 | mStream = stream; |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 102 | setMax(mAudioManager.getStreamMaxVolume(mStream)); |
| ryanywlin | 156fd91 | 2018-04-25 10:56:36 +0800 | [diff] [blame] | 103 | // Use getStreamMinVolumeInt for non-public stream type |
| 104 | // eg: AudioManager.STREAM_BLUETOOTH_SCO |
| 105 | setMin(mAudioManager.getStreamMinVolumeInt(mStream)); |
| Doris Ling | b7490be | 2017-08-08 16:52:42 -0700 | [diff] [blame] | 106 | setProgress(mAudioManager.getStreamVolume(mStream)); |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | public void setCallback(Callback callback) { |
| 110 | mCallback = callback; |
| 111 | } |
| 112 | |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 113 | public void setListener(Listener listener) { |
| 114 | mListener = listener; |
| 115 | } |
| 116 | |
| John Spurlock | aaaa54e | 2014-12-08 15:20:33 -0500 | [diff] [blame] | 117 | public void onActivityResume() { |
| 118 | if (mStopped) { |
| 119 | init(); |
| 120 | } |
| 121 | } |
| 122 | |
| Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 123 | public void onActivityPause() { |
| John Spurlock | aaaa54e | 2014-12-08 15:20:33 -0500 | [diff] [blame] | 124 | mStopped = true; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 125 | if (mVolumizer != null) { |
| 126 | mVolumizer.stop(); |
| Sheng Wang | 176ee34 | 2016-08-19 17:09:32 +0800 | [diff] [blame] | 127 | mVolumizer = null; |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 128 | } |
| 129 | } |
| Sheng Wang | 176ee34 | 2016-08-19 17:09:32 +0800 | [diff] [blame] | 130 | |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 131 | @Override |
| Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 132 | public void onBindViewHolder(PreferenceViewHolder view) { |
| 133 | super.onBindViewHolder(view); |
| John Spurlock | aaaa54e | 2014-12-08 15:20:33 -0500 | [diff] [blame] | 134 | mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar); |
| 135 | mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon); |
| 136 | mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text); |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 137 | mTitle = (TextView) view.findViewById(com.android.internal.R.id.title); |
| John Spurlock | aaaa54e | 2014-12-08 15:20:33 -0500 | [diff] [blame] | 138 | init(); |
| 139 | } |
| 140 | |
| jackqdyulei | f25c9b0 | 2019-02-27 10:05:56 -0800 | [diff] [blame] | 141 | protected void init() { |
| John Spurlock | aaaa54e | 2014-12-08 15:20:33 -0500 | [diff] [blame] | 142 | if (mSeekBar == null) return; |
| Mill Chen | c69899c | 2023-07-07 20:52:13 +0800 | [diff] [blame] | 143 | // It's unnecessary to set up relevant volumizer configuration if preference is disabled. |
| 144 | if (!isEnabled()) { |
| 145 | mSeekBar.setEnabled(false); |
| 146 | return; |
| 147 | } |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 148 | final SeekBarVolumizer.Callback sbvc = new SeekBarVolumizer.Callback() { |
| 149 | @Override |
| 150 | public void onSampleStarting(SeekBarVolumizer sbv) { |
| 151 | if (mCallback != null) { |
| 152 | mCallback.onSampleStarting(sbv); |
| 153 | } |
| 154 | } |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 155 | @Override |
| 156 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { |
| 157 | if (mCallback != null) { |
| 158 | mCallback.onStreamValueChanged(mStream, progress); |
| 159 | } |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 160 | overrideSeekBarStateDescription(formatStateDescription(progress)); |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 161 | } |
| 162 | @Override |
| John Spurlock | f82154d | 2015-06-10 17:46:58 -0400 | [diff] [blame] | 163 | public void onMuted(boolean muted, boolean zenMuted) { |
| 164 | if (mMuted == muted && mZenMuted == zenMuted) return; |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 165 | mMuted = muted; |
| John Spurlock | f82154d | 2015-06-10 17:46:58 -0400 | [diff] [blame] | 166 | mZenMuted = zenMuted; |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 167 | updateIconView(); |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 168 | if (mListener != null) { |
| 169 | mListener.onUpdateMuteState(); |
| 170 | } |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 171 | } |
| Hugh Chen | 432d073 | 2020-08-26 14:32:53 +0800 | [diff] [blame] | 172 | @Override |
| 173 | public void onStartTrackingTouch(SeekBarVolumizer sbv) { |
| 174 | if (mCallback != null) { |
| 175 | mCallback.onStartTrackingTouch(sbv); |
| 176 | } |
| Chaohui Wang | f311566 | 2022-04-26 20:04:39 +0800 | [diff] [blame] | 177 | mJankMonitor.begin(InteractionJankMonitor.Configuration.Builder |
| 178 | .withView(CUJ_SETTINGS_SLIDER, mSeekBar) |
| 179 | .setTag(getKey())); |
| 180 | } |
| 181 | @Override |
| 182 | public void onStopTrackingTouch(SeekBarVolumizer sbv) { |
| 183 | mJankMonitor.end(CUJ_SETTINGS_SLIDER); |
| Hugh Chen | 432d073 | 2020-08-26 14:32:53 +0800 | [diff] [blame] | 184 | } |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 185 | }; |
| 186 | final Uri sampleUri = mStream == AudioManager.STREAM_MUSIC ? getMediaVolumeUri() : null; |
| John Spurlock | 8531553 | 2014-05-27 13:12:35 -0400 | [diff] [blame] | 187 | if (mVolumizer == null) { |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 188 | mVolumizer = mSeekBarVolumizerFactory.create(mStream, sampleUri, sbvc); |
| John Spurlock | 8531553 | 2014-05-27 13:12:35 -0400 | [diff] [blame] | 189 | } |
| John Spurlock | af05fda | 2014-10-08 12:34:50 -0400 | [diff] [blame] | 190 | mVolumizer.start(); |
| John Spurlock | 8531553 | 2014-05-27 13:12:35 -0400 | [diff] [blame] | 191 | mVolumizer.setSeekBar(mSeekBar); |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 192 | updateIconView(); |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 193 | updateSuppressionText(); |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 194 | if (mListener != null) { |
| 195 | mListener.onUpdateMuteState(); |
| 196 | } |
| Dan Sandler | cb9f351 | 2014-09-02 01:05:27 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| jackqdyulei | f25c9b0 | 2019-02-27 10:05:56 -0800 | [diff] [blame] | 199 | protected void updateIconView() { |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 200 | if (mIconView == null) return; |
| 201 | if (mIconResId != 0) { |
| 202 | mIconView.setImageResource(mIconResId); |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 203 | } else if (mMuteIconResId != 0 && isMuted()) { |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 204 | mIconView.setImageResource(mMuteIconResId); |
| 205 | } else { |
| 206 | mIconView.setImageDrawable(getIcon()); |
| 207 | } |
| 208 | } |
| 209 | |
| Dan Sandler | cb9f351 | 2014-09-02 01:05:27 +0200 | [diff] [blame] | 210 | public void showIcon(int resId) { |
| 211 | // Instead of using setIcon, which will trigger listeners, this just decorates the |
| 212 | // preference temporarily with a new icon. |
| John Spurlock | c868f70 | 2014-11-28 15:39:11 -0500 | [diff] [blame] | 213 | if (mIconResId == resId) return; |
| 214 | mIconResId = resId; |
| 215 | updateIconView(); |
| 216 | } |
| 217 | |
| 218 | public void setMuteIcon(int resId) { |
| 219 | if (mMuteIconResId == resId) return; |
| 220 | mMuteIconResId = resId; |
| 221 | updateIconView(); |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | private Uri getMediaVolumeUri() { |
| 225 | return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" |
| Fabrice Di Meglio | dbaf080 | 2014-06-17 11:37:55 -0700 | [diff] [blame] | 226 | + getContext().getPackageName() |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 227 | + "/" + R.raw.media_volume); |
| 228 | } |
| 229 | |
| Michael Mikhail | b222b96 | 2023-07-07 18:37:45 +0000 | [diff] [blame] | 230 | @VisibleForTesting |
| 231 | CharSequence formatStateDescription(int progress) { |
| 232 | // This code follows the same approach in ProgressBar.java, but it rounds down the percent |
| 233 | // to match it with what the talkback feature says after any progress change. (b/285458191) |
| 234 | // Cache the locale-appropriate NumberFormat. Configuration locale is guaranteed |
| 235 | // non-null, so the first time this is called we will always get the appropriate |
| 236 | // NumberFormat, then never regenerate it unless the locale changes on the fly. |
| 237 | Locale curLocale = getContext().getResources().getConfiguration().getLocales().get(0); |
| 238 | if (mLocale == null || !mLocale.equals(curLocale)) { |
| 239 | mLocale = curLocale; |
| 240 | mNumberFormat = NumberFormat.getPercentInstance(mLocale); |
| 241 | } |
| 242 | return mNumberFormat.format(getPercent(progress)); |
| 243 | } |
| 244 | |
| 245 | @VisibleForTesting |
| 246 | double getPercent(float progress) { |
| 247 | final float maxProgress = getMax(); |
| 248 | final float minProgress = getMin(); |
| 249 | final float diffProgress = maxProgress - minProgress; |
| 250 | if (diffProgress <= 0.0f) { |
| 251 | return 0.0f; |
| 252 | } |
| 253 | final float percent = (progress - minProgress) / diffProgress; |
| 254 | return Math.floor(Math.max(0.0f, Math.min(1.0f, percent)) * 100) / 100; |
| 255 | } |
| 256 | |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 257 | public void setSuppressionText(String text) { |
| 258 | if (Objects.equals(text, mSuppressionText)) return; |
| 259 | mSuppressionText = text; |
| 260 | updateSuppressionText(); |
| 261 | } |
| 262 | |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 263 | protected boolean isMuted() { |
| 264 | return mMuted && !mZenMuted; |
| 265 | } |
| 266 | |
| jackqdyulei | f25c9b0 | 2019-02-27 10:05:56 -0800 | [diff] [blame] | 267 | protected void updateSuppressionText() { |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 268 | if (mSuppressionTextView != null && mSeekBar != null) { |
| 269 | mSuppressionTextView.setText(mSuppressionText); |
| 270 | final boolean showSuppression = !TextUtils.isEmpty(mSuppressionText); |
| Julia Reynolds | 0ddba4c | 2018-04-17 09:11:43 -0400 | [diff] [blame] | 271 | mSuppressionTextView.setVisibility(showSuppression ? View.VISIBLE : View.GONE); |
| John Spurlock | fdebfc3 | 2014-11-14 14:32:01 -0500 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 275 | /** |
| 276 | * Update content description of title to improve talkback announcements. |
| 277 | */ |
| 278 | protected void updateContentDescription(CharSequence contentDescription) { |
| 279 | if (mTitle == null) return; |
| 280 | mTitle.setContentDescription(contentDescription); |
| 281 | } |
| 282 | |
| Michael Mikhail | 7c9958a | 2023-06-26 20:16:30 +0000 | [diff] [blame] | 283 | protected void setAccessibilityLiveRegion(int mode) { |
| 284 | if (mTitle == null) return; |
| 285 | mTitle.setAccessibilityLiveRegion(mode); |
| 286 | } |
| 287 | |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 288 | public interface Callback { |
| 289 | void onSampleStarting(SeekBarVolumizer sbv); |
| Dan Sandler | cb9f351 | 2014-09-02 01:05:27 +0200 | [diff] [blame] | 290 | void onStreamValueChanged(int stream, int progress); |
| Hugh Chen | 432d073 | 2020-08-26 14:32:53 +0800 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Callback reporting that the seek bar is start tracking. |
| 294 | */ |
| 295 | void onStartTrackingTouch(SeekBarVolumizer sbv); |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 296 | } |
| Michael Mikhail | 2f39330 | 2023-06-21 16:58:20 +0000 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * Listener to view updates in volumeSeekbarPreference. |
| 300 | */ |
| 301 | public interface Listener { |
| 302 | |
| 303 | /** |
| 304 | * Listener to mute state updates. |
| 305 | */ |
| 306 | void onUpdateMuteState(); |
| 307 | } |
| John Spurlock | 81bef1d7 | 2014-05-16 15:50:13 -0400 | [diff] [blame] | 308 | } |