diff --git a/lawnchair/res/values/strings.xml b/lawnchair/res/values/strings.xml
index 92bc87b2fb..0f0313edf3 100644
--- a/lawnchair/res/values/strings.xml
+++ b/lawnchair/res/values/strings.xml
@@ -223,9 +223,6 @@
Avoid using cached icons from icon packs
Will cause icon to reload regularly, this is not required if icon pack doesn\'t update regularly
- Icon swipe gestures
- Perform actions when swiping left or right on icons instead of moving the home screen
-
Deck layout
Show a layout option to hide the app drawer and automatically add new apps to the home screen
diff --git a/lawnchair/src/app/lawnchair/gestures/DirectionalGestureListener.kt b/lawnchair/src/app/lawnchair/gestures/DirectionalGestureListener.kt
index 4a01c8daf9..7149083c73 100644
--- a/lawnchair/src/app/lawnchair/gestures/DirectionalGestureListener.kt
+++ b/lawnchair/src/app/lawnchair/gestures/DirectionalGestureListener.kt
@@ -12,10 +12,17 @@ import kotlin.math.abs
abstract class DirectionalGestureListener(ctx: Context?) : OnTouchListener {
private val mGestureDetector = GestureDetector(ctx, GestureListener())
+ private var handledGesture = false
+
+ fun onTouchEvent(event: MotionEvent): Boolean {
+ handledGesture = false
+ mGestureDetector.onTouchEvent(event)
+ return handledGesture
+ }
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean {
- return mGestureDetector.onTouchEvent(event)
+ return onTouchEvent(event)
}
inner class GestureListener : SimpleOnGestureListener() {
@@ -38,7 +45,7 @@ abstract class DirectionalGestureListener(ctx: Context?) : OnTouchListener {
Log.d("GESTURE_DETECTION", "onFling: y " + shouldReactToSwipe(diffY, velocityY))
Log.d("GESTURE_DETECTION", "onFling: X " + shouldReactToSwipe(diffX, velocityX))
- return when {
+ handledGesture = when {
shouldReactToSwipe(diffY, velocityY) -> {
if (diffY < 0) {
Log.d("GESTURE_DETECTION", "Swipe Up Detected")
@@ -47,7 +54,6 @@ abstract class DirectionalGestureListener(ctx: Context?) : OnTouchListener {
Log.d("GESTURE_DETECTION", "Swipe Down Detected")
onSwipeDown()
}
- true
}
shouldReactToSwipe(diffX, velocityX) -> {
@@ -58,18 +64,18 @@ abstract class DirectionalGestureListener(ctx: Context?) : OnTouchListener {
Log.d("GESTURE_DETECTION", "Swipe Left Detected")
onSwipeLeft()
}
- true
}
else -> false
}
+ return handledGesture
}
}
- abstract fun onSwipeRight()
- abstract fun onSwipeLeft()
- abstract fun onSwipeTop()
- abstract fun onSwipeDown()
+ abstract fun onSwipeRight(): Boolean
+ abstract fun onSwipeLeft(): Boolean
+ abstract fun onSwipeTop(): Boolean
+ abstract fun onSwipeDown(): Boolean
companion object {
private const val SWIPE_THRESHOLD = 100
diff --git a/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt b/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt
index 70873db0f5..af2c2580e2 100644
--- a/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt
+++ b/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt
@@ -7,15 +7,15 @@ import app.lawnchair.gestures.config.GestureHandlerConfig
import app.lawnchair.gestures.type.GestureType
import app.lawnchair.launcher
import app.lawnchair.preferences2.PreferenceManager2
-import com.android.launcher3.model.data.ItemInfo
+import app.lawnchair.util.firstBlocking
+import com.android.launcher3.util.ComponentKey
import com.android.launcher3.util.VibratorWrapper
-import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
class IconGestureListener(
private val context: Context,
private val prefs: PreferenceManager2,
- private val cmp: ItemInfo?,
+ private val componentKey: ComponentKey?,
) : DirectionalGestureListener(context) {
override fun onSwipeRight() = handleGesture(GestureType.SWIPE_RIGHT)
@@ -23,20 +23,45 @@ class IconGestureListener(
override fun onSwipeTop() = handleGesture(GestureType.SWIPE_UP)
override fun onSwipeDown() = handleGesture(GestureType.SWIPE_DOWN)
- private fun handleGesture(gestureType: GestureType) {
+ /** Check if there's any gesture configured for this entry */
+ fun hasAnyGestureConfigured(): Boolean {
+ return GestureType.entries.any(::hasGestureConfigured)
+ }
+
+ /** Check if there's a horizontal gesture configured for this entry. (Swipe left/right) */
+ fun hasHorizontalGestureConfigured(): Boolean {
+ return hasGestureConfigured(GestureType.SWIPE_LEFT) ||
+ hasGestureConfigured(GestureType.SWIPE_RIGHT)
+ }
+
+ /** Check if there's a specific gesture configured for this entry
+ * @param gestureType The type of gesture to check */
+ private fun hasGestureConfigured(gestureType: GestureType): Boolean {
+ return resolveGesture(gestureType) != null
+ }
+
+ /** Launch gesture configured operation for a specific gesture type
+ * @param gestureType The type of gesture that triggered the event */
+ private fun handleGesture(gestureType: GestureType): Boolean {
+ val gesture = resolveGesture(gestureType) ?: return false
+
Log.d("GESTURE_HANDLER", "Handling gesture: ${gestureType.name}")
- cmp?.componentKey?.let {
- context.launcher.lifecycleScope.launch {
- val gesture = prefs.getGestureForApp(it, gestureType).firstOrNull()
- if (gesture !is GestureHandlerConfig.NoOp) {
- Log.d("GESTURE_HANDLER", "Triggering gesture: ${gestureType.name}")
- VibratorWrapper.INSTANCE.get(context.launcher).vibrate(VibratorWrapper.OVERVIEW_HAPTIC)
- gesture?.createHandler(context)?.onTrigger(context.launcher)
- } else {
- Log.d("GESTURE_HANDLER", "NoOp gesture, ignoring")
- }
- }
+ context.launcher.lifecycleScope.launch {
+ Log.d("GESTURE_HANDLER", "Triggering gesture: ${gestureType.name}")
+ // Lawnchair-TODO: Migrate to MSDL vibration?
+ VibratorWrapper.INSTANCE.get(context.launcher).vibrate(VibratorWrapper.OVERVIEW_HAPTIC)
+ gesture.createHandler(context).onTrigger(context.launcher)
}
+
+ return true
+ }
+
+ /** Get gesture handler for that app's component
+ * @param gestureType The type of gesture to resolve for the current component */
+ private fun resolveGesture(gestureType: GestureType): GestureHandlerConfig? {
+ val currentComponentKey = componentKey ?: return null
+ val gesture = prefs.getGestureForApp(currentComponentKey, gestureType).firstBlocking()
+ return gesture.takeUnless { it is GestureHandlerConfig.NoOp }
}
}
diff --git a/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt b/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt
index d6e5bcef38..6c5098a128 100644
--- a/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt
+++ b/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt
@@ -193,8 +193,7 @@ fun CustomizeAppDialog(
)
}
}
-
- if (preferenceManager2.iconSwipeGestures.asState().value && context.launcher.stateManager.state != LauncherState.ALL_APPS) {
+ if (context.launcher.stateManager.state != LauncherState.ALL_APPS) {
PreferenceGroup(heading = stringResource(R.string.gestures_label)) {
listOf(
GestureType.SWIPE_LEFT,
diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
index 0bb250b48c..a8821cf977 100644
--- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
+++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
@@ -750,11 +750,6 @@ class PreferenceManager2 @Inject constructor(
onSet = { reloadHelper.reloadGrid() },
)
- val iconSwipeGestures = preference(
- key = booleanPreferencesKey(name = "icon_swipe_gestures"),
- defaultValue = false,
- )
-
val doubleTapGestureHandler = serializablePreference(
key = stringPreferencesKey("double_tap_gesture_handler"),
defaultValue = GestureHandlerConfig.Sleep,
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt
index ce314e4e1b..c22190696a 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt
@@ -86,13 +86,6 @@ fun ExperimentalFeaturesPreferences(
description = stringResource(id = R.string.workspace_increase_max_grid_size_description),
)
}
- Item {
- SwitchPreference(
- adapter = prefs2.iconSwipeGestures.getAdapter(),
- label = stringResource(R.string.icon_swipe_gestures),
- description = stringResource(R.string.icon_swipe_gestures_description),
- )
- }
Item {
SwitchPreference(
adapter = prefs2.showDeckLayout.getAdapter(),
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 6b731f4f55..91c84d1b29 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -254,6 +254,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
private final PreferenceManager2 pref2;
private IconGestureListener mGestureListener;
+ private boolean mShouldHandleIconSwipeTouch; // Lawnchair: Icon swipe gesture feature
public BubbleTextView(Context context) {
this(context, null, 0);
@@ -379,6 +380,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
setTranslationY(0);
setMaxLines(1);
setVisibility(VISIBLE);
+
+ // Lawnchair: Icon swipe gesture feature
+ mGestureListener = null;
+ mShouldHandleIconSwipeTouch = false;
}
private void cancelDotScaleAnim() {
@@ -498,6 +503,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
protected void setItemInfo(ItemInfoWithIcon itemInfo) {
setTag(itemInfo);
+ // Lawnchair: Icon swipe gesture feature
+ mGestureListener = shouldSupportIconSwipeGestures()
+ ? new IconGestureListener(getContext(), pref2, itemInfo.getComponentKey())
+ : null;
}
@VisibleForTesting
@@ -687,6 +696,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
&& shouldIgnoreTouchDown(event.getX(), event.getY())) {
return false;
}
+ // Lawnchair: Icon swipe gesture feature
+ if (handleIconSwipeTouchEvent(event)) {
+ return true;
+ }
if (isLongClickable()) {
super.onTouchEvent(event);
mLongPressHelper.onTouchEvent(event);
@@ -711,6 +724,72 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|| x > getWidth() - getPaddingRight();
}
+ /** Lawnchair: Handle icon swipe gesture feature, self-explanatory.
+ * Only do horizontal gesture at the moment
+ * @param event The type of MotionEvent to handle */
+ private boolean handleIconSwipeTouchEvent(MotionEvent event) {
+ if (!shouldSupportIconSwipeGestures()) {
+ return false;
+ }
+
+ int action = event.getActionMasked();
+ if (action == MotionEvent.ACTION_DOWN) {
+ mShouldHandleIconSwipeTouch = hasConfiguredIconSwipeGesture();
+ }
+
+ if (!mShouldHandleIconSwipeTouch || mGestureListener == null) {
+ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+ mShouldHandleIconSwipeTouch = false;
+ }
+ return false;
+ }
+
+ boolean handled = mGestureListener.onTouchEvent(event);
+ if (handled) {
+ cancelLongPress();
+ MotionEvent cancelEvent = MotionEvent.obtain(event);
+ cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
+ super.onTouchEvent(cancelEvent);
+ mLongPressHelper.onTouchEvent(cancelEvent);
+ cancelEvent.recycle();
+ setPressed(false);
+ refreshDrawableState();
+ mShouldHandleIconSwipeTouch = false;
+ return true;
+ }
+
+ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+ mShouldHandleIconSwipeTouch = false;
+ }
+ return false;
+ }
+
+ /** Lawnchair: Check eligibility for icon swipe gesture to be greenlit */
+ private boolean isIconSwipeGestureEnabledForCurrentState() {
+ return !(mActivity instanceof Launcher launcher
+ && launcher.isInState(LauncherState.EDIT_MODE));
+ }
+
+ /** Lawnchair: Check if icon swipe feature is enabled, and has a gesture configured for it */
+ public boolean hasConfiguredIconSwipeGesture() {
+ return mGestureListener != null
+ && isIconSwipeGestureEnabledForCurrentState()
+ && mGestureListener.hasAnyGestureConfigured();
+ }
+
+ /** Lawnchair: Check if icon swipe feature is enabled,
+ * and has a horizontal gesture configured for it */
+ public boolean hasConfiguredHorizontalIconSwipeGesture() {
+ return mGestureListener != null
+ && isIconSwipeGestureEnabledForCurrentState()
+ && mGestureListener.hasHorizontalGestureConfigured();
+ }
+
+ /** Lawnchair: Get supported swipe target which are within workspace or within folder */
+ private boolean shouldSupportIconSwipeGestures() {
+ return mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER;
+ }
+
void setStayPressed(boolean stayPressed) {
mStayPressed = stayPressed;
refreshDrawableState();
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 9c98f4c60f..2e2f7e5e87 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -271,6 +271,7 @@ public class Workspace extends PagedView
private FolderIcon mDragOverFolderIcon = null;
private boolean mCreateUserFolderOnDrop = false;
private boolean mAddToExistingFolderOnDrop = false;
+ private boolean mDisallowPagedViewInterceptForIconSwipe = false;
// Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget)
private float mXDown;
@@ -1185,52 +1186,91 @@ public class Workspace extends PagedView
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
- // pE-TODO(Reimpl): Check Icon Swipe Gesture
- if (ev.getAction() == MotionEvent.ACTION_UP) {
- View touchedView = findViewAtPosition(ev.getX(), ev.getY());
- Boolean iconSwipeGestures = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getIconSwipeGestures());
-
- if (iconSwipeGestures && touchedView instanceof ShortcutAndWidgetContainer container) {
- container.onTouchEvent(ev);
- return false;
- }
- }
-
+ if (shouldSkipPagedViewInterceptionForIconSwipe(ev)) {
+ return false;
+ } // Lawnchair: Icon swipe gesture feature
if (isTrackpadMultiFingerSwipe(ev)) {
return false;
}
return super.onInterceptTouchEvent(ev);
}
- private View findViewAtPosition(float x, float y) {
- for (int i = 0; i < getChildCount(); i++) {
- View child = getChildAt(i);
- if (child instanceof CellLayout) {
- CellLayout cellLayout = (CellLayout) child;
- View foundView = findViewInCellLayout(cellLayout, x - child.getLeft(), y - child.getTop());
- if (foundView != null) {
- return foundView;
+ // Lawnchair: Icon swipe gesture feature
+ private boolean shouldSkipPagedViewInterceptionForIconSwipe(MotionEvent ev) {
+ switch (ev.getActionMasked()) {
+ case MotionEvent.ACTION_DOWN:
+ mDisallowPagedViewInterceptForIconSwipe = isTouchOnIconWithHorizontalSwipeGesture(
+ ev.getX(), ev.getY());
+ if (mDisallowPagedViewInterceptForIconSwipe) {
+ resetTouchState();
+ return true;
}
+ return false;
+
+ case MotionEvent.ACTION_MOVE:
+ return mDisallowPagedViewInterceptForIconSwipe;
+
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ boolean shouldSkip = mDisallowPagedViewInterceptForIconSwipe;
+ mDisallowPagedViewInterceptForIconSwipe = false;
+ if (shouldSkip) {
+ resetTouchState();
+ }
+ return shouldSkip;
+
+ default:
+ return false;
+ }
+ }
+
+ // Lawnchair: Icon swipe gesture feature
+ private boolean isTouchOnIconWithHorizontalSwipeGesture(float x, float y) {
+ BubbleTextView touchedIcon = findIconAtPosition(x, y);
+ return touchedIcon != null && touchedIcon.hasConfiguredHorizontalIconSwipeGesture();
+ }
+
+ // Lawnchair: Icon swipe gesture feature
+ private BubbleTextView findIconAtPosition(float x, float y) {
+ for (int i = getChildCount() - 1; i >= 0; i--) {
+ View child = getChildAt(i);
+ if (!(child instanceof CellLayout cellLayout)) {
+ continue;
+ }
+ float localX = x - child.getLeft();
+ float localY = y - child.getTop();
+ if (!Utilities.pointInView(cellLayout, localX, localY, 0)) {
+ continue;
+ }
+ BubbleTextView foundView = findIconInCellLayout(cellLayout, localX, localY);
+ if (foundView != null) {
+ return foundView;
}
}
return null;
}
- private View findViewInCellLayout(CellLayout cellLayout, float x, float y) {
- final int count = cellLayout.getChildCount();
- for (int i = count - 1; i >= 0; i--) {
- View child = cellLayout.getChildAt(i);
- if (child.getVisibility() == VISIBLE && isPointInsideView(x, y, child)) {
- return child;
+ // Lawnchair: Icon swipe gesture feature
+ private BubbleTextView findIconInCellLayout(CellLayout cellLayout, float x, float y) {
+ ShortcutAndWidgetContainer container = cellLayout.getShortcutsAndWidgets();
+ float containerX = x - container.getLeft();
+ float containerY = y - container.getTop();
+ for (int i = container.getChildCount() - 1; i >= 0; i--) {
+ View child = container.getChildAt(i);
+ if (!(child instanceof BubbleTextView bubbleTextView)
+ || child.getVisibility() != VISIBLE) {
+ continue;
+ }
+ if (Utilities.pointInView(child,
+ containerX - child.getLeft(),
+ containerY - child.getTop(),
+ 0)) {
+ return bubbleTextView;
}
}
return null;
}
- private boolean isPointInsideView(float x, float y, View view) {
- return x >= view.getLeft() && x <= view.getRight() &&
- y >= view.getTop() && y <= view.getBottom();
- }
/**
* Needed here because launcher has a fullscreen exclusion rect and doesn't pilfer the pointers.
diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java
index 4f83be7d7a..27167aaa42 100644
--- a/src/com/android/launcher3/folder/FolderPagedView.java
+++ b/src/com/android/launcher3/folder/FolderPagedView.java
@@ -30,6 +30,7 @@ import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewDebug;
@@ -104,6 +105,7 @@ public class FolderPagedView extends PagedView implements Cli
private boolean mViewsBound = false;
private boolean mCanAnnouncePageDescription;
+ private boolean mDisallowPagedViewInterceptForIconSwipe; // Lawnchair: Icon swipe gesture feature
public FolderPagedView(Context context, AttributeSet attrs) {
this(
@@ -164,6 +166,91 @@ public class FolderPagedView extends PagedView implements Cli
}
}
+ // Lawnchair: Icon swipe gesture feature
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ if (shouldSkipPagedViewInterceptionForIconSwipe(ev)) {
+ return false;
+ }
+ return super.onInterceptTouchEvent(ev);
+ }
+
+ // Lawnchair: Icon swipe gesture feature
+ private boolean shouldSkipPagedViewInterceptionForIconSwipe(MotionEvent ev) {
+ switch (ev.getActionMasked()) {
+ case MotionEvent.ACTION_DOWN:
+ mDisallowPagedViewInterceptForIconSwipe = isTouchOnIconWithHorizontalSwipeGesture(
+ ev.getX(), ev.getY());
+ if (mDisallowPagedViewInterceptForIconSwipe) {
+ resetTouchState();
+ return true;
+ }
+ return false;
+
+ case MotionEvent.ACTION_MOVE:
+ return mDisallowPagedViewInterceptForIconSwipe;
+
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ boolean shouldSkip = mDisallowPagedViewInterceptForIconSwipe;
+ mDisallowPagedViewInterceptForIconSwipe = false;
+ if (shouldSkip) {
+ resetTouchState();
+ }
+ return shouldSkip;
+
+ default:
+ return false;
+ }
+ }
+
+ // Lawnchair: Icon swipe gesture feature
+ private boolean isTouchOnIconWithHorizontalSwipeGesture(float x, float y) {
+ BubbleTextView touchedIcon = findIconAtPosition(x, y);
+ return touchedIcon != null && touchedIcon.hasConfiguredHorizontalIconSwipeGesture();
+ }
+
+ /** Lawnchair: Find icon at specific position */
+ private BubbleTextView findIconAtPosition(float x, float y) {
+ for (int i = getChildCount() - 1; i >= 0; i--) {
+ View page = getChildAt(i);
+ if (!(page instanceof CellLayout cellLayout)) {
+ continue;
+ }
+ float localX = x - page.getLeft();
+ float localY = y - page.getTop();
+ if (!Utilities.pointInView(cellLayout, localX, localY, 0)) {
+ continue;
+ }
+ BubbleTextView foundView = findIconInCellLayout(cellLayout, localX, localY);
+ if (foundView != null) {
+ return foundView;
+ }
+ }
+ return null;
+ }
+
+ /** Lawnchair: Find icon in cell layout */
+ private BubbleTextView findIconInCellLayout(CellLayout cellLayout, float x, float y) {
+ ShortcutAndWidgetContainer container = cellLayout.getShortcutsAndWidgets();
+ float containerX = x - container.getLeft();
+ float containerY = y - container.getTop();
+ for (int i = container.getChildCount() - 1; i >= 0; i--) {
+ View child = container.getChildAt(i);
+ if (!(child instanceof BubbleTextView bubbleTextView)
+ || child.getVisibility() != View.VISIBLE) {
+ continue;
+ }
+ if (Utilities.pointInView(child,
+ containerX - child.getLeft(),
+ containerY - child.getTop(),
+ 0)) {
+ return bubbleTextView;
+ }
+ }
+ return null;
+ }
+
/**
* Binds items to the layout.
*/