Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import android.os.IBinder;
import android.view.WindowManager;
import org.androidannotations.annotations.res.StringRes;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import static;
import static;
import static;
import static;
public final class CustomMatcher {
private CustomMatcher() {
public static void isToastMessageDisplayed(@StringRes int textId) {
public static void isToastMessageDisplayed(String text) {
public static Matcher<Root> isToast() {
return new ToastMatcher();
public static class ToastMatcher extends TypeSafeMatcher<Root> {
public void describeTo(Description description) {
description.appendText("is toast");
public boolean matchesSafely(Root root) {
int type = root.getWindowLayoutParams().get().type;
if ((type == WindowManager.LayoutParams.TYPE_TOAST)) {
IBinder windowToken = root.getDecorView().getWindowToken();
IBinder appToken = root.getDecorView().getApplicationWindowToken();
// windowToken == appToken means this window isn't contained by any other windows.
// if it was a window for an activity, it would have TYPE_BASE_APPLICATION.
if (windowToken == appToken)
return true;
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.