本文整理汇总了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();
}
示例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());
}
示例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);
}
示例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();
}
示例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());
}
});
}
示例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());
}
}
});
}