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

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

SystemUI: Add double tap to sleep gesture

Change-Id: I4c54718e8ec8774677d13917b3a7ffa3b4b18cb5
parent bed8ca15
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2924,6 +2924,12 @@ public final class Settings {
         */
        public static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";

        /**
         *  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
@@ -24,6 +24,9 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.GestureDetector;
import android.os.PowerManager;
import android.provider.Settings;

import com.android.systemui.EventLogTags;
import com.android.systemui.R;
@@ -39,12 +42,27 @@ public class PhoneStatusBarView extends PanelBar {
    PanelView mNotificationPanel;
    private final PhoneStatusBarTransitions mBarTransitions;
    private ScrimController mScrimController;
    private GestureDetector mDoubleTapGesture;

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

        Resources res = getContext().getResources();
        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() {
@@ -141,6 +159,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);
    }