diff options
Diffstat (limited to 'tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java')
-rw-r--r-- | tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 306fe4870..d89ec8b5d 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -51,6 +51,7 @@ import android.view.accessibility.AccessibilityEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.Configurator; @@ -59,6 +60,7 @@ import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; +import com.android.launcher3.ResourceUtils; import com.android.launcher3.testing.TestProtocol; import com.android.systemui.shared.system.QuickStepContract; @@ -67,6 +69,8 @@ import org.junit.Assert; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.Collections; import java.util.Deque; import java.util.LinkedList; import java.util.List; @@ -141,6 +145,15 @@ public final class LauncherInstrumentation { /** * Constructs the root of TAPL hierarchy. You get all other objects from it. */ + public LauncherInstrumentation() { + this(InstrumentationRegistry.getInstrumentation()); + } + + /** + * Constructs the root of TAPL hierarchy. You get all other objects from it. + * Deprecated: use the constructor without parameters instead. + */ + @Deprecated public LauncherInstrumentation(Instrumentation instrumentation) { mInstrumentation = instrumentation; mDevice = UiDevice.getInstance(instrumentation); @@ -765,7 +778,36 @@ public final class LauncherInstrumentation { TestProtocol.stateOrdinalToString(parcel.getInt(TestProtocol.STATE_FIELD))); } - void scroll(UiObject2 container, Direction direction, float percent, Rect margins, int steps) { + int getBottomGestureSize() { + return ResourceUtils.getNavbarSize( + ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, getResources()) + 1; + } + + int getBottomGestureMargin(UiObject2 container) { + return container.getVisibleBounds().bottom - getRealDisplaySize().y + + getBottomGestureSize(); + } + + void scrollToLastVisibleRow(UiObject2 container, Collection<UiObject2> items, int topPadding) { + final UiObject2 lowestItem = Collections.max(items, (i1, i2) -> + Integer.compare(i1.getVisibleBounds().top, i2.getVisibleBounds().top)); + + final int gestureStart = lowestItem.getVisibleBounds().top + getTouchSlop(); + final int distance = gestureStart - container.getVisibleBounds().top - topPadding; + final int bottomMargin = container.getVisibleBounds().height() - distance; + + scroll( + container, + Direction.DOWN, + new Rect( + 0, + 0, + 0, + Math.max(bottomMargin, getBottomGestureMargin(container))), + 150); + } + + void scroll(UiObject2 container, Direction direction, Rect margins, int steps) { final Rect rect = container.getVisibleBounds(); if (margins != null) { rect.left += margins.left; @@ -783,7 +825,7 @@ public final class LauncherInstrumentation { case UP: { startX = endX = rect.centerX(); final int vertCenter = rect.centerY(); - final float halfGestureHeight = rect.height() * percent / 2.0f; + final float halfGestureHeight = rect.height() / 2.0f; startY = (int) (vertCenter - halfGestureHeight) + 1; endY = (int) (vertCenter + halfGestureHeight); } @@ -791,7 +833,7 @@ public final class LauncherInstrumentation { case DOWN: { startX = endX = rect.centerX(); final int vertCenter = rect.centerY(); - final float halfGestureHeight = rect.height() * percent / 2.0f; + final float halfGestureHeight = rect.height() / 2.0f; startY = (int) (vertCenter + halfGestureHeight) - 1; endY = (int) (vertCenter - halfGestureHeight); } @@ -799,7 +841,7 @@ public final class LauncherInstrumentation { case LEFT: { startY = endY = rect.centerY(); final int horizCenter = rect.centerX(); - final float halfGestureWidth = rect.width() * percent / 2.0f; + final float halfGestureWidth = rect.width() / 2.0f; startX = (int) (horizCenter - halfGestureWidth) + 1; endX = (int) (horizCenter + halfGestureWidth); } @@ -807,7 +849,7 @@ public final class LauncherInstrumentation { case RIGHT: { startY = endY = rect.centerY(); final int horizCenter = rect.centerX(); - final float halfGestureWidth = rect.width() * percent / 2.0f; + final float halfGestureWidth = rect.width() / 2.0f; startX = (int) (horizCenter + halfGestureWidth) - 1; endX = (int) (horizCenter - halfGestureWidth); } |