Add inline toggle for Prevent Ringing gesture.
- Fork sound_settings_v2 for dev. - Replace Preference with PrimarySwitchPreference for the Prevent Ringing entry. - When the toggle is on, only show the status text without the on/off info. - Remove unused codes. Bug: 174964721 Test: robotests Change-Id: I990f5c778436c8058d4a5953c7f15a9a7eb580d8
This commit is contained in:
@@ -11666,11 +11666,9 @@
|
||||
<!-- Option for prevent ringing setting -->
|
||||
<string name="prevent_ringing_option_none">Do nothing</string>
|
||||
<!-- Summary for prevent ringing setting -->
|
||||
<string name="prevent_ringing_option_vibrate_summary">On (vibrate)</string>
|
||||
<string name="prevent_ringing_option_vibrate_summary">Vibrate</string>
|
||||
<!-- Summary for prevent ringing setting -->
|
||||
<string name="prevent_ringing_option_mute_summary">On (mute)</string>
|
||||
<!-- Summary for prevent ringing setting -->
|
||||
<string name="prevent_ringing_option_none_summary">Off</string>
|
||||
<string name="prevent_ringing_option_mute_summary">Mute</string>
|
||||
|
||||
<!-- Title for detail page of wifi network [CHAR LIMIT=30] -->
|
||||
<string name="pref_title_network_details">Network details</string>
|
||||
|
@@ -118,7 +118,7 @@
|
||||
settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
|
||||
settings:keywords="@string/keywords_media_controls"/>
|
||||
|
||||
<Preference
|
||||
<com.android.settings.widget.PrimarySwitchPreference
|
||||
android:key="gesture_prevent_ringing_sound"
|
||||
android:title="@string/gesture_prevent_ringing_sound_title"
|
||||
android:order="-107"
|
||||
|
251
res/xml/sound_settings_v2.xml
Normal file
251
res/xml/sound_settings_v2.xml
Normal file
@@ -0,0 +1,251 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 The Android Open Source Project
|
||||
|
||||
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"
|
||||
android:title="@string/sound_settings"
|
||||
android:key="sound_settings"
|
||||
settings:keywords="@string/keywords_sounds"
|
||||
settings:initialExpandedChildrenCount="9">
|
||||
|
||||
<!-- Remote volume group -->
|
||||
<PreferenceCategory
|
||||
android:key="remote_media_group"
|
||||
android:title=""
|
||||
android:order="-185"
|
||||
settings:allowDividerBelow="true"
|
||||
settings:controller="com.android.settings.notification.RemoteVolumeGroupController">
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Media volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="media_volume"
|
||||
android:icon="@drawable/ic_media_stream"
|
||||
android:title="@string/media_volume_option_title"
|
||||
android:order="-180"
|
||||
settings:controller="com.android.settings.notification.MediaVolumePreferenceController"/>
|
||||
|
||||
<!-- Media output switcher -->
|
||||
<Preference
|
||||
android:key="media_output"
|
||||
android:title="@string/media_output_title"
|
||||
android:dialogTitle="@string/media_output_title"
|
||||
android:order="-175"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.sound.MediaOutputPreferenceController"/>
|
||||
|
||||
<!-- Call volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="call_volume"
|
||||
android:icon="@drawable/ic_local_phone_24_lib"
|
||||
android:title="@string/call_volume_option_title"
|
||||
android:order="-170"
|
||||
settings:controller="com.android.settings.notification.CallVolumePreferenceController"/>
|
||||
|
||||
<!-- Hands free profile output switcher -->
|
||||
<ListPreference
|
||||
android:key="take_call_on_output"
|
||||
android:title="@string/take_call_on_title"
|
||||
android:dialogTitle="@string/take_call_on_title"
|
||||
android:order="-165"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/>
|
||||
|
||||
<!-- Ring volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="ring_volume"
|
||||
android:icon="@drawable/ic_notifications"
|
||||
android:title="@string/ring_volume_option_title"
|
||||
android:order="-160"
|
||||
settings:controller="com.android.settings.notification.RingVolumePreferenceController"/>
|
||||
|
||||
|
||||
<!-- Alarm volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="alarm_volume"
|
||||
android:icon="@*android:drawable/ic_audio_alarm"
|
||||
android:title="@string/alarm_volume_option_title"
|
||||
android:order="-150"
|
||||
settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"/>
|
||||
|
||||
<!-- Notification volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="notification_volume"
|
||||
android:icon="@drawable/ic_notifications"
|
||||
android:title="@string/notification_volume_option_title"
|
||||
android:order="-140"
|
||||
settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"/>
|
||||
|
||||
<!-- Also vibrate for calls -->
|
||||
<Preference
|
||||
android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
|
||||
android:key="vibrate_for_calls"
|
||||
android:title="@string/vibrate_when_ringing_title"
|
||||
android:order="-130"
|
||||
settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"
|
||||
settings:keywords="@string/keywords_vibrate_for_calls"/>
|
||||
|
||||
<!-- Interruptions -->
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="zen_mode"
|
||||
android:title="@string/zen_mode_settings_title"
|
||||
android:fragment="com.android.settings.notification.zen.ZenModeSettings"
|
||||
android:order="-120"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:controller="com.android.settings.notification.zen.ZenModePreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="media_controls_summary"
|
||||
android:title="@string/media_controls_title"
|
||||
android:fragment="com.android.settings.sound.MediaControlsSettings"
|
||||
android:order="-110"
|
||||
settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
|
||||
settings:keywords="@string/keywords_media_controls"/>
|
||||
|
||||
<com.android.settings.widget.PrimarySwitchPreference
|
||||
android:key="gesture_prevent_ringing_sound"
|
||||
android:title="@string/gesture_prevent_ringing_sound_title"
|
||||
android:order="-107"
|
||||
android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
|
||||
settings:controller="com.android.settings.gestures.PreventRingingParentPreferenceController"/>
|
||||
|
||||
<!-- Phone ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="phone_ringtone"
|
||||
android:title="@string/ringtone_title"
|
||||
android:dialogTitle="@string/ringtone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:ringtoneType="ringtone"
|
||||
android:order="-100"
|
||||
settings:keywords="@string/sound_settings"/>
|
||||
|
||||
<!-- Default notification ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="notification_ringtone"
|
||||
android:title="@string/notification_ringtone_title"
|
||||
android:dialogTitle="@string/notification_ringtone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:ringtoneType="notification"
|
||||
android:order="-90"/>
|
||||
|
||||
<!-- Default alarm ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="alarm_ringtone"
|
||||
android:title="@string/alarm_ringtone_title"
|
||||
android:dialogTitle="@string/alarm_ringtone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:persistent="false"
|
||||
android:ringtoneType="alarm"
|
||||
android:order="-80"/>
|
||||
|
||||
<!-- Other sounds -->
|
||||
<PreferenceCategory
|
||||
android:key="other_sounds_and_vibrations_category"
|
||||
android:title="@string/other_sound_category_preference_title"
|
||||
android:order="-50">
|
||||
|
||||
<!-- Dial pad tones -->
|
||||
<SwitchPreference
|
||||
android:key="dial_pad_tones"
|
||||
android:title="@string/dial_pad_tones_title"/>
|
||||
|
||||
<!-- Screen locking sounds -->
|
||||
<SwitchPreference
|
||||
android:key="screen_locking_sounds"
|
||||
android:title="@string/screen_locking_sounds_title"/>
|
||||
|
||||
<!-- Charging sounds -->
|
||||
<SwitchPreference
|
||||
android:key="charging_sounds"
|
||||
android:title="@string/charging_sounds_title"/>
|
||||
|
||||
<!-- Docking sounds -->
|
||||
<SwitchPreference
|
||||
android:key="docking_sounds"
|
||||
android:title="@string/docking_sounds_title"/>
|
||||
|
||||
<!-- Touch sounds -->
|
||||
<SwitchPreference
|
||||
android:key="touch_sounds"
|
||||
android:title="@string/touch_sounds_title"/>
|
||||
|
||||
<!-- Vibrate on touch -->
|
||||
<SwitchPreference
|
||||
android:key="vibrate_on_touch"
|
||||
android:title="@string/vibrate_on_touch_title"
|
||||
android:summary="@string/vibrate_on_touch_summary"
|
||||
settings:keywords="@string/keywords_vibrate_on_touch"/>
|
||||
|
||||
<!-- Dock speaker plays -->
|
||||
<DropDownPreference
|
||||
android:key="dock_audio_media"
|
||||
android:title="@string/dock_audio_media_title"
|
||||
android:summary="%s"/>
|
||||
|
||||
<!-- Boot sounds -->
|
||||
<SwitchPreference
|
||||
android:key="boot_sounds"
|
||||
android:title="@string/boot_sounds_title"/>
|
||||
|
||||
<!-- Emergency tone -->
|
||||
<DropDownPreference
|
||||
android:key="emergency_tone"
|
||||
android:title="@string/emergency_tone_title"
|
||||
android:summary="%s"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<com.android.settings.widget.WorkOnlyCategory
|
||||
android:key="sound_work_settings_section"
|
||||
android:title="@string/sound_work_settings"
|
||||
android:order="100">
|
||||
|
||||
<!-- Use the same sounds of the work profile -->
|
||||
<SwitchPreference
|
||||
android:key="work_use_personal_sounds"
|
||||
android:title="@string/work_use_personal_sounds_title"
|
||||
android:summary="@string/work_use_personal_sounds_summary"
|
||||
android:disableDependentsState="true"/>
|
||||
|
||||
<!-- Work phone ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="work_ringtone"
|
||||
android:title="@string/work_ringtone_title"
|
||||
android:dialogTitle="@string/work_alarm_ringtone_title"
|
||||
android:ringtoneType="ringtone"
|
||||
android:dependency="work_use_personal_sounds"/>
|
||||
|
||||
<!-- Default work notification ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="work_notification_ringtone"
|
||||
android:title="@string/work_notification_ringtone_title"
|
||||
android:dialogTitle="@string/work_alarm_ringtone_title"
|
||||
android:ringtoneType="notification"
|
||||
android:dependency="work_use_personal_sounds"/>
|
||||
|
||||
<!-- Default work alarm ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="work_alarm_ringtone"
|
||||
android:title="@string/work_alarm_ringtone_title"
|
||||
android:dialogTitle="@string/work_alarm_ringtone_title"
|
||||
android:persistent="false"
|
||||
android:ringtoneType="alarm"
|
||||
android:dependency="work_use_personal_sounds"/>
|
||||
|
||||
</com.android.settings.widget.WorkOnlyCategory>
|
||||
</PreferenceScreen>
|
@@ -20,20 +20,84 @@ import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE;
|
||||
import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
|
||||
import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public class PreventRingingParentPreferenceController extends BasePreferenceController {
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.widget.PrimarySwitchPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/** The controller manages the behaviour of the Prevent Ringing gesture setting. */
|
||||
public class PreventRingingParentPreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
final String SECURE_KEY = VOLUME_HUSH_GESTURE;
|
||||
|
||||
private PrimarySwitchPreference mPreference;
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
public PreventRingingParentPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
mSettingObserver = new SettingObserver(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
final int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE,
|
||||
Settings.Secure.VOLUME_HUSH_VIBRATE);
|
||||
return preventRinging != Settings.Secure.VOLUME_HUSH_OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
final int preventRingingSetting = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE);
|
||||
final int newRingingSetting = preventRingingSetting == Settings.Secure.VOLUME_HUSH_OFF
|
||||
? Settings.Secure.VOLUME_HUSH_VIBRATE
|
||||
: preventRingingSetting;
|
||||
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE, isChecked
|
||||
? newRingingSetting
|
||||
: Settings.Secure.VOLUME_HUSH_OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final int value = Settings.Secure.getInt(
|
||||
mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE);
|
||||
CharSequence summary;
|
||||
switch (value) {
|
||||
case VOLUME_HUSH_VIBRATE:
|
||||
summary = mContext.getText(R.string.prevent_ringing_option_vibrate_summary);
|
||||
break;
|
||||
case VOLUME_HUSH_MUTE:
|
||||
summary = mContext.getText(R.string.prevent_ringing_option_mute_summary);
|
||||
break;
|
||||
default:
|
||||
summary = null;
|
||||
}
|
||||
preference.setSummary(summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getResources().getBoolean(
|
||||
@@ -42,20 +106,45 @@ public class PreventRingingParentPreferenceController extends BasePreferenceCont
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
int value = Settings.Secure.getInt(
|
||||
mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE);
|
||||
int summary;
|
||||
switch (value) {
|
||||
case VOLUME_HUSH_VIBRATE:
|
||||
summary = R.string.prevent_ringing_option_vibrate_summary;
|
||||
break;
|
||||
case VOLUME_HUSH_MUTE:
|
||||
summary = R.string.prevent_ringing_option_mute_summary;
|
||||
break;
|
||||
default:
|
||||
summary = R.string.prevent_ringing_option_none_summary;
|
||||
public void onStart() {
|
||||
if (mSettingObserver != null) {
|
||||
mSettingObserver.register(mContext.getContentResolver());
|
||||
mSettingObserver.onChange(false, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mSettingObserver != null) {
|
||||
mSettingObserver.unregister(mContext.getContentResolver());
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingObserver extends ContentObserver {
|
||||
private final Uri mVolumeHushGestureUri = Settings.Secure.getUriFor(
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE);
|
||||
|
||||
private final Preference mPreference;
|
||||
|
||||
SettingObserver(Preference preference) {
|
||||
super(new Handler());
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
public void register(ContentResolver cr) {
|
||||
cr.registerContentObserver(mVolumeHushGestureUri, false, this);
|
||||
}
|
||||
|
||||
public void unregister(ContentResolver cr) {
|
||||
cr.unregisterContentObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (uri == null || mVolumeHushGestureUri.equals(uri)) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
return mContext.getText(summary);
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,7 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Switch;
|
||||
|
||||
@@ -39,7 +35,6 @@ public class PreventRingingSwitchPreferenceController extends AbstractPreference
|
||||
|
||||
private static final String KEY = "gesture_prevent_ringing_switch";
|
||||
private final Context mContext;
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
@VisibleForTesting
|
||||
SwitchBar mSwitch;
|
||||
@@ -60,7 +55,6 @@ public class PreventRingingSwitchPreferenceController extends AbstractPreference
|
||||
if (isAvailable()) {
|
||||
LayoutPreference pref = screen.findPreference(getPreferenceKey());
|
||||
if (pref != null) {
|
||||
mSettingObserver = new SettingObserver(pref);
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE,
|
||||
@@ -113,32 +107,4 @@ public class PreventRingingSwitchPreferenceController extends AbstractPreference
|
||||
? newRingingSetting
|
||||
: Settings.Secure.VOLUME_HUSH_OFF);
|
||||
}
|
||||
|
||||
private class SettingObserver extends ContentObserver {
|
||||
private final Uri VOLUME_HUSH_GESTURE = Settings.Secure.getUriFor(
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE);
|
||||
|
||||
private final Preference mPreference;
|
||||
|
||||
public SettingObserver(Preference preference) {
|
||||
super(new Handler());
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
public void register(ContentResolver cr) {
|
||||
cr.registerContentObserver(VOLUME_HUSH_GESTURE, false, this);
|
||||
}
|
||||
|
||||
public void unregister(ContentResolver cr) {
|
||||
cr.unregisterContentObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (uri == null || VOLUME_HUSH_GESTURE.equals(uri)) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import android.os.Message;
|
||||
import android.os.UserHandle;
|
||||
import android.preference.SeekBarVolumizer;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
@@ -33,6 +34,7 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.RingtonePreference;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.core.OnActivityResultListener;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
@@ -152,6 +154,9 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
|
||||
return R.xml.sound_settings_v2;
|
||||
}
|
||||
return R.xml.sound_settings;
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,8 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -50,12 +52,14 @@ public class PreventRingingParentPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private PreventRingingParentPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
mController = new PreventRingingParentPreferenceController(mContext, "test_key");
|
||||
mPreference = new Preference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,17 +84,43 @@ public class PreventRingingParentPreferenceControllerTest {
|
||||
public void updateState_summaryUpdated() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_MUTE);
|
||||
assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText(
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getText(
|
||||
R.string.prevent_ringing_option_mute_summary));
|
||||
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_VIBRATE);
|
||||
assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText(
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getText(
|
||||
R.string.prevent_ringing_option_vibrate_summary));
|
||||
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_OFF);
|
||||
assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText(
|
||||
R.string.prevent_ringing_option_none_summary));
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_vibrate_shouldReturnTrue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_VIBRATE);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_mute_shouldReturnTrue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_MUTE);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_off_shouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_OFF);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user