OSDN Git Service

Add video to each gesture preference screen.
authorFan Zhang <zhfan@google.com>
Wed, 9 Nov 2016 19:35:10 +0000 (11:35 -0800)
committerFan Zhang <zhfan@google.com>
Thu, 10 Nov 2016 23:24:45 +0000 (15:24 -0800)
- Refactor GesturePreference to a generic VideoPreference.
- The old video_preference.xml is only for magnification video, so
  renamed.
- And use VideoPreference in gesture setting pages.
- Refactor common logic into GesturePreferenceController.

Bug: 32637613
Test: RunSettingsRoboTests

Change-Id: I58580b01a32873cb32c5dc5bf2ec021d5b1400cc

31 files changed:
res/layout/magnification_video_preference.xml [new file with mode: 0644]
res/layout/video_preference.xml
res/values/attrs.xml
res/xml/double_tap_power_settings.xml
res/xml/double_tap_screen_settings.xml
res/xml/double_twist_gesture_settings.xml
res/xml/pick_up_gesture_settings.xml
res/xml/swipe_to_notification_settings.xml
src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java
src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
src/com/android/settings/gestures/DoubleTapPowerSettings.java
src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
src/com/android/settings/gestures/DoubleTapScreenSettings.java
src/com/android/settings/gestures/DoubleTwistGestureSettings.java
src/com/android/settings/gestures/DoubleTwistPreferenceController.java
src/com/android/settings/gestures/GesturePreferenceController.java [new file with mode: 0644]
src/com/android/settings/gestures/GestureSettings.java
src/com/android/settings/gestures/PickupGesturePreferenceController.java
src/com/android/settings/gestures/PickupGestureSettings.java
src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
src/com/android/settings/gestures/SwipeToNotificationSettings.java
src/com/android/settings/inputmethod/InputAndGestureSettings.java
src/com/android/settings/notification/ConfigureNotificationSettings.java
src/com/android/settings/widget/VideoPreference.java [new file with mode: 0644]
tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java [new file with mode: 0644]
tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java
tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java

diff --git a/res/layout/magnification_video_preference.xml b/res/layout/magnification_video_preference.xml
new file mode 100644 (file)
index 0000000..fe7f26f
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:id="@+id/video_background"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:src="@drawable/accessibility_screen_magnification_background"
+        android:scaleType="fitXY"
+        android:adjustViewBounds="true"
+        android:importantForAccessibility="noHideDescendants" />
+
+    <VideoView
+        android:id="@+id/video"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignTop="@id/video_background"
+        android:layout_centerHorizontal="true"
+        android:importantForAccessibility="noHideDescendants" />
+
+</RelativeLayout>
\ No newline at end of file
index fe7f26f..8b0e619 100644 (file)
@@ -1,38 +1,57 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
+<!--
+  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
+  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
+       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.
--->
-<RelativeLayout
+  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.
+  -->
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/gesture_animation_view"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content">
+    android:layout_height="wrap_content"
+    android:background="@color/gestures_setting_background_color"
+    android:clipToPadding="false"
+    android:gravity="center"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall"
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+    android:orientation="horizontal">
 
-    <ImageView
-        android:id="@+id/video_background"
-        android:layout_width="match_parent"
+    <com.android.settings.widget.AspectRatioFrameLayout
+        android:layout_width="240dp"
         android:layout_height="wrap_content"
-        android:src="@drawable/accessibility_screen_magnification_background"
-        android:scaleType="fitXY"
-        android:adjustViewBounds="true"
-        android:importantForAccessibility="noHideDescendants" />
-
-    <VideoView
-        android:id="@+id/video"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignTop="@id/video_background"
-        android:layout_centerHorizontal="true"
-        android:importantForAccessibility="noHideDescendants" />
+        android:padding="@dimen/gesture_animation_padding">
+
+        <TextureView
+            android:id="@+id/video_texture_view"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_gravity="center"/>
+
+        <ImageView
+            android:id="@+id/video_preview_image"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:scaleType="fitXY"/>
+
+        <ImageView
+            android:id="@+id/video_play_button"
+            android:layout_width="@dimen/gestures_play_button_size"
+            android:layout_height="@dimen/gestures_play_button_size"
+            android:src="@drawable/ic_gesture_play_button"
+            android:gravity="center"
+            android:layout_gravity="center"/>
+
+    </com.android.settings.widget.AspectRatioFrameLayout>
+
+</LinearLayout>
 
-</RelativeLayout>
\ No newline at end of file
index 6df41d2..9a74fa5 100644 (file)
         <attr name="preview" format="reference" />
     </declare-styleable>
 
+    <declare-styleable name="VideoPreference">
+        <attr name="animation" format="reference" />
+        <attr name="preview" format="reference" />
+    </declare-styleable>
+
     <!-- For AspectRatioFrameLayout -->
     <declare-styleable name="AspectRatioFrameLayout">
         <attr name="aspectRatio" format="float" />
index b8835ea..3376f3c 100644 (file)
   limitations under the License.
   -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_double_tap_power_video"
+        app:animation="@raw/gesture_double_tap"
+        app:preview="@drawable/gesture_double_tap"/>
 
     <SwitchPreference
         android:key="gesture_double_tap_power"
index e1ba7c9..a76a487 100644 (file)
   limitations under the License.
   -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_double_tap_screen_video"
+        app:animation="@raw/gesture_ambient_tap"
+        app:preview="@drawable/gesture_ambient_tap"/>
 
     <SwitchPreference
         android:key="gesture_double_tap_screen"
index 2cf9d5e..e8d0abe 100644 (file)
   limitations under the License.
   -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_double_twist_video"
+        app:animation="@raw/gesture_twist"
+        app:preview="@drawable/gesture_twist"/>
 
     <SwitchPreference
         android:key="gesture_double_twist"
index e335a83..4ef81a2 100644 (file)
   limitations under the License.
   -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_pick_up_video"
+        app:animation="@raw/gesture_ambient_lift"
+        app:preview="@drawable/gesture_ambient_lift"/>
 
     <SwitchPreference
         android:key="gesture_pick_up"
index 3be44bd..a4dedfb 100644 (file)
   limitations under the License.
   -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_swipe_down_fingerprint_video"
+        app:animation="@raw/gesture_fingerprint_swipe"
+        app:preview="@drawable/gesture_fingerprint_swipe"/>
 
     <SwitchPreference
         android:key="gesture_swipe_down_fingerprint"
index 7b7e43f..8f13e08 100644 (file)
@@ -120,7 +120,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePr
         mVideoPreference = new VideoPreference(getPrefContext());
         mVideoPreference.setSelectable(false);
         mVideoPreference.setPersistent(false);
-        mVideoPreference.setLayoutResource(R.layout.video_preference);
+        mVideoPreference.setLayoutResource(R.layout.magnification_video_preference);
 
         final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
         preferenceScreen.setOrderingAsAdded(false);
index dbce755..f55b183 100644 (file)
@@ -62,6 +62,13 @@ public abstract class ObservablePreferenceFragment extends PreferenceFragment {
 
     @CallSuper
     @Override
+    public void onStop() {
+        mLifecycle.onStop();
+        super.onStop();
+    }
+
+    @CallSuper
+    @Override
     public void onResume() {
         mLifecycle.onResume();
         super.onResume();
index 7838ae7..cb36879 100644 (file)
@@ -19,17 +19,16 @@ 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;
+import com.android.settings.core.lifecycle.Lifecycle;
 
-public class DoubleTapPowerPreferenceController extends PreferenceController
-        implements Preference.OnPreferenceChangeListener {
+public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
 
+    private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
     private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
 
-    public DoubleTapPowerPreferenceController(Context context) {
-        super(context);
+    public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
     }
 
     @Override
@@ -39,8 +38,8 @@ public class DoubleTapPowerPreferenceController extends PreferenceController
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        return false;
+    protected String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
     }
 
     @Override
@@ -49,20 +48,6 @@ public class DoubleTapPowerPreferenceController extends PreferenceController
     }
 
     @Override
-    public void updateState(Preference preference) {
-        final boolean isEnabled = isDoubleTapEnabled();
-        if (preference != null) {
-            if (preference instanceof TwoStatePreference) {
-                ((TwoStatePreference) preference).setChecked(isEnabled);
-            } else {
-                preference.setSummary(isEnabled
-                        ? com.android.settings.R.string.gesture_setting_on
-                        : com.android.settings.R.string.gesture_setting_off);
-            }
-        }
-    }
-
-    @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         boolean enabled = (boolean) newValue;
         Settings.Secure.putInt(mContext.getContentResolver(),
@@ -70,7 +55,8 @@ public class DoubleTapPowerPreferenceController extends PreferenceController
         return true;
     }
 
-    private boolean isDoubleTapEnabled() {
+    @Override
+    protected boolean isSwitchPrefEnabled() {
         final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
                 Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
         return cameraDisabled == 0;
index 8244165..521c665 100644 (file)
@@ -52,7 +52,7 @@ public class DoubleTapPowerSettings extends DashboardFragment {
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
         final List<PreferenceController> controllers = new ArrayList<>();
-        controllers.add(new DoubleTapPowerPreferenceController(context));
+        controllers.add(new DoubleTapPowerPreferenceController(context, getLifecycle()));
         return controllers;
     }
 }
index be1c53f..722d66a 100644 (file)
@@ -20,23 +20,22 @@ import android.annotation.UserIdInt;
 import android.content.Context;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
-import android.support.v7.preference.TwoStatePreference;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 
-public class DoubleTapScreenPreferenceController extends PreferenceController
-        implements Preference.OnPreferenceChangeListener {
+public class DoubleTapScreenPreferenceController extends GesturePreferenceController {
 
+    private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video";
     private static final String PREF_KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
 
     private final AmbientDisplayConfiguration mAmbientConfig;
     @UserIdInt
     private final int mUserId;
 
-    public DoubleTapScreenPreferenceController(Context context, AmbientDisplayConfiguration config,
-            @UserIdInt int userId) {
-        super(context);
+    public DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle,
+            AmbientDisplayConfiguration config, @UserIdInt int userId) {
+        super(context, lifecycle);
         mAmbientConfig = config;
         mUserId = userId;
     }
@@ -47,25 +46,6 @@ public class DoubleTapScreenPreferenceController extends PreferenceController
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        return false;
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        final boolean isEnabled = mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
-        if (preference != null) {
-            if (preference instanceof TwoStatePreference) {
-                ((TwoStatePreference) preference).setChecked(isEnabled);
-            } else {
-                preference.setSummary(isEnabled
-                        ? com.android.settings.R.string.gesture_setting_on
-                        : com.android.settings.R.string.gesture_setting_off);
-            }
-        }
-    }
-
-    @Override
     public String getPreferenceKey() {
         return PREF_KEY_DOUBLE_TAP_SCREEN;
     }
@@ -77,4 +57,14 @@ public class DoubleTapScreenPreferenceController extends PreferenceController
                 Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
         return true;
     }
+
+    @Override
+    protected String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
+    }
+
+    @Override
+    protected boolean isSwitchPrefEnabled() {
+        return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
+    }
 }
index 12e3b64..3c53947 100644 (file)
@@ -54,8 +54,8 @@ public class DoubleTapScreenSettings extends DashboardFragment {
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
         final List<PreferenceController> controllers = new ArrayList<>();
-        controllers.add(new DoubleTapScreenPreferenceController(
-                context, new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
+        controllers.add(new DoubleTapScreenPreferenceController(context, getLifecycle(),
+                new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
         return controllers;
     }
 }
index 4f8d2de..07b40bb 100644 (file)
@@ -52,7 +52,7 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
         final List<PreferenceController> controllers = new ArrayList<>();
-        controllers.add(new DoubleTwistPreferenceController(context));
+        controllers.add(new DoubleTwistPreferenceController(context, getLifecycle()));
         return controllers;
     }
 }
index 071255b..5192484 100644 (file)
@@ -22,19 +22,18 @@ import android.hardware.Sensor;
 import android.hardware.SensorManager;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
-import android.support.v7.preference.TwoStatePreference;
 import android.text.TextUtils;
 
 import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 
-public class DoubleTwistPreferenceController extends PreferenceController
-        implements Preference.OnPreferenceChangeListener {
+public class DoubleTwistPreferenceController extends GesturePreferenceController {
 
+    private static final String PREF_KEY_VIDEO = "gesture_double_twist_video";
     private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
 
-    public DoubleTwistPreferenceController(Context context) {
-        super(context);
+    public DoubleTwistPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
     }
 
     @Override
@@ -44,30 +43,25 @@ public class DoubleTwistPreferenceController extends PreferenceController
     }
 
     @Override
-    public void updateState(Preference preference) {
-        final boolean isEnabled = isDoubleTwistEnabled();
-        if (preference != null) {
-            if (preference instanceof TwoStatePreference) {
-                ((TwoStatePreference) preference).setChecked(isEnabled);
-            } else {
-                preference.setSummary(isEnabled
-                        ? com.android.settings.R.string.gesture_setting_on
-                        : com.android.settings.R.string.gesture_setting_off);
-            }
-        }
+    protected String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        return false;
+    public String getPreferenceKey() {
+        return PREF_KEY_DOUBLE_TWIST;
     }
 
     @Override
-    public String getPreferenceKey() {
-        return PREF_KEY_DOUBLE_TWIST;
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean enabled = (boolean) newValue;
+        Settings.Secure.putInt(mContext.getContentResolver(),
+                Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
+        return true;
     }
 
-    private boolean isDoubleTwistEnabled() {
+    @Override
+    protected boolean isSwitchPrefEnabled() {
         final int doubleTwistEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
                 Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
         return doubleTwistEnabled != 0;
@@ -88,12 +82,4 @@ public class DoubleTwistPreferenceController extends PreferenceController
         }
         return false;
     }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        final boolean enabled = (boolean) newValue;
-        Settings.Secure.putInt(mContext.getContentResolver(),
-                Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
-        return true;
-    }
 }
diff --git a/src/com/android/settings/gestures/GesturePreferenceController.java b/src/com/android/settings/gestures/GesturePreferenceController.java
new file mode 100644 (file)
index 0000000..345f7b7
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.support.v7.preference.TwoStatePreference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnStart;
+import com.android.settings.core.lifecycle.events.OnStop;
+import com.android.settings.widget.VideoPreference;
+
+public abstract class GesturePreferenceController extends PreferenceController
+        implements Preference.OnPreferenceChangeListener, LifecycleObserver, OnStart, OnStop {
+
+    private VideoPreference mVideoPreference;
+
+    public GesturePreferenceController(Context context, Lifecycle lifecycle) {
+        super(context);
+        if (lifecycle != null) {
+            lifecycle.addObserver(this);
+        }
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        if (isAvailable()) {
+            mVideoPreference = (VideoPreference) screen.findPreference(getVideoPrefKey());
+        }
+    }
+
+    @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);
+            }
+        }
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        return false;
+    }
+
+    @Override
+    public void onStop() {
+        if (mVideoPreference != null) {
+            mVideoPreference.onViewInvisible();
+        }
+    }
+
+    @Override
+    public void onStart() {
+        if (mVideoPreference != null) {
+            mVideoPreference.onViewVisible();
+        }
+    }
+
+    protected abstract String getVideoPrefKey();
+
+    protected abstract boolean isSwitchPrefEnabled();
+}
index 792150e..98ed5fb 100644 (file)
@@ -30,6 +30,7 @@ import com.android.internal.hardware.AmbientDisplayConfiguration;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
@@ -56,13 +57,14 @@ public class GestureSettings extends DashboardFragment {
     protected List<PreferenceController> getPreferenceControllers(Context context) {
         final AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context);
         final List<PreferenceController> controllers = new ArrayList<>();
-        controllers.add(new SwipeToNotificationPreferenceController(context));
-        controllers.add(new DoubleTapPowerPreferenceController(context));
-        controllers.add(new DoubleTwistPreferenceController(context));
+        final Lifecycle lifecycle = getLifecycle();
+        controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle));
+        controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle));
+        controllers.add(new DoubleTwistPreferenceController(context, lifecycle));
         controllers.add(new PickupGesturePreferenceController(
-                context, ambientConfig, UserHandle.myUserId()));
+                context, lifecycle, ambientConfig, UserHandle.myUserId()));
         controllers.add(new DoubleTapScreenPreferenceController(
-                context, ambientConfig, UserHandle.myUserId()));
+                context, lifecycle, ambientConfig, UserHandle.myUserId()));
         return controllers;
     }
 
@@ -167,17 +169,17 @@ public class GestureSettings extends DashboardFragment {
                     ArrayList<String> result = new ArrayList<String>();
                     AmbientDisplayConfiguration ambientConfig
                             = new AmbientDisplayConfiguration(context);
-                    new DoubleTapPowerPreferenceController(context)
+                    new DoubleTapPowerPreferenceController(context, null /* lifecycle */)
                             .updateNonIndexableKeys(result);
                     new PickupGesturePreferenceController(
-                            context, ambientConfig, UserHandle.myUserId())
+                            context, null /* lifecycle */, ambientConfig, UserHandle.myUserId())
                             .updateNonIndexableKeys(result);
                     new DoubleTapScreenPreferenceController(
-                            context, ambientConfig, UserHandle.myUserId())
+                            context, null /* lifecycle */, ambientConfig, UserHandle.myUserId())
                             .updateNonIndexableKeys(result);
-                    new SwipeToNotificationPreferenceController(context)
+                    new SwipeToNotificationPreferenceController(context, null /* lifecycle */)
                             .updateNonIndexableKeys(result);
-                    new DoubleTwistPreferenceController(context)
+                    new DoubleTwistPreferenceController(context, null /* lifecycle */)
                             .updateNonIndexableKeys(result);
                     return result;
                 }
index b37e756..225e1d0 100644 (file)
@@ -20,23 +20,22 @@ import android.annotation.UserIdInt;
 import android.content.Context;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
-import android.support.v7.preference.TwoStatePreference;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 
-public class PickupGesturePreferenceController extends PreferenceController
-        implements Preference.OnPreferenceChangeListener {
+public class PickupGesturePreferenceController extends GesturePreferenceController {
 
+    private static final String PREF_VIDEO_KEY = "gesture_pick_up_video";
     private static final String PREF_KEY_PICK_UP = "gesture_pick_up";
 
     private final AmbientDisplayConfiguration mAmbientConfig;
     @UserIdInt
     private final int mUserId;
 
-    public PickupGesturePreferenceController(Context context, AmbientDisplayConfiguration config,
-            @UserIdInt int userId) {
-        super(context);
+    public PickupGesturePreferenceController(Context context, Lifecycle lifecycle,
+            AmbientDisplayConfiguration config, @UserIdInt int userId) {
+        super(context, lifecycle);
         mAmbientConfig = config;
         mUserId = userId;
     }
@@ -47,27 +46,18 @@ public class PickupGesturePreferenceController extends PreferenceController
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        return false;
+    protected String getVideoPrefKey() {
+        return PREF_VIDEO_KEY;
     }
 
     @Override
-    public String getPreferenceKey() {
-        return PREF_KEY_PICK_UP;
+    protected boolean isSwitchPrefEnabled() {
+        return mAmbientConfig.pulseOnPickupEnabled(mUserId);
     }
 
     @Override
-    public void updateState(Preference preference) {
-        final boolean isEnabled = mAmbientConfig.pulseOnPickupEnabled(mUserId);
-        if (preference != null) {
-            if (preference instanceof TwoStatePreference) {
-                ((TwoStatePreference) preference).setChecked(isEnabled);
-            } else {
-                preference.setSummary(isEnabled
-                        ? com.android.settings.R.string.gesture_setting_on
-                        : com.android.settings.R.string.gesture_setting_off);
-            }
-        }
+    public String getPreferenceKey() {
+        return PREF_KEY_PICK_UP;
     }
 
     @Override
index 96f0796..1298dfe 100644 (file)
@@ -54,8 +54,8 @@ public class PickupGestureSettings extends DashboardFragment {
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
         final List<PreferenceController> controllers = new ArrayList<>();
-        controllers.add(new PickupGesturePreferenceController(
-                context, new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
+        controllers.add(new PickupGesturePreferenceController(context, getLifecycle(),
+                new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
         return controllers;
     }
 }
index 0bacefb..01af974 100644 (file)
@@ -19,18 +19,16 @@ 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.R;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 
-public class SwipeToNotificationPreferenceController extends PreferenceController
-        implements Preference.OnPreferenceChangeListener {
+public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
 
+    private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
     private static final String PREF_KEY_SWIPE_DOWN_FINGERPRINT = "gesture_swipe_down_fingerprint";
 
-    public SwipeToNotificationPreferenceController(Context context) {
-        super(context);
+    public SwipeToNotificationPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
     }
 
     @Override
@@ -44,18 +42,8 @@ public class SwipeToNotificationPreferenceController extends PreferenceControlle
     }
 
     @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-        final boolean isEnabled = isSystemUINavigationEnabled();
-        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);
-            }
-        }
+    protected String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
     }
 
     @Override
@@ -64,16 +52,17 @@ public class SwipeToNotificationPreferenceController extends PreferenceControlle
                 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;
     }
+
+    @Override
+    protected boolean isSwitchPrefEnabled() {
+        return Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0)
+                == 1;
+    }
 }
index a351fdd..7eeba29 100644 (file)
@@ -52,7 +52,7 @@ public class SwipeToNotificationSettings extends DashboardFragment {
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
         final List<PreferenceController> controllers = new ArrayList<>();
-        controllers.add(new SwipeToNotificationPreferenceController(context));
+        controllers.add(new SwipeToNotificationPreferenceController(context, getLifecycle()));
         return controllers;
     }
 }
index 965cdec..eecfd31 100644 (file)
@@ -23,6 +23,7 @@ import android.support.annotation.VisibleForTesting;
 import com.android.internal.hardware.AmbientDisplayConfiguration;
 import com.android.settings.R;
 import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.gestures.DoubleTapPowerPreferenceController;
 import com.android.settings.gestures.DoubleTapScreenPreferenceController;
@@ -62,6 +63,7 @@ public class InputAndGestureSettings extends DashboardFragment {
 
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
+        final Lifecycle lifecycle = getLifecycle();
         final GameControllerPreferenceController gameControllerPreferenceController
                 = new GameControllerPreferenceController(context);
         getLifecycle().addObserver(gameControllerPreferenceController);
@@ -72,13 +74,14 @@ public class InputAndGestureSettings extends DashboardFragment {
         final List<PreferenceController> controllers = new ArrayList<>();
         controllers.add(gameControllerPreferenceController);
         // Gestures
-        controllers.add(new SwipeToNotificationPreferenceController(context));
-        controllers.add(new DoubleTwistPreferenceController(context));
-        controllers.add(new DoubleTapPowerPreferenceController(context));
+
+        controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle));
+        controllers.add(new DoubleTwistPreferenceController(context, lifecycle));
+        controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle));
         controllers.add(new PickupGesturePreferenceController(
-                context, mAmbientDisplayConfig, UserHandle.myUserId()));
+                context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
         controllers.add(new DoubleTapScreenPreferenceController(
-                context, mAmbientDisplayConfig, UserHandle.myUserId()));
+                context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
         return controllers;
     }
 
index 59bd238..fd59c97 100644 (file)
@@ -62,7 +62,7 @@ public class ConfigureNotificationSettings extends DashboardFragment {
         mLockScreenNotificationController = new LockScreenNotificationPreferenceController(context);
         getLifecycle().addObserver(pulseController);
         getLifecycle().addObserver(mLockScreenNotificationController);
-        controllers.add(new SwipeToNotificationPreferenceController(context));
+        controllers.add(new SwipeToNotificationPreferenceController(context, getLifecycle()));
         controllers.add(pulseController);
         controllers.add(mLockScreenNotificationController);
         return controllers;
diff --git a/src/com/android/settings/widget/VideoPreference.java b/src/com/android/settings/widget/VideoPreference.java
new file mode 100644 (file)
index 0000000..c8786dc
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * 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.widget;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.SurfaceTexture;
+import android.media.MediaPlayer;
+import android.net.Uri;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.Surface;
+import android.view.TextureView;
+import android.view.View;
+import android.widget.ImageView;
+
+import com.android.settings.R;
+
+/**
+ * A full width preference that hosts a MP4 video.
+ */
+public class VideoPreference extends Preference {
+
+    private static final String TAG = "VideoPreference";
+    private final Context mContext;
+
+    private Uri mVideoPath;
+    private MediaPlayer mMediaPlayer;
+    private boolean mAnimationAvailable;
+    private boolean mVideoReady;
+    private int mPreviewResource;
+
+    public VideoPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        mContext = context;
+        TypedArray attributes = context.getTheme().obtainStyledAttributes(
+                attrs,
+                com.android.settings.R.styleable.VideoPreference,
+                0, 0);
+        try {
+            int animation = attributes.getResourceId(R.styleable.VideoPreference_animation, 0);
+            mVideoPath = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
+                    .authority(context.getPackageName())
+                    .appendPath(String.valueOf(animation))
+                    .build();
+            mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
+            if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
+                setLayoutResource(R.layout.video_preference);
+
+                mPreviewResource = attributes.getResourceId(
+                        R.styleable.VideoPreference_preview, 0);
+
+                mMediaPlayer.setOnSeekCompleteListener(mp -> mVideoReady = true);
+
+                mMediaPlayer.setOnPreparedListener(mediaPlayer -> mediaPlayer.setLooping(true));
+                mAnimationAvailable = true;
+            }
+        } catch (Exception e) {
+            Log.w(TAG, "Animation resource not found. Will not show animation.");
+        } finally {
+            attributes.recycle();
+        }
+    }
+
+    @Override
+    public void onBindViewHolder(PreferenceViewHolder holder) {
+        super.onBindViewHolder(holder);
+
+        if (!mAnimationAvailable) {
+            return;
+        }
+
+        final TextureView video = (TextureView) holder.findViewById(R.id.video_texture_view);
+        final ImageView imageView = (ImageView) holder.findViewById(R.id.video_preview_image);
+        final ImageView playButton = (ImageView) holder.findViewById(R.id.video_play_button);
+        imageView.setImageResource(mPreviewResource);
+
+        video.setOnClickListener(v -> {
+            if (mMediaPlayer != null) {
+                if (mMediaPlayer.isPlaying()) {
+                    mMediaPlayer.pause();
+                    playButton.setVisibility(View.VISIBLE);
+                } else {
+                    mMediaPlayer.start();
+                    playButton.setVisibility(View.GONE);
+                }
+            }
+        });
+
+        video.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
+            @Override
+            public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
+                    int height) {
+                if (mMediaPlayer != null) {
+                    mMediaPlayer.setSurface(new Surface(surfaceTexture));
+                    mVideoReady = false;
+                    mMediaPlayer.seekTo(0);
+                }
+            }
+
+            @Override
+            public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width,
+                    int height) {
+            }
+
+            @Override
+            public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
+                imageView.setVisibility(View.VISIBLE);
+                return false;
+            }
+
+            @Override
+            public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
+                if (mVideoReady && imageView.getVisibility() == View.VISIBLE) {
+                    imageView.setVisibility(View.GONE);
+                }
+                if (mMediaPlayer != null && !mMediaPlayer.isPlaying() &&
+                        playButton.getVisibility() != View.VISIBLE) {
+                    playButton.setVisibility(View.VISIBLE);
+                }
+            }
+        });
+    }
+
+    @Override
+    public void onDetached() {
+        if (mMediaPlayer != null) {
+            mMediaPlayer.stop();
+            mMediaPlayer.reset();
+            mMediaPlayer.release();
+        }
+        super.onDetached();
+    }
+
+    public void onViewVisible() {
+        if (mVideoReady && mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
+            mMediaPlayer.seekTo(0);
+        }
+    }
+
+    public void onViewInvisible() {
+        if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
+            mMediaPlayer.pause();
+        }
+    }
+}
index 9024e0b..6a2e4ea 100644 (file)
@@ -18,11 +18,8 @@ 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.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
@@ -36,10 +33,7 @@ import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
 
 import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
-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 com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -55,81 +49,46 @@ public class DoubleTapPowerPreferenceControllerTest {
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mController = new DoubleTapPowerPreferenceController(mContext);
+        mController = new DoubleTapPowerPreferenceController(mContext, null);
     }
 
     @Test
-    public void display_configIsTrue_shouldDisplay() {
+    public void isAvailable_configIsTrue_shouldReturnTrue() {
         when(mContext.getResources().
                 getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled))
                 .thenReturn(true);
-        mController.displayPreference(mScreen);
 
-        verify(mScreen, never()).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
-    public void display_configIsFalse_shouldNotDisplay() {
+    public void isAvailable_configIsTrue_shouldReturnFalse() {
         when(mContext.getResources().
                 getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled))
                 .thenReturn(false);
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
 
-        mController.displayPreference(mScreen);
-
-        verify(mScreen).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
-    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
+    public void testSwitchEnabled_configIsNotSet_shouldReturnTrue() {
         // Set the setting to be enabled.
         final Context context = ShadowApplication.getInstance().getApplicationContext();
         Settings.System.putInt(context.getContentResolver(),
                 CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
+        mController = new DoubleTapPowerPreferenceController(context, null);
 
-        // Run through updateState
-        mController = new DoubleTapPowerPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify pref is checked (as setting is enabled).
-        verify(preference).setChecked(true);
+        assertThat(mController.isSwitchPrefEnabled()).isTrue();
     }
 
     @Test
-    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
+    public void testSwitchEnabled_configIsSet_shouldReturnFalse() {
         // Set the setting to be disabled.
         final Context context = ShadowApplication.getInstance().getApplicationContext();
         Settings.System.putInt(context.getContentResolver(),
                 CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 1);
+        mController = new DoubleTapPowerPreferenceController(context, null);
 
-        // Run through updateState
-        mController = new DoubleTapPowerPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify pref is unchecked (as setting is disabled).
-        verify(preference).setChecked(false);
+        assertThat(mController.isSwitchPrefEnabled()).isFalse();
     }
-
-    @Test
-    public void updateState_notTwoStatePreference_setSummary() {
-        // Mock a regular preference
-        final Preference preference = mock(Preference.class);
-        // Set the setting to be disabled.
-        final Context context = ShadowApplication.getInstance().getApplicationContext();
-        Settings.System.putInt(context.getContentResolver(),
-                CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 1);
-
-        // Run through updateState
-        mController = new DoubleTapPowerPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify summary is set to off (as setting is disabled).
-        verify(preference).setSummary(R.string.gesture_setting_off);
-    }
-
 }
index 1e8020e..a25d34b 100644 (file)
 package com.android.settings.gestures;
 
 import android.content.Context;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.support.v7.preference.TwoStatePreference;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
-import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
@@ -34,11 +30,8 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.any;
+import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.anyInt;
-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(SettingsRobolectricTestRunner.class)
@@ -47,8 +40,6 @@ public class DoubleTapScreenPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private PreferenceScreen mScreen;
     @Mock
     private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
     private DoubleTapScreenPreferenceController mController;
@@ -57,68 +48,35 @@ public class DoubleTapScreenPreferenceControllerTest {
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mController = new DoubleTapScreenPreferenceController(
-                mContext, mAmbientDisplayConfiguration, 0);
+                mContext, null, mAmbientDisplayConfiguration, 0);
     }
 
     @Test
-    public void display_configIsTrue_shouldDisplay() {
+    public void isAvailable_configIsTrue_shouldReturnTrue() {
         when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true);
 
-        mController.displayPreference(mScreen);
-
-        verify(mScreen, never()).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
-    public void display_configIsFalse_shouldNotDisplay() {
+    public void isAvailable_configIsFalse_shouldReturnFalse() {
         when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false);
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
-
-        mController.displayPreference(mScreen);
 
-        verify(mScreen).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
-    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
+    public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
         // Set the setting to be enabled.
         when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true);
 
-        // Run through updateState
-        mController.updateState(preference);
-
-        // Verify pref is checked (as setting is enabled).
-        verify(preference).setChecked(true);
+        assertThat(mController.isSwitchPrefEnabled()).isTrue();
     }
 
     @Test
-    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
-        // Set the setting to be disabled.
+    public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
         when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
 
-        // Run through updateState
-        mController.updateState(preference);
-
-        // Verify pref is unchecked (as setting is disabled).
-        verify(preference).setChecked(false);
-    }
-
-    @Test
-    public void updateState_notTwoStatePreference_setSummary() {
-        // Mock a regular preference
-        final Preference preference = mock(Preference.class);
-        // Set the setting to be disabled.
-        when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
-
-        // Run through updateState
-        mController.updateState(preference);
-
-        // Verify summary is set to off (as setting is disabled).
-        verify(preference).setSummary(R.string.gesture_setting_off);
+        assertThat(mController.isSwitchPrefEnabled()).isFalse();
     }
 }
index 8692661..5b02182 100644 (file)
@@ -20,9 +20,6 @@ import android.content.Context;
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
 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.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
@@ -40,11 +37,9 @@ import java.util.ArrayList;
 import java.util.List;
 
 import static android.provider.Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED;
-import static org.mockito.Matchers.any;
+import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.anyInt;
 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(SettingsRobolectricTestRunner.class)
@@ -54,19 +49,17 @@ public class DoubleTwistPreferenceControllerTest {
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private PreferenceScreen mScreen;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private SensorManager mSensorManager;
     private DoubleTwistPreferenceController mController;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mController = new DoubleTwistPreferenceController(mContext);
+        mController = new DoubleTwistPreferenceController(mContext, null);
     }
 
     @Test
-    public void display_hasSensor_shouldDisplay() {
+    public void isAvailable_hasSensor_shouldReturnTrue() {
         // Mock sensors
         final List<Sensor> sensorList = new ArrayList<>();
         sensorList.add(mock(Sensor.class));
@@ -75,28 +68,17 @@ public class DoubleTwistPreferenceControllerTest {
         when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
         when(sensorList.get(0).getName()).thenReturn("test");
         when(sensorList.get(0).getVendor()).thenReturn("test");
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
-
-        // Run through display
-        mController.displayPreference(mScreen);
 
-        // Verify preference is not removed
-        verify(mScreen, never()).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
-    public void display_noSensor_shouldNotDisplay() {
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
-
-        mController.displayPreference(mScreen);
-
-        verify(mScreen).removePreference(any(Preference.class));
+    public void isAvailable_noSensor_shouldReturnFalse() {
+        assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
-    public void display_differentSensor_shouldNotDisplay() {
+    public void isAvailable_differentSensor_shouldReturnFalse() {
         // Mock sensors
         final List<Sensor> sensorList = new ArrayList<>();
         sensorList.add(mock(Sensor.class));
@@ -104,68 +86,29 @@ public class DoubleTwistPreferenceControllerTest {
         when(mContext.getSystemService(Context.SENSOR_SERVICE)).thenReturn(mSensorManager);
         when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
         when(sensorList.get(0).getName()).thenReturn("not_test");
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
-
-        // Run through display
-        mController.displayPreference(mScreen);
 
-        // Verify preference is not removed
-        verify(mScreen).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isFalse();
     }
 
-
     @Test
-    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
+    public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
         // Set the setting to be enabled.
         final Context context = ShadowApplication.getInstance().getApplicationContext();
         Settings.System.putInt(context.getContentResolver(),
                 CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
+        mController = new DoubleTwistPreferenceController(context, null);
 
-        // Run through updateState
-        mController = new DoubleTwistPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify pref is checked (as setting is enabled).
-        verify(preference).setChecked(true);
-    }
-
-    @Test
-    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
-        // Set the setting to be disabled.
-        final Context context = ShadowApplication.getInstance().getApplicationContext();
-        Settings.System.putInt(context.getContentResolver(),
-                CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
-
-        // Run through updateState
-        mController = new DoubleTwistPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify pref is unchecked (as setting is disabled).
-        verify(preference).setChecked(false);
+        assertThat(mController.isSwitchPrefEnabled()).isTrue();
     }
 
     @Test
-    public void updateState_notTwoStatePreference_setSummary() {
-        // Mock a regular preference
-        final Preference preference = mock(Preference.class);
+    public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
         // Set the setting to be disabled.
         final Context context = ShadowApplication.getInstance().getApplicationContext();
         Settings.System.putInt(context.getContentResolver(),
                 CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
+        mController = new DoubleTwistPreferenceController(context, null);
 
-        // Run through updateState
-        mController = new DoubleTwistPreferenceController(context);
-        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(mController.isSwitchPrefEnabled()).isFalse();
     }
-
 }
diff --git a/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java
new file mode 100644 (file)
index 0000000..01c1921
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * 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.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.support.v7.preference.TwoStatePreference;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.widget.VideoPreference;
+
+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.annotation.Config;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+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(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class GesturePreferenceControllerTest {
+
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private PreferenceScreen mScreen;
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Lifecycle mLifecycle;
+    private TestPrefController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mController = new TestPrefController(mContext, mLifecycle);
+    }
+
+    @Test
+    public void display_configIsTrue_shouldDisplay() {
+        mController.mIsPrefAvailable = true;
+        when(mScreen.findPreference(anyString())).thenReturn(mock(VideoPreference.class));
+
+        mController.displayPreference(mScreen);
+
+        verify(mScreen, never()).removePreference(any(Preference.class));
+    }
+
+    @Test
+    public void display_configIsFalse_shouldNotDisplay() {
+        mController.mIsPrefAvailable = false;
+        when(mScreen.findPreference(mController.getPreferenceKey()))
+                .thenReturn(mock(Preference.class));
+
+        mController.displayPreference(mScreen);
+
+        verify(mScreen).removePreference(any(Preference.class));
+    }
+
+    @Test
+    public void onStart_shouldStartVideoPreference() {
+        final VideoPreference videoPreference = mock(VideoPreference.class);
+        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
+        mController.mIsPrefAvailable = true;
+
+        mController.displayPreference(mScreen);
+        mController.onStart();
+
+        verify(videoPreference).onViewVisible();
+    }
+
+    @Test
+    public void onStop_shouldStopVideoPreference() {
+        final VideoPreference videoPreference = mock(VideoPreference.class);
+        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
+        mController.mIsPrefAvailable = true;
+
+        mController.displayPreference(mScreen);
+        mController.onStop();
+
+        verify(videoPreference).onViewInvisible();
+    }
+
+    @Test
+    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
+        // Mock a TwoStatePreference
+        final TwoStatePreference preference = mock(TwoStatePreference.class);
+        // Set the setting to be enabled.
+        mController.mIsPrefEnabled = true;
+        // Run through updateState
+        mController.updateState(preference);
+
+        // Verify pref is checked (as setting is enabled).
+        verify(preference).setChecked(true);
+    }
+
+    @Test
+    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
+        // Mock a TwoStatePreference
+        final TwoStatePreference preference = mock(TwoStatePreference.class);
+        // Set the setting to be disabled.
+        mController.mIsPrefEnabled = false;
+
+        // Run through updateState
+        mController.updateState(preference);
+
+        // Verify pref is unchecked (as setting is disabled).
+        verify(preference).setChecked(false);
+    }
+
+    @Test
+    public void updateState_notTwoStatePreference_setSummary() {
+        // Mock a regular preference
+        final Preference preference = mock(Preference.class);
+        // Set the setting to be disabled.
+        mController.mIsPrefEnabled = false;
+
+        // Run through updateState
+        mController.updateState(preference);
+
+        // Verify summary is set to off (as setting is disabled).
+        verify(preference).setSummary(com.android.settings.R.string.gesture_setting_off);
+    }
+
+    private class TestPrefController extends GesturePreferenceController {
+
+        boolean mIsPrefAvailable;
+        boolean mIsPrefEnabled;
+
+        public TestPrefController(Context context,
+                Lifecycle lifecycle) {
+            super(context, lifecycle);
+        }
+
+        @Override
+        public boolean isAvailable() {
+            return mIsPrefAvailable;
+        }
+
+        @Override
+        public String getPreferenceKey() {
+            return null;
+        }
+
+        @Override
+        protected String getVideoPrefKey() {
+            return null;
+        }
+
+        @Override
+        protected boolean isSwitchPrefEnabled() {
+            return mIsPrefEnabled;
+        }
+
+        @Override
+        public boolean onPreferenceChange(Preference preference, Object newValue) {
+            return false;
+        }
+    }
+}
index 217d0b8..66ae679 100644 (file)
 package com.android.settings.gestures;
 
 import android.content.Context;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.support.v7.preference.TwoStatePreference;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
-import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
@@ -34,11 +30,8 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.any;
+import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.anyInt;
-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(SettingsRobolectricTestRunner.class)
@@ -47,8 +40,6 @@ public class PIckupGesturePreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private PreferenceScreen mScreen;
     @Mock
     private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
 
@@ -58,69 +49,37 @@ public class PIckupGesturePreferenceControllerTest {
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mController = new PickupGesturePreferenceController(
-                mContext, mAmbientDisplayConfiguration, 0);
+                mContext, null, mAmbientDisplayConfiguration, 0);
     }
 
     @Test
-    public void display_configIsTrue_shouldDisplay() {
+    public void isAvailable_configIsTrue_shouldReturnTrue() {
         when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(true);
 
-        mController.displayPreference(mScreen);
-
-        verify(mScreen, never()).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
-    public void display_configIsFalse_shouldNotDisplay() {
+    public void isAvailable_configIsFalse_shouldReturnFalse() {
         when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(false);
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
-
-        mController.displayPreference(mScreen);
 
-        verify(mScreen).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
-    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
+    public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
         // Set the setting to be enabled.
         when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true);
 
-        // Run through updateState
-        mController.updateState(preference);
-
-        // Verify pref is checked (as setting is enabled).
-        verify(preference).setChecked(true);
-    }
-
-    @Test
-    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
-        // Set the setting to be disabled.
-        when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
-
-        // Run through updateState
-        mController.updateState(preference);
-
-        // Verify pref is unchecked (as setting is disabled).
-        verify(preference).setChecked(false);
+        assertThat(mController.isSwitchPrefEnabled()).isTrue();
     }
 
     @Test
-    public void updateState_notTwoStatePreference_setSummary() {
-        // Mock a regular preference
-        final Preference preference = mock(Preference.class);
+    public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
         // Set the setting to be disabled.
         when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
 
-        // Run through updateState
-        mController.updateState(preference);
-
-        // Verify summary is set to off (as setting is disabled).
-        verify(preference).setSummary(R.string.gesture_setting_off);
+        assertThat(mController.isSwitchPrefEnabled()).isFalse();
     }
 
 }
index e484135..7b34666 100644 (file)
@@ -18,11 +18,7 @@ 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.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
@@ -36,10 +32,7 @@ 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 com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -48,85 +41,50 @@ 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);
+        mController = new SwipeToNotificationPreferenceController(mContext, null);
     }
 
     @Test
-    public void display_configIsTrue_shouldDisplay() {
+    public void isAvailable_configIsTrue_shouldReturnTrue() {
         when(mContext.getResources().
                 getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys))
                 .thenReturn(true);
-        mController.displayPreference(mScreen);
 
-        verify(mScreen, never()).removePreference(any(Preference.class));
+        assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
-    public void display_configIsFalse_shouldNotDisplay() {
+    public void isAvailable_configIsFalse_shouldReturnFalse() {
         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));
+        assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
-    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
+    public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
         // Set the setting to be enabled.
         final Context context = ShadowApplication.getInstance().getApplicationContext();
         Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1);
+        mController = new SwipeToNotificationPreferenceController(context, null);
 
-        // Run through updateState
-        mController = new SwipeToNotificationPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify pref is checked (as setting is enabled).
-        verify(preference).setChecked(true);
-    }
-
-    @Test
-    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
-        // Mock a TwoStatePreference
-        final TwoStatePreference preference = mock(TwoStatePreference.class);
-        // Set the setting to be disabled.
-        final Context context = ShadowApplication.getInstance().getApplicationContext();
-        Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
-
-        // Run through updateState
-        mController = new SwipeToNotificationPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify pref is unchecked (as setting is disabled).
-        verify(preference).setChecked(false);
+        assertThat(mController.isSwitchPrefEnabled()).isTrue();
     }
 
     @Test
-    public void updateState_notTwoStatePreference_setSummary() {
-        // Mock a regular preference
-        final Preference preference = mock(Preference.class);
+    public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
         // Set the setting to be disabled.
         final Context context = ShadowApplication.getInstance().getApplicationContext();
         Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
+        mController = new SwipeToNotificationPreferenceController(context, null);
 
-        // Run through updateState
-        mController = new SwipeToNotificationPreferenceController(context);
-        mController.updateState(preference);
-
-        // Verify summary is set to off (as setting is disabled).
-        verify(preference).setSummary(R.string.gesture_setting_off);
+        assertThat(mController.isSwitchPrefEnabled()).isFalse();
     }
 }