Skip to content

Commit dc7cdd8

Browse files
author
Sunny Goyal
committed
Sending original motion events to launcher overlay along with inferred values
Bug: 273828110 Flag: aconfig use_activity_overlay disabled Test: Manual Change-Id: I23cd72a964a647a0fd830befa096f3328e12ff8a
1 parent f843af4 commit dc7cdd8

File tree

6 files changed

+115
-24
lines changed

6 files changed

+115
-24
lines changed

src/com/android/launcher3/Launcher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
import com.android.systemui.plugins.LauncherOverlayPlugin;
259259
import com.android.systemui.plugins.PluginListener;
260260
import com.android.systemui.plugins.shared.LauncherOverlayManager;
261-
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
261+
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy;
262262
import com.android.wm.shell.Flags;
263263

264264
import java.io.FileDescriptor;
@@ -2810,7 +2810,7 @@ public void setWaitingForResult(PendingRequestArgs args) {
28102810
/**
28112811
* Call this after onCreate to set or clear overlay.
28122812
*/
2813-
public void setLauncherOverlay(LauncherOverlay overlay) {
2813+
public void setLauncherOverlay(LauncherOverlayTouchProxy overlay) {
28142814
mWorkspace.setLauncherOverlay(overlay);
28152815
}
28162816

src/com/android/launcher3/PagedView.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ protected void updateIsBeingDraggedOnTouchDown(MotionEvent ev) {
11401140
mEdgeGlowLeft.onPullDistance(0f, 1f - displacement);
11411141
}
11421142
if (!mEdgeGlowRight.isFinished()) {
1143-
mEdgeGlowRight.onPullDistance(0f, displacement);
1143+
mEdgeGlowRight.onPullDistance(0f, displacement, ev);
11441144
}
11451145
}
11461146

@@ -1320,10 +1320,10 @@ public boolean onTouchEvent(MotionEvent ev) {
13201320
int consumed = 0;
13211321
if (delta < 0 && mEdgeGlowRight.getDistance() != 0f) {
13221322
consumed = Math.round(size *
1323-
mEdgeGlowRight.onPullDistance(delta / size, displacement));
1323+
mEdgeGlowRight.onPullDistance(delta / size, displacement, ev));
13241324
} else if (delta > 0 && mEdgeGlowLeft.getDistance() != 0f) {
13251325
consumed = Math.round(-size *
1326-
mEdgeGlowLeft.onPullDistance(-delta / size, 1 - displacement));
1326+
mEdgeGlowLeft.onPullDistance(-delta / size, 1 - displacement, ev));
13271327
}
13281328
delta -= consumed;
13291329
}
@@ -1341,22 +1341,21 @@ public boolean onTouchEvent(MotionEvent ev) {
13411341
final float pulledToX = oldScroll + delta;
13421342

13431343
if (pulledToX < mMinScroll) {
1344-
mEdgeGlowLeft.onPullDistance(-delta / size, 1.f - displacement);
1344+
mEdgeGlowLeft.onPullDistance(-delta / size, 1.f - displacement, ev);
13451345
if (!mEdgeGlowRight.isFinished()) {
1346-
mEdgeGlowRight.onRelease();
1346+
mEdgeGlowRight.onRelease(ev);
13471347
}
13481348
} else if (pulledToX > mMaxScroll) {
1349-
mEdgeGlowRight.onPullDistance(delta / size, displacement);
1349+
mEdgeGlowRight.onPullDistance(delta / size, displacement, ev);
13501350
if (!mEdgeGlowLeft.isFinished()) {
1351-
mEdgeGlowLeft.onRelease();
1351+
mEdgeGlowLeft.onRelease(ev);
13521352
}
13531353
}
13541354

13551355
if (!mEdgeGlowLeft.isFinished() || !mEdgeGlowRight.isFinished()) {
13561356
postInvalidateOnAnimation();
13571357
}
13581358
}
1359-
13601359
} else {
13611360
awakenScrollBars();
13621361
}
@@ -1456,10 +1455,11 @@ mCurrentPage < getChildCount() - 1) {
14561455
}
14571456
invalidate();
14581457
}
1458+
mEdgeGlowLeft.onFlingVelocity(velocity);
1459+
mEdgeGlowRight.onFlingVelocity(velocity);
14591460
}
1460-
1461-
mEdgeGlowLeft.onRelease();
1462-
mEdgeGlowRight.onRelease();
1461+
mEdgeGlowLeft.onRelease(ev);
1462+
mEdgeGlowRight.onRelease(ev);
14631463
// End any intermediate reordering states
14641464
resetTouchState();
14651465
break;
@@ -1468,8 +1468,8 @@ mCurrentPage < getChildCount() - 1) {
14681468
if (mIsBeingDragged) {
14691469
runOnPageScrollsInitialized(this::snapToDestination);
14701470
}
1471-
mEdgeGlowLeft.onRelease();
1472-
mEdgeGlowRight.onRelease();
1471+
mEdgeGlowLeft.onRelease(ev);
1472+
mEdgeGlowRight.onRelease(ev);
14731473
resetTouchState();
14741474
break;
14751475

src/com/android/launcher3/Workspace.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
import com.android.launcher3.widget.WidgetManagerHelper;
126126
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
127127
import com.android.launcher3.widget.util.WidgetSizes;
128-
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
129128
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks;
129+
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy;
130130

131131
import java.util.ArrayList;
132132
import java.util.Iterator;
@@ -1237,7 +1237,7 @@ protected void onPageEndTransition() {
12371237
mLauncher.onPageEndTransition();
12381238
}
12391239

1240-
public void setLauncherOverlay(LauncherOverlay overlay) {
1240+
public void setLauncherOverlay(LauncherOverlayTouchProxy overlay) {
12411241
final EdgeEffectCompat newEffect;
12421242
if (overlay == null) {
12431243
newEffect = new EdgeEffectCompat(getContext());

src/com/android/launcher3/util/EdgeEffectCompat.java

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.android.launcher3.util;
1717

1818
import android.content.Context;
19+
import android.view.MotionEvent;
1920
import android.widget.EdgeEffect;
2021

2122
import com.android.launcher3.Utilities;
@@ -43,4 +44,14 @@ public float onPullDistance(float deltaDistance, float displacement) {
4344
return deltaDistance;
4445
}
4546
}
47+
48+
public float onPullDistance(float deltaDistance, float displacement, MotionEvent ev) {
49+
return onPullDistance(deltaDistance, displacement);
50+
}
51+
52+
public void onFlingVelocity(int velocity) { }
53+
54+
public void onRelease(MotionEvent ev) {
55+
onRelease();
56+
}
4657
}

src/com/android/launcher3/util/OverlayEdgeEffect.java

+48-6
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717

1818
import android.content.Context;
1919
import android.graphics.Canvas;
20+
import android.os.SystemClock;
21+
import android.view.MotionEvent;
2022
import android.widget.EdgeEffect;
2123

24+
import com.android.launcher3.BuildConfig;
2225
import com.android.launcher3.Utilities;
23-
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
26+
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy;
2427

2528
/**
2629
* Extension of {@link EdgeEffect} which shows the Launcher overlay
2730
*/
2831
public class OverlayEdgeEffect extends EdgeEffectCompat {
2932

3033
protected float mDistance;
31-
protected final LauncherOverlay mOverlay;
34+
protected final LauncherOverlayTouchProxy mOverlay;
3235
protected boolean mIsScrolling;
3336
protected final boolean mIsRtl;
3437

35-
public OverlayEdgeEffect(Context context, LauncherOverlay overlay) {
38+
public OverlayEdgeEffect(Context context, LauncherOverlayTouchProxy overlay) {
3639
super(context);
3740
mOverlay = overlay;
3841
mIsRtl = Utilities.isRtl(context.getResources());
@@ -44,12 +47,30 @@ public float getDistance() {
4447
}
4548

4649
public float onPullDistance(float deltaDistance, float displacement) {
50+
// Fallback implementation, will never actually get called
51+
if (BuildConfig.IS_DEBUG_DEVICE) {
52+
throw new RuntimeException("Wrong method called");
53+
}
54+
MotionEvent mv = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
55+
MotionEvent.ACTION_MOVE, displacement, 0, 0);
56+
try {
57+
return onPullDistance(deltaDistance, displacement, mv);
58+
} finally {
59+
mv.recycle();
60+
}
61+
}
62+
63+
@Override
64+
public float onPullDistance(float deltaDistance, float displacement, MotionEvent ev) {
4765
mDistance = Math.max(0f, deltaDistance + mDistance);
4866
if (!mIsScrolling) {
49-
mOverlay.onScrollInteractionBegin();
67+
int originalAction = ev.getAction();
68+
ev.setAction(MotionEvent.ACTION_DOWN);
69+
mOverlay.onOverlayMotionEvent(ev, 0);
70+
ev.setAction(originalAction);
5071
mIsScrolling = true;
5172
}
52-
mOverlay.onScrollChange(mDistance, mIsRtl);
73+
mOverlay.onOverlayMotionEvent(ev, mDistance);
5374
return mDistance > 0 ? deltaDistance : 0;
5475
}
5576

@@ -63,9 +84,30 @@ public boolean isFinished() {
6384

6485
@Override
6586
public void onRelease() {
87+
// Fallback implementation, will never actually get called
88+
if (BuildConfig.IS_DEBUG_DEVICE) {
89+
throw new RuntimeException("Wrong method called");
90+
}
91+
MotionEvent mv = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
92+
MotionEvent.ACTION_UP, mDistance, 0, 0);
93+
onRelease(mv);
94+
mv.recycle();
95+
}
96+
97+
@Override
98+
public void onFlingVelocity(int velocity) {
99+
mOverlay.onFlingVelocity(velocity);
100+
}
101+
102+
@Override
103+
public void onRelease(MotionEvent ev) {
66104
if (mIsScrolling) {
105+
int originalAction = ev.getAction();
106+
ev.setAction(MotionEvent.ACTION_UP);
107+
mOverlay.onOverlayMotionEvent(ev, mDistance);
108+
ev.setAction(originalAction);
109+
67110
mDistance = 0;
68-
mOverlay.onScrollInteractionEnd();
69111
mIsScrolling = false;
70112
}
71113
}

src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.android.systemui.plugins.shared;
1717

18+
import android.view.MotionEvent;
19+
1820
import java.io.PrintWriter;
1921

2022
/**
@@ -47,7 +49,11 @@ default void onActivityStopped() { }
4749

4850
default void onActivityDestroyed() { }
4951

50-
interface LauncherOverlay {
52+
/**
53+
* @deprecated use LauncherOverlayTouchProxy directly
54+
*/
55+
@Deprecated
56+
interface LauncherOverlay extends LauncherOverlayTouchProxy {
5157

5258
/**
5359
* Touch interaction leading to overscroll has begun
@@ -70,6 +76,38 @@ interface LauncherOverlay {
7076
* @param callbacks A set of callbacks provided by Launcher in relation to the overlay
7177
*/
7278
void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
79+
80+
@Override
81+
default void onFlingVelocity(float velocity) { }
82+
83+
@Override
84+
default void onOverlayMotionEvent(MotionEvent ev, float scrollProgress) {
85+
switch (ev.getAction()) {
86+
case MotionEvent.ACTION_DOWN -> onScrollInteractionBegin();
87+
case MotionEvent.ACTION_MOVE -> onScrollChange(scrollProgress, false);
88+
case MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> onScrollInteractionEnd();
89+
}
90+
91+
}
92+
}
93+
94+
interface LauncherOverlayTouchProxy {
95+
96+
/**
97+
* Called just before finishing scroll interaction to indicate the fling velocity
98+
*/
99+
void onFlingVelocity(float velocity);
100+
101+
/**
102+
* Called to dispatch various motion events to the overlay
103+
*/
104+
void onOverlayMotionEvent(MotionEvent ev, float scrollProgress);
105+
106+
/**
107+
* Called when the launcher is ready to use the overlay
108+
* @param callbacks A set of callbacks provided by Launcher in relation to the overlay
109+
*/
110+
default void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) { }
73111
}
74112

75113
interface LauncherOverlayCallbacks {

0 commit comments

Comments
 (0)