public void clickLongOnScreen ( float x , float y , int time , View view ) { boolean successfull = false ; int retry = 0 ; SecurityException ex = null ; long downTime = SystemClock . uptimeMillis ( ) ; long eventTime = SystemClock . uptimeMillis ( ) ; MotionEvent event = MotionEvent . obtain ( downTime , eventTime , MotionEvent . ACTION_DOWN , x , y , 0 ) ; while ( ! successfull && retry < 20 ) { try { inst . sendPointerSync ( event ) ; successfull = true ; sleeper . sleep ( MINI_WAIT ) ; } catch ( SecurityException e ) { ex = e ; dialogUtils . hideSoftKeyboard ( null , false , true ) ; sleeper . sleep ( MINI_WAIT ) ; retry ++ ; View identicalView = viewFetcher . getIdenticalView ( view ) ; if ( identicalView != null ) { float [ ] xyToClick = getClickCoordinates ( identicalView ) ; x = xyToClick [ 0 ] ; y = xyToClick [ 1 ] ; } } } if ( ! successfull ) { Assert . fail ( "Long click at (" + x + ", " + y + ") can not be completed! (" + ( ex != null ? ex . getClass ( ) . getName ( ) + ": " + ex . getMessage ( ) : "null" ) + ")" ) ; } eventTime = SystemClock . uptimeMillis ( ) ; event = MotionEvent . obtain ( downTime , eventTime , MotionEvent . ACTION_MOVE , x + 1.0f , y + 1.0f , 0 ) ; inst . sendPointerSync ( event ) ; if ( time > 0 ) sleeper . sleep ( time ) ; else sleeper . sleep ( ( int ) ( ViewConfiguration . getLongPressTimeout ( ) * 2.5f ) ) ; eventTime = SystemClock . uptimeMillis ( ) ; event = MotionEvent . obtain ( downTime , eventTime , MotionEvent . ACTION_UP , x , y , 0 ) ; inst . sendPointerSync ( event ) ; sleeper . sleep ( ) ; }
Long clicks a given coordinate on the screen .