當前位置: 首頁>>代碼示例>>Java>>正文


Java Instrumentation.runOnMainSync方法代碼示例

本文整理匯總了Java中android.app.Instrumentation.runOnMainSync方法的典型用法代碼示例。如果您正苦於以下問題:Java Instrumentation.runOnMainSync方法的具體用法?Java Instrumentation.runOnMainSync怎麽用?Java Instrumentation.runOnMainSync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Instrumentation的用法示例。


在下文中一共展示了Instrumentation.runOnMainSync方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: callOnMainSync

import android.app.Instrumentation; //導入方法依賴的package包/類
private static <X> X callOnMainSync(Instrumentation instrumentation, final Callable<X> callable)
        throws Exception {
    final AtomicReference<X> retAtomic = new AtomicReference<>();
    final AtomicReference<Throwable> exceptionAtomic = new AtomicReference<>();
    instrumentation.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            try {
                retAtomic.set(callable.call());
            } catch (Throwable e) {
                exceptionAtomic.set(e);
            }
        }
    });
    final Throwable exception = exceptionAtomic.get();
    if (exception != null) {
        Throwables.propagateIfInstanceOf(exception, Exception.class);
        Throwables.propagate(exception);
    }
    return retAtomic.get();
}
 
開發者ID:Adyen,項目名稱:adyen-android,代碼行數:22,代碼來源:EspressoTestUtils.java

示例2: searchFragmentShouldCollectDisposablesAndReleaseThemInOnDestroy

import android.app.Instrumentation; //導入方法依賴的package包/類
@Test
public void searchFragmentShouldCollectDisposablesAndReleaseThemInOnDestroy() {
    CompositeDisposable composite = new CompositeDisposable();
    decorate().searchFragmentSubcomponent().withCompositeDisposable(() -> composite);
    final MainActivity activity = rule.launchActivity(null);
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.runOnMainSync(() ->
    {
        ((ViewPager)activity.findViewById(R.id.container)).setCurrentItem(2);
        assertEquals(1, composite.size());
        activity.finish();
    });
    instrumentation.waitForIdleSync();
    SystemClock.sleep(500);
    assertTrue(composite.isDisposed());
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:17,代碼來源:WeatherFragmentTest.java

示例3: testBitmap

import android.app.Instrumentation; //導入方法依賴的package包/類
@Test
public void testBitmap() {
    final Instrumentation instr = InstrumentationRegistry.getInstrumentation();
    final BitmapPoller poller = new BitmapPoller(5);
    instr.runOnMainSync(new Runnable() {
        public void run() {
            final FlutterView flutterView = (FlutterView) activityRule.getActivity().findViewById(
                R.id.flutter_view);

            // Call onPostResume to start the engine's renderer even if the activity
            // is paused in the test environment.
            flutterView.onPostResume();

            poller.start(flutterView);
        }
    });

    Bitmap bitmap = null;
    try {
        bitmap = poller.waitForBitmap();
    } catch (InterruptedException e) {
        fail(e.getMessage());
    }

    assertNotNull(bitmap);
    assertTrue(bitmap.getWidth() > 0);
    assertTrue(bitmap.getHeight() > 0);

    // Check that a pixel matches the default Material background color.
    assertTrue(bitmap.getPixel(bitmap.getWidth() - 1, bitmap.getHeight() - 1) == 0xFFFAFAFA);
}
 
開發者ID:yushulx,項目名稱:flutter-android-aar,代碼行數:32,代碼來源:ExampleInstrumentedTest.java

示例4: removesLocationUpdatesOnStop

import android.app.Instrumentation; //導入方法依賴的package包/類
@Test
public void removesLocationUpdatesOnStop() throws Throwable {
    final MainActivity activity = rule.launchActivity(null);
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.runOnMainSync(() -> {
        instrumentation.callActivityOnPause(activity);
        verify(locationService, times(0)).removeUpdates();
        instrumentation.callActivityOnStop(activity);
        verify(locationService).removeUpdates();
    });
    instrumentation.waitForIdleSync();
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:13,代碼來源:SimpleEspressoTest.java

示例5: makeAllProgressBarsIdle

import android.app.Instrumentation; //導入方法依賴的package包/類
public static void makeAllProgressBarsIdle(Instrumentation instrumentation, final Activity activity) {
    instrumentation.runOnMainSync(new Runnable() {
        public void run() {
            makeAllProgressBarsIdle(activity.findViewById(android.R.id.content).getRootView());
        }
    });
}
 
開發者ID:erdo,項目名稱:asaf-project,代碼行數:8,代碼來源:ProgressBarIdler.java

示例6: makeAllProgressBarsIdleForAllResumedActivities

import android.app.Instrumentation; //導入方法依賴的package包/類
public static void makeAllProgressBarsIdleForAllResumedActivities(Instrumentation instrumentation) {
    instrumentation.runOnMainSync(new Runnable() {
        public void run() {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if (resumedActivities.isEmpty()) {
                throw new RuntimeException("Could not change orientation");
            }
            for (Activity activity : resumedActivities) {
                makeAllProgressBarsIdle(activity.findViewById(android.R.id.content).getRootView());
            }
        }
    });
}
 
開發者ID:erdo,項目名稱:asaf-project,代碼行數:14,代碼來源:ProgressBarIdler.java


注:本文中的android.app.Instrumentation.runOnMainSync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。