mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Lawnchair: Swipe down on Workspace to expand statusbar
This commit is contained in:
@@ -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,66 @@
|
||||
package app.lawnchair.gestures
|
||||
|
||||
import android.view.View.OnTouchListener
|
||||
import android.view.GestureDetector
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.MotionEvent
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.View
|
||||
import java.lang.Exception
|
||||
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
|
||||
}
|
||||
|
||||
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
||||
var result = false
|
||||
try {
|
||||
val diffY = e2.y - e1.y
|
||||
val diffX = e2.x - e1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > SWIPE_THRESHOLD && abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffX > 0) {
|
||||
onSwipeRight()
|
||||
} else {
|
||||
onSwipeLeft()
|
||||
}
|
||||
result = true
|
||||
}
|
||||
} else if (abs(diffY) > SWIPE_THRESHOLD && abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffY > 0) {
|
||||
onSwipeBottom()
|
||||
} else {
|
||||
onSwipeTop()
|
||||
}
|
||||
result = true
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun onSwipeRight() {}
|
||||
fun onSwipeLeft() {}
|
||||
fun onSwipeTop() {}
|
||||
open fun onSwipeBottom() {}
|
||||
|
||||
init {
|
||||
mGestureDetector = GestureDetector(ctx, GestureListener())
|
||||
}
|
||||
}
|
||||
29
lawnchair/src/app/lawnchair/gestures/SwipeDownGesture.java
Normal file
29
lawnchair/src/app/lawnchair/gestures/SwipeDownGesture.java
Normal file
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user