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