summaryrefslogtreecommitdiff
path: root/test-runner
diff options
context:
space:
mode:
authorCharles Chen <charlesccchen@google.com>2020-05-11 10:57:46 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-11 10:57:46 +0000
commitd4b479ad3d33a6abc114b3fc3153a15998bd5f07 (patch)
tree23b1b2254b896bc80fbe684ed9fea703f241926b /test-runner
parent1f5b6d887f56cbf494f1d9fdf85a78fe46139f7c (diff)
parent242f71725b7f8e6fcf5a2feb38cfc376be56ba97 (diff)
Merge "Add WindowMetricsHelper" into rvc-dev am: 5681f3e796 am: 8a1786f075 am: a02900fbf1 am: 242f71725b
Change-Id: I9558dc4196f1ffb9481b5c0330a401afdfc9acd6
Diffstat (limited to 'test-runner')
-rw-r--r--test-runner/src/android/test/TouchUtils.java49
1 files changed, 33 insertions, 16 deletions
diff --git a/test-runner/src/android/test/TouchUtils.java b/test-runner/src/android/test/TouchUtils.java
index f2f0be73c010..1122cd8fc341 100644
--- a/test-runner/src/android/test/TouchUtils.java
+++ b/test-runner/src/android/test/TouchUtils.java
@@ -16,16 +16,23 @@
package android.test;
+import static android.view.WindowInsets.Type.displayCutout;
+import static android.view.WindowInsets.Type.navigationBars;
+
import android.app.Activity;
import android.app.Instrumentation;
-import android.graphics.Point;
+import android.graphics.Insets;
+import android.graphics.Rect;
import android.os.SystemClock;
-import android.view.Display;
+import android.util.Size;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
+import android.view.WindowInsets;
+import android.view.WindowManager;
+import android.view.WindowMetrics;
/**
* Reusable methods for generating touch events. These methods can be used with
@@ -59,13 +66,12 @@ public class TouchUtils {
* @param activity The activity that is in the foreground of the test case
*/
public static void dragQuarterScreenDown(InstrumentationTestCase test, Activity activity) {
- Display display = activity.getWindowManager().getDefaultDisplay();
- final Point size = new Point();
- display.getSize(size);
+ WindowManager wm = activity.getWindowManager();
+ final Size size = getSizeExcludingNavigationBarAndCutout(wm.getCurrentWindowMetrics());
- final float x = size.x / 2.0f;
- final float fromY = size.y * 0.5f;
- final float toY = size.y * 0.75f;
+ final float x = size.getWidth() / 2.0f;
+ final float fromY = size.getHeight() * 0.5f;
+ final float toY = size.getHeight() * 0.75f;
drag(test, x, x, fromY, toY, 4);
}
@@ -89,17 +95,27 @@ public class TouchUtils {
* @param activity The activity that is in the foreground of the test case
*/
public static void dragQuarterScreenUp(InstrumentationTestCase test, Activity activity) {
- Display display = activity.getWindowManager().getDefaultDisplay();
- final Point size = new Point();
- display.getSize(size);
+ WindowManager wm = activity.getWindowManager();
+ final Size size = getSizeExcludingNavigationBarAndCutout(wm.getCurrentWindowMetrics());
- final float x = size.x / 2.0f;
- final float fromY = size.y * 0.5f;
- final float toY = size.y * 0.25f;
+ final float x = size.getWidth() / 2.0f;
+ final float fromY = size.getHeight() * 0.5f;
+ final float toY = size.getHeight() * 0.25f;
drag(test, x, x, fromY, toY, 4);
}
+ private static Size getSizeExcludingNavigationBarAndCutout(WindowMetrics windowMetrics) {
+ WindowInsets windowInsets = windowMetrics.getWindowInsets();
+ final Insets insetsWithCutout = windowInsets
+ .getInsetsIgnoringVisibility(navigationBars() | displayCutout());
+ final int insetsWidth = insetsWithCutout.left + insetsWithCutout.right;
+ final int insetsHeight = insetsWithCutout.top + insetsWithCutout.bottom;
+
+ Rect bounds = windowMetrics.getBounds();
+ return new Size(bounds.width() - insetsWidth, bounds.height() - insetsHeight);
+ }
+
/**
* Scroll a ViewGroup to the bottom by repeatedly calling
* {@link #dragQuarterScreenUp(InstrumentationTestCase, Activity)}
@@ -222,8 +238,9 @@ public class TouchUtils {
*/
public static void dragViewToBottom(InstrumentationTestCase test, Activity activity, View v,
int stepCount) {
- int screenHeight =
- activity.getWindowManager().getCurrentWindowMetrics().getBounds().height();
+ WindowManager wm = activity.getWindowManager();
+ final int screenHeight = getSizeExcludingNavigationBarAndCutout(
+ wm.getCurrentWindowMetrics()).getHeight();
int[] xy = new int[2];
v.getLocationOnScreen(xy);