当前位置: 首页>>代码示例>>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;未经允许,请勿转载。