Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d06f8d6f authored by Dalingrin's avatar Dalingrin Committed by Steve Kondik
Browse files

SystemUI: Add double tap to sleep gesture

Change-Id: I4c54718e8ec8774677d13917b3a7ffa3b4b18cb5
parent 03f21176
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3694,6 +3694,12 @@ public final class Settings {
         * the setting value. See an example above.
         */

        /**
         *  Enable statusbar double tap gesture on to put device to sleep
         * @hide
         */
        public static final String DOUBLE_TAP_SLEEP_GESTURE = "double_tap_sleep_gesture";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+22 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.GestureDetector;
import android.os.PowerManager;
import android.provider.Settings;

import com.android.systemui.DejankUtils;
import com.android.systemui.EventLogTags;
@@ -48,11 +51,26 @@ public class PhoneStatusBarView extends PanelBar {
            }
        }
    };
    private GestureDetector mDoubleTapGesture;

    public PhoneStatusBarView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mBarTransitions = new PhoneStatusBarTransitions(this);

        mDoubleTapGesture = new GestureDetector(mContext, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                Log.d(TAG, "Gesture!!");
                if(pm != null)
                    pm.goToSleep(e.getEventTime());
                else
                    Log.d(TAG, "getSystemService returned null PowerManager");

                return true;
            }
        });
    }

    public BarTransitions getBarTransitions() {
@@ -131,6 +149,10 @@ public class PhoneStatusBarView extends PanelBar {
            }
        }

        if (Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.DOUBLE_TAP_SLEEP_GESTURE, 0) == 1)
            mDoubleTapGesture.onTouchEvent(event);

        return barConsumedEvent || super.onTouchEvent(event);
    }