Show notification panel on downward swipe (#2099)

This commit is contained in:
Patryk Michalik
2021-03-24 08:18:20 +01:00
committed by GitHub
4 changed files with 98 additions and 0 deletions
+1
View File
@@ -45,6 +45,7 @@
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<!-- TODO(b/150802536): Enabled only for ENABLE_FIXED_ROTATION_TRANSFORM feature flag -->
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
@@ -0,0 +1,63 @@
package app.lawnchair.gestures
import android.annotation.SuppressLint
import android.content.Context
import android.view.GestureDetector
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import kotlin.math.abs
open class DirectionalGestureListener(ctx: Context?) : OnTouchListener {
private val mGestureDetector: GestureDetector
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean {
return mGestureDetector.onTouchEvent(event)
}
@Suppress("PrivatePropertyName")
private inner class GestureListener : SimpleOnGestureListener() {
private val SWIPE_THRESHOLD = 100
private val SWIPE_VELOCITY_THRESHOLD = 100
override fun onDown(e: MotionEvent): Boolean {
return true
}
private fun shouldReactToSwipe(diff: Float, velocity: Float): Boolean =
abs(diff) > SWIPE_THRESHOLD && abs(velocity) > SWIPE_VELOCITY_THRESHOLD
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
return try {
val diffY = e2.y - e1.y
val diffX = e2.x - e1.x
when {
abs(diffX) > abs(diffY) && shouldReactToSwipe(diffX, velocityX) -> {
if (diffX > 0) onSwipeRight() else onSwipeLeft()
true
}
shouldReactToSwipe(diffY, velocityY) -> {
if (diffY > 0) onSwipeBottom() else onSwipeTop()
true
}
else -> false
}
} catch (exception: Exception) {
exception.printStackTrace()
false
}
}
}
fun onSwipeRight() {}
fun onSwipeLeft() {}
fun onSwipeTop() {}
open fun onSwipeBottom() {}
init {
mGestureDetector = GestureDetector(ctx, GestureListener())
}
}
@@ -0,0 +1,29 @@
package app.lawnchair.gestures;
import android.annotation.SuppressLint;
import android.app.StatusBarManager;
import android.content.Context;
import android.os.Build;
import androidx.annotation.RequiresApi;
import com.android.quickstep.TouchInteractionService;
public class SwipeDownGesture extends DirectionalGestureListener {
private final Context mContext;
public SwipeDownGesture(Context context) {
super(context);
mContext = context;
}
@SuppressLint("WrongConstant")
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void onSwipeBottom() {
if (!TouchInteractionService.isInitialized()) {
((StatusBarManager) mContext.getSystemService("statusbar")).expandNotificationsPanel();
}
}
}
@@ -43,6 +43,8 @@ import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.views.OptionsPopupView;
import app.lawnchair.gestures.SwipeDownGesture;
/**
* Helper class to handle touch on empty space in workspace and show options popup on long press
*/
@@ -69,6 +71,7 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe
private int mLongPressState = STATE_CANCELLED;
private final GestureDetector mGestureDetector;
private final SwipeDownGesture mSwipeDown;
public WorkspaceTouchListener(Launcher launcher, Workspace workspace) {
mLauncher = launcher;
@@ -77,10 +80,12 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe
// likely to cause movement.
mTouchSlop = 2 * ViewConfiguration.get(launcher).getScaledTouchSlop();
mGestureDetector = new GestureDetector(workspace.getContext(), this);
mSwipeDown = new SwipeDownGesture(workspace.getContext());
}
@Override
public boolean onTouch(View view, MotionEvent ev) {
mSwipeDown.onTouch(view, ev);
mGestureDetector.onTouchEvent(ev);
int action = ev.getActionMasked();