Exemple #1
0
  /**
   * Waits for a text to be shown.
   *
   * @param classToFilterBy the class to filter by
   * @param text the text that needs to be shown, specified as a regular expression.
   * @param expectedMinimumNumberOfMatches the minimum number of matches of text that must be shown.
   *     {@code 0} means any number of matches
   * @param timeout the amount of time in milliseconds to wait
   * @param scroll {@code true} if scrolling should be performed
   * @param onlyVisible {@code true} if only visible text views should be waited for
   * @param hardStoppage {@code true} if search is to be stopped when timeout expires
   * @return {@code true} if text is found and {@code false} if it is not found before the timeout
   */
  public <T extends TextView> T waitForText(
      Class<T> classToFilterBy,
      String text,
      int expectedMinimumNumberOfMatches,
      long timeout,
      boolean scroll,
      boolean onlyVisible,
      boolean hardStoppage) {
    final long endTime = SystemClock.uptimeMillis() + timeout;

    while (true) {
      final boolean timedOut = SystemClock.uptimeMillis() > endTime;
      if (timedOut) {
        return null;
      }

      sleeper.sleep();

      if (!hardStoppage) timeout = 0;

      final T textViewToReturn =
          searcher.searchFor(
              classToFilterBy, text, expectedMinimumNumberOfMatches, timeout, scroll, onlyVisible);

      if (textViewToReturn != null) {
        return textViewToReturn;
      }
    }
  }
Exemple #2
0
  /**
   * 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;
  }
Exemple #3
0
  /**
   * Waits for a view to be shown.
   *
   * @param viewClass the {@code View} class to wait for
   * @param index the index of the view that is expected to be shown.
   * @param timeout the amount of time in milliseconds to wait
   * @param scroll {@code true} if scrolling should be performed
   * @return {@code true} if view is shown and {@code false} if it is not shown before the timeout
   */
  public <T extends View> boolean waitForView(
      final Class<T> viewClass, final int index, final int timeout, final boolean scroll) {
    Set<T> uniqueViews = new HashSet<T>();
    final long endTime = SystemClock.uptimeMillis() + timeout;
    boolean foundMatchingView;

    while (SystemClock.uptimeMillis() < endTime) {
      sleeper.sleep();

      foundMatchingView = searcher.searchFor(uniqueViews, viewClass, index);

      if (foundMatchingView) return true;

      if (scroll) scroller.scrollDown();
    }
    return false;
  }
Exemple #4
0
  /**
   * Waits for a view to be shown.
   *
   * @param viewClass the {@code View} class to wait for
   * @param index the index of the view that is expected to be shown
   * @param sleep true if should sleep
   * @param scroll {@code true} if scrolling should be performed
   * @return {@code true} if view is shown and {@code false} if it is not shown before the timeout
   */
  public <T extends View> boolean waitForView(
      final Class<T> viewClass, final int index, boolean sleep, boolean scroll) {
    Set<T> uniqueViews = new HashSet<T>();
    boolean foundMatchingView;

    while (true) {

      if (sleep) sleeper.sleep();

      foundMatchingView = searcher.searchFor(uniqueViews, viewClass, index);

      if (foundMatchingView) return true;

      if (scroll && !scroller.scrollDown()) return false;

      if (!scroll) return false;
    }
  }