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

Commit b91d0aa8 authored by Rashed Abdel-Tawab's avatar Rashed Abdel-Tawab Committed by Bruno Martins
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>

[Pig]: Forward port to R

Change-Id: Ic1a40d4340890905de2631c666270e81c390d261
parent 00a166d6
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.animation.ValueAnimator;
import android.app.ActivityManager;
import android.app.Fragment;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Canvas;
@@ -45,6 +46,7 @@ import android.os.PowerManager;
import android.os.SystemClock;
import android.util.Log;
import android.util.MathUtils;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.VelocityTracker;
@@ -194,6 +196,8 @@ public 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();
@@ -421,6 +425,8 @@ public class NotificationPanelViewController extends PanelViewController {
    private final NotificationLockscreenUserManager mLockscreenUserManager;
    private final ShadeController mShadeController;
    private int mDisplayId;
    private boolean mDoubleTapToSleepEnabled;
    private GestureDetector mDoubleTapGesture;

    /**
     * Cache the resource id of the theme to avoid unnecessary work in onThemeChanged.
@@ -505,7 +511,7 @@ public class NotificationPanelViewController extends PanelViewController {
            MediaHierarchyManager mediaHierarchyManager,
            BiometricUnlockController biometricUnlockController,
            StatusBarKeyguardViewManager statusBarKeyguardViewManager,
            TunerService tunerService) {
            TunerService tunerService, Context context) {
        super(view, falsingManager, dozeLog, keyguardStateController,
                (SysuiStatusBarStateController) statusBarStateController, vibratorHelper,
                latencyTracker, flingAnimationUtilsBuilder, statusBarTouchableRegionManager);
@@ -564,6 +570,16 @@ public 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;
            }
        });
        mShadeController = shadeController;
        mLockscreenUserManager = notificationLockscreenUserManager;
        mEntryManager = notificationEntryManager;
@@ -3182,6 +3198,10 @@ public class NotificationPanelViewController extends PanelViewController {
                    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) {
@@ -3641,6 +3661,7 @@ public class NotificationPanelViewController extends PanelViewController {
            mZenModeController.addCallback(mZenModeControllerCallback);
            mConfigurationController.addCallback(mConfigurationListener);
            mTunerService.addTunable(this, STATUS_BAR_QUICK_QS_PULLDOWN);
            mTunerService.addTunable(this, DOUBLE_TAP_SLEEP_GESTURE);
            mUpdateMonitor.registerCallback(mKeyguardUpdateCallback);
            // Theme might have changed between inflating this view and attaching it to the
            // window, so
@@ -3662,6 +3683,8 @@ public 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);
            }
        }
    }
+26 −2
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.systemui.statusbar.phone;
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;

import android.app.StatusBarManager;
import android.content.Context;
import android.graphics.RectF;
import android.hardware.display.AmbientDisplayConfiguration;
import android.media.AudioManager;
import android.media.session.MediaSessionLegacyHelper;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
@@ -55,6 +57,8 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.util.InjectionInflationController;

import lineageos.providers.LineageSettings;

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

@@ -101,12 +105,18 @@ public class NotificationShadeWindowViewController {
    private final DockManager mDockManager;
    private final NotificationPanelViewController mNotificationPanelViewController;
    private final SuperStatusBarViewFactory mStatusBarViewFactory;
    private final PowerManager mPowerManager;

    // Used for determining view / touch intersection
    private int[] mTempLocation = new int[2];
    private RectF mTempRect = new RectF();
    private boolean mIsTrackingBarGesture = false;

    private static final String DOUBLE_TAP_SLEEP_GESTURE =
            "lineagesystem:" + LineageSettings.System.DOUBLE_TAP_SLEEP_GESTURE;
    private boolean mDoubleTapToSleepEnabled;
    private int mQuickQsTotalHeight;

    @Inject
    public NotificationShadeWindowViewController(
            InjectionInflationController injectionInflationController,
@@ -129,7 +139,8 @@ public class NotificationShadeWindowViewController {
            NotificationShadeDepthController depthController,
            NotificationShadeWindowView notificationShadeWindowView,
            NotificationPanelViewController notificationPanelViewController,
            SuperStatusBarViewFactory statusBarViewFactory) {
            SuperStatusBarViewFactory statusBarViewFactory,
            Context context) {
        mInjectionInflationController = injectionInflationController;
        mCoordinator = coordinator;
        mPulseExpansionHandler = pulseExpansionHandler;
@@ -151,6 +162,7 @@ public class NotificationShadeWindowViewController {
        mNotificationPanelViewController = notificationPanelViewController;
        mDepthController = depthController;
        mStatusBarViewFactory = statusBarViewFactory;
        mPowerManager = context.getSystemService(PowerManager.class);

        // This view is not part of the newly inflated expanded status bar.
        mBrightnessMirror = mView.findViewById(R.id.brightness_mirror);
@@ -170,11 +182,18 @@ public class NotificationShadeWindowViewController {
                    break;
                case Settings.Secure.DOZE_TAP_SCREEN_GESTURE:
                    mSingleTapEnabled = configuration.tapGestureEnabled(UserHandle.USER_CURRENT);
                    break;
                case DOUBLE_TAP_SLEEP_GESTURE:
                    mDoubleTapToSleepEnabled = TunerService.parseIntegerSwitch(newValue, true);
                    break;
            }
        };
        mTunerService.addTunable(tunable,
                Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE);
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
                DOUBLE_TAP_SLEEP_GESTURE);
        mQuickQsTotalHeight = mView.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.quick_qs_total_height);

        GestureDetector.SimpleOnGestureListener gestureListener =
                new GestureDetector.SimpleOnGestureListener() {
@@ -190,6 +209,11 @@ public class NotificationShadeWindowViewController {

                    @Override
                    public boolean onDoubleTap(MotionEvent e) {
                        if (!mStatusBarStateController.isDozing() && mDoubleTapToSleepEnabled
                                && e.getY() < mQuickQsTotalHeight) {
                            mPowerManager.goToSleep(e.getEventTime());
                            return true;
                        }
                        if (mDoubleTapEnabled || mSingleTapEnabled) {
                            mService.wakeUpIfDozing(
                                    SystemClock.uptimeMillis(), mView, "DOUBLE_TAP");