Java Code Examples for android.app.Instrumentation#sendPointerSync()
The following examples show how to use
android.app.Instrumentation#sendPointerSync() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MotionEventUtils.java From ListViewAnimations with Apache License 2.0 | 6 votes |
public static void dispatchMotionEvents(final Instrumentation instrumentation, final Iterable<MotionEvent> motionEvents, final boolean wait) throws InterruptedException { for (final MotionEvent event : motionEvents) { int i = 0; boolean success = false; do { try { instrumentation.sendPointerSync(event); success = true; } catch (SecurityException ignored) { i++; } } while (i < 3 && !success); Thread.sleep(100); } if (wait) { /* We need to wait for the fling animation to complete */ Thread.sleep(1500); } }
Example 2
Source File: MotionEventUtils.java From ListViewAnimations with Apache License 2.0 | 6 votes |
public static void dispatchMotionEvents(final Instrumentation instrumentation, final Iterable<MotionEvent> motionEvents, final boolean wait) throws InterruptedException { for (final MotionEvent event : motionEvents) { int i = 0; boolean success = false; do { try { instrumentation.sendPointerSync(event); success = true; } catch (SecurityException e) { i++; if (i > 3) { throw e; } } } while (i < 3 && !success); Thread.sleep(100); } if (wait) { /* We need to wait for the fling animation to complete */ Thread.sleep(1500); } }
Example 3
Source File: InteractionUtil.java From litho with Apache License 2.0 | 5 votes |
public static void click(Point location) { final long time = SystemClock.uptimeMillis(); final MotionEvent actionDownEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, location.x, location.y, 0); final MotionEvent actionUpEvent = MotionEvent.obtain( time + 100, time + 100, MotionEvent.ACTION_UP, location.x, location.y, 0); final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); instrumentation.sendPointerSync(actionDownEvent); instrumentation.sendPointerSync(actionUpEvent); instrumentation.waitForIdleSync(); }
Example 4
Source File: AppBarHorizontalScrollingTest.java From material-components-android with Apache License 2.0 | 5 votes |
private void emulateButtonClick( Instrumentation instrumentation, float emulatedTapX, float emulatedTapY) { // Note that the reason to not use Espresso's click() view action is so that we can // faithfully emulate what was happening in the reported bug. We don't want the events // to be sent directly to the button, but rather be processed by the parent coordinator // layout, so that we reproduce what is happening as the events are processed at the level // of that parent. // Inject DOWN event long downTime = SystemClock.uptimeMillis(); MotionEvent eventDown = MotionEvent.obtain( downTime, downTime, MotionEvent.ACTION_DOWN, emulatedTapX, emulatedTapY, 1); instrumentation.sendPointerSync(eventDown); // Inject MOVE event long moveTime = SystemClock.uptimeMillis(); MotionEvent eventMove = MotionEvent.obtain( moveTime, moveTime, MotionEvent.ACTION_MOVE, emulatedTapX, emulatedTapY, 1); instrumentation.sendPointerSync(eventMove); // Inject UP event long upTime = SystemClock.uptimeMillis(); MotionEvent eventUp = MotionEvent.obtain(upTime, upTime, MotionEvent.ACTION_UP, emulatedTapX, emulatedTapY, 1); instrumentation.sendPointerSync(eventUp); // Wait for the system to process all events in the queue instrumentation.waitForIdleSync(); }
Example 5
Source File: AuthenticatorActivityTest.java From google-authenticator-android with Apache License 2.0 | 5 votes |
@Test public void testClickEmptySpaceOnListUnselectItem() throws InterruptedException { accountDb.add( "first", "7777777777777777", OtpType.HOTP, null, null, AccountDb.GOOGLE_ISSUER_NAME); AuthenticatorActivity activity = activityTestRule.launchActivity(null); EmptySpaceClickableDragSortListView userList = activity.findViewById(R.id.user_list); assertThat(activity.actionMode).isNull(); onView(equalTo(userList.getChildAt(0))).perform(longClick()); assertThat(activity.actionMode).isNotNull(); Point size = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(size); int height = size.y; int width = size.x; Instrumentation instr = InstrumentationRegistry.getInstrumentation(); long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis(); instr.sendPointerSync( MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, height / 2, width / 2, 0)); instr.sendPointerSync( MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, height / 2, width / 2, 0)); // We need to delay to wait for the contextual action bar is completely removed. Thread.sleep(CLICK_DELAY_INTERVAL); assertThat(activity.actionMode).isNull(); }