/** * Waits for a given view. * * @param view the view to wait for * @param timeout the amount of time in milliseconds to wait * @param scroll {@code true} if scrolling should be performed * @param checkIsShown {@code true} if view.isShown() should be used * @return {@code true} if view is shown and {@code false} if it is not shown before the timeout */ public View waitForView(View view, int timeout, boolean scroll, boolean checkIsShown) { long endTime = SystemClock.uptimeMillis() + timeout; int retry = 0; if (view == null) return null; while (SystemClock.uptimeMillis() < endTime) { final boolean foundAnyMatchingView = searcher.searchFor(view); if (checkIsShown && foundAnyMatchingView && !view.isShown()) { sleeper.sleepMini(); retry++; View identicalView = viewFetcher.getIdenticalView(view); if (identicalView != null && !view.equals(identicalView)) { view = identicalView; } if (retry > 5) { return view; } continue; } if (foundAnyMatchingView) { return view; } if (scroll) scroller.scrollDown(); sleeper.sleep(); } return view; }
/** Gets the proper view to use for a screenshot. */ private View getScreenshotView() { View decorView = viewFetcher.getRecentDecorView(viewFetcher.getWindowDecorViews()); final long endTime = SystemClock.uptimeMillis() + Timeout.getSmallTimeout(); while (decorView == null) { final boolean timedOut = SystemClock.uptimeMillis() > endTime; if (timedOut) { return null; } sleeper.sleepMini(); decorView = viewFetcher.getRecentDecorView(viewFetcher.getWindowDecorViews()); } wrapAllGLViews(decorView); return decorView; }