Add swipe to see notification to "Notification preferences"
Bug: 31799948 Test: RunSettingsRoboTests Change-Id: Ib892ca4d5596c1c89e1efaf636a3eefd7cee371a
This commit is contained in:
@@ -15,29 +15,33 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
android:title="@string/configure_notification_settings"
|
||||||
android:title="@string/configure_notification_settings"
|
android:key="configure_notification_settings">
|
||||||
android:key="configure_notification_settings" >
|
|
||||||
|
|
||||||
<!-- Pulse notification light -->
|
<!-- Pulse notification light -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="notification_pulse"
|
android:key="notification_pulse"
|
||||||
android:title="@string/notification_pulse_title" />
|
android:title="@string/notification_pulse_title"/>
|
||||||
|
|
||||||
<!-- When device is locked -->
|
<!-- When device is locked -->
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<com.android.settings.notification.RestrictedDropDownPreference
|
||||||
android:key="lock_screen_notifications"
|
android:key="lock_screen_notifications"
|
||||||
android:title="@string/lock_screen_notifications_title"
|
android:title="@string/lock_screen_notifications_title"
|
||||||
android:summary="%s" />
|
android:summary="%s"/>
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="gesture_swipe_down_fingerprint"
|
||||||
|
android:title="@string/fingerprint_swipe_for_notifications_title"
|
||||||
|
android:summary="@string/fingerprint_swipe_for_notifications_summary"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="lock_screen_notifications_profile_header"
|
android:key="lock_screen_notifications_profile_header"
|
||||||
android:title="@string/profile_section_header" >
|
android:title="@string/profile_section_header">
|
||||||
|
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<com.android.settings.notification.RestrictedDropDownPreference
|
||||||
android:key="lock_screen_notifications_profile"
|
android:key="lock_screen_notifications_profile"
|
||||||
android:title="@string/lock_screen_notifications_title"
|
android:title="@string/lock_screen_notifications_title"
|
||||||
android:summary="%s" />
|
android:summary="%s"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
@@ -34,9 +34,9 @@ import android.view.ViewGroup;
|
|||||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -53,11 +53,11 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
|
private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
|
||||||
private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
|
private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
|
||||||
private static final String PREF_KEY_PICK_UP = "gesture_pick_up";
|
private static final String PREF_KEY_PICK_UP = "gesture_pick_up";
|
||||||
private static final String PREF_KEY_SWIPE_DOWN_FINGERPRINT = "gesture_swipe_down_fingerprint";
|
|
||||||
private static final String PREF_KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
|
private static final String PREF_KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
|
||||||
private static final String DEBUG_DOZE_COMPONENT = "debug.doze.component";
|
private static final String DEBUG_DOZE_COMPONENT = "debug.doze.component";
|
||||||
|
|
||||||
private List<GesturePreference> mPreferences;
|
private List<GesturePreference> mPreferences;
|
||||||
|
private SwipeToNotificationPreferenceController mSwipeToNotificationPreferenceController;
|
||||||
|
|
||||||
private AmbientDisplayConfiguration mAmbientConfig;
|
private AmbientDisplayConfiguration mAmbientConfig;
|
||||||
|
|
||||||
@@ -66,6 +66,8 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.gesture_settings);
|
addPreferencesFromResource(R.xml.gesture_settings);
|
||||||
Context context = getActivity();
|
Context context = getActivity();
|
||||||
|
mSwipeToNotificationPreferenceController =
|
||||||
|
new SwipeToNotificationPreferenceController(context);
|
||||||
mPreferences = new ArrayList();
|
mPreferences = new ArrayList();
|
||||||
|
|
||||||
// Double tap power for camera
|
// Double tap power for camera
|
||||||
@@ -93,11 +95,7 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fingerprint slide for notifications
|
// Fingerprint slide for notifications
|
||||||
if (isSystemUINavigationAvailable(context)) {
|
mSwipeToNotificationPreferenceController.displayPreference(getPreferenceScreen());
|
||||||
addPreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT, isSystemUINavigationEnabled(context));
|
|
||||||
} else {
|
|
||||||
removePreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Double twist for camera mode
|
// Double twist for camera mode
|
||||||
if (isDoubleTwistAvailable(context)) {
|
if (isDoubleTwistAvailable(context)) {
|
||||||
@@ -112,7 +110,7 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
RecyclerView listview = getListView();
|
RecyclerView listview = getListView();
|
||||||
listview.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
listview.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
@@ -136,6 +134,13 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
mSwipeToNotificationPreferenceController.updateState(
|
||||||
|
findPreference(mSwipeToNotificationPreferenceController.getPreferenceKey()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@@ -163,9 +168,6 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
|
Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
|
||||||
} else if (PREF_KEY_DOUBLE_TAP_SCREEN.equals(key)) {
|
} else if (PREF_KEY_DOUBLE_TAP_SCREEN.equals(key)) {
|
||||||
Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
|
Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
|
||||||
} else if (PREF_KEY_SWIPE_DOWN_FINGERPRINT.equals(key)) {
|
|
||||||
Secure.putInt(getContentResolver(),
|
|
||||||
Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, enabled ? 1 : 0);
|
|
||||||
} else if (PREF_KEY_DOUBLE_TWIST.equals(key)) {
|
} else if (PREF_KEY_DOUBLE_TWIST.equals(key)) {
|
||||||
Secure.putInt(getContentResolver(),
|
Secure.putInt(getContentResolver(),
|
||||||
Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
|
Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
|
||||||
@@ -188,16 +190,6 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
|
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSystemUINavigationAvailable(Context context) {
|
|
||||||
return context.getResources().getBoolean(
|
|
||||||
com.android.internal.R.bool.config_supportSystemNavigationKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isSystemUINavigationEnabled(Context context) {
|
|
||||||
return Secure.getInt(context.getContentResolver(), Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0)
|
|
||||||
== 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isDoubleTwistAvailable(Context context) {
|
private static boolean isDoubleTwistAvailable(Context context) {
|
||||||
return hasSensor(context, R.string.gesture_double_twist_sensor_name,
|
return hasSensor(context, R.string.gesture_double_twist_sensor_name,
|
||||||
R.string.gesture_double_twist_sensor_vendor);
|
R.string.gesture_double_twist_sensor_vendor);
|
||||||
@@ -227,42 +219,41 @@ public class GestureSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
@Override
|
@Override
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||||
boolean enabled) {
|
boolean enabled) {
|
||||||
ArrayList<SearchIndexableResource> result =
|
ArrayList<SearchIndexableResource> result =
|
||||||
new ArrayList<SearchIndexableResource>();
|
new ArrayList<SearchIndexableResource>();
|
||||||
|
|
||||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||||
sir.xmlResId = R.xml.gesture_settings;
|
sir.xmlResId = R.xml.gesture_settings;
|
||||||
result.add(sir);
|
result.add(sir);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
ArrayList<String> result = new ArrayList<String>();
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
AmbientDisplayConfiguration ambientConfig
|
AmbientDisplayConfiguration ambientConfig
|
||||||
= new AmbientDisplayConfiguration(context);
|
= new AmbientDisplayConfiguration(context);
|
||||||
if (!isCameraDoubleTapPowerGestureAvailable(context.getResources())) {
|
if (!isCameraDoubleTapPowerGestureAvailable(context.getResources())) {
|
||||||
result.add(PREF_KEY_DOUBLE_TAP_POWER);
|
result.add(PREF_KEY_DOUBLE_TAP_POWER);
|
||||||
|
}
|
||||||
|
if (!ambientConfig.pulseOnPickupAvailable()) {
|
||||||
|
result.add(PREF_KEY_PICK_UP);
|
||||||
|
}
|
||||||
|
if (!ambientConfig.pulseOnDoubleTapAvailable()) {
|
||||||
|
result.add(PREF_KEY_DOUBLE_TAP_SCREEN);
|
||||||
|
}
|
||||||
|
new SwipeToNotificationPreferenceController(context)
|
||||||
|
.updateNonIndexableKeys(result);
|
||||||
|
if (!isDoubleTwistAvailable(context)) {
|
||||||
|
result.add(PREF_KEY_DOUBLE_TWIST);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (!ambientConfig.pulseOnPickupAvailable()) {
|
};
|
||||||
result.add(PREF_KEY_PICK_UP);
|
|
||||||
}
|
|
||||||
if (!ambientConfig.pulseOnDoubleTapAvailable()) {
|
|
||||||
result.add(PREF_KEY_DOUBLE_TAP_SCREEN);
|
|
||||||
}
|
|
||||||
if (!isSystemUINavigationAvailable(context)) {
|
|
||||||
result.add(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
|
|
||||||
}
|
|
||||||
if (!isDoubleTwistAvailable(context)) {
|
|
||||||
result.add(PREF_KEY_DOUBLE_TWIST);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.TwoStatePreference;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
|
||||||
|
public class SwipeToNotificationPreferenceController extends PreferenceController
|
||||||
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private static final String PREF_KEY_SWIPE_DOWN_FINGERPRINT = "gesture_swipe_down_fingerprint";
|
||||||
|
|
||||||
|
public SwipeToNotificationPreferenceController(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return PREF_KEY_SWIPE_DOWN_FINGERPRINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
if (preference != null && preference instanceof TwoStatePreference) {
|
||||||
|
((TwoStatePreference) preference).setChecked(isSystemUINavigationEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isAvailable() {
|
||||||
|
return mContext.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_supportSystemNavigationKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSystemUINavigationEnabled() {
|
||||||
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0)
|
||||||
|
== 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, (boolean) newValue ? 1 : 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -17,11 +17,14 @@
|
|||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -59,8 +62,21 @@ public class ConfigureNotificationSettings extends DashboardFragment {
|
|||||||
mLockScreenNotificationController = new LockScreenNotificationPreferenceController(context);
|
mLockScreenNotificationController = new LockScreenNotificationPreferenceController(context);
|
||||||
getLifecycle().addObserver(pulseController);
|
getLifecycle().addObserver(pulseController);
|
||||||
getLifecycle().addObserver(mLockScreenNotificationController);
|
getLifecycle().addObserver(mLockScreenNotificationController);
|
||||||
|
controllers.add(new SwipeToNotificationPreferenceController(context));
|
||||||
controllers.add(pulseController);
|
controllers.add(pulseController);
|
||||||
controllers.add(mLockScreenNotificationController);
|
controllers.add(mLockScreenNotificationController);
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||||
|
final Context context = getContext();
|
||||||
|
if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context).isEnabled()) {
|
||||||
|
final String prefKey = getPreferenceController(
|
||||||
|
SwipeToNotificationPreferenceController.class)
|
||||||
|
.getPreferenceKey();
|
||||||
|
removePreference(prefKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.support.v7.preference.TwoStatePreference;
|
||||||
|
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class SwipeToNotificationPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private SwipeToNotificationPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mController = new SwipeToNotificationPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void display_configIsTrue_shouldDisplay() {
|
||||||
|
when(mContext.getResources().
|
||||||
|
getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys))
|
||||||
|
.thenReturn(true);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void display_configIsFalse_shouldNotDisplay() {
|
||||||
|
when(mContext.getResources().
|
||||||
|
getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys))
|
||||||
|
.thenReturn(false);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||||
|
.thenReturn(mock(Preference.class));
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mScreen).removePreference(any(Preference.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||||
|
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
|
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1);
|
||||||
|
|
||||||
|
mController = new SwipeToNotificationPreferenceController(context);
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
verify(preference).setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||||
|
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
|
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
|
||||||
|
|
||||||
|
mController = new SwipeToNotificationPreferenceController(context);
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
verify(preference).setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user