Skip to content

Commit

Permalink
Double tap to sleep on statusbar [1/2]
Browse files Browse the repository at this point in the history
abc ezio84: use existing lockscreen doubletap gesture listener
and abcutils screenoff action

Change-Id: Ib2f884047dd3754e96152148ea9bd042374a2045
  • Loading branch information
maxwen authored and ezio84 committed Dec 14, 2017
1 parent dabf622 commit 4467b77
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
6 changes: 6 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4077,6 +4077,12 @@ public boolean validate(String value) {
*/
public static final String QS_TILE_TITLE_VISIBILITY = "qs_tile_title_visibility";

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.View;
import android.view.ViewConfiguration;

import com.android.internal.util.abc.AbcUtils;
import com.android.systemui.ExpandHelper;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.Interpolators;
Expand Down Expand Up @@ -57,15 +58,31 @@ public class DragDownHelper implements Gefingerpoken {
private float mLastHeight;
private FalsingManager mFalsingManager;

// omni additions start
private boolean mDoubleTapToSleepEnabled;
private int mStatusBarHeaderHeight;
private long mLastDownEvent = -1;
private long mDoubleTapTimeout;
private Runnable mGoToSleep;

public DragDownHelper(Context context, View host, ExpandHelper.Callback callback,
DragDownCallback dragDownCallback) {
mMinDragDistance = context.getResources().getDimensionPixelSize(
R.dimen.keyguard_drag_down_min_distance);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mDoubleTapTimeout = ViewConfiguration.get(context).getDoubleTapTimeout();
mCallback = callback;
mDragDownCallback = dragDownCallback;
mHost = host;
mFalsingManager = FalsingManager.getInstance(context);
mStatusBarHeaderHeight = context
.getResources().getDimensionPixelSize(R.dimen.status_bar_header_height_keyguard);
mGoToSleep = new Runnable() {
@Override
public void run() {
AbcUtils.switchScreenOff(context);
}
};
}

@Override
Expand All @@ -80,6 +97,20 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
mStartingChild = null;
mInitialTouchY = y;
mInitialTouchX = x;

if (mDoubleTapToSleepEnabled && y < mStatusBarHeaderHeight) {
long eventTime = event.getEventTime();
if (mLastDownEvent != -1) {
long diff = eventTime - mLastDownEvent;

if (diff < mDoubleTapTimeout) {
mGoToSleep.run();
}
mLastDownEvent = -1;
} else {
mLastDownEvent = eventTime;
}
}
break;

case MotionEvent.ACTION_MOVE:
Expand Down Expand Up @@ -255,4 +286,8 @@ public interface DragDownCallback {
void setEmptyDragAmount(float amount);
boolean isFalsingCheckNeeded();
}

public void updateDoubleTapToSleep(boolean updateDoubleTapToSleep) {
mDoubleTapToSleepEnabled = updateDoubleTapToSleep;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,19 @@ public void run() {
private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
private boolean mUserSetupComplete;

private GestureDetector mLockscreenDoubleTapToSleep;
private GestureDetector mDoubleTapToSleepGesture;
private boolean mIsLockscreenDoubleTapEnabled;

private int mStatusBarHeaderHeight;

public NotificationPanelView(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(!DEBUG);
mFalsingManager = FalsingManager.getInstance(context);

mPowerManager = context.getSystemService(PowerManager.class);
mLockscreenDoubleTapToSleep = new GestureDetector(context,

mDoubleTapToSleepGesture = new GestureDetector(context,
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
Expand Down Expand Up @@ -323,6 +327,8 @@ protected void loadDimens() {
R.dimen.max_notification_fadeout_height);
mIndicationBottomPadding = getResources().getDimensionPixelSize(
R.dimen.keyguard_indication_bottom_padding);
mStatusBarHeaderHeight = getResources().getDimensionPixelSize(
R.dimen.status_bar_height);
}

public void updateResources() {
Expand Down Expand Up @@ -847,9 +853,11 @@ public boolean onTouchEvent(MotionEvent event) {
if (mBlockTouches || (mQs != null && mQs.isCustomizing())) {
return false;
}
if (mIsLockscreenDoubleTapEnabled
&& mStatusBarState == StatusBarState.KEYGUARD) {
mLockscreenDoubleTapToSleep.onTouchEvent(event);
if ((mIsLockscreenDoubleTapEnabled
&& mStatusBarState == StatusBarState.KEYGUARD) ||
(!mQsExpanded && mDoubleTapToSleepEnabled
&& event.getY() < mStatusBarHeaderHeight)) {
mDoubleTapToSleepGesture.onTouchEvent(event);
}
initDownStates(event);
if (mListenForHeadsUp && !mHeadsUpTouchHelper.isTrackingHeadsUp()
Expand Down Expand Up @@ -2706,4 +2714,8 @@ public LockIcon getLockIcon() {
public void setQsQuickPulldown(boolean isQsQuickPulldown) {
mOneFingerQuickSettingsIntercept = isQsQuickPulldown;
}

public void updateDoubleTapToSleep(boolean doubleTapToSleepEnabled) {
mDoubleTapToSleepEnabled = doubleTapToSleepEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ private final void logf(String fmt, Object... args) {
private boolean mIgnoreXTouchSlop;
private boolean mExpandLatencyTracking;

// omni additions start
protected boolean mDoubleTapToSleepEnabled;

protected void onExpandingFinished() {
mBar.onExpandingFinished();
}
Expand Down Expand Up @@ -323,7 +326,7 @@ public boolean onTouchEvent(MotionEvent event) {
cancelPeek();
onTrackingStarted();
}
if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()) {
if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp() && !mDoubleTapToSleepEnabled) {
startOpening();
}
break;
Expand Down Expand Up @@ -399,7 +402,7 @@ public boolean onTouchEvent(MotionEvent event) {
return !mGestureWaitForTouchSlop || mTracking;
}

private void startOpening() {;
private void startOpening() {
runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
false /* collapseWhenFinished */);
notifyBarPanelExpansionChanged();
Expand Down Expand Up @@ -478,7 +481,7 @@ private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCa
}
} else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking) {
long timePassed = SystemClock.uptimeMillis() - mDownTime;
if (timePassed < ViewConfiguration.getLongPressTimeout()) {
if (timePassed < ViewConfiguration.getLongPressTimeout() && !mDoubleTapToSleepEnabled) {
// Lets show the user that he can actually expand the panel
runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5907,6 +5907,9 @@ void observe() {
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.QS_TILE_TITLE_VISIBILITY),
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.DOUBLE_TAP_SLEEP_GESTURE),
false, this, UserHandle.USER_ALL);
}

@Override
Expand Down Expand Up @@ -5934,6 +5937,9 @@ public void onChange(boolean selfChange, Uri uri) {
} else if (uri.equals(Settings.System.getUriFor(Settings.System.QS_TILE_TITLE_VISIBILITY))) {
updateQsPanelResources();
setQsPanelOptions();
} else if (uri.equals(Settings.System.getUriFor(
Settings.System.DOUBLE_TAP_SLEEP_GESTURE))) {
setStatusBarWindowViewOptions();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,22 @@ public void reportActivityRelaunched() {

public void setStatusBarWindowViewOptions() {
ContentResolver resolver = mContext.getContentResolver();
boolean isDoubleTapEnabled = Settings.System.getIntForUser(resolver,
boolean isDoubleTapLockscreenEnabled = Settings.System.getIntForUser(resolver,
Settings.System.DOUBLE_TAP_SLEEP_LOCKSCREEN, 1, UserHandle.USER_CURRENT) == 1;
boolean isQsQuickPulldown = Settings.System.getIntForUser(resolver,
Settings.System.STATUS_BAR_QUICK_QS_PULLDOWN, 1, UserHandle.USER_CURRENT) == 1;
boolean doubleTapToSleepEnabled = Settings.System.getIntForUser(resolver,
Settings.System.DOUBLE_TAP_SLEEP_GESTURE, 1, UserHandle.USER_CURRENT) == 1;

if (mNotificationPanel != null) {
mNotificationPanel.setLockscreenDoubleTapToSleep(isDoubleTapEnabled);
mNotificationPanel.setLockscreenDoubleTapToSleep(isDoubleTapLockscreenEnabled);
mNotificationPanel.setQsQuickPulldown(isQsQuickPulldown);
mNotificationPanel.updateDoubleTapToSleep(doubleTapToSleepEnabled);
}
if (mDragDownHelper != null) {
mDragDownHelper.updateDoubleTapToSleep(doubleTapToSleepEnabled);
}
}

}

0 comments on commit 4467b77

Please sign in to comment.