Пример #1
0
  public void flick(final int speedX, final int speedY) {
    List<View> scrollableContainer =
        ViewHierarchyAnalyzer.getDefaultInstance().findScrollableContainer();

    if (scrollableContainer == null) {
      // nothing to do
      return;
    }
    for (View view : scrollableContainer) {
      if (view instanceof AbsListView) {
        // ignore
      } else if (view instanceof ScrollView) {
        final ScrollView scrollView = (ScrollView) view;
        instrumentation.runOnUiThread(
            new Runnable() {
              public void run() {
                scrollView.fling(speedY);
              }
            });
      } else if (view instanceof WebView) {
        final WebView webView = (WebView) view;
        instrumentation.runOnUiThread(
            new Runnable() {
              public void run() {
                webView.flingScroll(speedX, speedY);
              }
            });
      }
    }
  }
Пример #2
0
  private void sendMotionEvents(final List<MotionEvent> eventsToSend) {

    try {
      instrumentation.waitForIdleSync();
      for (MotionEvent event : eventsToSend) {
        instrumentation.sendPointerSync(event);
      }
    } catch (SecurityException ignored) {
      ignored.printStackTrace();
    }
  }
Пример #3
0
  public void scroll(final int xOffset, final int yOffset) {
    List<View> scrollableContainer =
        ViewHierarchyAnalyzer.getDefaultInstance().findScrollableContainer();

    if (scrollableContainer == null) {
      // nothing to do
      return;
    }
    for (View view : scrollableContainer) {
      if (view instanceof AbsListView) {
        final AbsListView absListView = (AbsListView) view;
        instrumentation.runOnUiThread(
            new Runnable() {
              public void run() {
                absListView.scrollBy(xOffset, yOffset);
              }
            });
      } else if (view instanceof ScrollView) {
        final ScrollView scrollView = (ScrollView) view;
        instrumentation.runOnUiThread(
            new Runnable() {
              public void run() {
                scrollView.scrollBy(xOffset, yOffset);
              }
            });
      } else if (view instanceof WebView) {
        final WebView webView = (WebView) view;
        instrumentation.runOnUiThread(
            new Runnable() {
              public void run() {
                webView.scrollBy(xOffset, yOffset);
              }
            });
      }
    }
  }