--- /dev/null
+<?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
<?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
<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" />
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"
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"
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"
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"
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"
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);
@CallSuper
@Override
+ public void onStop() {
+ mLifecycle.onStop();
+ super.onStop();
+ }
+
+ @CallSuper
+ @Override
public void onResume() {
mLifecycle.onResume();
super.onResume();
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
}
@Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- return false;
+ protected String getVideoPrefKey() {
+ return PREF_KEY_VIDEO;
}
@Override
}
@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(),
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;
@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;
}
}
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;
}
}
@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;
}
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);
+ }
}
@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;
}
}
@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;
}
}
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
}
@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;
}
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;
- }
}
--- /dev/null
+/*
+ * 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();
+}
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;
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;
}
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;
}
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;
}
}
@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
@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;
}
}
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
}
@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
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;
+ }
}
@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;
}
}
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;
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
+ final Lifecycle lifecycle = getLifecycle();
final GameControllerPreferenceController gameControllerPreferenceController
= new GameControllerPreferenceController(context);
getLifecycle().addObserver(gameControllerPreferenceController);
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;
}
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;
--- /dev/null
+/*
+ * 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();
+ }
+ }
+}
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;
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)
@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);
- }
-
}
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;
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)
@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;
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();
}
}
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;
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)
@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));
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));
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();
}
-
}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
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;
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)
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private PreferenceScreen mScreen;
@Mock
private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
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();
}
}
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;
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)
@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();
}
}