OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview.test.util; | 5 package org.chromium.android_webview.test.util; |
6 | 6 |
7 import android.os.SystemClock; | 7 import android.os.SystemClock; |
8 import android.view.MotionEvent; | 8 import android.view.MotionEvent; |
9 import android.view.View; | 9 import android.view.View; |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 public void run() { | 69 public void run() { |
70 long downTime = dragStart(view, fromX, fromY); | 70 long downTime = dragStart(view, fromX, fromY); |
71 dragTo(view, fromX, toX, fromY, toY, stepCount, downTime); | 71 dragTo(view, fromX, toX, fromY, toY, stepCount, downTime); |
72 dragEnd(view, toX, toY, downTime); | 72 dragEnd(view, toX, toY, downTime); |
73 if (completionLatch != null) { | 73 if (completionLatch != null) { |
74 completionLatch.countDown(); | 74 completionLatch.countDown(); |
75 } | 75 } |
76 } | 76 } |
77 }); | 77 }); |
78 } | 78 } |
| 79 |
| 80 /** |
| 81 * Performs a single touch on the center of the supplied view. |
| 82 * This is safe to call from the instrumentation thread and will invoke the
touch |
| 83 * asynchronously. |
| 84 * |
| 85 * @param view The view the coordinates are relative to. |
| 86 */ |
| 87 public static void simulateTouchCenterOfView(final View view) throws Throwab
le { |
| 88 view.post(new Runnable() { |
| 89 @Override |
| 90 public void run() { |
| 91 long eventTime = SystemClock.uptimeMillis(); |
| 92 float x = (float) (view.getRight() - view.getLeft()) / 2; |
| 93 float y = (float) (view.getBottom() - view.getTop()) / 2; |
| 94 view.onTouchEvent(MotionEvent.obtain( |
| 95 eventTime, eventTime, MotionEvent.ACTION_DOWN, |
| 96 x, y, 0)); |
| 97 view.onTouchEvent(MotionEvent.obtain( |
| 98 eventTime, eventTime, MotionEvent.ACTION_UP, |
| 99 x, y, 0)); |
| 100 } |
| 101 }); |
| 102 } |
79 } | 103 } |
80 | 104 |
OLD | NEW |