Add swipe to see notification to "Notification preferences"

Bug: 31799948
Test: RunSettingsRoboTests
Change-Id: Ib892ca4d5596c1c89e1efaf636a3eefd7cee371a
This commit is contained in:
Fan Zhang
2016-10-24 14:15:21 -07:00
parent f83ce92aaf
commit 5b6478a349
5 changed files with 254 additions and 64 deletions

View File

@@ -15,7 +15,6 @@
-->
<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:key="configure_notification_settings">
@@ -30,6 +29,11 @@
android:title="@string/lock_screen_notifications_title"
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
android:key="lock_screen_notifications_profile_header"
android:title="@string/profile_section_header">

View File

@@ -34,9 +34,9 @@ import android.view.ViewGroup;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.SettingsPreferenceFragment;
import java.util.ArrayList;
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_TWIST = "gesture_double_twist";
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 DEBUG_DOZE_COMPONENT = "debug.doze.component";
private List<GesturePreference> mPreferences;
private SwipeToNotificationPreferenceController mSwipeToNotificationPreferenceController;
private AmbientDisplayConfiguration mAmbientConfig;
@@ -66,6 +66,8 @@ public class GestureSettings extends SettingsPreferenceFragment implements
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.gesture_settings);
Context context = getActivity();
mSwipeToNotificationPreferenceController =
new SwipeToNotificationPreferenceController(context);
mPreferences = new ArrayList();
// Double tap power for camera
@@ -93,11 +95,7 @@ public class GestureSettings extends SettingsPreferenceFragment implements
}
// Fingerprint slide for notifications
if (isSystemUINavigationAvailable(context)) {
addPreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT, isSystemUINavigationEnabled(context));
} else {
removePreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
}
mSwipeToNotificationPreferenceController.displayPreference(getPreferenceScreen());
// Double twist for camera mode
if (isDoubleTwistAvailable(context)) {
@@ -136,6 +134,13 @@ public class GestureSettings extends SettingsPreferenceFragment implements
return view;
}
@Override
public void onResume() {
super.onResume();
mSwipeToNotificationPreferenceController.updateState(
findPreference(mSwipeToNotificationPreferenceController.getPreferenceKey()));
}
@Override
public void 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);
} else if (PREF_KEY_DOUBLE_TAP_SCREEN.equals(key)) {
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)) {
Secure.putInt(getContentResolver(),
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);
}
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) {
return hasSensor(context, R.string.gesture_double_twist_sensor_name,
R.string.gesture_double_twist_sensor_vendor);
@@ -255,9 +247,8 @@ public class GestureSettings extends SettingsPreferenceFragment implements
if (!ambientConfig.pulseOnDoubleTapAvailable()) {
result.add(PREF_KEY_DOUBLE_TAP_SCREEN);
}
if (!isSystemUINavigationAvailable(context)) {
result.add(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
}
new SwipeToNotificationPreferenceController(context)
.updateNonIndexableKeys(result);
if (!isDoubleTwistAvailable(context)) {
result.add(PREF_KEY_DOUBLE_TWIST);
}

View File

@@ -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;
}
}

View File

@@ -17,11 +17,14 @@
package com.android.settings.notification;
import android.content.Context;
import android.os.Bundle;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
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.List;
@@ -59,8 +62,21 @@ public class ConfigureNotificationSettings extends DashboardFragment {
mLockScreenNotificationController = new LockScreenNotificationPreferenceController(context);
getLifecycle().addObserver(pulseController);
getLifecycle().addObserver(mLockScreenNotificationController);
controllers.add(new SwipeToNotificationPreferenceController(context));
controllers.add(pulseController);
controllers.add(mLockScreenNotificationController);
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);
}
}
}

View File

@@ -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);
}
}