Add more gesture setting pages.
Bug: 32637613
Test: make -j40 RunSettingsRoboTests
Change-Id: I77f90b8b7e3348ed717ee78693860f48e13070f2
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index bfadc24..949b6b7 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -97,7 +97,12 @@
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageDetail;
import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.gestures.DoubleTapPowerSettings;
+import com.android.settings.gestures.DoubleTapScreenPreferenceController;
+import com.android.settings.gestures.DoubleTapScreenSettings;
+import com.android.settings.gestures.DoubleTwistGestureSettings;
import com.android.settings.gestures.GestureSettings;
+import com.android.settings.gestures.PickupGestureSettings;
import com.android.settings.gestures.SwipeToNotificationSettings;
import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
import com.android.settings.inputmethod.InputAndGestureSettings;
@@ -350,6 +355,10 @@
AccountSettings.class.getName(),
GestureSettings.class.getName(),
SwipeToNotificationSettings.class.getName(),
+ DoubleTapPowerSettings.class.getName(),
+ DoubleTapScreenSettings.class.getName(),
+ PickupGestureSettings.class.getName(),
+ DoubleTwistGestureSettings.class.getName(),
CryptKeeperSettings.class.getName(),
DataUsageSummary.class.getName(),
DreamSettings.class.getName(),
diff --git a/src/com/android/settings/core/InstrumentedFragment.java b/src/com/android/settings/core/InstrumentedFragment.java
index 533d2af..45e855e 100644
--- a/src/com/android/settings/core/InstrumentedFragment.java
+++ b/src/com/android/settings/core/InstrumentedFragment.java
@@ -43,6 +43,10 @@
protected final int INPUT_AND_GESTURE_CATEGORY_FRAGMENT = PLACEHOLDER_METRIC + 6;
protected final int LANGUAGE_AND_REGION_CATEGORY_FRAGMENT = PLACEHOLDER_METRIC + 7;
protected final int GESTURE_SWIPE_TO_NOTIFICATION = PLACEHOLDER_METRIC + 8;
+ protected final int GESTURE_DOUBLE_TAP_POWER = PLACEHOLDER_METRIC + 9;
+ protected final int GESTURE_PICKUP = PLACEHOLDER_METRIC + 10;
+ protected final int GESTURE_DOUBLE_TAP_SCREEN = PLACEHOLDER_METRIC + 11;
+ protected final int GESTURE_DOUBLE_TWIST = PLACEHOLDER_METRIC + 12;
public InstrumentedFragment() {
// Mixin that logs visibility change for activity.
diff --git a/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java b/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
new file mode 100644
index 0000000..7838ae7
--- /dev/null
+++ b/src/com/android/settings/gestures/DoubleTapPowerPreferenceController.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.gestures;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+
+import com.android.settings.core.PreferenceController;
+
+public class DoubleTapPowerPreferenceController extends PreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
+
+ public DoubleTapPowerPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ return false;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_DOUBLE_TAP_POWER;
+ }
+
+ @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(),
+ Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? 0 : 1);
+ return true;
+ }
+
+ private boolean isDoubleTapEnabled() {
+ 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
new file mode 100644
index 0000000..8244165
--- /dev/null
+++ b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
@@ -0,0 +1,58 @@
+/*
+ * 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 com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DoubleTapPowerSettings extends DashboardFragment {
+
+ private static final String TAG = "DoubleTapPower";
+
+ @Override
+ public int getMetricsCategory() {
+ return GESTURE_DOUBLE_TAP_POWER;
+ }
+
+ @Override
+ protected String getCategoryKey() {
+ return null;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.double_tap_power_settings;
+ }
+
+ @Override
+ protected List<PreferenceController> getPreferenceControllers(Context context) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new DoubleTapPowerPreferenceController(context));
+ return controllers;
+ }
+}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
new file mode 100644
index 0000000..be1c53f
--- /dev/null
+++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
@@ -0,0 +1,80 @@
+/*
+ * 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.annotation.UserIdInt;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+
+import com.android.internal.hardware.AmbientDisplayConfiguration;
+import com.android.settings.core.PreferenceController;
+
+public class DoubleTapScreenPreferenceController extends PreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ 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);
+ mAmbientConfig = config;
+ mUserId = userId;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mAmbientConfig.pulseOnDoubleTapAvailable();
+ }
+
+ @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;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean enabled = (boolean) newValue;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
+ return true;
+ }
+}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenSettings.java b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
new file mode 100644
index 0000000..12e3b64
--- /dev/null
+++ b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
@@ -0,0 +1,61 @@
+/*
+ * 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.os.UserHandle;
+
+import com.android.internal.hardware.AmbientDisplayConfiguration;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DoubleTapScreenSettings extends DashboardFragment {
+
+ private static final String TAG = "DoubleTapScreen";
+
+ @Override
+ public int getMetricsCategory() {
+ return GESTURE_DOUBLE_TAP_SCREEN;
+ }
+
+ @Override
+ protected String getCategoryKey() {
+ return null;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.double_tap_screen_settings;
+ }
+
+ @Override
+ protected List<PreferenceController> getPreferenceControllers(Context context) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new DoubleTapScreenPreferenceController(
+ context, 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
new file mode 100644
index 0000000..4f8d2de
--- /dev/null
+++ b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
@@ -0,0 +1,58 @@
+/*
+ * 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 com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DoubleTwistGestureSettings extends DashboardFragment {
+
+ private static final String TAG = "DoubleTwistGesture";
+
+ @Override
+ public int getMetricsCategory() {
+ return GESTURE_DOUBLE_TWIST;
+ }
+
+ @Override
+ protected String getCategoryKey() {
+ return null;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.double_twist_gesture_settings;
+ }
+
+ @Override
+ protected List<PreferenceController> getPreferenceControllers(Context context) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new DoubleTwistPreferenceController(context));
+ return controllers;
+ }
+}
diff --git a/src/com/android/settings/gestures/DoubleTwistPreferenceController.java b/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
new file mode 100644
index 0000000..071255b
--- /dev/null
+++ b/src/com/android/settings/gestures/DoubleTwistPreferenceController.java
@@ -0,0 +1,99 @@
+/*
+ * 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.content.res.Resources;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+
+public class DoubleTwistPreferenceController extends PreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
+
+ public DoubleTwistPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return hasSensor(R.string.gesture_double_twist_sensor_name,
+ R.string.gesture_double_twist_sensor_vendor);
+ }
+
+ @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;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_DOUBLE_TWIST;
+ }
+
+ private boolean isDoubleTwistEnabled() {
+ final int doubleTwistEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
+ return doubleTwistEnabled != 0;
+ }
+
+ private boolean hasSensor(int nameResId, int vendorResId) {
+ final Resources resources = mContext.getResources();
+ final String name = resources.getString(nameResId);
+ final String vendor = resources.getString(vendorResId);
+ if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
+ final SensorManager sensorManager =
+ (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
+ for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
+ if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
+ return true;
+ }
+ }
+ }
+ 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/GestureSettings.java b/src/com/android/settings/gestures/GestureSettings.java
index c68d922..8ba4d0b 100644
--- a/src/com/android/settings/gestures/GestureSettings.java
+++ b/src/com/android/settings/gestures/GestureSettings.java
@@ -17,16 +17,11 @@
package com.android.settings.gestures;
import android.content.Context;
-import android.content.res.Resources;
-import android.hardware.Sensor;
-import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
-import android.provider.Settings.Secure;
import android.support.v7.preference.Preference;
import android.support.v7.widget.RecyclerView;
-import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -34,7 +29,8 @@
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -46,66 +42,39 @@
* This will create individual switch preference for each gesture and handle updates when each
* preference is updated
*/
-public class GestureSettings extends SettingsPreferenceFragment implements
- Preference.OnPreferenceChangeListener, Indexable {
+public class GestureSettings extends DashboardFragment {
private static final String TAG = "GestureSettings";
- private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
- private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
- private static final String PREF_KEY_PICK_UP = "gesture_pick_up";
- private static final String PREF_KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
- private static final String DEBUG_DOZE_COMPONENT = "debug.doze.component";
-
private List<GesturePreference> mPreferences;
- private SwipeToNotificationPreferenceController mSwipeToNotificationPreferenceController;
-
- private AmbientDisplayConfiguration mAmbientConfig;
@Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.gesture_settings);
- Context context = getActivity();
- mSwipeToNotificationPreferenceController =
- new SwipeToNotificationPreferenceController(context);
+ protected int getPreferenceScreenResId() {
+ return R.xml.gesture_settings;
+ }
+
+ @Override
+ 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));
+ controllers.add(new PickupGesturePreferenceController(
+ context, ambientConfig, UserHandle.myUserId()));
+ controllers.add(new DoubleTapScreenPreferenceController(
+ context, ambientConfig, UserHandle.myUserId()));
+ return controllers;
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ super.onCreatePreferences(savedInstanceState, rootKey);
mPreferences = new ArrayList();
-
- // Double tap power for camera
- if (isCameraDoubleTapPowerGestureAvailable(getResources())) {
- int cameraDisabled = Secure.getInt(
- getContentResolver(), Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
- addPreference(PREF_KEY_DOUBLE_TAP_POWER, cameraDisabled == 0);
- } else {
- removePreference(PREF_KEY_DOUBLE_TAP_POWER);
- }
-
- // Ambient Display
- mAmbientConfig = new AmbientDisplayConfiguration(context);
- if (mAmbientConfig.pulseOnPickupAvailable()) {
- boolean pickup = mAmbientConfig.pulseOnPickupEnabled(UserHandle.myUserId());
- addPreference(PREF_KEY_PICK_UP, pickup);
- } else {
- removePreference(PREF_KEY_PICK_UP);
- }
- if (mAmbientConfig.pulseOnDoubleTapAvailable()) {
- boolean doubleTap = mAmbientConfig.pulseOnDoubleTapEnabled(UserHandle.myUserId());
- addPreference(PREF_KEY_DOUBLE_TAP_SCREEN, doubleTap);
- } else {
- removePreference(PREF_KEY_DOUBLE_TAP_SCREEN);
- }
-
- // Fingerprint slide for notifications
- mSwipeToNotificationPreferenceController.displayPreference(getPreferenceScreen());
-
- // Double twist for camera mode
- if (isDoubleTwistAvailable(context)) {
- int doubleTwistEnabled = Secure.getInt(
- getContentResolver(), Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
- addPreference(PREF_KEY_DOUBLE_TWIST, doubleTwistEnabled != 0);
- } else {
- removePreference(PREF_KEY_DOUBLE_TWIST);
- }
-
+ addPreferenceToTrackingList(SwipeToNotificationPreferenceController.class);
+ addPreferenceToTrackingList(DoubleTapScreenPreferenceController.class);
+ addPreferenceToTrackingList(DoubleTwistPreferenceController.class);
+ addPreferenceToTrackingList(PickupGesturePreferenceController.class);
+ addPreferenceToTrackingList(DoubleTapPowerPreferenceController.class);
}
@Override
@@ -135,13 +104,6 @@
}
@Override
- public void onResume() {
- super.onResume();
- mSwipeToNotificationPreferenceController.updateState(
- findPreference(mSwipeToNotificationPreferenceController.getPreferenceKey()));
- }
-
- @Override
public void onStart() {
super.onStart();
for (GesturePreference preference : mPreferences) {
@@ -158,21 +120,13 @@
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- boolean enabled = (boolean) newValue;
- String key = preference.getKey();
- if (PREF_KEY_DOUBLE_TAP_POWER.equals(key)) {
- Secure.putInt(getContentResolver(),
- Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? 0 : 1);
- } else if (PREF_KEY_PICK_UP.equals(key)) {
- Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
- } else if (PREF_KEY_DOUBLE_TAP_SCREEN.equals(key)) {
- Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
- } else if (PREF_KEY_DOUBLE_TWIST.equals(key)) {
- Secure.putInt(getContentResolver(),
- Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
- }
- return true;
+ protected String getCategoryKey() {
+ return null;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
}
@Override
@@ -185,37 +139,12 @@
return MetricsEvent.SETTINGS_GESTURES;
}
- private static boolean isCameraDoubleTapPowerGestureAvailable(Resources res) {
- return res.getBoolean(
- com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
- }
-
- private static boolean isDoubleTwistAvailable(Context context) {
- return hasSensor(context, R.string.gesture_double_twist_sensor_name,
- R.string.gesture_double_twist_sensor_vendor);
- }
-
- private static boolean hasSensor(Context context, int nameResId, int vendorResId) {
- Resources resources = context.getResources();
- String name = resources.getString(nameResId);
- String vendor = resources.getString(vendorResId);
- if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
- SensorManager sensorManager =
- (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
- if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
- return true;
- }
- }
+ private <T extends PreferenceController> void addPreferenceToTrackingList(Class<T> clazz) {
+ final PreferenceController controller = getPreferenceController(clazz);
+ final Preference preference = findPreference(controller.getPreferenceKey());
+ if (preference != null && preference instanceof GesturePreference) {
+ mPreferences.add((GesturePreference) preference);
}
- return false;
- }
-
- private void addPreference(String key, boolean enabled) {
- GesturePreference preference = (GesturePreference) findPreference(key);
- preference.setChecked(enabled);
- preference.setOnPreferenceChangeListener(this);
- mPreferences.add(preference);
}
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -238,22 +167,19 @@
ArrayList<String> result = new ArrayList<String>();
AmbientDisplayConfiguration ambientConfig
= new AmbientDisplayConfiguration(context);
- if (!isCameraDoubleTapPowerGestureAvailable(context.getResources())) {
- result.add(PREF_KEY_DOUBLE_TAP_POWER);
- }
- if (!ambientConfig.pulseOnPickupAvailable()) {
- result.add(PREF_KEY_PICK_UP);
- }
- if (!ambientConfig.pulseOnDoubleTapAvailable()) {
- result.add(PREF_KEY_DOUBLE_TAP_SCREEN);
- }
+ new DoubleTapPowerPreferenceController(context)
+ .updateNonIndexableKeys(result);
+ new PickupGesturePreferenceController(
+ context, ambientConfig, UserHandle.myUserId())
+ .updateNonIndexableKeys(result);
+ new DoubleTapScreenPreferenceController(
+ context, ambientConfig, UserHandle.myUserId())
+ .updateNonIndexableKeys(result);
new SwipeToNotificationPreferenceController(context)
.updateNonIndexableKeys(result);
- if (!isDoubleTwistAvailable(context)) {
- result.add(PREF_KEY_DOUBLE_TWIST);
- }
+ new DoubleTwistPreferenceController(context)
+ .updateNonIndexableKeys(result);
return result;
}
};
-
}
diff --git a/src/com/android/settings/gestures/PickupGesturePreferenceController.java b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
new file mode 100644
index 0000000..b37e756
--- /dev/null
+++ b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
@@ -0,0 +1,81 @@
+/*
+ * 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.annotation.UserIdInt;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+
+import com.android.internal.hardware.AmbientDisplayConfiguration;
+import com.android.settings.core.PreferenceController;
+
+public class PickupGesturePreferenceController extends PreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ 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);
+ mAmbientConfig = config;
+ mUserId = userId;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mAmbientConfig.pulseOnPickupAvailable();
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ return false;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_PICK_UP;
+ }
+
+ @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(),
+ Settings.Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
+ return true;
+ }
+
+}
diff --git a/src/com/android/settings/gestures/PickupGestureSettings.java b/src/com/android/settings/gestures/PickupGestureSettings.java
new file mode 100644
index 0000000..96f0796
--- /dev/null
+++ b/src/com/android/settings/gestures/PickupGestureSettings.java
@@ -0,0 +1,61 @@
+/*
+ * 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.os.UserHandle;
+
+import com.android.internal.hardware.AmbientDisplayConfiguration;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PickupGestureSettings extends DashboardFragment {
+
+ private static final String TAG = "PickupGestureSettings";
+
+ @Override
+ public int getMetricsCategory() {
+ return GESTURE_PICKUP;
+ }
+
+ @Override
+ protected String getCategoryKey() {
+ return null;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.pick_up_gesture_settings;
+ }
+
+ @Override
+ protected List<PreferenceController> getPreferenceControllers(Context context) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new PickupGesturePreferenceController(
+ context, new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
+ return controllers;
+ }
+}
diff --git a/src/com/android/settings/inputmethod/InputAndGestureSettings.java b/src/com/android/settings/inputmethod/InputAndGestureSettings.java
index c3f0e7b..965cdec 100644
--- a/src/com/android/settings/inputmethod/InputAndGestureSettings.java
+++ b/src/com/android/settings/inputmethod/InputAndGestureSettings.java
@@ -17,10 +17,17 @@
package com.android.settings.inputmethod;
import android.content.Context;
+import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
+import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.gestures.DoubleTapPowerPreferenceController;
+import com.android.settings.gestures.DoubleTapScreenPreferenceController;
+import com.android.settings.gestures.DoubleTwistPreferenceController;
+import com.android.settings.gestures.PickupGesturePreferenceController;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
import com.android.settingslib.drawer.CategoryKey;
@@ -31,6 +38,8 @@
private static final String TAG = "InputAndGestureSettings";
+ private AmbientDisplayConfiguration mAmbientDisplayConfig;
+
@Override
public int getMetricsCategory() {
return INPUT_AND_GESTURE_CATEGORY_FRAGMENT;
@@ -57,10 +66,24 @@
= new GameControllerPreferenceController(context);
getLifecycle().addObserver(gameControllerPreferenceController);
+ if (mAmbientDisplayConfig == null) {
+ mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
+ }
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 PickupGesturePreferenceController(
+ context, mAmbientDisplayConfig, UserHandle.myUserId()));
+ controllers.add(new DoubleTapScreenPreferenceController(
+ context, mAmbientDisplayConfig, UserHandle.myUserId()));
return controllers;
}
+
+ @VisibleForTesting
+ void setAmbientDisplayConfig(AmbientDisplayConfiguration ambientConfig) {
+ mAmbientDisplayConfig = ambientConfig;
+ }
}