Events checking for long press events
Also fixing duplicate long press events resulting from both framework and Launcher own detection reporting long presses. Change-Id: Ib46de5bd60850f1c5578992c8c1172ddbc0961f3
This commit is contained in:
1 parent
d4e7782d75
commit
e277fec466
9 files changed
+47
-5
No files matched your search
@@ -33,6 +33,8 @@ import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
|
||||
/**
|
||||
* Class to handle long-clicks on workspace items and start drag as a result.
|
||||
@@ -46,6 +48,7 @@ public class ItemLongClickListener {
|
||||
ItemLongClickListener::onAllAppsItemLongClick;
|
||||
|
||||
private static boolean onWorkspaceItemLongClick(View v) {
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onWorkspaceItemLongClick");
|
||||
Launcher launcher = Launcher.getLauncher(v.getContext());
|
||||
if (!canStartDrag(launcher)) return false;
|
||||
if (!launcher.isInState(NORMAL) && !launcher.isInState(OVERVIEW)) return false;
|
||||
@@ -75,6 +78,8 @@ public class ItemLongClickListener {
|
||||
}
|
||||
|
||||
private static boolean onAllAppsItemLongClick(View v) {
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onAllAppsItemLongClick");
|
||||
v.cancelLongPress();
|
||||
Launcher launcher = Launcher.getLauncher(v.getContext());
|
||||
if (!canStartDrag(launcher)) return false;
|
||||
// When we have exited all apps or are in transition, disregard long clicks
|
||||
|
||||
@@ -38,6 +38,8 @@ import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
import com.android.launcher3.views.OptionsPopupView;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
||||
@@ -165,6 +167,7 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent event) {
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Workspace.longPress");
|
||||
if (mLongPressState == STATE_REQUESTED) {
|
||||
if (canHandleLongPress()) {
|
||||
mLongPressState = STATE_PENDING_PARENT_INFORM;
|
||||
|
||||
@@ -33,6 +33,8 @@ import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.popup.PopupDataProvider;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
||||
@@ -92,6 +94,8 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Widgets.onLongClick");
|
||||
v.cancelLongPress();
|
||||
if (!ItemLongClickListener.canStartDrag(mLauncher)) return false;
|
||||
|
||||
if (v instanceof WidgetCell) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.regex.Pattern;
|
||||
public final class AppIcon extends Launchable {
|
||||
|
||||
private static final Pattern START_EVENT = Pattern.compile("start:");
|
||||
private static final Pattern LONG_CLICK_EVENT = Pattern.compile("onAllAppsItemLongClick");
|
||||
|
||||
AppIcon(LauncherInstrumentation launcher, UiObject2 icon) {
|
||||
super(launcher, icon);
|
||||
@@ -47,10 +48,15 @@ public final class AppIcon extends Launchable {
|
||||
public AppIconMenu openMenu() {
|
||||
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
|
||||
return new AppIconMenu(mLauncher, mLauncher.clickAndGet(
|
||||
mObject, "deep_shortcuts_container"));
|
||||
mObject, "deep_shortcuts_container", LONG_CLICK_EVENT));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addExpectedEventsForLongClick() {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLongPressIndicator() {
|
||||
return "deep_shortcuts_container";
|
||||
|
||||
@@ -40,6 +40,10 @@ public class AppIconMenuItem extends Launchable {
|
||||
return mObject.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addExpectedEventsForLongClick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLongPressIndicator() {
|
||||
return "drop_target_bar";
|
||||
|
||||
@@ -92,9 +92,12 @@ abstract class Launchable {
|
||||
: launchableCenter.x + width / 2,
|
||||
displaySize.y / 2),
|
||||
getLongPressIndicator(),
|
||||
startsActivity);
|
||||
startsActivity,
|
||||
() -> addExpectedEventsForLongClick());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void addExpectedEventsForLongClick();
|
||||
|
||||
protected abstract String getLongPressIndicator();
|
||||
}
|
||||
@@ -1173,10 +1173,12 @@ public final class LauncherInstrumentation {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
UiObject2 clickAndGet(@NonNull final UiObject2 target, @NonNull String resName) {
|
||||
UiObject2 clickAndGet(
|
||||
@NonNull final UiObject2 target, @NonNull String resName, Pattern longClickEvent) {
|
||||
final Point targetCenter = target.getVisibleCenter();
|
||||
final long downTime = SystemClock.uptimeMillis();
|
||||
sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, targetCenter, GestureScope.INSIDE);
|
||||
expectEvent(TestProtocol.SEQUENCE_MAIN, longClickEvent);
|
||||
final UiObject2 result = waitForLauncherObject(resName);
|
||||
sendPointer(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, targetCenter,
|
||||
GestureScope.INSIDE);
|
||||
|
||||
@@ -18,11 +18,17 @@ package com.android.launcher3.tapl;
|
||||
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Widget in workspace or a widget list.
|
||||
*/
|
||||
public final class Widget extends Launchable {
|
||||
|
||||
private static final Pattern LONG_CLICK_EVENT = Pattern.compile("Widgets.onLongClick");
|
||||
|
||||
Widget(LauncherInstrumentation launcher, UiObject2 icon) {
|
||||
super(launcher, icon);
|
||||
}
|
||||
@@ -35,4 +41,9 @@ public final class Widget extends Launchable {
|
||||
@Override
|
||||
protected void expectActivityStartEvents() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addExpectedEventsForLongClick() {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public final class Workspace extends Home {
|
||||
static final Pattern EVENT_CTRL_W_UP = Pattern.compile(
|
||||
"Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_W"
|
||||
+ ".*?metaState=META_CTRL_ON");
|
||||
private static final Pattern LONG_CLICK_EVENT = Pattern.compile("onWorkspaceItemLongClick");
|
||||
|
||||
private final UiObject2 mHotseat;
|
||||
|
||||
@@ -178,7 +179,9 @@ public final class Workspace extends Home {
|
||||
new Point(mLauncher.getDevice().getDisplayWidth(),
|
||||
workspace.getVisibleBounds().centerY()),
|
||||
"deep_shortcuts_container",
|
||||
false);
|
||||
false,
|
||||
() -> mLauncher.expectEvent(
|
||||
TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT));
|
||||
verifyActiveContainer();
|
||||
}
|
||||
}
|
||||
@@ -199,7 +202,7 @@ public final class Workspace extends Home {
|
||||
|
||||
static void dragIconToWorkspace(
|
||||
LauncherInstrumentation launcher, Launchable launchable, Point dest,
|
||||
String longPressIndicator, boolean startsActivity) {
|
||||
String longPressIndicator, boolean startsActivity, Runnable expectLongClickEvents) {
|
||||
LauncherInstrumentation.log("dragIconToWorkspace: begin");
|
||||
final Point launchableCenter = launchable.getObject().getVisibleCenter();
|
||||
final long downTime = SystemClock.uptimeMillis();
|
||||
@@ -208,6 +211,7 @@ public final class Workspace extends Home {
|
||||
launcher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN,
|
||||
launchableCenter, LauncherInstrumentation.GestureScope.INSIDE);
|
||||
LauncherInstrumentation.log("dragIconToWorkspace: sent down");
|
||||
expectLongClickEvents.run();
|
||||
launcher.waitForLauncherObject(longPressIndicator);
|
||||
LauncherInstrumentation.log("dragIconToWorkspace: indicator");
|
||||
launcher.movePointer(launchableCenter, dest, 10, downTime, true,
|
||||
|
||||
Reference in new issue
Block a user