public < T extends View > T waitForAndGetView ( int index , Class < T > classToFilterBy ) { long endTime = SystemClock . uptimeMillis ( ) + Timeout . getSmallTimeout ( ) ; while ( SystemClock . uptimeMillis ( ) <= endTime && ! waitForView ( classToFilterBy , index , true , true ) ) ; int numberOfUniqueViews = searcher . getNumberOfUniqueViews ( ) ; ArrayList < T > views = RobotiumUtils . removeInvisibleViews ( viewFetcher . getCurrentViews ( classToFilterBy , true ) ) ; if ( views . size ( ) < numberOfUniqueViews ) { int newIndex = index - ( numberOfUniqueViews - views . size ( ) ) ; if ( newIndex >= 0 ) index = newIndex ; } T view = null ; try { view = views . get ( index ) ; } catch ( IndexOutOfBoundsException exception ) { int match = index + 1 ; if ( match > 1 ) { Assert . fail ( match + " " + classToFilterBy . getSimpleName ( ) + "s" + " are not found!" ) ; } else { Assert . fail ( classToFilterBy . getSimpleName ( ) + " is not found!" ) ; } } views = null ; return view ; }
Waits for and returns a View .