From 8bba01874a8ee4663b85c4a540745377468e740b Mon Sep 17 00:00:00 2001 From: vadimt Date: Wed, 13 Mar 2019 18:37:41 -0700 Subject: Initial implementation for TAPL support for gestural navigation It cuts some corners, flaky and has magic constants, which will be addressed later. Change-Id: I0acc75338a3c6d0ead3afda01e25ba43eb095913 --- .../com/android/launcher3/tapl/Background.java | 56 ++++++++++++++++------ 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'tests/tapl/com/android/launcher3/tapl/Background.java') diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 2cde8ecd2..ef509edeb 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -22,6 +22,10 @@ import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName; import static org.junit.Assert.assertTrue; +import android.graphics.Point; +import android.os.SystemClock; +import android.view.MotionEvent; + import androidx.annotation.NonNull; import androidx.test.uiautomator.By; import androidx.test.uiautomator.Until; @@ -33,6 +37,8 @@ import com.android.launcher3.TestProtocol; * indicate Launcher as long as Launcher is not in Overview state. */ public class Background extends LauncherInstrumentation.VisibleContainer { + private static final int ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION = 500; + private static final int ZERO_BUTTON_SWIPE_UP_HOLD_DURATION = 400; Background(LauncherInstrumentation launcher) { super(launcher); @@ -59,19 +65,41 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } protected void goToOverviewUnchecked(int expectedState) { - if (mLauncher.isSwipeUpEnabled()) { - final int centerX = mLauncher.getDevice().getDisplayWidth() / 2; - final int startY = getSwipeStartY(); - final int swipeHeight = mLauncher.getTestInfo( - getSwipeHeightRequestName()). - getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); - - mLauncher.swipe( - centerX, startY, centerX, - startY - swipeHeight - mLauncher.getTouchSlop(), - expectedState); - } else { - mLauncher.waitForSystemUiObject("recent_apps").click(); + switch (mLauncher.getNavigationModel()) { + case ZERO_BUTTON: { + final int centerX = mLauncher.getDevice().getDisplayWidth() / 2; + final int startY = getSwipeStartY(); + final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()). + getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); + final Point start = new Point(centerX, startY); + final Point end = + new Point(centerX, startY - swipeHeight - mLauncher.getTouchSlop()); + + final long downTime = SystemClock.uptimeMillis(); + mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start); + mLauncher.movePointer(downTime, ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION, start, end); + LauncherInstrumentation.sleep(ZERO_BUTTON_SWIPE_UP_HOLD_DURATION); + mLauncher.sendPointer( + downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, end); + break; + } + + case TWO_BUTTON: { + final int centerX = mLauncher.getDevice().getDisplayWidth() / 2; + final int startY = getSwipeStartY(); + final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()). + getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); + + mLauncher.swipe( + centerX, startY, centerX, + startY - swipeHeight - mLauncher.getTouchSlop(), + expectedState); + break; + } + + case THREE_BUTTON: + mLauncher.waitForSystemUiObject("recent_apps").click(); + break; } } @@ -80,6 +108,6 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } protected int getSwipeStartY() { - return mLauncher.waitForSystemUiObject("home").getVisibleBounds().centerY(); + return mLauncher.waitForSystemUiObject("navigation_bar_frame").getVisibleBounds().centerY(); } } -- cgit v1.2.3