Files
Lawnchair/tests/src/com/android/launcher3/util/Wait.java
T
Sunny Goyal 6d02c7a033 Adding some UI tests
> Launcher app from all-apps
> Drag icon to all-apps and launch it
> Add widget from widget tray

Change-Id: I6bd6128a7b560a23a887d1fb40bfcda25b9b02e7
2016-05-26 17:20:22 -07:00

31 lines
825 B
Java

package com.android.launcher3.util;
import android.os.SystemClock;
/**
* A utility class for waiting for a condition to be true.
*/
public class Wait {
private static final long DEFAULT_SLEEP_MS = 200;
public static boolean atMost(Condition condition, long timeout) {
return atMost(condition, timeout, DEFAULT_SLEEP_MS);
}
public static boolean atMost(Condition condition, long timeout, long sleepMillis) {
long endTime = SystemClock.uptimeMillis() + timeout;
while (SystemClock.uptimeMillis() < endTime) {
try {
if (condition.isTrue()) {
return true;
}
} catch (Throwable t) {
// Ignore
}
SystemClock.sleep(sleepMillis);
}
return false;
}
}