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

Commit fee2c57f authored by Rashed Abdel-Tawab's avatar Rashed Abdel-Tawab Committed by Michael Bestas
Browse files

SystemUI: Add double tap to sleep gesture



Author: Roman Birg <roman@cyngn.com>
Date:   Sun Nov 23 06:54:06 2014 -0800

    SystemUI: double tap to sleep improvements

    * Make it more reliable
    * Add it to keyguard
    * Add a content observer to not always query Settings.System on every
    touch event

    Change-Id: I292c4d9d9f810843590b7a9ec6e15b99ac44009d
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

Author: Adnan Begovic <adnan@cyngn.com>
Date:   Wed Nov 11 12:05:59 2015 -0800

    fw: Move DOUBLE_TAP_SLEEP_GESTURE to CMSettings.

    Change-Id: I8274b7c241cef6835a1114a702e68c95b6d2e036

Author: Zhao Wei Liew <zhaoweiliew@gmail.com>
Date:   Fri Oct 7 08:56:25 2016 +0800

    SystemUI: Use Tuner API for CM settings

    Get rid of all the excess code by implementing TunerService.Tunable
    and observing any changes made to the settings through it.

    Remove UserContentObserver as the Tuner API handles user switches.

    Also remove some unused imports that were introduced in earlier
    CM commits, but were never removed since.

    Change-Id: Iecafafabdaec82b3b3c72293bea865de48f0e90a

Author: Altaf-Mahdi <altaf.mahdi@gmail.com>
Date:   Wed Nov 11 16:07:49 2015 -0500

    Double tap to sleep anywhere on the lock screen [1/3]

    Change-Id: I7dd46f3fafeb2e629974c0f32083d4d9774fb1de
    [neo: Using Tuner API.]
    Signed-off-by: default avatarPranav Vashi <neobuddy89@gmail.com>

Change-Id: Ic1a40d4340890905de2631c666270e81c390d261
parent a2019f5a
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.util.MathUtils;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.VelocityTracker;
@@ -158,6 +159,8 @@ public class NotificationPanelView extends PanelView implements

    private static final String STATUS_BAR_QUICK_QS_PULLDOWN =
            "lineagesystem:" + LineageSettings.System.STATUS_BAR_QUICK_QS_PULLDOWN;
    private static final String DOUBLE_TAP_SLEEP_GESTURE =
            "lineagesystem:" + LineageSettings.System.DOUBLE_TAP_SLEEP_GESTURE;

    private static final Rect mDummyDirtyRect = new Rect(0, 0, 1, 1);
    private static final Rect mEmptyRect = new Rect();
@@ -414,6 +417,9 @@ public class NotificationPanelView extends PanelView implements
            Dependency.get(ShadeController.class);
    private int mDisplayId;

    private boolean mDoubleTapToSleepEnabled;
    private GestureDetector mDoubleTapGesture;

    /**
     * Cache the resource id of the theme to avoid unnecessary work in onThemeChanged.
     *
@@ -486,6 +492,16 @@ public class NotificationPanelView extends PanelView implements
        });
        mBottomAreaShadeAlphaAnimator.setDuration(160);
        mBottomAreaShadeAlphaAnimator.setInterpolator(Interpolators.ALPHA_OUT);
        mDoubleTapGesture = new GestureDetector(mContext,
                new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                if (mPowerManager != null) {
                    mPowerManager.goToSleep(e.getEventTime());
                }
                return true;
            }
        });
    }

    /**
@@ -550,6 +566,7 @@ public class NotificationPanelView extends PanelView implements
        Dependency.get(ZenModeController.class).addCallback(this);
        Dependency.get(ConfigurationController.class).addCallback(this);
        Dependency.get(TunerService.class).addTunable(this, STATUS_BAR_QUICK_QS_PULLDOWN);
        Dependency.get(TunerService.class).addTunable(this, DOUBLE_TAP_SLEEP_GESTURE);
        mUpdateMonitor.registerCallback(mKeyguardUpdateCallback);
        // Theme might have changed between inflating this view and attaching it to the window, so
        // force a call to onThemeChanged
@@ -571,6 +588,8 @@ public class NotificationPanelView extends PanelView implements
    public void onTuningChanged(String key, String newValue) {
        if (STATUS_BAR_QUICK_QS_PULLDOWN.equals(key)) {
            mOneFingerQuickSettingsIntercept = newValue == null ? 1 : Integer.parseInt(newValue);
        } else if (DOUBLE_TAP_SLEEP_GESTURE.equals(key)) {
            mDoubleTapToSleepEnabled = newValue == null || Integer.parseInt(newValue) == 1;
        }
    }

@@ -1247,6 +1266,10 @@ public class NotificationPanelView extends PanelView implements
            return false;
        }

        if (mDoubleTapToSleepEnabled && mBarState == StatusBarState.KEYGUARD) {
            mDoubleTapGesture.onTouchEvent(event);
        }

        // Make sure the next touch won't the blocked after the current ends.
        if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
+25 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.media.AudioManager;
import android.media.session.MediaSessionLegacyHelper;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
@@ -71,6 +72,8 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll
import com.android.systemui.statusbar.phone.ScrimController.ScrimVisibility;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;

import java.io.FileDescriptor;
import java.io.PrintWriter;

@@ -81,6 +84,9 @@ public class StatusBarWindowView extends FrameLayout {
    public static final String TAG = "StatusBarWindowView";
    public static final boolean DEBUG = StatusBar.DEBUG;

    private static final String DOUBLE_TAP_SLEEP_GESTURE =
            "lineagesystem:" + LineageSettings.System.DOUBLE_TAP_SLEEP_GESTURE;

    private final GestureDetector mGestureDetector;
    private final StatusBarStateController mStatusBarStateController;
    private boolean mDoubleTapEnabled;
@@ -99,6 +105,9 @@ public class StatusBarWindowView extends FrameLayout {
    private final Paint mTransparentSrcPaint = new Paint();
    private FalsingManager mFalsingManager;

    private boolean mDoubleTapToSleepEnabled;
    private int mQuickQsTotalHeight;

    // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by
    // DecorView, but since this is a special window we have to roll our own.
    private View mFloatingActionModeOriginatingView;
@@ -125,6 +134,14 @@ public class StatusBarWindowView extends FrameLayout {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (!mService.isDozing() && mDoubleTapToSleepEnabled
                    && e.getY() < mQuickQsTotalHeight) {
                PowerManager pm = mContext.getSystemService(PowerManager.class);
                if (pm != null) {
                    pm.goToSleep(e.getEventTime());
                }
                return true;
            }
            if (mDoubleTapEnabled || mSingleTapEnabled) {
                mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this,
                        "DOUBLE_TAP");
@@ -141,6 +158,10 @@ public class StatusBarWindowView extends FrameLayout {
                break;
            case Settings.Secure.DOZE_TAP_SCREEN_GESTURE:
                mSingleTapEnabled = configuration.tapGestureEnabled(UserHandle.USER_CURRENT);
                break;
            case DOUBLE_TAP_SLEEP_GESTURE:
                mDoubleTapToSleepEnabled = newValue == null || Integer.parseInt(newValue) == 1;
                break;
        }
    };

@@ -161,7 +182,10 @@ public class StatusBarWindowView extends FrameLayout {
        mStatusBarStateController = Dependency.get(StatusBarStateController.class);
        Dependency.get(TunerService.class).addTunable(mTunable,
                Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE);
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
                DOUBLE_TAP_SLEEP_GESTURE);
        mQuickQsTotalHeight = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.quick_qs_total_height);
    }

    @Override