Merge "Cherrypick needed for merge conflict with ag/18875278" into tm-qpr-dev

This commit is contained in:
Sebastián Franco
2022-06-23 21:54:13 +00:00
committed by Android (Google) Code Review
4 changed files with 60 additions and 38 deletions

View File

@@ -521,6 +521,25 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
}
}
@Test
@PortraitLandscape
public void testDragShortcutToWorkspaceCell() throws Exception {
Point[] targets = getCornersAndCenterPositions();
for (Point target : targets) {
final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
try {
allApps.getAppIcon(APP_NAME)
.openDeepShortcutMenu()
.getMenuItem(0)
.dragToWorkspace(target.x, target.y);
} finally {
allApps.unfreeze();
}
}
}
/**
* @return List of workspace grid coordinates. Those are not pixels. See {@link
* Workspace#getIconGridDimensions()}

View File

@@ -22,8 +22,6 @@ import android.graphics.Rect;
import androidx.annotation.NonNull;
import androidx.test.uiautomator.UiObject2;
import java.util.function.Supplier;
/**
* App icon on the workspace or all apps.
*/
@@ -102,38 +100,6 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W
}
}
/**
* Drag an object to the given cell in workspace. The target cell must be empty.
*
* @param cellX zero based column number, starting from the left of the screen.
* @param cellY zero based row number, starting from the top of the screen.
*/
public HomeAppIcon dragToWorkspace(int cellX, int cellY) {
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
String.format("want to drag the icon to cell(%d, %d)", cellX, cellY))
) {
final Supplier<Point> dest = () -> Workspace.getCellCenter(mLauncher, cellX, cellY);
Workspace.dragIconToWorkspace(
mLauncher,
/* launchable= */ this,
dest,
() -> addExpectedEventsForLongClick(),
/*expectDropEvents= */ null);
try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) {
WorkspaceAppIcon appIcon =
(WorkspaceAppIcon) mLauncher.getWorkspace().getWorkspaceAppIcon(mAppName);
mLauncher.assertTrue(
String.format(
"The %s icon should be in the cell (%d, %d).", mAppName, cellX,
cellY),
appIcon.isInCell(cellX, cellY));
return appIcon;
}
}
}
/** This method requires public access, however should not be called in tests. */
@Override
public Launchable getLaunchable() {

View File

@@ -228,10 +228,11 @@ public final class Workspace extends Home {
private void dragIcon(UiObject2 workspace, HomeAppIcon homeAppIcon, int pageDelta) {
int pageWidth = mLauncher.getDevice().getDisplayWidth() / pagesPerScreen();
int targetX = (pageWidth / 2) + pageWidth * pageDelta;
int targetY = mLauncher.getVisibleBounds(workspace).centerY();
dragIconToWorkspace(
mLauncher,
homeAppIcon,
new Point(targetX, mLauncher.getVisibleBounds(workspace).centerY()),
() -> new Point(targetX, targetY),
false,
false,
() -> mLauncher.expectEvent(
@@ -386,7 +387,7 @@ public final class Workspace extends Home {
}
static void dragIconToWorkspace(LauncherInstrumentation launcher, Launchable launchable,
Point dest, boolean startsActivity, boolean isWidgetShortcut,
Supplier<Point> dest, boolean startsActivity, boolean isWidgetShortcut,
Runnable expectLongClickEvents) {
Runnable expectDropEvents = null;
if (startsActivity || isWidgetShortcut) {
@@ -394,7 +395,7 @@ public final class Workspace extends Home {
LauncherInstrumentation.EVENT_START);
}
dragIconToWorkspace(
launcher, launchable, () -> dest, expectLongClickEvents, expectDropEvents);
launcher, launchable, dest, expectLongClickEvents, expectDropEvents);
}
/**

View File

@@ -17,6 +17,8 @@ package com.android.launcher3.tapl;
import android.graphics.Point;
import java.util.function.Supplier;
/** Launchable that can serve as a source for dragging and dropping to the workspace. */
interface WorkspaceDragSource {
@@ -36,7 +38,7 @@ interface WorkspaceDragSource {
Workspace.dragIconToWorkspace(
launcher,
launchable,
new Point(
() -> new Point(
launchableCenter.x >= width
? launchableCenter.x - width / 2
: launchableCenter.x + width / 2,
@@ -47,6 +49,40 @@ interface WorkspaceDragSource {
}
}
/**
* Drag an object to the given cell in workspace. The target cell must be empty.
*
* @param cellX zero based column number, starting from the left of the screen.
* @param cellY zero based row number, starting from the top of the screen. *
*/
default HomeAppIcon dragToWorkspace(int cellX, int cellY) {
Launchable launchable = getLaunchable();
final String iconName = launchable.getObject().getText();
LauncherInstrumentation launcher = launchable.mLauncher;
try (LauncherInstrumentation.Closable e = launcher.eventsCheck();
LauncherInstrumentation.Closable c = launcher.addContextLayer(
String.format("want to drag the icon to cell(%d, %d)", cellX, cellY))) {
final Supplier<Point> dest = () -> Workspace.getCellCenter(launcher, cellX, cellY);
Workspace.dragIconToWorkspace(
launcher,
launchable,
dest,
launchable::addExpectedEventsForLongClick,
/*expectDropEvents= */ null);
try (LauncherInstrumentation.Closable ignore = launcher.addContextLayer("dragged")) {
WorkspaceAppIcon appIcon =
(WorkspaceAppIcon) launcher.getWorkspace().getWorkspaceAppIcon(iconName);
launcher.assertTrue(
String.format(
"The %s icon should be in the cell (%d, %d).", iconName, cellX,
cellY),
appIcon.isInCell(cellX, cellY));
return appIcon;
}
}
}
/** This method requires public access, however should not be called in tests. */
Launchable getLaunchable();
}