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

Commit 15b8ab9a authored by Rashed Abdel-Tawab's avatar Rashed Abdel-Tawab Committed by LuK1337
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>

Author: dianlujitao <dianlujitao@lineageos.org>
Date:   Thu Feb 27 12:57:07 2020 +0800

    SystemUI: Don't sleep on double tap below status bar

    Change-Id: Ic64c29eae63e96f34dc37cda355401b7e2cd2d39

Author: Arian <arian.kulmer@web.de>
Date:   2020-12-27 14:35:33 +0100

    NotificationPanelViewController: Fix DT2S gesture handling

    Change-Id: I9f2d3c63d397c998bea5137f747a9ad95ae2c746

[Pig]: Forward port to R
[bgcngm]: Forward port to S

Co-authored-by: default avatarMichael W <baddaemon87@gmail.com>
Change-Id: I7489204e348906dcf6e34fa04f2121974c22ddb9
parent 3fcfcff2
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.annotation.NonNull;
import android.app.Fragment;
import android.app.StatusBarManager;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -73,6 +74,7 @@ import android.transition.TransitionManager;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.MathUtils;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.VelocityTracker;
@@ -309,6 +311,8 @@ public final class NotificationPanelViewController extends PanelViewController {

    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 M_DUMMY_DIRTY_RECT = new Rect(0, 0, 1, 1);
    private static final Rect EMPTY_RECT = new Rect();
@@ -535,6 +539,8 @@ public final class NotificationPanelViewController extends PanelViewController {

    private final NotificationShadeDepthController mDepthController;
    private final int mDisplayId;
    private boolean mDoubleTapToSleepEnabled;
    private GestureDetector mDoubleTapGesture;

    private KeyguardIndicationController mKeyguardIndicationController;
    private int mHeadsUpInset;
@@ -788,7 +794,8 @@ public final class NotificationPanelViewController extends PanelViewController {
            CameraGestureHelper cameraGestureHelper,
            KeyguardBottomAreaViewModel keyguardBottomAreaViewModel,
            KeyguardBottomAreaInteractor keyguardBottomAreaInteractor,
            TunerService tunerService) {
            TunerService tunerService,
            Context context) {
        super(view,
                falsingManager,
                dozeLog,
@@ -882,6 +889,16 @@ public final class NotificationPanelViewController extends PanelViewController {
        });
        mBottomAreaShadeAlphaAnimator.setDuration(160);
        mBottomAreaShadeAlphaAnimator.setInterpolator(Interpolators.ALPHA_OUT);
        mDoubleTapGesture = new GestureDetector(context,
                new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                if (mPowerManager != null) {
                    mPowerManager.goToSleep(e.getEventTime());
                }
                return true;
            }
        });
        mConversationNotificationManager = conversationNotificationManager;
        mAuthController = authController;
        mLockIconViewController = lockIconViewController;
@@ -4269,6 +4286,10 @@ public final class NotificationPanelViewController extends PanelViewController {
                    return false;
                }

                if (mDoubleTapToSleepEnabled && !mPulsing && !mDozing) {
                    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) {
@@ -4816,6 +4837,7 @@ public final class NotificationPanelViewController extends PanelViewController {
            mStatusBarStateListener.onStateChanged(mStatusBarStateController.getState());
            mConfigurationController.addCallback(mConfigurationListener);
            mTunerService.addTunable(this, STATUS_BAR_QUICK_QS_PULLDOWN);
            mTunerService.addTunable(this, DOUBLE_TAP_SLEEP_GESTURE);
            // Theme might have changed between inflating this view and attaching it to the
            // window, so
            // force a call to onThemeChanged
@@ -4840,6 +4862,8 @@ public final class NotificationPanelViewController extends PanelViewController {
        public void onTuningChanged(String key, String newValue) {
            if (STATUS_BAR_QUICK_QS_PULLDOWN.equals(key)) {
                mOneFingerQuickSettingsIntercept = TunerService.parseInteger(newValue, 1);
            } else if (DOUBLE_TAP_SLEEP_GESTURE.equals(key)) {
                mDoubleTapToSleepEnabled = TunerService.parseIntegerSwitch(newValue, true);
            }
        }
    }
+37 −12
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.systemui.shade

import android.content.Context
import android.hardware.display.AmbientDisplayConfiguration
import android.os.PowerManager
import android.os.SystemClock
import android.os.UserHandle
import android.provider.Settings
@@ -32,6 +34,7 @@ import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent
import com.android.systemui.tuner.TunerService
import com.android.systemui.tuner.TunerService.Tunable
import lineageos.providers.LineageSettings;
import java.io.PrintWriter
import javax.inject.Inject

@@ -52,13 +55,22 @@ class PulsingGestureListener @Inject constructor(
        private val centralSurfaces: CentralSurfaces,
        private val ambientDisplayConfiguration: AmbientDisplayConfiguration,
        private val statusBarStateController: StatusBarStateController,
        private val powerManager: PowerManager,
        tunerService: TunerService,
        dumpManager: DumpManager
        dumpManager: DumpManager,
        context: Context
) : GestureDetector.SimpleOnGestureListener(), Dumpable {
    private var doubleTapEnabled = false
    private var singleTapEnabled = false
    private var doubleTapEnabledNative = false

    companion object {
        internal val DOUBLE_TAP_SLEEP_GESTURE =
            "lineagesystem:" + LineageSettings.System.DOUBLE_TAP_SLEEP_GESTURE
    }
    private var doubleTapToSleepEnabled = false
    private val quickQsOffsetHeight: Int

    init {
        val tunable = Tunable { key: String?, value: String? ->
            when (key) {
@@ -70,14 +82,20 @@ class PulsingGestureListener @Inject constructor(
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE ->
                    singleTapEnabled = ambientDisplayConfiguration.tapGestureEnabled(
                            UserHandle.USER_CURRENT)
                DOUBLE_TAP_SLEEP_GESTURE ->
                    doubleTapToSleepEnabled = TunerService.parseIntegerSwitch(value, true)
            }
        }
        tunerService.addTunable(tunable,
                Settings.Secure.DOUBLE_TAP_TO_WAKE,
                Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE)
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
                DOUBLE_TAP_SLEEP_GESTURE)

        dumpManager.registerDumpable(this)

        quickQsOffsetHeight = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.quick_qs_offset_height)
    }

    override fun onSingleTapUp(e: MotionEvent): Boolean {
@@ -103,17 +121,23 @@ class PulsingGestureListener @Inject constructor(
    override fun onDoubleTapEvent(e: MotionEvent): Boolean {
        // React to the [MotionEvent.ACTION_UP] event after double tap is detected. Falsing
        // checks MUST be on the ACTION_UP event.
        if (e.actionMasked == MotionEvent.ACTION_UP &&
                statusBarStateController.isDozing &&
        if (e.actionMasked == MotionEvent.ACTION_UP && !falsingManager.isFalseDoubleTap) {
            if (statusBarStateController.isDozing &&
                (doubleTapEnabled || singleTapEnabled || doubleTapEnabledNative) &&
                !falsingManager.isProximityNear &&
                !falsingManager.isFalseDoubleTap
                !falsingManager.isProximityNear
            ) {
                centralSurfaces.wakeUpIfDozing(
                        SystemClock.uptimeMillis(),
                        notificationShadeWindowView,
                        "PULSING_DOUBLE_TAP")
                return true
            } else if (!statusBarStateController.isDozing &&
                doubleTapToSleepEnabled &&
                e.getY() < quickQsOffsetHeight
            ) {
                powerManager.goToSleep(e.getEventTime())
                return true
            }
        }
        return false
    }
@@ -122,6 +146,7 @@ class PulsingGestureListener @Inject constructor(
        pw.println("singleTapEnabled=$singleTapEnabled")
        pw.println("doubleTapEnabled=$doubleTapEnabled")
        pw.println("doubleTapEnabledNative=$doubleTapEnabledNative")
        pw.println("doubleTapToSleepEnabled=$doubleTapToSleepEnabled")
        pw.println("isDocked=${dockManager.isDocked}")
        pw.println("isProxCovered=${falsingManager.isProximityNear}")
    }