summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHJ ChangLiao <hjchangliao@google.com>2018-04-02 17:06:55 +0800
committerHJ ChangLiao <hjchangliao@google.com>2018-04-09 15:27:32 +0800
commit22f53c0274e26b189bb220abcf05694acfc2b661 (patch)
tree8b82f21790cc995e9912c31ad8c285fbf2f63dc3
parent9914ef7635b0f03acb4608673a58b9aa458cf771 (diff)
downloadpackages_apps_Settings-22f53c0274e26b189bb220abcf05694acfc2b661.tar.gz
packages_apps_Settings-22f53c0274e26b189bb220abcf05694acfc2b661.tar.bz2
packages_apps_Settings-22f53c0274e26b189bb220abcf05694acfc2b661.zip
GesturesSettingPreferenceController to Toggle
Convert GesturesSettingPreferenceController to TogglePreferenceController, All of its children need follow the change, add setter and robotest for them: AssistGestureSettingsPreferenceController DoubleTapPowerPreferenceController DoubleTapScreenPreferenceController DoubleTwistPreferenceController PickupGesturePreferenceController SwipeToNotificationPreferenceController Change-Id: I792b2d370eea828bf345fb2b1cc3eac260eb66f4 Fixes: 74913806 Fixes: 67998110 Fixes: 67998098 Fixes: 67998048 Fixes: 67998069 Fixes: 67997452 Test: make RunSettingsRoboTests
-rw-r--r--res/xml/ambient_display_settings.xml8
-rw-r--r--res/xml/assist_gesture_settings.xml3
-rw-r--r--res/xml/configure_notification_settings.xml3
-rw-r--r--res/xml/double_tap_power_settings.xml3
-rw-r--r--res/xml/double_tap_screen_settings.xml3
-rw-r--r--res/xml/double_twist_gesture_settings.xml3
-rw-r--r--res/xml/gestures.xml21
-rw-r--r--res/xml/manage_assist.xml14
-rw-r--r--res/xml/pick_up_gesture_settings.xml3
-rw-r--r--res/xml/swipe_to_notification_settings.xml5
-rw-r--r--src/com/android/settings/applications/assist/ManageAssist.java8
-rw-r--r--src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java8
-rw-r--r--src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java4
-rw-r--r--src/com/android/settings/display/AmbientDisplaySettings.java41
-rw-r--r--src/com/android/settings/gestures/AssistGestureSettings.java8
-rw-r--r--src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java73
-rw-r--r--src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java31
-rw-r--r--src/com/android/settings/gestures/DoubleTapPowerSettings.java23
-rw-r--r--src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java39
-rw-r--r--src/com/android/settings/gestures/DoubleTapScreenSettings.java26
-rw-r--r--src/com/android/settings/gestures/DoubleTwistGestureSettings.java21
-rw-r--r--src/com/android/settings/gestures/DoubleTwistPreferenceController.java20
-rw-r--r--src/com/android/settings/gestures/GesturePreferenceController.java34
-rw-r--r--src/com/android/settings/gestures/GestureSettings.java38
-rw-r--r--src/com/android/settings/gestures/GesturesSettingPreferenceController.java34
-rw-r--r--src/com/android/settings/gestures/PickupGesturePreferenceController.java35
-rw-r--r--src/com/android/settings/gestures/PickupGestureSettings.java27
-rw-r--r--src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java24
-rw-r--r--src/com/android/settings/gestures/SwipeToNotificationSettings.java23
-rw-r--r--src/com/android/settings/notification/ConfigureNotificationSettings.java2
-rw-r--r--tests/robotests/assets/grandfather_slice_controller_not_in_xml2
-rw-r--r--tests/robotests/src/com/android/settings/display/AmbientDisplaySettingsTest.java40
-rw-r--r--tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java8
-rw-r--r--tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java17
-rw-r--r--tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java16
-rw-r--r--tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java16
-rw-r--r--tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java27
-rw-r--r--tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java16
-rw-r--r--tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java14
-rw-r--r--tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java8
40 files changed, 320 insertions, 429 deletions
diff --git a/res/xml/ambient_display_settings.xml b/res/xml/ambient_display_settings.xml
index a23aeaa633..4688a80afc 100644
--- a/res/xml/ambient_display_settings.xml
+++ b/res/xml/ambient_display_settings.xml
@@ -35,12 +35,14 @@
<Preference
android:key="ambient_display_double_tap"
android:title="@string/ambient_display_title"
- android:fragment="com.android.settings.gestures.DoubleTapScreenSettings" />
+ android:fragment="com.android.settings.gestures.DoubleTapScreenSettings"
+ settings:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
<Preference
android:key="ambient_display_pick_up"
android:title="@string/ambient_display_pickup_title"
- android:fragment="com.android.settings.gestures.PickupGestureSettings" />
+ android:fragment="com.android.settings.gestures.PickupGestureSettings"
+ settings:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
</PreferenceCategory>
@@ -52,7 +54,7 @@
android:key="ambient_display_notification"
android:title="@string/doze_title"
android:summary="@string/doze_summary"
- settings:controller="com.android.settings.display.AmbientDisplayNotificationsPreferenceController"/>
+ settings:controller="com.android.settings.display.AmbientDisplayNotificationsPreferenceController" />
</PreferenceCategory>
diff --git a/res/xml/assist_gesture_settings.xml b/res/xml/assist_gesture_settings.xml
index 53b6526f95..b2ceac94ec 100644
--- a/res/xml/assist_gesture_settings.xml
+++ b/res/xml/assist_gesture_settings.xml
@@ -29,6 +29,7 @@
<SwitchPreference
android:key="gesture_assist"
android:title="@string/assist_gesture_title"
- app:keywords="@string/keywords_assist_gesture_launch" />
+ app:keywords="@string/keywords_assist_gesture_launch"
+ app:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
</PreferenceScreen>
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index 73c1d6fc89..612f5e7623 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -46,7 +46,8 @@
<Preference
android:key="gesture_swipe_down_fingerprint_notifications"
android:title="@string/fingerprint_swipe_for_notifications_title"
- android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
+ android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
+ settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
<com.android.settingslib.RestrictedPreference
android:key="zen_mode_notifications"
diff --git a/res/xml/double_tap_power_settings.xml b/res/xml/double_tap_power_settings.xml
index 26d0415beb..6614899982 100644
--- a/res/xml/double_tap_power_settings.xml
+++ b/res/xml/double_tap_power_settings.xml
@@ -30,6 +30,7 @@
android:key="gesture_double_tap_power"
android:title="@string/double_tap_power_for_camera_title"
android:summary="@string/double_tap_power_for_camera_summary"
- app:keywords="@string/keywords_gesture" />
+ app:keywords="@string/keywords_gesture"
+ app:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />
</PreferenceScreen> \ No newline at end of file
diff --git a/res/xml/double_tap_screen_settings.xml b/res/xml/double_tap_screen_settings.xml
index d40602e082..4d2e1682b8 100644
--- a/res/xml/double_tap_screen_settings.xml
+++ b/res/xml/double_tap_screen_settings.xml
@@ -30,6 +30,7 @@
android:key="gesture_double_tap_screen"
android:title="@string/ambient_display_title"
android:summary="@string/ambient_display_summary"
- app:keywords="@string/keywords_gesture" />
+ app:keywords="@string/keywords_gesture"
+ app:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
</PreferenceScreen> \ No newline at end of file
diff --git a/res/xml/double_twist_gesture_settings.xml b/res/xml/double_twist_gesture_settings.xml
index a2af1e481a..1da862d8bb 100644
--- a/res/xml/double_twist_gesture_settings.xml
+++ b/res/xml/double_twist_gesture_settings.xml
@@ -30,6 +30,7 @@
android:key="gesture_double_twist"
android:title="@string/double_twist_for_camera_mode_title"
android:summary="@string/double_twist_for_camera_mode_summary"
- app:keywords="@string/keywords_gesture" />
+ app:keywords="@string/keywords_gesture"
+ app:controller="com.android.settings.gestures.DoubleTwistPreferenceController" />
</PreferenceScreen> \ No newline at end of file
diff --git a/res/xml/gestures.xml b/res/xml/gestures.xml
index 7083a3116b..0eaa2a6b50 100644
--- a/res/xml/gestures.xml
+++ b/res/xml/gestures.xml
@@ -17,38 +17,45 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="gesture_settings_screen"
- android:title="@string/gesture_preference_title" >
+ android:title="@string/gesture_preference_title">
<Preference
android:key="gesture_assist_input_summary"
android:title="@string/assist_gesture_title"
- android:fragment="com.android.settings.gestures.AssistGestureSettings" />
+ android:fragment="com.android.settings.gestures.AssistGestureSettings"
+ settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
<Preference
android:key="gesture_swipe_down_fingerprint_input_summary"
android:title="@string/fingerprint_swipe_for_notifications_title"
- android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
+ android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
+ settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
<Preference
android:key="gesture_double_tap_power_input_summary"
android:title="@string/double_tap_power_for_camera_title"
- android:fragment="com.android.settings.gestures.DoubleTapPowerSettings" />
+ android:fragment="com.android.settings.gestures.DoubleTapPowerSettings"
+ settings:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />
<Preference
android:key="gesture_double_twist_input_summary"
android:title="@string/double_twist_for_camera_mode_title"
- android:fragment="com.android.settings.gestures.DoubleTwistGestureSettings" />
+ android:fragment="com.android.settings.gestures.DoubleTwistGestureSettings"
+ settings:controller="com.android.settings.gestures.DoubleTwistPreferenceController" />
<Preference
android:key="gesture_double_tap_screen_input_summary"
android:title="@string/ambient_display_title"
- android:fragment="com.android.settings.gestures.DoubleTapScreenSettings" />
+ android:fragment="com.android.settings.gestures.DoubleTapScreenSettings"
+ settings:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
<Preference
android:key="gesture_pick_up_input_summary"
android:title="@string/ambient_display_pickup_title"
- android:fragment="com.android.settings.gestures.PickupGestureSettings" />
+ android:fragment="com.android.settings.gestures.PickupGestureSettings"
+ settings:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
<Preference
android:key="gesture_prevent_ringing_summary"
diff --git a/res/xml/manage_assist.xml b/res/xml/manage_assist.xml
index 047f1ca8ba..dec8bc3d44 100644
--- a/res/xml/manage_assist.xml
+++ b/res/xml/manage_assist.xml
@@ -17,6 +17,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="manage_assist_screen"
android:title="@string/assist_and_voice_input_title">
@@ -24,31 +25,32 @@
android:key="default_assist"
android:title="@string/default_assist_title"
android:summary="@string/summary_placeholder"
- android:fragment="com.android.settings.applications.assist.DefaultAssistPicker"/>
+ android:fragment="com.android.settings.applications.assist.DefaultAssistPicker" />
<Preference
android:key="gesture_assist_application"
android:title="@string/assist_gesture_title"
- android:fragment="com.android.settings.gestures.AssistGestureSettings"/>
+ android:fragment="com.android.settings.gestures.AssistGestureSettings"
+ settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
<SwitchPreference
android:key="context"
android:title="@string/assist_access_context_title"
- android:summary="@string/assist_access_context_summary"/>
+ android:summary="@string/assist_access_context_summary" />
<SwitchPreference
android:key="screenshot"
android:title="@string/assist_access_screenshot_title"
- android:summary="@string/assist_access_screenshot_summary"/>
+ android:summary="@string/assist_access_screenshot_summary" />
<SwitchPreference
android:key="flash"
android:title="@string/assist_flash_title"
- android:summary="@string/assist_flash_summary"/>
+ android:summary="@string/assist_flash_summary" />
<com.android.settings.widget.GearPreference
android:key="voice_input_settings"
android:title="@string/voice_input_settings_title"
- android:fragment="com.android.settings.applications.assist.DefaultVoiceInputPicker"/>
+ android:fragment="com.android.settings.applications.assist.DefaultVoiceInputPicker" />
</PreferenceScreen>
diff --git a/res/xml/pick_up_gesture_settings.xml b/res/xml/pick_up_gesture_settings.xml
index e1414cd585..ccf2d8ae20 100644
--- a/res/xml/pick_up_gesture_settings.xml
+++ b/res/xml/pick_up_gesture_settings.xml
@@ -30,6 +30,7 @@
android:key="gesture_pick_up"
android:title="@string/ambient_display_pickup_title"
android:summary="@string/ambient_display_pickup_summary"
- app:keywords="@string/keywords_gesture" />
+ app:keywords="@string/keywords_gesture"
+ app:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
</PreferenceScreen> \ No newline at end of file
diff --git a/res/xml/swipe_to_notification_settings.xml b/res/xml/swipe_to_notification_settings.xml
index 5b53c102d7..04dc0c791d 100644
--- a/res/xml/swipe_to_notification_settings.xml
+++ b/res/xml/swipe_to_notification_settings.xml
@@ -23,12 +23,13 @@
<com.android.settings.widget.VideoPreference
android:key="gesture_swipe_down_fingerprint_video"
app:animation="@raw/gesture_fingerprint_swipe"
- app:preview="@drawable/gesture_fingerprint_swipe"/>
+ app:preview="@drawable/gesture_fingerprint_swipe" />
<SwitchPreference
android:key="gesture_swipe_down_fingerprint"
android:title="@string/fingerprint_swipe_for_notifications_title"
android:summary="@string/fingerprint_swipe_for_notifications_summary"
- app:keywords="@string/keywords_gesture"/>
+ app:keywords="@string/keywords_gesture"
+ app:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
</PreferenceScreen> \ No newline at end of file
diff --git a/src/com/android/settings/applications/assist/ManageAssist.java b/src/com/android/settings/applications/assist/ManageAssist.java
index 5a46941e39..cd85aca897 100644
--- a/src/com/android/settings/applications/assist/ManageAssist.java
+++ b/src/com/android/settings/applications/assist/ManageAssist.java
@@ -63,6 +63,12 @@ public class ManageAssist extends DashboardFragment {
}
@Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ use(AssistGestureSettingsPreferenceController.class).setAssistOnly(true);
+ }
+
+ @Override
public void onResume() {
super.onResume();
@@ -75,8 +81,6 @@ public class ManageAssist extends DashboardFragment {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new DefaultAssistPreferenceController(context, "default_assist",
true /* showSetting */));
- controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle,
- KEY_ASSIST, true /* assistOnly */));
controllers.add(new AssistContextPreferenceController(context, lifecycle));
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
diff --git a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
index 5de49bb3ea..a6d5363d79 100644
--- a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
+++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
@@ -69,12 +69,16 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
return true;
}
- public void setConfig(AmbientDisplayConfiguration config) {
+ public AmbientDisplayAlwaysOnPreferenceController setConfig(
+ AmbientDisplayConfiguration config) {
mConfig = config;
+ return this;
}
- public void setCallback(OnPreferenceChangedCallback callback) {
+ public AmbientDisplayAlwaysOnPreferenceController setCallback(
+ OnPreferenceChangedCallback callback) {
mCallback = callback;
+ return this;
}
public static boolean isAlwaysOnEnabled(AmbientDisplayConfiguration config) {
diff --git a/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java b/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java
index 9cff0884b2..15eb8b3b2b 100644
--- a/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java
+++ b/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java
@@ -56,8 +56,10 @@ public class AmbientDisplayNotificationsPreferenceController extends
*
* @param config AmbientDisplayConfiguration for this controller
*/
- public void setConfig(AmbientDisplayConfiguration config) {
+ public AmbientDisplayNotificationsPreferenceController setConfig(
+ AmbientDisplayConfiguration config) {
mConfig = config;
+ return this;
}
@Override
diff --git a/src/com/android/settings/display/AmbientDisplaySettings.java b/src/com/android/settings/display/AmbientDisplaySettings.java
index 92a009b001..ba3e1ee46e 100644
--- a/src/com/android/settings/display/AmbientDisplaySettings.java
+++ b/src/com/android/settings/display/AmbientDisplaySettings.java
@@ -46,35 +46,18 @@ public class AmbientDisplaySettings extends DashboardFragment {
public static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on";
private static final String TAG = "AmbientDisplaySettings";
- private static final int MY_USER_ID = UserHandle.myUserId();
-
- private static final String KEY_AMBIENT_DISPLAY_DOUBLE_TAP = "ambient_display_double_tap";
- private static final String KEY_AMBIENT_DISPLAY_PICK_UP = "ambient_display_pick_up";
- private static final String KEY_AMBIENT_DISPLAY_NOTIFICATION = "ambient_display_notification";
private AmbientDisplayConfiguration mConfig;
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- Lifecycle lifecycle, AmbientDisplayConfiguration config) {
-
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle, config,
- MY_USER_ID, KEY_AMBIENT_DISPLAY_DOUBLE_TAP));
- controllers.add(new PickupGesturePreferenceController(context, lifecycle, config,
- MY_USER_ID, KEY_AMBIENT_DISPLAY_PICK_UP));
- return controllers;
- }
-
@Override
public void onAttach(Context context) {
super.onAttach(context);
- final AmbientDisplayAlwaysOnPreferenceController controller = use(
- AmbientDisplayAlwaysOnPreferenceController.class);
- controller.setConfig(getConfig(context));
- controller.setCallback(this::updatePreferenceStates);
- final AmbientDisplayNotificationsPreferenceController notificationController = use(
- AmbientDisplayNotificationsPreferenceController.class);
- notificationController.setConfig(getConfig(context));
+ use(AmbientDisplayAlwaysOnPreferenceController.class)
+ .setConfig(getConfig(context))
+ .setCallback(this::updatePreferenceStates);
+ use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
+ use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
+ use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
}
@Override
@@ -88,11 +71,6 @@ public class AmbientDisplaySettings extends DashboardFragment {
}
@Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getLifecycle(), getConfig(context));
- }
-
- @Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.AMBIENT_DISPLAY_SETTINGS;
}
@@ -109,13 +87,6 @@ public class AmbientDisplaySettings extends DashboardFragment {
result.add(sir);
return result;
}
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null,
- new AmbientDisplayConfiguration(context));
- }
};
private AmbientDisplayConfiguration getConfig(Context context) {
diff --git a/src/com/android/settings/gestures/AssistGestureSettings.java b/src/com/android/settings/gestures/AssistGestureSettings.java
index 19c00bc6d9..ffe223443e 100644
--- a/src/com/android/settings/gestures/AssistGestureSettings.java
+++ b/src/com/android/settings/gestures/AssistGestureSettings.java
@@ -84,9 +84,11 @@ public class AssistGestureSettings extends DashboardFragment {
@Override
protected boolean isPageSearchEnabled(Context context) {
- return new AssistGestureSettingsPreferenceController(context,
- null /* lifecycle */, null /* key */, false /* assistOnly */)
- .isAvailable();
+ AssistGestureSettingsPreferenceController controller =
+ new AssistGestureSettingsPreferenceController(context,
+ "gesture_assist_input_summary");
+ controller.setAssistOnly(false);
+ return controller.isAvailable();
}
};
}
diff --git a/src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java b/src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java
index 1ecba0d1ed..fd94f9f223 100644
--- a/src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java
+++ b/src/com/android/settings/gestures/AssistGestureSettingsPreferenceController.java
@@ -24,7 +24,6 @@ import android.content.Intent;
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.internal.annotations.VisibleForTesting;
import com.android.settings.R;
@@ -32,11 +31,8 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.search.ResultPayload;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.core.lifecycle.events.OnResume;
-public class AssistGestureSettingsPreferenceController extends GesturePreferenceController
- implements OnResume {
+public class AssistGestureSettingsPreferenceController extends GesturePreferenceController {
private static final String PREF_KEY_VIDEO = "gesture_assist_video";
@@ -55,30 +51,25 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
@VisibleForTesting
boolean mAssistOnly;
- public AssistGestureSettingsPreferenceController(Context context, Lifecycle lifecycle,
- String key, boolean assistOnly) {
- super(context, lifecycle);
+ public AssistGestureSettingsPreferenceController(Context context,
+ String key) {
+ super(context, key);
mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
mWasAvailable = isAvailable();
mAssistGesturePrefKey = key;
- mAssistOnly = assistOnly;
}
@Override
- public boolean isAvailable() {
- if (mAssistOnly) {
- return mFeatureProvider.isSupported(mContext);
- } else {
- return mFeatureProvider.isSensorAvailable(mContext);
- }
+ public int getAvailabilityStatus() {
+ final boolean isAvailable = mAssistOnly ? mFeatureProvider.isSupported(mContext)
+ : mFeatureProvider.isSensorAvailable(mContext);
+ return isAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
public void displayPreference(PreferenceScreen screen) {
mScreen = screen;
mPreference = screen.findPreference(getPreferenceKey());
- // Call super last or AbstractPreferenceController might remove the preference from the
- // screen (if !isAvailable()) before we can save a reference to it.
super.displayPreference(screen);
}
@@ -92,6 +83,11 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
}
}
+ public AssistGestureSettingsPreferenceController setAssistOnly(boolean assistOnly) {
+ mAssistOnly = assistOnly;
+ return this;
+ }
+
private void updatePreference() {
if (mPreference == null) {
return;
@@ -117,31 +113,9 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
}
@Override
- public void updateState(Preference preference) {
- boolean isEnabled = isAssistGestureEnabled() && mFeatureProvider.isSupported(mContext);
-
- if (!mAssistOnly) {
- isEnabled = isEnabled || isSilenceGestureEnabled();
- }
-
- if (preference != null) {
- if (preference instanceof TwoStatePreference) {
- ((TwoStatePreference) preference).setChecked(isSwitchPrefEnabled());
- } else {
- preference.setSummary(isEnabled
- ? R.string.gesture_setting_on
- : R.string.gesture_setting_off);
- }
- }
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean enabled = (boolean) newValue;
- Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY_ASSIST,
- enabled ? ON : OFF);
- updateState(preference);
- return true;
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY_ASSIST,
+ isChecked ? ON : OFF);
}
@Override
@@ -150,17 +124,22 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
}
@Override
- public String getPreferenceKey() {
- return mAssistGesturePrefKey;
+ public CharSequence getSummary() {
+ boolean isEnabled = isAssistGestureEnabled() && mFeatureProvider.isSupported(mContext);
+ if (!mAssistOnly) {
+ isEnabled = isEnabled || isSilenceGestureEnabled();
+ }
+ return mContext.getText(
+ isEnabled ? R.string.gesture_setting_on : R.string.gesture_setting_off);
}
@Override
- protected boolean isSwitchPrefEnabled() {
- // Does nothing
- return true;
+ public boolean isChecked() {
+ return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY_ASSIST, OFF) == ON;
}
@Override
+ //TODO (b/69808376): Remove result payload
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
AssistGestureSettings.class.getName(), mAssistGesturePrefKey,
diff --git a/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java b/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
index 049ee18067..aebda18129 100644
--- a/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
@@ -23,13 +23,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
-import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.search.ResultPayload;
-import com.android.settingslib.core.lifecycle.Lifecycle;
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
@@ -43,8 +41,8 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
- public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle, String key) {
- super(context, lifecycle);
+ public DoubleTapPowerPreferenceController(Context context, String key) {
+ super(context, key);
mDoubleTapPowerKey = key;
}
@@ -59,8 +57,8 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
}
@Override
- public boolean isAvailable() {
- return isGestureAvailable(mContext);
+ public int getAvailabilityStatus() {
+ return isGestureAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -69,25 +67,20 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
}
@Override
- public String getPreferenceKey() {
- return mDoubleTapPowerKey;
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- boolean enabled = (boolean) newValue;
- Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
- return true;
- }
-
- @Override
- protected boolean isSwitchPrefEnabled() {
+ public boolean isChecked() {
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
SECURE_KEY, ON);
return cameraDisabled == ON;
}
@Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
+ isChecked ? ON : OFF);
+ }
+
+ @Override
+ //TODO (b/69808376): Remove result payload
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey,
diff --git a/src/com/android/settings/gestures/DoubleTapPowerSettings.java b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
index 4d8098651a..8afd2c1f64 100644
--- a/src/com/android/settings/gestures/DoubleTapPowerSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
@@ -26,11 +26,8 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,7 +35,6 @@ import java.util.List;
public class DoubleTapPowerSettings extends DashboardFragment {
private static final String TAG = "DoubleTapPower";
- private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_tap_power_suggestion_complete";
@@ -67,19 +63,6 @@ public class DoubleTapPowerSettings extends DashboardFragment {
return R.xml.double_tap_power_settings;
}
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getLifecycle());
- }
-
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- Lifecycle lifecycle) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle,
- KEY_DOUBLE_TAP_POWER));
- return controllers;
- }
-
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -89,11 +72,5 @@ public class DoubleTapPowerSettings extends DashboardFragment {
sir.xmlResId = R.xml.double_tap_power_settings;
return Arrays.asList(sir);
}
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null /* lifecycle */);
- }
};
}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
index aa08e6f21d..00fb95633d 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
@@ -20,6 +20,7 @@ import android.annotation.UserIdInt;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.UserHandle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.annotation.VisibleForTesting;
@@ -29,7 +30,6 @@ import com.android.settings.R;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.search.ResultPayload;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import static android.provider.Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP;
@@ -43,18 +43,21 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
private final String SECURE_KEY = DOZE_PULSE_ON_DOUBLE_TAP;
- private final AmbientDisplayConfiguration mAmbientConfig;
+ private AmbientDisplayConfiguration mAmbientConfig;
@UserIdInt
private final int mUserId;
- public DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle,
- AmbientDisplayConfiguration config, @UserIdInt int userId, String key) {
- super(context, lifecycle);
- mAmbientConfig = config;
- mUserId = userId;
+ public DoubleTapScreenPreferenceController(Context context, String key) {
+ super(context, key);
+ mUserId = UserHandle.myUserId();
mDoubleTapScreenPrefKey = key;
}
+ public DoubleTapScreenPreferenceController setConfig(AmbientDisplayConfiguration config) {
+ mAmbientConfig = config;
+ return this;
+ }
+
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
return isSuggestionComplete(new AmbientDisplayConfiguration(context), prefs);
}
@@ -67,20 +70,17 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
}
@Override
- public boolean isAvailable() {
- return mAmbientConfig.pulseOnDoubleTapAvailable();
- }
-
- @Override
- public String getPreferenceKey() {
- return mDoubleTapScreenPrefKey;
+ public int getAvailabilityStatus() {
+ if (mAmbientConfig == null) {
+ mAmbientConfig = new AmbientDisplayConfiguration(mContext);
+ }
+ return mAmbientConfig.pulseOnDoubleTapAvailable() ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean enabled = (boolean) newValue;
- Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
- return true;
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
+ isChecked ? ON : OFF);
}
@Override
@@ -89,11 +89,12 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
}
@Override
- protected boolean isSwitchPrefEnabled() {
+ public boolean isChecked() {
return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
}
@Override
+ //TODO (b/69808376): Remove result payload
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey,
diff --git a/src/com/android/settings/gestures/DoubleTapScreenSettings.java b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
index 8ea3ed56a6..fcea8e4062 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
@@ -28,8 +28,6 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
@@ -40,7 +38,6 @@ import java.util.List;
public class DoubleTapScreenSettings extends DashboardFragment {
private static final String TAG = "DoubleTapScreen";
- private static final String KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_tap_screen_suggestion_complete";
@@ -52,6 +49,9 @@ public class DoubleTapScreenSettings extends DashboardFragment {
.getSuggestionFeatureProvider(context);
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
+
+ use(DoubleTapScreenPreferenceController.class)
+ .setConfig(new AmbientDisplayConfiguration(context));
}
@Override
@@ -74,20 +74,6 @@ public class DoubleTapScreenSettings extends DashboardFragment {
return R.string.help_url_double_tap_screen;
}
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getLifecycle());
- }
-
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- Lifecycle lifecycle) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle,
- new AmbientDisplayConfiguration(context), UserHandle.myUserId(),
- KEY_DOUBLE_TAP_SCREEN));
- return controllers;
- }
-
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -97,11 +83,5 @@ public class DoubleTapScreenSettings extends DashboardFragment {
sir.xmlResId = R.xml.double_tap_screen_settings;
return Arrays.asList(sir);
}
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null /* lifecycle */);
- }
};
}
diff --git a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
index ac51959ea3..145a06c55f 100644
--- a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
+++ b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
@@ -26,11 +26,8 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,7 +35,6 @@ import java.util.List;
public class DoubleTwistGestureSettings extends DashboardFragment {
private static final String TAG = "DoubleTwistGesture";
- private static final String KEY_DOUBLE_TWIST = "gesture_double_twist";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_twist_suggestion_complete";
@@ -67,18 +63,6 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
return R.xml.double_twist_gesture_settings;
}
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getLifecycle());
- }
-
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- Lifecycle lifecycle) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST));
- return controllers;
- }
-
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -88,11 +72,6 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
sir.xmlResId = R.xml.double_twist_gesture_settings;
return Arrays.asList(sir);
}
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, null /* lifecycle */);
- }
};
}
diff --git a/src/com/android/settings/gestures/DoubleTwistPreferenceController.java b/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
index 922f74b907..f819508a55 100644
--- a/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
@@ -25,12 +25,10 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
-import android.support.v7.preference.Preference;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settingslib.core.lifecycle.Lifecycle;
public class DoubleTwistPreferenceController extends GesturePreferenceController {
@@ -41,8 +39,8 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
private final String mDoubleTwistPrefKey;
private final UserManager mUserManager;
- public DoubleTwistPreferenceController(Context context, Lifecycle lifecycle, String key) {
- super(context, lifecycle);
+ public DoubleTwistPreferenceController(Context context, String key) {
+ super(context, key);
mDoubleTwistPrefKey = key;
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
}
@@ -69,8 +67,8 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
}
@Override
- public boolean isAvailable() {
- return isGestureAvailable(mContext);
+ public int getAvailabilityStatus() {
+ return isGestureAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -84,9 +82,8 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final int enabled = (boolean) newValue ? ON : OFF;
- setDoubleTwistPreference(mContext, mUserManager, enabled);
+ public boolean setChecked(boolean isChecked) {
+ setDoubleTwistPreference(mContext, mUserManager, isChecked ? ON : OFF);
return true;
}
@@ -97,12 +94,13 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
final int managedProfileUserId = getManagedProfileId(userManager);
if (managedProfileUserId != UserHandle.USER_NULL) {
Settings.Secure.putIntForUser(context.getContentResolver(),
- Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled, managedProfileUserId);
+ Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled,
+ managedProfileUserId);
}
}
@Override
- protected boolean isSwitchPrefEnabled() {
+ public boolean isChecked() {
final int doubleTwistEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, ON);
return doubleTwistEnabled != 0;
diff --git a/src/com/android/settings/gestures/GesturePreferenceController.java b/src/com/android/settings/gestures/GesturePreferenceController.java
index a7f8997014..7f1100bbf6 100644
--- a/src/com/android/settings/gestures/GesturePreferenceController.java
+++ b/src/com/android/settings/gestures/GesturePreferenceController.java
@@ -24,19 +24,17 @@ import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.TogglePreferenceController;
import com.android.settings.widget.VideoPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
-public abstract class GesturePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
- LifecycleObserver, OnResume, OnPause, OnCreate, OnSaveInstanceState {
+public abstract class GesturePreferenceController extends TogglePreferenceController
+ implements Preference.OnPreferenceChangeListener,
+ LifecycleObserver, OnResume, OnPause, OnCreate, OnSaveInstanceState {
@VisibleForTesting
static final String KEY_VIDEO_PAUSED = "key_video_paused";
@@ -45,11 +43,8 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
@VisibleForTesting
boolean mVideoPaused;
- public GesturePreferenceController(Context context, Lifecycle lifecycle) {
- super(context);
- if (lifecycle != null) {
- lifecycle.addObserver(this);
- }
+ public GesturePreferenceController(Context context, String key) {
+ super(context, key);
}
@Override
@@ -63,14 +58,9 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- final boolean isEnabled = isSwitchPrefEnabled();
if (preference != null) {
- if (preference instanceof TwoStatePreference) {
- ((TwoStatePreference) preference).setChecked(isEnabled);
- } else {
- preference.setSummary(isEnabled
- ? R.string.gesture_setting_on
- : R.string.gesture_setting_off);
+ if (!(preference instanceof TwoStatePreference)) {
+ preference.setSummary(getSummary());
}
// Different meanings of "Enabled" for the Preference and Controller.
preference.setEnabled(canHandleClicks());
@@ -78,6 +68,12 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
}
@Override
+ public CharSequence getSummary() {
+ return mContext.getText(
+ isChecked() ? R.string.gesture_setting_on : R.string.gesture_setting_off);
+ }
+
+ @Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
@@ -106,8 +102,6 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
protected abstract String getVideoPrefKey();
- protected abstract boolean isSwitchPrefEnabled();
-
protected boolean canHandleClicks() {
return true;
}
diff --git a/src/com/android/settings/gestures/GestureSettings.java b/src/com/android/settings/gestures/GestureSettings.java
index fbed0f6e84..5efcc4d0a1 100644
--- a/src/com/android/settings/gestures/GestureSettings.java
+++ b/src/com/android/settings/gestures/GestureSettings.java
@@ -67,33 +67,32 @@ public class GestureSettings extends DashboardFragment {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- if (mAmbientDisplayConfig == null) {
- mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
- }
-
- return buildPreferenceControllers(context, getLifecycle(), mAmbientDisplayConfig);
+ return buildPreferenceControllers(context, getLifecycle());
}
static List<AbstractPreferenceController> buildPreferenceControllers(
- @NonNull Context context, @Nullable Lifecycle lifecycle,
- @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) {
+ @NonNull Context context, @Nullable Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle,
- KEY_ASSIST, false /* assistOnly */));
- controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle,
- KEY_SWIPE_DOWN));
- controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST));
- controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle,
- KEY_DOUBLE_TAP_POWER));
- controllers.add(new PickupGesturePreferenceController(context, lifecycle,
- ambientDisplayConfiguration, UserHandle.myUserId(), KEY_PICK_UP));
- controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle,
- ambientDisplayConfiguration, UserHandle.myUserId(), KEY_DOUBLE_TAP_SCREEN));
controllers.add(new PreventRingingPreferenceController(
context, lifecycle, UserHandle.myUserId(), KEY_PREVENT_RINGING));
return controllers;
}
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ use(AssistGestureSettingsPreferenceController.class).setAssistOnly(false);
+ use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
+ use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
+ }
+
+ private AmbientDisplayConfiguration getConfig(Context context) {
+ if (mAmbientDisplayConfig == null) {
+ mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
+ }
+ return mAmbientDisplayConfig;
+ }
+
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -107,8 +106,7 @@ public class GestureSettings extends DashboardFragment {
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
- return buildPreferenceControllers(context, null,
- new AmbientDisplayConfiguration(context));
+ return buildPreferenceControllers(context, null);
}
@Override
diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
index 1df5b900b5..e4e24d85bb 100644
--- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
+++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
@@ -19,6 +19,7 @@ package com.android.settings.gestures;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
+import android.support.annotation.NonNull;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
@@ -33,6 +34,7 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle
private List<AbstractPreferenceController> mGestureControllers;
private static final String KEY_GESTURES_SETTINGS = "gesture_settings";
+ private static final String FAKE_PREF_KEY = "fake_key_only_for_get_available";
public GesturesSettingPreferenceController(Context context) {
super(context, KEY_GESTURES_SETTINGS);
@@ -42,16 +44,38 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle
@Override
public int getAvailabilityStatus() {
if (mGestureControllers == null) {
- mGestureControllers = GestureSettings.buildPreferenceControllers(mContext,
- null /* lifecycle */, new AmbientDisplayConfiguration(mContext));
+ mGestureControllers = buildAllPreferenceControllers(mContext);
}
boolean isAvailable = false;
for (AbstractPreferenceController controller : mGestureControllers) {
isAvailable = isAvailable || controller.isAvailable();
}
- return isAvailable
- ? AVAILABLE
- : DISABLED_UNSUPPORTED;
+ return isAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ /**
+ * Get all controllers for their availability status when doing getAvailabilityStatus.
+ * Do not use this method to add controllers into fragment, most of below controllers already
+ * convert to TogglePreferenceController, please register them in xml.
+ * The key is fake because those controllers won't be use to control preference.
+ */
+ private static List<AbstractPreferenceController> buildAllPreferenceControllers(
+ @NonNull Context context) {
+ final AmbientDisplayConfiguration ambientDisplayConfiguration =
+ new AmbientDisplayConfiguration(context);
+ final List<AbstractPreferenceController> controllers =
+ GestureSettings.buildPreferenceControllers(context, null);
+
+ controllers.add(new AssistGestureSettingsPreferenceController(context, FAKE_PREF_KEY)
+ .setAssistOnly(false));
+ controllers.add(new SwipeToNotificationPreferenceController(context, FAKE_PREF_KEY));
+ controllers.add(new DoubleTwistPreferenceController(context, FAKE_PREF_KEY));
+ controllers.add(new DoubleTapPowerPreferenceController(context, FAKE_PREF_KEY));
+ controllers.add(new PickupGesturePreferenceController(context, FAKE_PREF_KEY)
+ .setConfig(ambientDisplayConfiguration));
+ controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY)
+ .setConfig(ambientDisplayConfiguration));
+ return controllers;
}
@Override
diff --git a/src/com/android/settings/gestures/PickupGesturePreferenceController.java b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
index 02107c123d..46318f5710 100644
--- a/src/com/android/settings/gestures/PickupGesturePreferenceController.java
+++ b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
@@ -22,8 +22,8 @@ import android.annotation.UserIdInt;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.UserHandle;
import android.provider.Settings;
-import android.support.v7.preference.Preference;
import android.support.annotation.VisibleForTesting;
import com.android.internal.hardware.AmbientDisplayConfiguration;
@@ -31,7 +31,6 @@ import com.android.settings.R;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.search.ResultPayload;
-import com.android.settingslib.core.lifecycle.Lifecycle;
public class PickupGesturePreferenceController extends GesturePreferenceController {
@@ -43,18 +42,21 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
private final String SECURE_KEY = DOZE_PULSE_ON_PICK_UP;
- private final AmbientDisplayConfiguration mAmbientConfig;
+ private AmbientDisplayConfiguration mAmbientConfig;
@UserIdInt
private final int mUserId;
- public PickupGesturePreferenceController(Context context, Lifecycle lifecycle,
- AmbientDisplayConfiguration config, @UserIdInt int userId, String key) {
- super(context, lifecycle);
- mAmbientConfig = config;
- mUserId = userId;
+ public PickupGesturePreferenceController(Context context, String key) {
+ super(context, key);
+ mUserId = UserHandle.myUserId();
mPickUpPrefKey = key;
}
+ public PickupGesturePreferenceController setConfig(AmbientDisplayConfiguration config) {
+ mAmbientConfig = config;
+ return this;
+ }
+
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context);
return prefs.getBoolean(PickupGestureSettings.PREF_KEY_SUGGESTION_COMPLETE, false)
@@ -62,8 +64,11 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
}
@Override
- public boolean isAvailable() {
- return mAmbientConfig.pulseOnPickupAvailable();
+ public int getAvailabilityStatus() {
+ if (mAmbientConfig == null) {
+ mAmbientConfig = new AmbientDisplayConfiguration(mContext);
+ }
+ return mAmbientConfig.pulseOnPickupAvailable() ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -72,7 +77,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
}
@Override
- protected boolean isSwitchPrefEnabled() {
+ public boolean isChecked() {
return mAmbientConfig.pulseOnPickupEnabled(mUserId);
}
@@ -82,11 +87,9 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean enabled = (boolean) newValue;
- Settings.Secure.putInt(mContext.getContentResolver(),
- SECURE_KEY, enabled ? ON : OFF);
- return true;
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
+ isChecked ? ON : OFF);
}
@Override
diff --git a/src/com/android/settings/gestures/PickupGestureSettings.java b/src/com/android/settings/gestures/PickupGestureSettings.java
index 4576b79043..05aba4e99e 100644
--- a/src/com/android/settings/gestures/PickupGestureSettings.java
+++ b/src/com/android/settings/gestures/PickupGestureSettings.java
@@ -18,7 +18,6 @@ package com.android.settings.gestures;
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import com.android.internal.hardware.AmbientDisplayConfiguration;
@@ -28,11 +27,8 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -40,7 +36,6 @@ import java.util.List;
public class PickupGestureSettings extends DashboardFragment {
private static final String TAG = "PickupGestureSettings";
- private static final String KEY_PICK_UP = "gesture_pick_up";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_pickup_gesture_suggestion_complete";
@@ -52,6 +47,9 @@ public class PickupGestureSettings extends DashboardFragment {
.getSuggestionFeatureProvider(context);
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
+
+ use(PickupGesturePreferenceController.class)
+ .setConfig(new AmbientDisplayConfiguration(context));
}
@Override
@@ -74,19 +72,6 @@ public class PickupGestureSettings extends DashboardFragment {
return R.string.help_url_pickup_gesture;
}
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getLifecycle());
- }
-
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- Lifecycle lifecycle) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new PickupGesturePreferenceController(context, lifecycle,
- new AmbientDisplayConfiguration(context), UserHandle.myUserId(), KEY_PICK_UP));
- return controllers;
- }
-
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -96,12 +81,6 @@ public class PickupGestureSettings extends DashboardFragment {
sir.xmlResId = R.xml.pick_up_gesture_settings;
return Arrays.asList(sir);
}
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null /* lifecycle */);
- }
};
}
diff --git a/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java b/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
index b50968f27e..d755d72778 100644
--- a/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
+++ b/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
@@ -21,10 +21,8 @@ import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
-import android.support.v7.preference.Preference;
import com.android.settings.Utils;
-import com.android.settingslib.core.lifecycle.Lifecycle;
public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
@@ -32,14 +30,11 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
private static final int OFF = 0;
private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
- private final String mSwipeDownFingerPrefKey;
private static final String SECURE_KEY = SYSTEM_NAVIGATION_KEYS_ENABLED;
- public SwipeToNotificationPreferenceController(Context context, Lifecycle lifecycle,
- String key) {
- super(context, lifecycle);
- mSwipeDownFingerPrefKey = key;
+ public SwipeToNotificationPreferenceController(Context context, String key) {
+ super(context, key);
}
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
@@ -55,28 +50,23 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
}
@Override
- public String getPreferenceKey() {
- return mSwipeDownFingerPrefKey;
- }
-
- @Override
protected String getVideoPrefKey() {
return PREF_KEY_VIDEO;
}
@Override
- public boolean isAvailable() {
- return SwipeToNotificationPreferenceController.isAvailable(mContext);
+ public int getAvailabilityStatus() {
+ return isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- setSwipeToNotification(mContext, (boolean) newValue);
+ public boolean setChecked(boolean isChecked) {
+ setSwipeToNotification(mContext, isChecked);
return true;
}
@Override
- protected boolean isSwitchPrefEnabled() {
+ public boolean isChecked() {
return isSwipeToNotificationOn(mContext);
}
diff --git a/src/com/android/settings/gestures/SwipeToNotificationSettings.java b/src/com/android/settings/gestures/SwipeToNotificationSettings.java
index 3ab3389821..7ae8644b22 100644
--- a/src/com/android/settings/gestures/SwipeToNotificationSettings.java
+++ b/src/com/android/settings/gestures/SwipeToNotificationSettings.java
@@ -26,11 +26,8 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -39,8 +36,6 @@ public class SwipeToNotificationSettings extends DashboardFragment {
private static final String TAG = "SwipeToNotifSettings";
- private static final String KEY = "gesture_swipe_down_fingerprint";
-
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_swipe_to_notification_suggestion_complete";
@@ -68,18 +63,6 @@ public class SwipeToNotificationSettings extends DashboardFragment {
return R.xml.swipe_to_notification_settings;
}
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getLifecycle());
- }
-
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- Lifecycle lifecycle) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY));
- return controllers;
- }
-
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -89,11 +72,5 @@ public class SwipeToNotificationSettings extends DashboardFragment {
sir.xmlResId = R.xml.swipe_to_notification_settings;
return Arrays.asList(sir);
}
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null /* lifecycle */);
- }
};
}
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 34678581b8..a768ab44e7 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -108,8 +108,6 @@ public class ConfigureNotificationSettings extends DashboardFragment {
}
controllers.add(new RecentNotifyingAppsPreferenceController(
context, new NotificationBackend(), app, host));
- controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle,
- KEY_SWIPE_DOWN));
controllers.add(badgeController);
controllers.add(pulseController);
controllers.add(lockScreenNotificationController);
diff --git a/tests/robotests/assets/grandfather_slice_controller_not_in_xml b/tests/robotests/assets/grandfather_slice_controller_not_in_xml
index ae1c86a7b3..5a0999739d 100644
--- a/tests/robotests/assets/grandfather_slice_controller_not_in_xml
+++ b/tests/robotests/assets/grandfather_slice_controller_not_in_xml
@@ -1,2 +1,2 @@
com.android.settings.testutils.FakeToggleController
-com.android.settings.testutils.FakeSliderController
+com.android.settings.testutils.FakeSliderController \ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/display/AmbientDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/display/AmbientDisplaySettingsTest.java
index 2f6125294c..4361b7c6f3 100644
--- a/tests/robotests/src/com/android/settings/display/AmbientDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/display/AmbientDisplaySettingsTest.java
@@ -24,6 +24,8 @@ import static org.mockito.Mockito.verify;
import android.content.Context;
+import com.android.settings.gestures.DoubleTapScreenPreferenceController;
+import com.android.settings.gestures.PickupGesturePreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -48,18 +50,48 @@ public class AmbientDisplaySettingsTest {
}
@Test
- public void onAttach_shouldInvokeSetters() {
- final AmbientDisplayAlwaysOnPreferenceController controller = mock(
- AmbientDisplayAlwaysOnPreferenceController.class);
+ public void onAttach_alwaysOn_shouldInvokeSetters() {
+ final AmbientDisplayAlwaysOnPreferenceController controller = spy(
+ new AmbientDisplayAlwaysOnPreferenceController(mContext, "key"));
doReturn(controller).when(mTestFragment).use(
AmbientDisplayAlwaysOnPreferenceController.class);
mTestFragment.onAttach(mContext);
-
verify(controller).setConfig(any());
verify(controller).setCallback(any());
}
+ @Test
+ public void onAttach_notifications_shouldInvokeSetters() {
+ final AmbientDisplayNotificationsPreferenceController controller = spy(
+ new AmbientDisplayNotificationsPreferenceController(mContext, "key"));
+ doReturn(controller).when(mTestFragment).use(
+ AmbientDisplayNotificationsPreferenceController.class);
+
+ mTestFragment.onAttach(mContext);
+ verify(controller).setConfig(any());
+ }
+
+ @Test
+ public void onAttach_doubleTap_shouldInvokeSetters() {
+ final DoubleTapScreenPreferenceController controller = spy(
+ new DoubleTapScreenPreferenceController(mContext, "key"));
+ doReturn(controller).when(mTestFragment).use(DoubleTapScreenPreferenceController.class);
+
+ mTestFragment.onAttach(mContext);
+ verify(controller).setConfig(any());
+ }
+
+ @Test
+ public void onAttach_pickUp_shouldInvokeSetters() {
+ final PickupGesturePreferenceController controller = spy(
+ new PickupGesturePreferenceController(mContext, "key"));
+ doReturn(controller).when(mTestFragment).use(PickupGesturePreferenceController.class);
+
+ mTestFragment.onAttach(mContext);
+ verify(controller).setConfig(any());
+ }
+
public static class TestFragment extends AmbientDisplaySettings {
@Override
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
index 3b5facd4fd..bd96f0f4ba 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
@@ -55,8 +55,8 @@ public class AssistGestureSettingsPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
- mController =
- new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST, false);
+ mController = new AssistGestureSettingsPreferenceController(mContext, KEY_ASSIST);
+ mController.setAssistOnly(false);
}
@Test
@@ -76,8 +76,8 @@ public class AssistGestureSettingsPreferenceControllerTest {
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
AssistGestureSettingsPreferenceController controller =
- new AssistGestureSettingsPreferenceController(context, null /* lifecycle */,
- KEY_ASSIST, false /* assistOnly */);
+ new AssistGestureSettingsPreferenceController(context, KEY_ASSIST);
+ controller.setAssistOnly(false);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
index e8c036e1b8..d681bc36f2 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
@@ -56,7 +56,7 @@ public class DoubleTapPowerPreferenceControllerTest {
public void setUp() {
mContext = RuntimeEnvironment.application;
mContentResolver = mContext.getContentResolver();
- mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
+ mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
}
@After
@@ -81,28 +81,27 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
- public void testSwitchEnabled_configIsNotSet_shouldReturnTrue() {
+ public void testIsChecked_configIsNotSet_shouldReturnTrue() {
// Set the setting to be enabled.
Settings.System.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
- mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
+ mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
- assertThat(mController.isSwitchPrefEnabled()).isTrue();
+ assertThat(mController.isChecked()).isTrue();
}
@Test
- public void testSwitchEnabled_configIsSet_shouldReturnFalse() {
+ public void testIsChecked_configIsSet_shouldReturnFalse() {
// Set the setting to be disabled.
Settings.System.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
- mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
+ mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
- assertThat(mController.isSwitchPrefEnabled()).isFalse();
+ assertThat(mController.isChecked()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
DoubleTapPowerPreferenceController controller =
- new DoubleTapPowerPreferenceController(mContext, null /* lifecycle */,
- KEY_DOUBLE_TAP_POWER);
+ new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
index 344156c2e6..cc9347ddff 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
@@ -56,8 +56,8 @@ public class DoubleTapScreenPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new DoubleTapScreenPreferenceController(
- mContext, null, mAmbientDisplayConfiguration, 0, KEY_DOUBLE_TAP_SCREEN);
+ mController = new DoubleTapScreenPreferenceController(mContext, KEY_DOUBLE_TAP_SCREEN);
+ mController.setConfig(mAmbientDisplayConfiguration);
}
@Test
@@ -75,26 +75,26 @@ public class DoubleTapScreenPreferenceControllerTest {
}
@Test
- public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
+ public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true);
- assertThat(mController.isSwitchPrefEnabled()).isTrue();
+ assertThat(mController.isChecked()).isTrue();
}
@Test
- public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
+ public void testIsChecked_configIsNotSet_shouldReturnFalse() {
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
- assertThat(mController.isSwitchPrefEnabled()).isFalse();
+ assertThat(mController.isChecked()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
DoubleTapScreenPreferenceController controller =
- new DoubleTapScreenPreferenceController(context, null /* lifecycle */,
- mAmbientDisplayConfiguration, 0 /* userid */, KEY_DOUBLE_TAP_SCREEN);
+ new DoubleTapScreenPreferenceController(context, KEY_DOUBLE_TAP_SCREEN);
+ controller.setConfig(mAmbientDisplayConfiguration);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
index d633ebe427..901da37086 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
@@ -61,7 +61,7 @@ public class DoubleTwistPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
- mController = new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST);
+ mController = new DoubleTwistPreferenceController(mContext, KEY_DOUBLE_TWIST);
}
@After
@@ -120,7 +120,7 @@ public class DoubleTwistPreferenceControllerTest {
Settings.Secure.putIntForUser(
null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
DoubleTwistPreferenceController controller =
- spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
+ spy(new DoubleTwistPreferenceController(mContext, KEY_DOUBLE_TWIST));
ShadowDoubleTwistPreferenceController.setManagedProfileId(managedId);
// enable the gesture
@@ -135,24 +135,24 @@ public class DoubleTwistPreferenceControllerTest {
}
@Test
- public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
+ public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
- mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
+ mController = new DoubleTwistPreferenceController(context, KEY_DOUBLE_TWIST);
- assertThat(mController.isSwitchPrefEnabled()).isTrue();
+ assertThat(mController.isChecked()).isTrue();
}
@Test
- public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
+ public void testIsChecked_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
- mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
+ mController = new DoubleTwistPreferenceController(context, KEY_DOUBLE_TWIST);
- assertThat(mController.isSwitchPrefEnabled()).isFalse();
+ assertThat(mController.isChecked()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java
index 361c95da37..d4b77060d3 100644
--- a/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java
@@ -17,6 +17,9 @@
package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
+
+import static junit.framework.Assert.assertEquals;
+
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -31,7 +34,6 @@ import android.support.v7.preference.TwoStatePreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.VideoPreference;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -49,7 +51,6 @@ public class GesturePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Lifecycle mLifecycle;
private TestPrefController mController;
private Preference mPreference;
@@ -57,7 +58,7 @@ public class GesturePreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new TestPrefController(mContext, mLifecycle);
+ mController = new TestPrefController(mContext, "testKey");
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
@@ -187,7 +188,8 @@ public class GesturePreferenceControllerTest {
mController.updateState(preference);
// Verify summary is set to off (as setting is disabled).
- verify(preference).setSummary(com.android.settings.R.string.gesture_setting_off);
+ assertThat(preference.getSummary()).isEqualTo(
+ mContext.getString(com.android.settings.R.string.gesture_setting_off));
}
private class TestPrefController extends GesturePreferenceController {
@@ -196,18 +198,13 @@ public class GesturePreferenceControllerTest {
boolean mIsPrefEnabled;
private TestPrefController(Context context,
- Lifecycle lifecycle) {
- super(context, lifecycle);
- }
-
- @Override
- public boolean isAvailable() {
- return mIsPrefAvailable;
+ String key) {
+ super(context, key);
}
@Override
- public String getPreferenceKey() {
- return "testKey";
+ public int getAvailabilityStatus() {
+ return mIsPrefAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -216,12 +213,12 @@ public class GesturePreferenceControllerTest {
}
@Override
- protected boolean isSwitchPrefEnabled() {
+ public boolean isChecked() {
return mIsPrefEnabled;
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
+ public boolean setChecked(boolean isChecked) {
return false;
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
index 09e9ff7ee8..6aa451ce12 100644
--- a/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
@@ -57,8 +57,8 @@ public class PickupGesturePreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new PickupGesturePreferenceController(
- mContext, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
+ mController = new PickupGesturePreferenceController(mContext, KEY_PICK_UP);
+ mController.setConfig(mAmbientDisplayConfiguration);
}
@Test
@@ -76,19 +76,19 @@ public class PickupGesturePreferenceControllerTest {
}
@Test
- public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
+ public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true);
- assertThat(mController.isSwitchPrefEnabled()).isTrue();
+ assertThat(mController.isChecked()).isTrue();
}
@Test
- public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
+ public void testIsChecked_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
- assertThat(mController.isSwitchPrefEnabled()).isFalse();
+ assertThat(mController.isChecked()).isFalse();
}
@Test
@@ -111,8 +111,8 @@ public class PickupGesturePreferenceControllerTest {
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
PickupGesturePreferenceController controller =
- new PickupGesturePreferenceController(
- context, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
+ new PickupGesturePreferenceController(context, KEY_PICK_UP);
+ controller.setConfig(mAmbientDisplayConfiguration);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
index 69226b6f46..c164fbf737 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
@@ -53,7 +53,7 @@ public class SwipeToNotificationPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
+ mController = new SwipeToNotificationPreferenceController(mContext, KEY_SWIPE_DOWN);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
.thenReturn(mFingerprintManager);
@@ -93,27 +93,27 @@ public class SwipeToNotificationPreferenceControllerTest {
}
@Test
- public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
+ public void testIsChecked_configIsSet_shouldReturnTrue() {
stubFingerprintSupported(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
// Set the setting to be enabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1);
- mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
+ mController = new SwipeToNotificationPreferenceController(context, KEY_SWIPE_DOWN);
- assertThat(mController.isSwitchPrefEnabled()).isTrue();
+ assertThat(mController.isChecked()).isTrue();
}
@Test
- public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
+ public void testIsChecked_configIsNotSet_shouldReturnFalse() {
stubFingerprintSupported(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
// Set the setting to be disabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
- mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
+ mController = new SwipeToNotificationPreferenceController(context, KEY_SWIPE_DOWN);
- assertThat(mController.isSwitchPrefEnabled()).isFalse();
+ assertThat(mController.isChecked()).isFalse();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
index 78f191723f..78e8603655 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
@@ -54,14 +54,6 @@ public class SwipeToNotificationSettingsTest {
}
@Test
- public void testGetPreferenceControllers_shouldAllBeCreated() {
- final List<AbstractPreferenceController> controllers =
- mFragment.createPreferenceControllers(mContext);
-
- assertThat(controllers.isEmpty()).isFalse();
- }
-
- @Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
SwipeToNotificationSettings.SEARCH_INDEX_DATA_PROVIDER