Merge "Update style of main media setting toggle" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6812256031
@@ -20,14 +20,17 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/media_controls_title">
|
||||
|
||||
<SwitchPreference
|
||||
<com.android.settings.widget.SettingsMainSwitchPreference
|
||||
android:key="media_controls_resume_switch"
|
||||
android:title="@string/media_controls_summary"
|
||||
android:summary="@string/media_controls_resume_description"
|
||||
app:keywords="@string/keywords_media_controls"
|
||||
app:controller="com.android.settings.sound.MediaControlsPreferenceController"
|
||||
app:allowDividerAbove="true" />
|
||||
|
||||
<com.android.settingslib.widget.TopIntroPreference
|
||||
android:title="@string/media_controls_resume_description"
|
||||
app:searchable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="media_controls_resumable_apps"
|
||||
android:title="@string/media_controls_apps_title"
|
||||
|
@@ -20,32 +20,47 @@ import static android.provider.Settings.Secure.MEDIA_CONTROLS_RESUME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
/**
|
||||
* Toggle for media controls settings
|
||||
*/
|
||||
public class MediaControlsPreferenceController extends TogglePreferenceController {
|
||||
public class MediaControlsPreferenceController extends BasePreferenceController
|
||||
implements OnMainSwitchChangeListener {
|
||||
|
||||
public MediaControlsPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
int val = Settings.Secure.getInt(mContext.getContentResolver(), MEDIA_CONTROLS_RESUME, 1);
|
||||
return val == 1;
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
SettingsMainSwitchPreference mainSwitch = screen.findPreference(mPreferenceKey);
|
||||
mainSwitch.addOnSwitchChangeListener(this);
|
||||
mainSwitch.setChecked(isChecked());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
int val = isChecked ? 1 : 0;
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), MEDIA_CONTROLS_RESUME, val);
|
||||
@VisibleForTesting
|
||||
protected boolean isChecked() {
|
||||
int val = Settings.Secure.getInt(mContext.getContentResolver(), MEDIA_CONTROLS_RESUME, 1);
|
||||
return val == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
int val = isChecked ? 1 : 0;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), MEDIA_CONTROLS_RESUME, val);
|
||||
}
|
||||
}
|
||||
|
@@ -76,7 +76,7 @@ public class MediaControlsPreferenceControllerTest {
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
|
||||
mController.setChecked(false);
|
||||
mController.onSwitchChanged(null /* switchView */, false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver,
|
||||
Settings.Secure.MEDIA_CONTROLS_RESUME, -1)).isEqualTo(0);
|
||||
@@ -89,7 +89,7 @@ public class MediaControlsPreferenceControllerTest {
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
|
||||
mController.setChecked(true);
|
||||
mController.onSwitchChanged(null /* switchView */, true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver,
|
||||
Settings.Secure.MEDIA_CONTROLS_RESUME, -1)).isEqualTo(1);
|
||||
|
Reference in New Issue
Block a user