Add summary to PreventRingingParent
Parent preference previously didn't have a summary Moved summary test to PreventRingingParentPreferenceControllerTest Test: PreventRingingParentPreferenceControllerTest.java Change-Id: I2891e1ccffc4ea8007c8bd25689f242ee34c652c
This commit is contained in:
@@ -16,12 +16,20 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import android.content.Context;
|
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.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
public class PreventRingingParentPreferenceController extends BasePreferenceController {
|
public class PreventRingingParentPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
final String SECURE_KEY = VOLUME_HUSH_GESTURE;
|
||||||
|
|
||||||
public PreventRingingParentPreferenceController(Context context, String preferenceKey) {
|
public PreventRingingParentPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
}
|
}
|
||||||
@@ -33,4 +41,21 @@ public class PreventRingingParentPreferenceController extends BasePreferenceCont
|
|||||||
? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
return mContext.getText(summary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,8 +50,6 @@ public class PreventRingingPreferenceController extends PreventRingingParentPref
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mVideoPaused;
|
boolean mVideoPaused;
|
||||||
|
|
||||||
private final String SECURE_KEY = VOLUME_HUSH_GESTURE;
|
|
||||||
|
|
||||||
public PreventRingingPreferenceController(Context context, String key) {
|
public PreventRingingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
}
|
}
|
||||||
@@ -95,24 +93,6 @@ public class PreventRingingPreferenceController extends PreventRingingParentPref
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
return mContext.getString(summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
|
@@ -16,14 +16,25 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
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_OFF;
|
||||||
|
import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -41,18 +52,20 @@ public class PreventRingingParentPreferenceControllerTest {
|
|||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PreventRingingParentPreferenceController mController;
|
private PreventRingingParentPreferenceController mController;
|
||||||
|
private final String VIBRATE_SUMMARY = "On (vibrate)";
|
||||||
|
private final String MUTE_SUMMARY = "On (mute)";
|
||||||
|
private final String NONE_SUMMARY = "Off";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
|
||||||
|
|
||||||
mController = new PreventRingingParentPreferenceController(mContext, "test_key");
|
mController = new PreventRingingParentPreferenceController(mContext, "test_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_configIsTrue_shouldAvailableUnSearchable() {
|
public void testIsAvailable_configIsTrue_shouldAvailableUnSearchable() {
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
when(mResources.getBoolean(
|
when(mResources.getBoolean(
|
||||||
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true);
|
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true);
|
||||||
|
|
||||||
@@ -61,9 +74,28 @@ public class PreventRingingParentPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_configIsFalse_shouldReturnFalse() {
|
public void testIsAvailable_configIsFalse_shouldReturnFalse() {
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
when(mResources.getBoolean(
|
when(mResources.getBoolean(
|
||||||
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false);
|
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_summaryUpdated() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||||
|
VOLUME_HUSH_MUTE);
|
||||||
|
assertThat(mController.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(
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -87,29 +87,6 @@ public class PreventRingingPreferenceControllerTest {
|
|||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_mute() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
|
|
||||||
Settings.Secure.VOLUME_HUSH_MUTE);
|
|
||||||
assertEquals(mContext.getString(R.string.prevent_ringing_option_mute_summary),
|
|
||||||
mController.getSummary());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_vibrate() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
|
|
||||||
Settings.Secure.VOLUME_HUSH_VIBRATE);
|
|
||||||
assertEquals(mContext.getString(R.string.prevent_ringing_option_vibrate_summary),
|
|
||||||
mController.getSummary());
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_other() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
|
|
||||||
7);
|
|
||||||
assertEquals(mContext.getString(R.string.prevent_ringing_option_none_summary),
|
|
||||||
mController.getSummary());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_mute() {
|
public void testUpdateState_mute() {
|
||||||
ListPreference pref = mock(ListPreference.class);
|
ListPreference pref = mock(ListPreference.class);
|
||||||
|
Reference in New Issue
Block a user