本文整理汇总了Java中com.android.launcher3.MainThreadExecutor类的典型用法代码示例。如果您正苦于以下问题:Java MainThreadExecutor类的具体用法?Java MainThreadExecutor怎么用?Java MainThreadExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MainThreadExecutor类属于com.android.launcher3包,在下文中一共展示了MainThreadExecutor类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runOnUiThread
import com.android.launcher3.MainThreadExecutor; //导入依赖的package包/类
/**
* Converts the condition to be run on UI thread.
*/
public static Condition runOnUiThread(final Condition condition) {
final MainThreadExecutor executor = new MainThreadExecutor();
return new Condition() {
@Override
public boolean isTrue() throws Throwable {
final AtomicBoolean value = new AtomicBoolean(false);
final Throwable[] exceptions = new Throwable[1];
final CountDownLatch latch = new CountDownLatch(1);
executor.execute(new Runnable() {
@Override
public void run() {
try {
value.set(condition.isTrue());
} catch (Throwable e) {
exceptions[0] = e;
}
}
});
latch.await(1, TimeUnit.SECONDS);
if (exceptions[0] != null) {
throw exceptions[0];
}
return value.get();
}
};
}