// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/CustomMatchers.java
// @SuppressWarnings("SpellCheckingInspection")
// @NonNull
// static Matcher<View> withCompoundDrawable(@DrawableRes final int resourceId) {
//     return new BoundedMatcher<View, TextView>(TextView.class) {
//         @Override
//         public void describeTo(@NonNull Description description) {
//             description.appendText("has compound drawable resource " + resourceId);
//         }
// 
//         @Override
//         public boolean matchesSafely(@NonNull TextView textView) {
//             for (Drawable drawable : textView.getCompoundDrawables()) {
//                 if (sameBitmap(textView.getContext(), drawable, resourceId)) {
//                     return true;
//                 }
//             }
//             return false;
//         }
//     };
// }
// 
// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/CustomViewActions.java
// @NonNull
// static ViewAction waitMsec(final long msec) {
//     return new ViewAction() {
//         @NonNull
//         @Override
//         public Matcher<View> getConstraints() {
//             return any(View.class);
//         }
// 
//         @NonNull
//         @Override
//         public String getDescription() {
//             return "Wait " + msec + " msec.";
//         }
// 
//         @Override
//         public void perform(@NonNull UiController uiController, View view) {
//             uiController.loopMainThreadForAtLeast(msec);
//         }
//     };
// }
// 
// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/TimeIntervalMatcher.java
// @NonNull
// public static TimeIntervalMatcher inTimeInterval(long min, long max) {
//     return new TimeIntervalMatcher(min, max);
// }


import android.content.Context;
import android.os.Build;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.ViewInteraction;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.pressImeActionButton;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasFocus;
import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.isFocusable;
import static androidx.test.espresso.matcher.ViewMatchers.isFocused;
import static androidx.test.espresso.matcher.ViewMatchers.isNotChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isNotEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.isNotFocused;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.onefishtwo.bbqtimer.CustomMatchers.withCompoundDrawable;
import static com.onefishtwo.bbqtimer.CustomViewActions.waitMsec;
import static com.onefishtwo.bbqtimer.TimeIntervalMatcher.inTimeInterval;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.assertEquals;
        playPauseButton.perform(waitMsec(1000));
        playPauseButton.perform(click()); // Pause
        checkPausedAt(time1);
    }

    /** Checks the enable-reminders checkbox and the minutes picker. */
    private void checkReminder(boolean expectEnabled) {
        enableRemindersToggle.check(matches(isCompletelyDisplayed()));
        minutesPicker.check(matches(isCompletelyDisplayed()));

        if (expectEnabled) {
            enableRemindersToggle.check(matches(isChecked()));
            minutesPicker.check(matches(isEnabled()));
            minutesPicker.check(matches(isFocusable()));
        } else {
            enableRemindersToggle.check(matches(isNotChecked()));
            minutesPicker.check(matches(isNotEnabled()));
            if (Build.VERSION.SDK_INT > 27) { // disabled but still has focus on API ≤ 27!
                minutesPicker.check(matches(isNotFocused()));
            }
        }
    }

    /** Checks that the UI is in the fully Stopped at 00:00 state. */
    private void checkStopped() {
        playPauseButton.check(matches(isCompletelyDisplayed()));
        resetButton.check(matches(isCompletelyDisplayed()));
        stopButton.check(matches(not(isDisplayed())));
        timeView.check(matches(withText("00:00.0")));

// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/CustomMatchers.java
// @SuppressWarnings("SpellCheckingInspection")
// @NonNull
// static Matcher<View> withCompoundDrawable(@DrawableRes final int resourceId) {
//     return new BoundedMatcher<View, TextView>(TextView.class) {
//         @Override
//         public void describeTo(@NonNull Description description) {
//             description.appendText("has compound drawable resource " + resourceId);
//         }
// 
//         @Override
//         public boolean matchesSafely(@NonNull TextView textView) {
//             for (Drawable drawable : textView.getCompoundDrawables()) {
//                 if (sameBitmap(textView.getContext(), drawable, resourceId)) {
//                     return true;
//                 }
//             }
//             return false;
//         }
//     };
// }
// 
// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/CustomViewActions.java
// @NonNull
// static ViewAction waitMsec(final long msec) {
//     return new ViewAction() {
//         @NonNull
//         @Override
//         public Matcher<View> getConstraints() {
//             return any(View.class);
//         }
// 
//         @NonNull
//         @Override
//         public String getDescription() {
//             return "Wait " + msec + " msec.";
//         }
// 
//         @Override
//         public void perform(@NonNull UiController uiController, View view) {
//             uiController.loopMainThreadForAtLeast(msec);
//         }
//     };
// }
// 
// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/TimeIntervalMatcher.java
// @NonNull
// public static TimeIntervalMatcher inTimeInterval(long min, long max) {
//     return new TimeIntervalMatcher(min, max);
// }


// Path: app/src/androidTest/java/com/onefishtwo/bbqtimer/InAppUITest.java
import android.content.Context;
import android.os.Build;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.ViewInteraction;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.pressImeActionButton;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasFocus;
import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.isFocusable;
import static androidx.test.espresso.matcher.ViewMatchers.isFocused;
import static androidx.test.espresso.matcher.ViewMatchers.isNotChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isNotEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.isNotFocused;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.onefishtwo.bbqtimer.CustomMatchers.withCompoundDrawable;
import static com.onefishtwo.bbqtimer.CustomViewActions.waitMsec;
import static com.onefishtwo.bbqtimer.TimeIntervalMatcher.inTimeInterval;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.assertEquals;

        playPauseButton.perform(waitMsec(1000));
        playPauseButton.perform(click()); // Pause
        checkPausedAt(time1);
    }

    /** Checks the enable-reminders checkbox and the minutes picker. */
    private void checkReminder(boolean expectEnabled) {
        enableRemindersToggle.check(matches(isCompletelyDisplayed()));
        minutesPicker.check(matches(isCompletelyDisplayed()));

        if (expectEnabled) {
            enableRemindersToggle.check(matches(isChecked()));
            minutesPicker.check(matches(isEnabled()));
            minutesPicker.check(matches(isFocusable()));
        } else {
            enableRemindersToggle.check(matches(isNotChecked()));
            minutesPicker.check(matches(isNotEnabled()));
            if (Build.VERSION.SDK_INT > 27) { // disabled but still has focus on API ≤ 27!
                minutesPicker.check(matches(isNotFocused()));
            }
        }
    }

    /** Checks that the UI is in the fully Stopped at 00:00 state. */
    private void checkStopped() {
        playPauseButton.check(matches(isCompletelyDisplayed()));
        resetButton.check(matches(isCompletelyDisplayed()));
        stopButton.check(matches(not(isDisplayed())));
        timeView.check(matches(withText("00:00.0")));

        playPauseButton.check(matches(withCompoundDrawable(R.drawable.ic_play)));