Instrumentation runOnMainSync - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Instrumentation runOnMainSync method.

This code example shows how to use the following methods:runOnMainSync, get
     * 
     * @param <R> Type of result to return 
     */ 
    public <R> R runTestOnUiThreadAndGetResult(Callable<R> callable)
            throws Exception { 
        FutureTask<R> task = new FutureTask<R>(callable);
        getInstrumentation().waitForIdleSync();
        getInstrumentation().runOnMainSync(task);
        return task.get();
    } 
 
    /** 
     * Loads url on the UI thread and blocks until onPageFinished is called. 
     */ 
    protected void loadUrlSync(final WebView webview,
                               CallbackHelper onPageFinishedHelper,
                               final String url) throws Exception {
        int currentCallCount = onPageFinishedHelper.getCallCount();
        loadUrlAsync(webview, url);
        onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
6
CodeRank
This code example shows how to use the following methods:runOnMainSync
    } 
 
    public static <R> R runOnMainSyncAndGetResult(Instrumentation instrumentation,
            Callable<R> callable) throws Throwable {
        FutureTask<R> task = new FutureTask<R>(callable);
        instrumentation.runOnMainSync(task);
        try { 
            return task.get();
        } catch (ExecutionException e) {
            // Unwrap the cause of the exception and re-throw it. 
            throw e.getCause();
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:runOnMainSync, get
     * 
     * @param <R> Type of result to return 
     */ 
    public <R> R runTestOnUiThreadAndGetResult(Callable<R> callable)
            throws Throwable { 
        FutureTask<R> task = new FutureTask<R>(callable);
        getInstrumentation().waitForIdleSync();
        getInstrumentation().runOnMainSync(task);
        try { 
            return task.get();
        } catch (ExecutionException e) {
            // Unwrap the cause of the exception and re-throw it. 
            throw e.getCause();
        } 
    } 
 
    protected void enableJavaScriptOnUiThread(final AwContents awContents) {
        getInstrumentation().runOnMainSync(new Runnable() {
            @Override 
            public void run() { 
5
CodeRank
This code example shows how to use the following methods:runOnMainSync
This code example shows how to use the following methods:runOnMainSync
     * 
     * @param instrumentation Instrumentation object used by the test. 
     * @param v The view to call performClick on. 
     */ 
    public static void performClickOnMainSync(Instrumentation instrumentation, final View v) {
        instrumentation.runOnMainSync(new Runnable() {
            @Override 
            public void run() { 
                v.performClick();
            } 
        }); 
    } 
 
    /** 
     * Clicks on specified view in the given {@link Activity}. 
     * 
     * @param test The test case using this utility. 
     * @param activity Activity containing the view. 
     * @param id The view to be clicked. 
     * @return {@code true} if a view with the given id exists. 
5
CodeRank
This code example shows how to use the following methods:runOnMainSync
     * 
     * @param instrumentation Instrumentation object used by the test. 
     * @param v The view to call performClick on. 
     */ 
    public static void performClickOnMainSync(Instrumentation instrumentation, final View v) {
        instrumentation.runOnMainSync(new Runnable() {
            @Override 
            public void run() { 
                v.performClick();
            } 
        }); 
    } 
 
    /** 
     * Clicks on specified view in the given {@link Activity}. 
     * 
     * @param test The test case using this utility. 
     * @param activity Activity containing the view. 
     * @param id The view to be clicked. 
     * @return {@code true} if a view with the given id exists. 
5
CodeRank
This code example shows how to use the following methods:runOnMainSync, get
     * 
     * @param <R> Type of result to return 
     */ 
    public <R> R runTestOnUiThreadAndGetResult(Callable<R> callable)
            throws Exception { 
        FutureTask<R> task = new FutureTask<R>(callable);
        getInstrumentation().waitForIdleSync();
        getInstrumentation().runOnMainSync(task);
        return task.get();
    } 
 
    protected void enableJavaScriptOnUiThread(final AwContents awContents) {
        getInstrumentation().runOnMainSync(new Runnable() {
            @Override 
            public void run() { 
                awContents.getContentViewCore().getContentSettings().setJavaScriptEnabled(true);
            } 
        }); 
    } 
 
5
CodeRank
This code example shows how to use the following methods:runOnMainSync
This code example shows how to use the following methods:runOnMainSync
 
 
        // ---------------------------------------------------------- 
        private void scrollToLine(final int line)
        { 
            instrumentation.runOnMainSync(new Runnable() {
                public void run() 
                { 
                    ((AbsListView) view).setSelection(line);
                } 
            }); 
        } 
    } 
} 
3
CodeRank
This code example shows how to use the following methods:runOnMainSync
        @Override 
        public void run() { 
          invokePreferencePerformClick(preference, preferenceScreen);
        } 
      }, null); 
      instrumentation.runOnMainSync(task);
      try { 
        task.get();
      } catch (Exception e) {
        throw new RuntimeException("Failed to click on preference on main thread", e);
      } 
    } 
  } 
 
  private static void invokePreferencePerformClick( 
      Preference preference, PreferenceScreen preferenceScreen) {
    try { 
      Method performClickMethod =
          Preference.class.getDeclaredMethod("performClick", PreferenceScreen.class);
      performClickMethod.setAccessible(true);
3
CodeRank

Related Instrumentation runOnMainSync Questions & Answers:

runOnMainSync Method Overview
Execute a call on the application's main thread, blocking until it is complete.
See Code Examples for other Android Instrumentation Methods: