Settings: Introduce Adaptive Playback [2/2]
* Animation by Sahul Krishan * Adapt to Android 11 by @mickaelmendes50 [Hernán Castañón] Adaptive Playback: allow choosing no timeout. Co-authored-by: Hernán Castañón Álvarez <herna@paranoidandroid.co> Change-Id: I82c20b89d06b722d8f9da1bdb14eb096a7d088c9 AdaptivePlayback: Add a intro text to the fragment * Let's help users to understand what the feature does by adding a little introduction text. Change-Id: Ie9ef15d7f60ab2197c30c79434c9fb876c498cd5 Co-authored-by: AshutoshSundresh <ashutoshsundresh@gmail.com> Signed-off-by: Mesquita <mesquita@aospa.co> Settings: Move "Adaptive Playback" option to Sound Settings. * Our gestures category looks bloated with features. Move this to Sound Settings where it feels better and more homely. Change-Id: I28fd022a4998141435a1e89a027b7a1fe6f75537 Signed-off-by: Mesquita <mesquita@aospa.co> AdaptivePlayback: Rename it to 'Smart Pause' to keep a better fluency * As we already have an 'Adaptive Sound' in sound settings Change-Id: Iaca4b7d65fe490ee6462ba49907316930deaeaa5 Signed-off-by: Mesquita <mesquita@aospa.co> Change-Id: I82c20b89d06b722d8f9da1bdb14eb096a7d088c9
This commit is contained in:
1
res/raw/lottie_adaptive_playback.json
Normal file
1
res/raw/lottie_adaptive_playback.json
Normal file
File diff suppressed because one or more lines are too long
@@ -341,4 +341,23 @@
|
||||
<!-- Pocket mode -->
|
||||
<string name="proximity_wake_title">Pocket mode</string>
|
||||
<string name="proximity_wake_summary">Check the proximity sensor prior to waking up screen</string>
|
||||
|
||||
<!-- Adaptive Playback -->
|
||||
<string name="adaptive_playback_screen_title">Smart Pause</string>
|
||||
<string name="adaptive_playback_enabled">Use smart pause</string>
|
||||
<string name="adaptive_playback_disabled_summary">Off</string>
|
||||
<string name="adaptive_playback_intro_text">Automatically pauses media when the volume is muted and will resume automatically when volume is restored within the set time.</string>
|
||||
<string name="adaptive_playback_timeout_title">Use a timeout of</string>
|
||||
<string name="adaptive_playback_timeout_none">No timeout</string>
|
||||
<string name="adaptive_playback_timeout_none_summary">On (no timeout)</string>
|
||||
<string name="adaptive_playback_timeout_30_secs">30 seconds</string>
|
||||
<string name="adaptive_playback_timeout_30_secs_summary">On (30 seconds)</string>
|
||||
<string name="adaptive_playback_timeout_1_min">1 minute</string>
|
||||
<string name="adaptive_playback_timeout_1_min_summary">On (1 minute)</string>
|
||||
<string name="adaptive_playback_timeout_2_min">2 minutes</string>
|
||||
<string name="adaptive_playback_timeout_2_min_summary">On (2 minutes)</string>
|
||||
<string name="adaptive_playback_timeout_5_min">5 minutes</string>
|
||||
<string name="adaptive_playback_timeout_5_min_summary">On (5 minutes)</string>
|
||||
<string name="adaptive_playback_timeout_10_min">10 minutes</string>
|
||||
<string name="adaptive_playback_timeout_10_min_summary">On (10 minutes)</string>
|
||||
</resources>
|
||||
|
||||
43
res/xml/adaptive_playback_sound_settings.xml
Normal file
43
res/xml/adaptive_playback_sound_settings.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2020-2022 Paranoid Android
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:key="sound_adaptive_playback_screen"
|
||||
android:title="@string/adaptive_playback_screen_title">
|
||||
|
||||
<com.android.settingslib.widget.IllustrationPreference
|
||||
android:key="adaptive_playback_header"
|
||||
settings:searchable="false"
|
||||
app:lottie_rawRes="@raw/lottie_adaptive_playback"/>
|
||||
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="sound_adaptive_playback_main_switch"
|
||||
android:title="@string/adaptive_playback_enabled"
|
||||
settings:controller="com.android.settings.sound.AdaptivePlaybackSwitchPreferenceController" />
|
||||
|
||||
<com.android.settingslib.widget.TopIntroPreference
|
||||
android:key="gesture_adaptive_playback_intro_text"
|
||||
android:title="@string/adaptive_playback_intro_text"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="sound_adaptive_playback_category"
|
||||
android:title="@string/adaptive_playback_timeout_title"
|
||||
settings:controller="com.android.settings.sound.AdaptivePlaybackSoundPreferenceController" />
|
||||
</PreferenceScreen>
|
||||
@@ -151,6 +151,14 @@
|
||||
android:order="-119"
|
||||
settings:keywords="@string/sound_settings"/>
|
||||
|
||||
<!-- Adaptive Playback -->
|
||||
<Preference
|
||||
android:key="sound_adaptive_playback_summary"
|
||||
android:title="@string/adaptive_playback_screen_title"
|
||||
android:fragment="com.android.settings.sound.AdaptivePlaybackSoundSettings"
|
||||
android:order="-109"
|
||||
settings:controller="com.android.settings.sound.AdaptivePlaybackParentPreferenceController" />
|
||||
|
||||
<!-- Live Caption -110 and Now Playing -105-->
|
||||
|
||||
<!-- Spatial audio -->
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Paranoid Android
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.sound;
|
||||
|
||||
import static android.provider.Settings.System.ADAPTIVE_PLAYBACK_ENABLED;
|
||||
import static android.provider.Settings.System.ADAPTIVE_PLAYBACK_TIMEOUT;
|
||||
|
||||
import static com.android.settings.sound.AdaptivePlaybackSoundPreferenceController.ADAPTIVE_PLAYBACK_TIMEOUT_10_MIN;
|
||||
import static com.android.settings.sound.AdaptivePlaybackSoundPreferenceController.ADAPTIVE_PLAYBACK_TIMEOUT_1_MIN;
|
||||
import static com.android.settings.sound.AdaptivePlaybackSoundPreferenceController.ADAPTIVE_PLAYBACK_TIMEOUT_2_MIN;
|
||||
import static com.android.settings.sound.AdaptivePlaybackSoundPreferenceController.ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS;
|
||||
import static com.android.settings.sound.AdaptivePlaybackSoundPreferenceController.ADAPTIVE_PLAYBACK_TIMEOUT_5_MIN;
|
||||
import static com.android.settings.sound.AdaptivePlaybackSoundPreferenceController.ADAPTIVE_PLAYBACK_TIMEOUT_NONE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class AdaptivePlaybackParentPreferenceController extends BasePreferenceController {
|
||||
|
||||
public AdaptivePlaybackParentPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
boolean enabled = Settings.System.getIntForUser(
|
||||
mContext.getContentResolver(), ADAPTIVE_PLAYBACK_ENABLED, 0,
|
||||
UserHandle.USER_CURRENT) != 0;
|
||||
int timeout = Settings.System.getIntForUser(
|
||||
mContext.getContentResolver(), ADAPTIVE_PLAYBACK_TIMEOUT,
|
||||
ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS,
|
||||
UserHandle.USER_CURRENT);
|
||||
int summary = R.string.adaptive_playback_disabled_summary;
|
||||
if (!enabled) {
|
||||
return mContext.getText(summary);
|
||||
}
|
||||
switch (timeout) {
|
||||
case ADAPTIVE_PLAYBACK_TIMEOUT_NONE ->
|
||||
summary = R.string.adaptive_playback_timeout_none_summary;
|
||||
case ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS ->
|
||||
summary = R.string.adaptive_playback_timeout_30_secs_summary;
|
||||
case ADAPTIVE_PLAYBACK_TIMEOUT_1_MIN ->
|
||||
summary = R.string.adaptive_playback_timeout_1_min_summary;
|
||||
case ADAPTIVE_PLAYBACK_TIMEOUT_2_MIN ->
|
||||
summary = R.string.adaptive_playback_timeout_2_min_summary;
|
||||
case ADAPTIVE_PLAYBACK_TIMEOUT_5_MIN ->
|
||||
summary = R.string.adaptive_playback_timeout_5_min_summary;
|
||||
case ADAPTIVE_PLAYBACK_TIMEOUT_10_MIN ->
|
||||
summary = R.string.adaptive_playback_timeout_10_min_summary;
|
||||
}
|
||||
return mContext.getText(summary);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Paranoid Android
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.sound;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
public class AdaptivePlaybackSoundPreferenceController extends BasePreferenceController
|
||||
implements SelectorWithWidgetPreference.OnClickListener, LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String KEY_NO_TIMEOUT = "adaptive_playback_timeout_none";
|
||||
private static final String KEY_30_SECS = "adaptive_playback_timeout_30_secs";
|
||||
private static final String KEY_1_MIN = "adaptive_playback_timeout_1_min";
|
||||
private static final String KEY_2_MIN = "adaptive_playback_timeout_2_min";
|
||||
private static final String KEY_5_MIN = "adaptive_playback_timeout_5_min";
|
||||
private static final String KEY_10_MIN = "adaptive_playback_timeout_10_min";
|
||||
|
||||
static final int ADAPTIVE_PLAYBACK_TIMEOUT_NONE = 0;
|
||||
static final int ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS = 30000;
|
||||
static final int ADAPTIVE_PLAYBACK_TIMEOUT_1_MIN = 60000;
|
||||
static final int ADAPTIVE_PLAYBACK_TIMEOUT_2_MIN = 120000;
|
||||
static final int ADAPTIVE_PLAYBACK_TIMEOUT_5_MIN = 300000;
|
||||
static final int ADAPTIVE_PLAYBACK_TIMEOUT_10_MIN = 600000;
|
||||
|
||||
private boolean mAdaptivePlaybackEnabled;
|
||||
private int mAdaptivePlaybackTimeout;
|
||||
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private SelectorWithWidgetPreference mTimeoutNonePref;
|
||||
private SelectorWithWidgetPreference mTimeout30SecPref;
|
||||
private SelectorWithWidgetPreference mTimeout1MinPref;
|
||||
private SelectorWithWidgetPreference mTimeout2MinPref;
|
||||
private SelectorWithWidgetPreference mTimeout5MinPref;
|
||||
private SelectorWithWidgetPreference mTimeout10MinPref;
|
||||
|
||||
private final SettingObserver mSettingObserver;
|
||||
|
||||
public AdaptivePlaybackSoundPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
|
||||
mSettingObserver = new SettingObserver(new Handler(Looper.getMainLooper()));
|
||||
mAdaptivePlaybackEnabled = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.ADAPTIVE_PLAYBACK_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
|
||||
mAdaptivePlaybackTimeout = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.ADAPTIVE_PLAYBACK_TIMEOUT, ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreferenceCategory = screen.findPreference(getPreferenceKey());
|
||||
mTimeoutNonePref = makeRadioPreference(KEY_NO_TIMEOUT,
|
||||
R.string.adaptive_playback_timeout_none);
|
||||
mTimeout30SecPref = makeRadioPreference(KEY_30_SECS,
|
||||
R.string.adaptive_playback_timeout_30_secs);
|
||||
mTimeout1MinPref = makeRadioPreference(KEY_1_MIN, R.string.adaptive_playback_timeout_1_min);
|
||||
mTimeout2MinPref = makeRadioPreference(KEY_2_MIN, R.string.adaptive_playback_timeout_2_min);
|
||||
mTimeout5MinPref = makeRadioPreference(KEY_5_MIN, R.string.adaptive_playback_timeout_5_min);
|
||||
mTimeout10MinPref = makeRadioPreference(KEY_10_MIN,
|
||||
R.string.adaptive_playback_timeout_10_min);
|
||||
updateState(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
|
||||
int adaptivePlaybackTimeout = keyToSetting(preference.getKey());
|
||||
if (adaptivePlaybackTimeout != Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.ADAPTIVE_PLAYBACK_TIMEOUT, ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS,
|
||||
UserHandle.USER_CURRENT)) {
|
||||
Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.ADAPTIVE_PLAYBACK_TIMEOUT, adaptivePlaybackTimeout,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean isTimeoutNone = mAdaptivePlaybackEnabled
|
||||
&& mAdaptivePlaybackTimeout == ADAPTIVE_PLAYBACK_TIMEOUT_NONE;
|
||||
final boolean isTimeout30Sec = mAdaptivePlaybackEnabled
|
||||
&& mAdaptivePlaybackTimeout == ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS;
|
||||
final boolean isTimeout1Min = mAdaptivePlaybackEnabled
|
||||
&& mAdaptivePlaybackTimeout == ADAPTIVE_PLAYBACK_TIMEOUT_1_MIN;
|
||||
final boolean isTimeout2Min = mAdaptivePlaybackEnabled
|
||||
&& mAdaptivePlaybackTimeout == ADAPTIVE_PLAYBACK_TIMEOUT_2_MIN;
|
||||
final boolean isTimeout5Min = mAdaptivePlaybackEnabled
|
||||
&& mAdaptivePlaybackTimeout == ADAPTIVE_PLAYBACK_TIMEOUT_5_MIN;
|
||||
final boolean isTimeout10Min = mAdaptivePlaybackEnabled
|
||||
&& mAdaptivePlaybackTimeout == ADAPTIVE_PLAYBACK_TIMEOUT_10_MIN;
|
||||
if (mTimeoutNonePref != null && mTimeoutNonePref.isChecked() != isTimeoutNone) {
|
||||
mTimeoutNonePref.setChecked(isTimeoutNone);
|
||||
}
|
||||
if (mTimeout30SecPref != null && mTimeout30SecPref.isChecked() != isTimeout30Sec) {
|
||||
mTimeout30SecPref.setChecked(isTimeout30Sec);
|
||||
}
|
||||
if (mTimeout1MinPref != null && mTimeout1MinPref.isChecked() != isTimeout1Min) {
|
||||
mTimeout1MinPref.setChecked(isTimeout1Min);
|
||||
}
|
||||
if (mTimeout2MinPref != null && mTimeout2MinPref.isChecked() != isTimeout2Min) {
|
||||
mTimeout2MinPref.setChecked(isTimeout2Min);
|
||||
}
|
||||
if (mTimeout5MinPref != null && mTimeout5MinPref.isChecked() != isTimeout5Min) {
|
||||
mTimeout5MinPref.setChecked(isTimeout5Min);
|
||||
}
|
||||
if (mTimeout10MinPref != null && mTimeout10MinPref.isChecked() != isTimeout10Min) {
|
||||
mTimeout10MinPref.setChecked(isTimeout10Min);
|
||||
}
|
||||
|
||||
if (mAdaptivePlaybackEnabled) {
|
||||
mPreferenceCategory.setEnabled(true);
|
||||
mTimeoutNonePref.setEnabled(true);
|
||||
mTimeout30SecPref.setEnabled(true);
|
||||
mTimeout1MinPref.setEnabled(true);
|
||||
mTimeout2MinPref.setEnabled(true);
|
||||
mTimeout5MinPref.setEnabled(true);
|
||||
mTimeout10MinPref.setEnabled(true);
|
||||
} else {
|
||||
mPreferenceCategory.setEnabled(false);
|
||||
mTimeoutNonePref.setEnabled(false);
|
||||
mTimeout30SecPref.setEnabled(false);
|
||||
mTimeout1MinPref.setEnabled(false);
|
||||
mTimeout2MinPref.setEnabled(false);
|
||||
mTimeout5MinPref.setEnabled(false);
|
||||
mTimeout10MinPref.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mSettingObserver.observe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
|
||||
}
|
||||
|
||||
private static int keyToSetting(String key) {
|
||||
switch (key) {
|
||||
case KEY_NO_TIMEOUT:
|
||||
return ADAPTIVE_PLAYBACK_TIMEOUT_NONE;
|
||||
case KEY_1_MIN:
|
||||
return ADAPTIVE_PLAYBACK_TIMEOUT_1_MIN;
|
||||
case KEY_2_MIN:
|
||||
return ADAPTIVE_PLAYBACK_TIMEOUT_2_MIN;
|
||||
case KEY_5_MIN:
|
||||
return ADAPTIVE_PLAYBACK_TIMEOUT_5_MIN;
|
||||
case KEY_10_MIN:
|
||||
return ADAPTIVE_PLAYBACK_TIMEOUT_10_MIN;
|
||||
default:
|
||||
return ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS;
|
||||
}
|
||||
}
|
||||
|
||||
private SelectorWithWidgetPreference makeRadioPreference(String key, int titleId) {
|
||||
SelectorWithWidgetPreference pref = new SelectorWithWidgetPreference(mPreferenceCategory.getContext());
|
||||
pref.setKey(key);
|
||||
pref.setTitle(titleId);
|
||||
pref.setOnClickListener(this);
|
||||
mPreferenceCategory.addPreference(pref);
|
||||
return pref;
|
||||
}
|
||||
|
||||
private final class SettingObserver extends ContentObserver {
|
||||
private final Uri ADAPTIVE_PLAYBACK = Settings.System.getUriFor(
|
||||
Settings.System.ADAPTIVE_PLAYBACK_ENABLED);
|
||||
private final Uri ADAPTIVE_PLAYBACK_TIMEOUT = Settings.System.getUriFor(
|
||||
Settings.System.ADAPTIVE_PLAYBACK_TIMEOUT);
|
||||
|
||||
public SettingObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public void observe() {
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
cr.registerContentObserver(ADAPTIVE_PLAYBACK, false, this, UserHandle.USER_ALL);
|
||||
cr.registerContentObserver(ADAPTIVE_PLAYBACK_TIMEOUT, false, this, UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (ADAPTIVE_PLAYBACK.equals(uri) || ADAPTIVE_PLAYBACK_TIMEOUT.equals(uri)) {
|
||||
mAdaptivePlaybackEnabled = Settings.System.getIntForUser(
|
||||
mContext.getContentResolver(), Settings.System.ADAPTIVE_PLAYBACK_ENABLED, 0,
|
||||
UserHandle.USER_CURRENT) != 0;
|
||||
mAdaptivePlaybackTimeout = Settings.System.getIntForUser(
|
||||
mContext.getContentResolver(), Settings.System.ADAPTIVE_PLAYBACK_TIMEOUT,
|
||||
ADAPTIVE_PLAYBACK_TIMEOUT_30_SECS, UserHandle.USER_CURRENT);
|
||||
updateState(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Paranoid Android
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.sound;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
|
||||
public class AdaptivePlaybackSoundSettings extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "AdaptivePlaybackSoundSettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.adaptive_playback_sound_settings;
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.adaptive_playback_sound_settings);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Paranoid Android
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.sound;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
public class AdaptivePlaybackSwitchPreferenceController extends
|
||||
TogglePreferenceController implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private MainSwitchPreference mPreference;
|
||||
private final SettingsObserver mSettingsObserver;
|
||||
|
||||
public AdaptivePlaybackSwitchPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mSettingsObserver = new SettingsObserver(new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.ADAPTIVE_PLAYBACK_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.ADAPTIVE_PLAYBACK_ENABLED, isChecked ? 1 : 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mSettingsObserver.observe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return NO_RES;
|
||||
}
|
||||
|
||||
private final class SettingsObserver extends ContentObserver {
|
||||
private final Uri ADAPTIVE_PLAYBACK = Settings.System.getUriFor(
|
||||
Settings.System.ADAPTIVE_PLAYBACK_ENABLED);
|
||||
|
||||
public SettingsObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public void observe() {
|
||||
mContext.getContentResolver().registerContentObserver(ADAPTIVE_PLAYBACK, false, this,
|
||||
UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (ADAPTIVE_PLAYBACK.equals(uri)) {
|
||||
mPreference.setChecked(isChecked());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user