Change the Drag Up and Drag Down simulation so they drag down to the bottom of the screen and to the top of the screen.

Previously, we ended the dragging at the border of the other extreme of the NumberPicker widget.
However, since the widget keeps listening to dragging events even if they are happening outside of the widget, ending the dragging at the border of the widget was somewhat arbitrary and did not reflect how people actually use it.
As a result, when we ended the dragging at the border of the widget, the tests failed unexpectedly based on the widget height and the touch slop value.

Test: CTS tests for Pixel 2 all passing. Note that testing on Volvo IHU is skipped because aosp branches do not support it yet.
Bug: 140960768
Change-Id: I06bda495be6f2cc1e56f03315bdb96abf0e17811
diff --git a/tests/tests/widget/src/android/widget/cts/NumberPickerTest.java b/tests/tests/widget/src/android/widget/cts/NumberPickerTest.java
index 7651f77..ac8e306 100644
--- a/tests/tests/widget/src/android/widget/cts/NumberPickerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/NumberPickerTest.java
@@ -34,6 +34,7 @@
 import android.app.Instrumentation;
 import android.content.res.ColorStateList;
 import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.graphics.Color;
 import android.text.TextUtils;
 import android.view.View;
@@ -74,7 +75,8 @@
     private Instrumentation mInstrumentation;
     private NumberPickerCtsActivity mActivity;
     private NumberPicker mNumberPicker;
-    @Mock private View.AccessibilityDelegate mMockA11yDelegate;
+    @Mock
+    private View.AccessibilityDelegate mMockA11yDelegate;
 
     @Rule
     public ActivityTestRule<NumberPickerCtsActivity> mActivityRule =
@@ -360,11 +362,17 @@
         mNumberPicker.getLocationOnScreen(numberPickerLocationOnScreen);
 
         try {
+            int screenHeight = Resources.getSystem().getDisplayMetrics().heightPixels;
+            int numberPickerMiddleX = numberPickerLocationOnScreen[0]
+                    + mNumberPicker.getWidth() / 2;
+            int numberPickerStartY = numberPickerLocationOnScreen[1] + 1;
+
             CtsTouchUtils.emulateDragGesture(mInstrumentation, mActivityRule,
-                    numberPickerLocationOnScreen[0] + mNumberPicker.getWidth() / 2,
-                    numberPickerLocationOnScreen[1] + 1,
+                    numberPickerMiddleX,
+                    numberPickerStartY,
                     0,
-                    mNumberPicker.getHeight() - 2);
+                    screenHeight - numberPickerStartY); // drag down to the bottom of the screen.
+
             Assert.assertTrue("Expected to get to IDLE state within 5 seconds",
                     latch.await(5, TimeUnit.SECONDS));
         } catch (Throwable t) {
@@ -422,14 +430,16 @@
         final int[] numberPickerLocationOnScreen = new int[2];
         mNumberPicker.getLocationOnScreen(numberPickerLocationOnScreen);
 
-
         ((View) mNumberPicker.getParent()).setAccessibilityDelegate(mMockA11yDelegate);
         try {
+            int numberPickerMiddleX =
+                    numberPickerLocationOnScreen[0] + mNumberPicker.getWidth() / 2;
+            int numberPickerEndY = numberPickerLocationOnScreen[1] + mNumberPicker.getHeight() - 1;
             CtsTouchUtils.emulateDragGesture(mInstrumentation, mActivityRule,
-                    numberPickerLocationOnScreen[0] + mNumberPicker.getWidth() / 2,
-                    numberPickerLocationOnScreen[1] + mNumberPicker.getHeight() - 1,
+                    numberPickerMiddleX,
+                    numberPickerEndY,
                     0,
-                    -(mNumberPicker.getHeight() - 2));
+                    -(numberPickerEndY)); // drag up to the top of the screen.
             Assert.assertTrue("Expected to get to IDLE state within 5 seconds",
                     latch.await(5, TimeUnit.SECONDS));
         } catch (Throwable t) {