MotoActions: Implement a dedicated pocket gesture toggle
authordianlujitao <dianlujitao@lineageos.org>
Wed, 2 Feb 2022 09:24:10 +0000 (17:24 +0800)
committerdianlujitao <dianlujitao@lineageos.org>
Sat, 12 Feb 2022 14:32:28 +0000 (22:32 +0800)
Change-Id: I23b41d396f88e897004e571c24a1128ef3e29d49

MotoActions/res/drawable/ic_pocket.xml [new file with mode: 0644]
MotoActions/res/xml/doze_panel.xml
MotoActions/src/org/lineageos/settings/device/DozePreferenceFragment.java
MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java
MotoActions/src/org/lineageos/settings/device/doze/StowSensor.java

diff --git a/MotoActions/res/drawable/ic_pocket.xml b/MotoActions/res/drawable/ic_pocket.xml
new file mode 100644 (file)
index 0000000..44ae6e2
--- /dev/null
@@ -0,0 +1,9 @@
+<!-- drawable/pocket.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?android:attr/colorControlNormal" >
+    <path android:fillColor="#000" android:pathData="M21.9,4.26C21.64,3.55 20.96,3.07 20.2,3.07H20.19L18.46,3.07H3.81C3.07,3.07 2.39,3.54 2.12,4.24C2.04,4.45 2,4.66 2,4.88V10.92L2.07,12.12C2.36,14.85 3.78,17.23 5.97,18.9C6,18.93 6.05,18.96 6.09,19H6.11C7.29,19.86 8.6,20.44 10,20.73C10.68,20.86 11.35,20.93 12,20.93C12.63,20.93 13.25,20.87 13.85,20.76C13.93,20.75 14,20.73 14.07,20.72C14.09,20.71 14.11,20.7 14.14,20.69C15.5,20.4 16.76,19.83 17.89,19H17.91C17.95,18.96 18,18.93 18.03,18.9C20.22,17.23 21.64,14.85 21.93,12.12L22,10.92V4.88C22,4.68 21.97,4.47 21.9,4.26M17.67,10.55L12.96,15.06C12.7,15.32 12.35,15.44 12,15.44C11.67,15.44 11.33,15.32 11.06,15.06L6.36,10.55C5.81,10.03 5.79,9.16 6.32,8.61C6.84,8.06 7.71,8.05 8.26,8.57L12,12.17L15.77,8.57C16.31,8.05 17.18,8.07 17.71,8.61C18.23,9.16 18.21,10.03 17.67,10.55Z" />
+</vector>
index 9ecb5f82492fef13f935770b727c2edce142a11e..628810fbbe8161c2b7228e22f82050601adca53d 100644 (file)
             android:summary="@string/hand_wave_gesture_summary"
             android:icon="@drawable/ic_hand" />
 
+        <SwitchPreference
+            android:key="gesture_pocket"
+            android:defaultValue="true"
+            android:title="@string/pocket_gesture_title"
+            android:summary="@string/pocket_gesture_summary"
+            android:icon="@drawable/ic_pocket" />
+
     </PreferenceCategory>
 </PreferenceScreen>
index 59bb626ca566bc5409e3b57af506e76c1b166f72..58f22afa3a715ef0a1b408064b189d385ee69472 100644 (file)
@@ -49,6 +49,7 @@ public class DozePreferenceFragment extends PreferenceFragment
 
     private SwitchPreference mHandwavePreference;
     private SwitchPreference mPickUpPreference;
+    private SwitchPreference mPocketPreference;
 
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@@ -77,6 +78,10 @@ public class DozePreferenceFragment extends PreferenceFragment
         mPickUpPreference.setEnabled(dozeEnabled);
         mPickUpPreference.setOnPreferenceChangeListener(this);
 
+        mPocketPreference = findPreference(MotoActionsSettings.GESTURE_POCKET_KEY);
+        mPocketPreference.setEnabled(dozeEnabled);
+        mPocketPreference.setOnPreferenceChangeListener(this);
+
         // Hide AOD if not supported and set all its dependents otherwise
         if (!MotoActionsSettings.alwaysOnDisplayAvailable(getActivity())) {
             getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
@@ -141,6 +146,7 @@ public class DozePreferenceFragment extends PreferenceFragment
 
         mHandwavePreference.setEnabled(isChecked);
         mPickUpPreference.setEnabled(isChecked);
+        mPocketPreference.setEnabled(isChecked);
     }
 
     @Override
index 863e2754a9e5378e7204acfce4310b92e6112e1f..50ceb613f07581e827660884de6546b45b378722 100644 (file)
@@ -42,6 +42,7 @@ public class MotoActionsSettings {
 
     static final String GESTURE_IR_WAKEUP_KEY = "gesture_hand_wave";
     static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
+    static final String GESTURE_POCKET_KEY = "gesture_pocket";
 
     static final String ALWAYS_ON_DISPLAY = "always_on_display";
 
@@ -51,6 +52,7 @@ public class MotoActionsSettings {
     private boolean mCameraGestureEnabled;
     private boolean mChopChopEnabled;
     private boolean mPickUpGestureEnabled;
+    private boolean mPocketGestureEnabled;
     private boolean mIrWakeUpEnabled;
     private boolean mIrSilencerEnabled;
     private boolean mFlipToMuteEnabled;
@@ -112,6 +114,10 @@ public class MotoActionsSettings {
         return isDozeEnabled() && !isAlwaysOnEnabled() && mPickUpGestureEnabled;
     }
 
+    public boolean isPocketGestureEnabled() {
+        return isDozeEnabled() && !isAlwaysOnEnabled() && mPocketGestureEnabled;
+    }
+
     public boolean isIrSilencerEnabled() {
         return mIrSilencerEnabled;
     }
@@ -137,6 +143,7 @@ public class MotoActionsSettings {
         mChopChopEnabled = sharedPreferences.getBoolean(GESTURE_CHOP_CHOP_KEY, true);
         mIrWakeUpEnabled = sharedPreferences.getBoolean(GESTURE_IR_WAKEUP_KEY, true);
         mPickUpGestureEnabled = sharedPreferences.getBoolean(GESTURE_PICK_UP_KEY, true);
+        mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, true);
         mIrSilencerEnabled = sharedPreferences.getBoolean(GESTURE_IR_SILENCER_KEY, false);
         mFlipToMuteEnabled = sharedPreferences.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
         mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
@@ -156,6 +163,8 @@ public class MotoActionsSettings {
                 mIrWakeUpEnabled = sharedPreferences.getBoolean(GESTURE_IR_WAKEUP_KEY, true);
             } else if (GESTURE_PICK_UP_KEY.equals(key)) {
                 mPickUpGestureEnabled = sharedPreferences.getBoolean(GESTURE_PICK_UP_KEY, true);
+            } else if (GESTURE_POCKET_KEY.equals(key)) {
+                mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_KEY, true);
             } else if (GESTURE_IR_SILENCER_KEY.equals(key)) {
                 mIrSilencerEnabled = sharedPreferences.getBoolean(GESTURE_IR_SILENCER_KEY, false);
             } else if (GESTURE_FLIP_TO_MUTE_KEY.equals(key)) {
index 8631261c06f9e9423800061839bf3f7ce84b2c66..f1d7b348bf00a7524f304625554675cf20c6d91d 100644 (file)
@@ -61,8 +61,7 @@ public class StowSensor implements ScreenStateNotifier, SensorEventListener {
 
     @Override
     public void screenTurnedOff() {
-        if (!mMotoActionsSettings.isIrWakeupEnabled() &&
-            mMotoActionsSettings.isPickUpEnabled() && !mEnabled) {
+        if (mMotoActionsSettings.isPocketGestureEnabled() && !mEnabled) {
             Log.d(TAG, "Enabling");
             mSensorHelper.registerListener(mSensor, this);
             mEnabled = true;