Export latest Android changes

This commit is contained in:
Martin Konicek
2015-09-22 11:15:50 +01:00
parent daba14264c
commit 71628638f6
3 changed files with 12 additions and 5 deletions

View File

@@ -22,28 +22,28 @@ public class UiThreadUtil {
@Nullable private static Handler sMainHandler;
/**
* @return whether the current thread is the UI thread.
* @return {@code true} if the current thread is the UI thread.
*/
public static boolean isOnUiThread() {
return Looper.getMainLooper().getThread() == Thread.currentThread();
}
/**
* Throws a {@link AssertionException} if the current thread is not the UI thread.
* Throws an {@link AssertionException} if the current thread is not the UI thread.
*/
public static void assertOnUiThread() {
SoftAssertions.assertCondition(isOnUiThread(), "Expected to run on UI thread!");
}
/**
* Throws a {@link AssertionException} if the current thread is the UI thread.
* Throws an {@link AssertionException} if the current thread is the UI thread.
*/
public static void assertNotOnUiThread() {
SoftAssertions.assertCondition(!isOnUiThread(), "Expected not to run on UI thread!");
}
/**
* Runs the given Runnable on the UI thread.
* Runs the given {@code Runnable} on the UI thread.
*/
public static void runOnUiThread(Runnable runnable) {
synchronized (UiThreadUtil.class) {