Add video to each gesture preference screen.
- 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
diff --git a/res/layout/magnification_video_preference.xml b/res/layout/magnification_video_preference.xml
new file mode 100644
index 0000000..fe7f26f
--- /dev/null
+++ b/res/layout/magnification_video_preference.xml
@@ -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
diff --git a/res/layout/video_preference.xml b/res/layout/video_preference.xml
index fe7f26f..8b0e619 100644
--- a/res/layout/video_preference.xml
+++ b/res/layout/video_preference.xml
@@ -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" />
+ android:padding="@dimen/gesture_animation_padding">
- <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" />
+ <TextureView
+ android:id="@+id/video_texture_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"/>
-</RelativeLayout>
\ No newline at end of file
+ <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>
+
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 6df41d2..9a74fa5 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -142,6 +142,11 @@
<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" />
diff --git a/res/xml/double_tap_power_settings.xml b/res/xml/double_tap_power_settings.xml
index b8835ea..3376f3c 100644
--- a/res/xml/double_tap_power_settings.xml
+++ b/res/xml/double_tap_power_settings.xml
@@ -15,7 +15,13 @@
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"
diff --git a/res/xml/double_tap_screen_settings.xml b/res/xml/double_tap_screen_settings.xml
index e1ba7c9..a76a487 100644
--- a/res/xml/double_tap_screen_settings.xml
+++ b/res/xml/double_tap_screen_settings.xml
@@ -15,7 +15,13 @@
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"
diff --git a/res/xml/double_twist_gesture_settings.xml b/res/xml/double_twist_gesture_settings.xml
index 2cf9d5e..e8d0abe 100644
--- a/res/xml/double_twist_gesture_settings.xml
+++ b/res/xml/double_twist_gesture_settings.xml
@@ -15,7 +15,13 @@
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"
diff --git a/res/xml/pick_up_gesture_settings.xml b/res/xml/pick_up_gesture_settings.xml
index e335a83..4ef81a2 100644
--- a/res/xml/pick_up_gesture_settings.xml
+++ b/res/xml/pick_up_gesture_settings.xml
@@ -15,7 +15,13 @@
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"
diff --git a/res/xml/swipe_to_notification_settings.xml b/res/xml/swipe_to_notification_settings.xml
index 3be44bd..a4dedfb 100644
--- a/res/xml/swipe_to_notification_settings.xml
+++ b/res/xml/swipe_to_notification_settings.xml
@@ -15,7 +15,13 @@
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"
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 7b7e43f..8f13e08 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -120,7 +120,7 @@
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);
diff --git a/src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java b/src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java
index dbce755..f55b183 100644
--- a/src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java
+++ b/src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java
@@ -62,6 +62,13 @@
@CallSuper
@Override
+ public void onStop() {
+ mLifecycle.onStop();
+ super.onStop();
+ }
+
+ @CallSuper
+ @Override
public void onResume() {
mLifecycle.onResume();
super.onResume();
diff --git a/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java b/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
index 7838ae7..cb36879 100644
--- a/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
@@ -19,17 +19,16 @@
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 @@
}
@Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- return false;
+ protected String getVideoPrefKey() {
+ return PREF_KEY_VIDEO;
}
@Override
@@ -49,20 +48,6 @@
}
@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 @@
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;
diff --git a/src/com/android/settings/gestures/DoubleTapPowerSettings.java b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
index 8244165..521c665 100644
--- a/src/com/android/settings/gestures/DoubleTapPowerSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
@@ -52,7 +52,7 @@
@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;
}
}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
index be1c53f..722d66a 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
@@ -20,23 +20,22 @@
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 @@
}
@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 @@
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);
+ }
}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenSettings.java b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
index 12e3b64..3c53947 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
@@ -54,8 +54,8 @@
@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;
}
}
diff --git a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
index 4f8d2de..07b40bb 100644
--- a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
+++ b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
@@ -52,7 +52,7 @@
@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;
}
}
diff --git a/src/com/android/settings/gestures/DoubleTwistPreferenceController.java b/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
index 071255b..5192484 100644
--- a/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
@@ -22,19 +22,18 @@
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,22 +43,8 @@
}
@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);
- }
- }
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- return false;
+ protected String getVideoPrefKey() {
+ return PREF_KEY_VIDEO;
}
@Override
@@ -67,7 +52,16 @@
return PREF_KEY_DOUBLE_TWIST;
}
- private boolean isDoubleTwistEnabled() {
+ @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;
+ }
+
+ @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 @@
}
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
index 0000000..345f7b7
--- /dev/null
+++ b/src/com/android/settings/gestures/GesturePreferenceController.java
@@ -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();
+}
diff --git a/src/com/android/settings/gestures/GestureSettings.java b/src/com/android/settings/gestures/GestureSettings.java
index 792150e..98ed5fb 100644
--- a/src/com/android/settings/gestures/GestureSettings.java
+++ b/src/com/android/settings/gestures/GestureSettings.java
@@ -30,6 +30,7 @@
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 @@
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 @@
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;
}
diff --git a/src/com/android/settings/gestures/PickupGesturePreferenceController.java b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
index b37e756..225e1d0 100644
--- a/src/com/android/settings/gestures/PickupGesturePreferenceController.java
+++ b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
@@ -20,23 +20,22 @@
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,8 +46,13 @@
}
@Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- return false;
+ protected String getVideoPrefKey() {
+ return PREF_VIDEO_KEY;
+ }
+
+ @Override
+ protected boolean isSwitchPrefEnabled() {
+ return mAmbientConfig.pulseOnPickupEnabled(mUserId);
}
@Override
@@ -57,20 +61,6 @@
}
@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);
- }
- }
- }
-
- @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(),
diff --git a/src/com/android/settings/gestures/PickupGestureSettings.java b/src/com/android/settings/gestures/PickupGestureSettings.java
index 96f0796..1298dfe 100644
--- a/src/com/android/settings/gestures/PickupGestureSettings.java
+++ b/src/com/android/settings/gestures/PickupGestureSettings.java
@@ -54,8 +54,8 @@
@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;
}
}
diff --git a/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java b/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
index 0bacefb..01af974 100644
--- a/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
+++ b/src/com/android/settings/gestures/SwipeToNotificationPreferenceController.java
@@ -19,18 +19,16 @@
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 @@
}
@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 @@
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;
+ }
}
diff --git a/src/com/android/settings/gestures/SwipeToNotificationSettings.java b/src/com/android/settings/gestures/SwipeToNotificationSettings.java
index a351fdd..7eeba29 100644
--- a/src/com/android/settings/gestures/SwipeToNotificationSettings.java
+++ b/src/com/android/settings/gestures/SwipeToNotificationSettings.java
@@ -52,7 +52,7 @@
@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;
}
}
diff --git a/src/com/android/settings/inputmethod/InputAndGestureSettings.java b/src/com/android/settings/inputmethod/InputAndGestureSettings.java
index 965cdec..eecfd31 100644
--- a/src/com/android/settings/inputmethod/InputAndGestureSettings.java
+++ b/src/com/android/settings/inputmethod/InputAndGestureSettings.java
@@ -23,6 +23,7 @@
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 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
+ final Lifecycle lifecycle = getLifecycle();
final GameControllerPreferenceController gameControllerPreferenceController
= new GameControllerPreferenceController(context);
getLifecycle().addObserver(gameControllerPreferenceController);
@@ -72,13 +74,14 @@
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;
}
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 59bd238..fd59c97 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -62,7 +62,7 @@
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
index 0000000..c8786dc
--- /dev/null
+++ b/src/com/android/settings/widget/VideoPreference.java
@@ -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();
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
index 9024e0b..6a2e4ea 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
@@ -18,11 +18,8 @@
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.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 @@
@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);
- }
-
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
index 1e8020e..a25d34b 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
@@ -17,12 +17,8 @@
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.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 @@
@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 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();
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
index 8692661..5b02182 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
@@ -20,9 +20,6 @@
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.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 @@
@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 @@
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 @@
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);
+ assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@Test
- public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
- // Mock a TwoStatePreference
- final TwoStatePreference preference = mock(TwoStatePreference.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 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_TWIST_TO_FLIP_ENABLED, 0);
-
- // 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);
- }
-
}
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
index 0000000..01c1921
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java
@@ -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;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java
index 217d0b8..66ae679 100644
--- a/tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java
@@ -17,12 +17,8 @@
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.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 @@
@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 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);
+ assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@Test
- public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
- // Mock a TwoStatePreference
- final TwoStatePreference preference = mock(TwoStatePreference.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 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.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();
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
index e484135..7b34666 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
@@ -18,11 +18,7 @@
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.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 @@
@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);
+ assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@Test
- public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
- // Mock a TwoStatePreference
- final TwoStatePreference preference = mock(TwoStatePreference.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 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.
- 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 summary is set to off (as setting is disabled).
- verify(preference).setSummary(R.string.gesture_setting_off);
+ assertThat(mController.isSwitchPrefEnabled()).isFalse();
}
}