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

Commit 0a965fbc authored by Rashed Abdel-Tawab's avatar Rashed Abdel-Tawab Committed by Bruno Martins
Browse files

SystemUI: add double tap to sleep gesture



Based on the following squashed changes, forward-ported to Oreo
and adapted to the Lineage SDK:

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 bbf9a43e
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -30,10 +30,12 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.PowerManager;
import android.util.AttributeSet;
import android.util.EventLog;
import android.util.FloatProperty;
import android.util.MathUtils;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
@@ -96,6 +98,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);

@@ -240,6 +244,9 @@ public class NotificationPanelView extends PanelView implements
    private ValueAnimator mDarkAnimator;

    private int mOneFingerQuickSettingsIntercept;
    private boolean mDoubleTapToSleepEnabled;
    private int mStatusBarHeaderHeight;
    private GestureDetector mDoubleTapGesture;

    public NotificationPanelView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -247,6 +254,16 @@ public class NotificationPanelView extends PanelView implements
        mFalsingManager = FalsingManager.getInstance(context);
        mQsOverscrollExpansionEnabled =
                getResources().getBoolean(R.bool.config_enableQuickSettingsOverscrollExpansion);
        mDoubleTapGesture = new GestureDetector(mContext,
                new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                if (pm != null)
                    pm.goToSleep(e.getEventTime());
                return true;
            }
        });
    }

    public void setStatusBar(StatusBar bar) {
@@ -281,7 +298,8 @@ public class NotificationPanelView extends PanelView implements
        super.onAttachedToWindow();
        FragmentHostManager.get(this).addTagListener(QS.TAG, mFragmentListener);
        Dependency.get(TunerService.class).addTunable(this,
                STATUS_BAR_QUICK_QS_PULLDOWN);
                STATUS_BAR_QUICK_QS_PULLDOWN,
                DOUBLE_TAP_SLEEP_GESTURE);
    }

    @Override
@@ -312,6 +330,8 @@ public class NotificationPanelView extends PanelView implements
                R.dimen.max_notification_fadeout_height);
        mIndicationBottomPadding = getResources().getDimensionPixelSize(
                R.dimen.keyguard_indication_bottom_padding);
        mStatusBarHeaderHeight =
                getResources().getDimensionPixelSize(R.dimen.status_bar_header_height);
    }

    public void updateResources() {
@@ -787,6 +807,10 @@ public class NotificationPanelView extends PanelView implements
        if (mBlockTouches || (mQs != null && mQs.isCustomizing())) {
            return false;
        }
        if (mDoubleTapToSleepEnabled
                && mStatusBarState == StatusBarState.KEYGUARD) {
            mDoubleTapGesture.onTouchEvent(event);
        }
        initDownStates(event);
        if (mListenForHeadsUp && !mHeadsUpTouchHelper.isTrackingHeadsUp()
                && mHeadsUpTouchHelper.onInterceptTouchEvent(event)) {
@@ -2585,6 +2609,9 @@ public class NotificationPanelView extends PanelView implements
                mOneFingerQuickSettingsIntercept =
                        newValue == null ? 1 : Integer.parseInt(newValue);
                break;
            case DOUBLE_TAP_SLEEP_GESTURE:
                mDoubleTapToSleepEnabled = newValue == null || Integer.parseInt(newValue) == 1;
                break;
            default:
                break;
        }
+52 −2
Original line number Diff line number Diff line
@@ -34,9 +34,12 @@ import android.media.session.MediaSessionLegacyHelper;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ActionMode;
import android.view.GestureDetector;
import android.view.InputDevice;
import android.view.InputQueue;
import android.view.KeyEvent;
@@ -56,17 +59,24 @@ import android.widget.FrameLayout;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.view.FloatingActionMode;
import com.android.internal.widget.FloatingToolbar;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.statusbar.DragDownHelper;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerServiceImpl;

import lineageos.providers.LineageSettings;

public class StatusBarWindowView extends FrameLayout {
public class StatusBarWindowView extends FrameLayout implements TunerService.Tunable {
    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 DragDownHelper mDragDownHelper;
    private DoubleTapHelper mDoubleTapHelper;
    private NotificationStackScrollLayout mStackScrollLayout;
@@ -80,6 +90,10 @@ public class StatusBarWindowView extends FrameLayout {
    private final Paint mTransparentSrcPaint = new Paint();
    private FalsingManager mFalsingManager;

    private boolean mDoubleTapToSleepEnabled;
    private int mStatusBarHeaderHeight;
    private GestureDetector mDoubleTapGesture;

    // 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;
@@ -99,6 +113,8 @@ public class StatusBarWindowView extends FrameLayout {
            mService.wakeUpIfDozing(SystemClock.uptimeMillis(), this);
            return true;
        }, null, null);
        mStatusBarHeaderHeight = context
                .getResources().getDimensionPixelSize(R.dimen.status_bar_header_height);
    }

    @Override
@@ -195,6 +211,23 @@ public class StatusBarWindowView extends FrameLayout {
    protected void onAttachedToWindow () {
        super.onAttachedToWindow();

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

                return true;
            }
        });

        // We need to ensure that our window doesn't suffer from overdraw which would normally
        // occur if our window is translucent. Since we are drawing the whole window anyway with
        // the scrim, we don't need the window to be cleared in the beginning.
@@ -210,6 +243,12 @@ public class StatusBarWindowView extends FrameLayout {
        }
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Dependency.get(TunerService.class).removeTunable(this);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (mService.interceptMediaKey(event)) {
@@ -288,6 +327,11 @@ public class StatusBarWindowView extends FrameLayout {
            return true;
        }
        boolean intercept = false;
        if (mDoubleTapToSleepEnabled
                && ev.getY() < mStatusBarHeaderHeight) {
            if (DEBUG) Log.w(TAG, "logging double tap gesture");
            mDoubleTapGesture.onTouchEvent(ev);
        }
        if (mNotificationPanel.isFullyExpanded()
                && mStackScrollLayout.getVisibility() == View.VISIBLE
                && mService.getBarState() == StatusBarState.KEYGUARD
@@ -736,5 +780,11 @@ public class StatusBarWindowView extends FrameLayout {
        }
    };

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (!DOUBLE_TAP_SLEEP_GESTURE.equals(key)) {
            return;
        }
        mDoubleTapToSleepEnabled = newValue == null || Integer.parseInt(newValue) == 1;
    }
}