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);
}
};
}
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);
}
}
};
}
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);
}
};
}
Aggregations