diff options
author | 2024-02-14 03:49:18 +0000 | |
---|---|---|
committer | 2024-02-14 03:49:18 +0000 | |
commit | bbb26c51d68b479ad83c46b49cbc5e3c943b018b (patch) | |
tree | f6be4cbada99a360014427079b95113132d566cd | |
parent | 64cdbf5c770ec63f50d44bd7c0c2f03dcac11310 (diff) | |
parent | dc7cdd8b0c9fcd0832102acad7d39c513bcfbbc1 (diff) |
Merge "Sending original motion events to launcher overlay along with inferred values" into main
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 26 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/util/EdgeEffectCompat.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher3/util/OverlayEdgeEffect.java | 54 | ||||
-rw-r--r-- | src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java | 40 |
6 files changed, 115 insertions, 24 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 496cb4eb30..2b203e110f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -258,7 +258,7 @@ import com.android.launcher3.widget.picker.WidgetsFullSheet; import com.android.systemui.plugins.LauncherOverlayPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.shared.LauncherOverlayManager; -import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; +import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy; import com.android.wm.shell.Flags; import java.io.FileDescriptor; @@ -2810,7 +2810,7 @@ public class Launcher extends StatefulActivity<LauncherState> /** * Call this after onCreate to set or clear overlay. */ - public void setLauncherOverlay(LauncherOverlay overlay) { + public void setLauncherOverlay(LauncherOverlayTouchProxy overlay) { mWorkspace.setLauncherOverlay(overlay); } diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index ca83245d42..1fede56442 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -1140,7 +1140,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou mEdgeGlowLeft.onPullDistance(0f, 1f - displacement); } if (!mEdgeGlowRight.isFinished()) { - mEdgeGlowRight.onPullDistance(0f, displacement); + mEdgeGlowRight.onPullDistance(0f, displacement, ev); } } @@ -1320,10 +1320,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou int consumed = 0; if (delta < 0 && mEdgeGlowRight.getDistance() != 0f) { consumed = Math.round(size * - mEdgeGlowRight.onPullDistance(delta / size, displacement)); + mEdgeGlowRight.onPullDistance(delta / size, displacement, ev)); } else if (delta > 0 && mEdgeGlowLeft.getDistance() != 0f) { consumed = Math.round(-size * - mEdgeGlowLeft.onPullDistance(-delta / size, 1 - displacement)); + mEdgeGlowLeft.onPullDistance(-delta / size, 1 - displacement, ev)); } delta -= consumed; } @@ -1341,14 +1341,14 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou final float pulledToX = oldScroll + delta; if (pulledToX < mMinScroll) { - mEdgeGlowLeft.onPullDistance(-delta / size, 1.f - displacement); + mEdgeGlowLeft.onPullDistance(-delta / size, 1.f - displacement, ev); if (!mEdgeGlowRight.isFinished()) { - mEdgeGlowRight.onRelease(); + mEdgeGlowRight.onRelease(ev); } } else if (pulledToX > mMaxScroll) { - mEdgeGlowRight.onPullDistance(delta / size, displacement); + mEdgeGlowRight.onPullDistance(delta / size, displacement, ev); if (!mEdgeGlowLeft.isFinished()) { - mEdgeGlowLeft.onRelease(); + mEdgeGlowLeft.onRelease(ev); } } @@ -1356,7 +1356,6 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou postInvalidateOnAnimation(); } } - } else { awakenScrollBars(); } @@ -1456,10 +1455,11 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou } invalidate(); } + mEdgeGlowLeft.onFlingVelocity(velocity); + mEdgeGlowRight.onFlingVelocity(velocity); } - - mEdgeGlowLeft.onRelease(); - mEdgeGlowRight.onRelease(); + mEdgeGlowLeft.onRelease(ev); + mEdgeGlowRight.onRelease(ev); // End any intermediate reordering states resetTouchState(); break; @@ -1468,8 +1468,8 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou if (mIsBeingDragged) { runOnPageScrollsInitialized(this::snapToDestination); } - mEdgeGlowLeft.onRelease(); - mEdgeGlowRight.onRelease(); + mEdgeGlowLeft.onRelease(ev); + mEdgeGlowRight.onRelease(ev); resetTouchState(); break; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index ac0d7cea36..86f31a1576 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -125,8 +125,8 @@ import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.widget.WidgetManagerHelper; import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener; import com.android.launcher3.widget.util.WidgetSizes; -import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks; +import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy; import java.util.ArrayList; import java.util.Iterator; @@ -1237,7 +1237,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T> mLauncher.onPageEndTransition(); } - public void setLauncherOverlay(LauncherOverlay overlay) { + public void setLauncherOverlay(LauncherOverlayTouchProxy overlay) { final EdgeEffectCompat newEffect; if (overlay == null) { newEffect = new EdgeEffectCompat(getContext()); diff --git a/src/com/android/launcher3/util/EdgeEffectCompat.java b/src/com/android/launcher3/util/EdgeEffectCompat.java index 491582b87f..ca3725923e 100644 --- a/src/com/android/launcher3/util/EdgeEffectCompat.java +++ b/src/com/android/launcher3/util/EdgeEffectCompat.java @@ -16,6 +16,7 @@ package com.android.launcher3.util; import android.content.Context; +import android.view.MotionEvent; import android.widget.EdgeEffect; import com.android.launcher3.Utilities; @@ -43,4 +44,14 @@ public class EdgeEffectCompat extends EdgeEffect { return deltaDistance; } } + + public float onPullDistance(float deltaDistance, float displacement, MotionEvent ev) { + return onPullDistance(deltaDistance, displacement); + } + + public void onFlingVelocity(int velocity) { } + + public void onRelease(MotionEvent ev) { + onRelease(); + } } diff --git a/src/com/android/launcher3/util/OverlayEdgeEffect.java b/src/com/android/launcher3/util/OverlayEdgeEffect.java index 2ef1e1ff43..d09d801d66 100644 --- a/src/com/android/launcher3/util/OverlayEdgeEffect.java +++ b/src/com/android/launcher3/util/OverlayEdgeEffect.java @@ -17,10 +17,13 @@ package com.android.launcher3.util; import android.content.Context; import android.graphics.Canvas; +import android.os.SystemClock; +import android.view.MotionEvent; import android.widget.EdgeEffect; +import com.android.launcher3.BuildConfig; import com.android.launcher3.Utilities; -import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; +import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy; /** * Extension of {@link EdgeEffect} which shows the Launcher overlay @@ -28,11 +31,11 @@ import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverla public class OverlayEdgeEffect extends EdgeEffectCompat { protected float mDistance; - protected final LauncherOverlay mOverlay; + protected final LauncherOverlayTouchProxy mOverlay; protected boolean mIsScrolling; protected final boolean mIsRtl; - public OverlayEdgeEffect(Context context, LauncherOverlay overlay) { + public OverlayEdgeEffect(Context context, LauncherOverlayTouchProxy overlay) { super(context); mOverlay = overlay; mIsRtl = Utilities.isRtl(context.getResources()); @@ -44,12 +47,30 @@ public class OverlayEdgeEffect extends EdgeEffectCompat { } public float onPullDistance(float deltaDistance, float displacement) { + // Fallback implementation, will never actually get called + if (BuildConfig.IS_DEBUG_DEVICE) { + throw new RuntimeException("Wrong method called"); + } + MotionEvent mv = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), + MotionEvent.ACTION_MOVE, displacement, 0, 0); + try { + return onPullDistance(deltaDistance, displacement, mv); + } finally { + mv.recycle(); + } + } + + @Override + public float onPullDistance(float deltaDistance, float displacement, MotionEvent ev) { mDistance = Math.max(0f, deltaDistance + mDistance); if (!mIsScrolling) { - mOverlay.onScrollInteractionBegin(); + int originalAction = ev.getAction(); + ev.setAction(MotionEvent.ACTION_DOWN); + mOverlay.onOverlayMotionEvent(ev, 0); + ev.setAction(originalAction); mIsScrolling = true; } - mOverlay.onScrollChange(mDistance, mIsRtl); + mOverlay.onOverlayMotionEvent(ev, mDistance); return mDistance > 0 ? deltaDistance : 0; } @@ -63,9 +84,30 @@ public class OverlayEdgeEffect extends EdgeEffectCompat { @Override public void onRelease() { + // Fallback implementation, will never actually get called + if (BuildConfig.IS_DEBUG_DEVICE) { + throw new RuntimeException("Wrong method called"); + } + MotionEvent mv = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), + MotionEvent.ACTION_UP, mDistance, 0, 0); + onRelease(mv); + mv.recycle(); + } + + @Override + public void onFlingVelocity(int velocity) { + mOverlay.onFlingVelocity(velocity); + } + + @Override + public void onRelease(MotionEvent ev) { if (mIsScrolling) { + int originalAction = ev.getAction(); + ev.setAction(MotionEvent.ACTION_UP); + mOverlay.onOverlayMotionEvent(ev, mDistance); + ev.setAction(originalAction); + mDistance = 0; - mOverlay.onScrollInteractionEnd(); mIsScrolling = false; } } diff --git a/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java b/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java index 54cc0bc755..a940774ff0 100644 --- a/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java +++ b/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java @@ -15,6 +15,8 @@ */ package com.android.systemui.plugins.shared; +import android.view.MotionEvent; + import java.io.PrintWriter; /** @@ -47,7 +49,11 @@ public interface LauncherOverlayManager { default void onActivityDestroyed() { } - interface LauncherOverlay { + /** + * @deprecated use LauncherOverlayTouchProxy directly + */ + @Deprecated + interface LauncherOverlay extends LauncherOverlayTouchProxy { /** * Touch interaction leading to overscroll has begun @@ -70,6 +76,38 @@ public interface LauncherOverlayManager { * @param callbacks A set of callbacks provided by Launcher in relation to the overlay */ void setOverlayCallbacks(LauncherOverlayCallbacks callbacks); + + @Override + default void onFlingVelocity(float velocity) { } + + @Override + default void onOverlayMotionEvent(MotionEvent ev, float scrollProgress) { + switch (ev.getAction()) { + case MotionEvent.ACTION_DOWN -> onScrollInteractionBegin(); + case MotionEvent.ACTION_MOVE -> onScrollChange(scrollProgress, false); + case MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> onScrollInteractionEnd(); + } + + } + } + + interface LauncherOverlayTouchProxy { + + /** + * Called just before finishing scroll interaction to indicate the fling velocity + */ + void onFlingVelocity(float velocity); + + /** + * Called to dispatch various motion events to the overlay + */ + void onOverlayMotionEvent(MotionEvent ev, float scrollProgress); + + /** + * Called when the launcher is ready to use the overlay + * @param callbacks A set of callbacks provided by Launcher in relation to the overlay + */ + default void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) { } } interface LauncherOverlayCallbacks { |