Search in sources :

Example 6 with UiController

use of androidx.test.espresso.UiController in project orgzly-android by orgzly.

the class EspressoUtils method closeSoftKeyboardWithDelay.

/**
 * Give keyboard time to close, to avoid java.lang.SecurityException
 * if hidden button is clicked next.
 */
static ViewAction closeSoftKeyboardWithDelay() {
    return new ViewAction() {

        /**
         * The delay time to allow the soft keyboard to dismiss.
         */
        private static final long KEYBOARD_DISMISSAL_DELAY_MILLIS = 1000L;

        /**
         * The real {@link CloseKeyboardAction} instance.
         */
        private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction();

        @Override
        public Matcher<View> getConstraints() {
            return mCloseSoftKeyboard.getConstraints();
        }

        @Override
        public String getDescription() {
            return mCloseSoftKeyboard.getDescription();
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            mCloseSoftKeyboard.perform(uiController, view);
            uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS);
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) CloseKeyboardAction(androidx.test.espresso.action.CloseKeyboardAction) UiController(androidx.test.espresso.UiController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Espresso.onView(androidx.test.espresso.Espresso.onView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 7 with UiController

use of androidx.test.espresso.UiController in project orgzly-android by orgzly.

the class EspressoUtils method clickClickableSpan.

public static ViewAction clickClickableSpan(final CharSequence textToClick) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return Matchers.instanceOf(TextView.class);
        }

        @Override
        public String getDescription() {
            return "Click text";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView textView = (TextView) view;
            Spanned spannable = (Spanned) textView.getText();
            ClickableSpan clickable = null;
            for (ClickableSpan span : SpanUtils.getSpans(spannable, ClickableSpan.class)) {
                int start = spannable.getSpanStart(span);
                int end = spannable.getSpanEnd(span);
                CharSequence sequence = spannable.subSequence(start, end);
                if (sequence.toString().contains(textToClick)) {
                    clickable = span;
                    break;
                }
            }
            if (clickable != null) {
                clickable.onClick(textView);
            } else {
                throw new IllegalStateException("No clickable span found in " + spannable);
            }
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Espresso.onView(androidx.test.espresso.Espresso.onView) TextView(android.widget.TextView) ListView(android.widget.ListView) Spanned(android.text.Spanned) ClickableSpan(android.text.style.ClickableSpan) ViewMatchers.withHint(androidx.test.espresso.matcher.ViewMatchers.withHint)

Example 8 with UiController

use of androidx.test.espresso.UiController in project collect by opendatakit.

the class FieldListUpdateTest method setRating.

public static ViewAction setRating(final float rating) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(RatingBar.class);
        }

        @Override
        public String getDescription() {
            return "Custom view action to set rating on RatingBar";
        }

        @Override
        public void perform(UiController uiController, View view) {
            RatingBar ratingBar = (RatingBar) view;
            ratingBar.setRating(rating);
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) RatingBar(android.widget.RatingBar)

Aggregations

View (android.view.View)8 UiController (androidx.test.espresso.UiController)8 ViewAction (androidx.test.espresso.ViewAction)8 Espresso.onView (androidx.test.espresso.Espresso.onView)6 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 TimeoutException (java.util.concurrent.TimeoutException)2 Activity (android.app.Activity)1 Spanned (android.text.Spanned)1 ClickableSpan (android.text.style.ClickableSpan)1 NumberPicker (android.widget.NumberPicker)1 RatingBar (android.widget.RatingBar)1 CloseKeyboardAction (androidx.test.espresso.action.CloseKeyboardAction)1 ViewMatchers.withHint (androidx.test.espresso.matcher.ViewMatchers.withHint)1 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)1 Matcher (org.hamcrest.Matcher)1