Sending original motion events to launcher overlay along with inferred values

Bug: 273828110
Flag: aconfig use_activity_overlay disabled
Test: Manual
Change-Id: I23cd72a964a647a0fd830befa096f3328e12ff8a
This commit is contained in:
Sunny Goyal
2024-02-13 14:56:36 -08:00
parent f843af4084
commit dc7cdd8b0c
6 changed files with 115 additions and 24 deletions

View File

@@ -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;
}
}