From aa1d43e9fd363ef107596cc49b9f1b5e3c372ef1 Mon Sep 17 00:00:00 2001 From: dianlujitao Date: Wed, 2 Feb 2022 17:24:10 +0800 Subject: [PATCH] MotoActions: Implement a dedicated pocket gesture toggle Change-Id: I23b41d396f88e897004e571c24a1128ef3e29d49 --- MotoActions/res/drawable/ic_pocket.xml | 9 +++++++++ MotoActions/res/xml/doze_panel.xml | 7 +++++++ .../settings/device/DozePreferenceFragment.java | 6 ++++++ .../lineageos/settings/device/MotoActionsSettings.java | 9 +++++++++ .../org/lineageos/settings/device/doze/StowSensor.java | 3 +-- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 MotoActions/res/drawable/ic_pocket.xml diff --git a/MotoActions/res/drawable/ic_pocket.xml b/MotoActions/res/drawable/ic_pocket.xml new file mode 100644 index 0000000..44ae6e2 --- /dev/null +++ b/MotoActions/res/drawable/ic_pocket.xml @@ -0,0 +1,9 @@ + + + + diff --git a/MotoActions/res/xml/doze_panel.xml b/MotoActions/res/xml/doze_panel.xml index 9ecb5f8..628810f 100644 --- a/MotoActions/res/xml/doze_panel.xml +++ b/MotoActions/res/xml/doze_panel.xml @@ -41,5 +41,12 @@ android:summary="@string/hand_wave_gesture_summary" android:icon="@drawable/ic_hand" /> + + diff --git a/MotoActions/src/org/lineageos/settings/device/DozePreferenceFragment.java b/MotoActions/src/org/lineageos/settings/device/DozePreferenceFragment.java index 59bb626..58f22af 100644 --- a/MotoActions/src/org/lineageos/settings/device/DozePreferenceFragment.java +++ b/MotoActions/src/org/lineageos/settings/device/DozePreferenceFragment.java @@ -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 diff --git a/MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java b/MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java index 863e275..50ceb61 100644 --- a/MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java +++ b/MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java @@ -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)) { diff --git a/MotoActions/src/org/lineageos/settings/device/doze/StowSensor.java b/MotoActions/src/org/lineageos/settings/device/doze/StowSensor.java index 8631261..f1d7b34 100644 --- a/MotoActions/src/org/lineageos/settings/device/doze/StowSensor.java +++ b/MotoActions/src/org/lineageos/settings/device/doze/StowSensor.java @@ -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; -- 2.20.1