From 6fe4e93d4a6802433241b7030c33a2e162f9280d Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 19 Mar 2019 12:16:39 -0700 Subject: [PATCH] Stop using magic constant 0.6 for returning from all apps to overview Bug: 123904290 Change-Id: If1b6caf562484649ee107532ffe21d25deff4b97 --- .../quickstep/TestInformationProvider.java | 18 ++++++++++++++++++ src/com/android/launcher3/TestProtocol.java | 2 ++ .../launcher3/tapl/AllAppsFromOverview.java | 8 +++++++- .../com/android/launcher3/tapl/Background.java | 8 ++++---- .../tapl/LauncherInstrumentation.java | 5 +++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/quickstep/src/com/android/quickstep/TestInformationProvider.java b/quickstep/src/com/android/quickstep/TestInformationProvider.java index 0c478d25e2..0c93dd6cf5 100644 --- a/quickstep/src/com/android/quickstep/TestInformationProvider.java +++ b/quickstep/src/com/android/quickstep/TestInformationProvider.java @@ -25,6 +25,9 @@ import android.os.Bundle; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.Launcher; +import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherState; import com.android.launcher3.TestProtocol; import com.android.launcher3.Utilities; import com.android.launcher3.uioverrides.OverviewState; @@ -82,6 +85,21 @@ public class TestInformationProvider extends ContentProvider { response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight); break; } + case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: { + final LauncherAppState launcherAppState = + LauncherAppState.getInstanceNoCreate(); + if (launcherAppState == null) return null; + + final Launcher launcher = (Launcher) launcherAppState.getModel().getCallback(); + if (launcher == null) return null; + + final float progress = LauncherState.OVERVIEW.getVerticalProgress(launcher) + - LauncherState.ALL_APPS.getVerticalProgress(launcher); + final float distance = + launcher.getAllAppsController().getShiftRange() * progress; + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance); + break; + } } return response; } diff --git a/src/com/android/launcher3/TestProtocol.java b/src/com/android/launcher3/TestProtocol.java index 5f752cc704..a4e4227153 100644 --- a/src/com/android/launcher3/TestProtocol.java +++ b/src/com/android/launcher3/TestProtocol.java @@ -36,4 +36,6 @@ public final class TestProtocol { "home-to-overview-swipe-height"; public static final String REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT = "background-to-overview-swipe-height"; + public static final String REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT = + "all-apps-to-overview-swipe-height"; } diff --git a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java index 264281502b..dcc51b50ba 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java @@ -23,6 +23,8 @@ import android.graphics.Point; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; +import com.android.launcher3.TestProtocol; + /** * Operations on AllApps opened from Overview. */ @@ -45,7 +47,11 @@ public final class AllAppsFromOverview extends AllApps { final UiObject2 qsb = mLauncher.waitForObjectInContainer( allAppsContainer, "search_container_all_apps"); final Point start = qsb.getVisibleCenter(); - final int endY = (int) (mLauncher.getDevice().getDisplayHeight() * 0.6); + final int swipeHeight = mLauncher.getTestInfo( + TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT). + getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); + + final int endY = start.y + swipeHeight + mLauncher.getTouchSlop(); LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe"); mLauncher.swipe(start.x, start.y, start.x, endY, OVERVIEW_STATE_ORDINAL); diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 7031cd34c0..2cde8ecd24 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -22,8 +22,6 @@ import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName; import static org.junit.Assert.assertTrue; -import android.view.ViewConfiguration; - import androidx.annotation.NonNull; import androidx.test.uiautomator.By; import androidx.test.uiautomator.Until; @@ -67,9 +65,11 @@ public class Background extends LauncherInstrumentation.VisibleContainer { final int swipeHeight = mLauncher.getTestInfo( getSwipeHeightRequestName()). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); - final int slop = ViewConfiguration.get(mLauncher.getContext()).getScaledTouchSlop(); - mLauncher.swipe(centerX, startY, centerX, startY - swipeHeight - slop, expectedState); + mLauncher.swipe( + centerX, startY, centerX, + startY - swipeHeight - mLauncher.getTouchSlop(), + expectedState); } else { mLauncher.waitForSystemUiObject("recent_apps").click(); } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index ce37348d3d..e3850ff0fd 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -32,6 +32,7 @@ import android.provider.Settings; import android.util.Log; import android.view.MotionEvent; import android.view.Surface; +import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; import androidx.annotation.NonNull; @@ -468,4 +469,8 @@ public final class LauncherInstrumentation { float getDisplayDensity() { return mInstrumentation.getTargetContext().getResources().getDisplayMetrics().density; } + + int getTouchSlop() { + return ViewConfiguration.get(getContext()).getScaledTouchSlop(); + } } \ No newline at end of file