Loading tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +19 −0 Original line number Diff line number Diff line Loading @@ -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()} Loading tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +0 −34 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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() { Loading tests/tapl/com/android/launcher3/tapl/Workspace.java +4 −3 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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) { Loading @@ -394,7 +395,7 @@ public final class Workspace extends Home { LauncherInstrumentation.EVENT_START); } dragIconToWorkspace( launcher, launchable, () -> dest, expectLongClickEvents, expectDropEvents); launcher, launchable, dest, expectLongClickEvents, expectDropEvents); } /** Loading tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java +37 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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, Loading @@ -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(); } Loading
tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +19 −0 Original line number Diff line number Diff line Loading @@ -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()} Loading
tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +0 −34 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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() { Loading
tests/tapl/com/android/launcher3/tapl/Workspace.java +4 −3 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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) { Loading @@ -394,7 +395,7 @@ public final class Workspace extends Home { LauncherInstrumentation.EVENT_START); } dragIconToWorkspace( launcher, launchable, () -> dest, expectLongClickEvents, expectDropEvents); launcher, launchable, dest, expectLongClickEvents, expectDropEvents); } /** Loading
tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java +37 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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, Loading @@ -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(); }