Last active
June 16, 2017 10:46
-
-
Save pablisco/d8a03f1b2ed0af038c3db28f4c99ee2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on global layout | |
@Rule | |
public final ActivityTestRule<AwesomeActivity> activityTestRule = new ActivityTestRule<CartActivity>(AwesomeActivity.class, true, false) { | |
@Override | |
protected void afterActivityLaunched() { | |
hideProgressBarAnimation(getActivity()); | |
} | |
}; | |
// When progressBar is added later | |
onView(isAssignableFrom(ProgressBar.class)).perform(removeProgressBarAnimation()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.posterxxl.test.util; | |
import android.app.Activity; | |
import android.graphics.drawable.Drawable; | |
import android.support.annotation.NonNull; | |
import android.support.test.espresso.UiController; | |
import android.support.test.espresso.ViewAction; | |
import android.support.test.espresso.core.deps.guava.collect.Iterables; | |
import android.support.test.espresso.util.TreeIterables; | |
import android.support.v4.content.ContextCompat; | |
import android.view.View; | |
import android.widget.ProgressBar; | |
import org.hamcrest.CoreMatchers; | |
import org.hamcrest.Matcher; | |
public class ViewActions { | |
private ViewActions() { | |
// hidden constructor | |
} | |
@NonNull | |
public static RemoveProgressBarAnimation removeProgressBarAnimation() { | |
return new RemoveProgressBarAnimation(); | |
} | |
public static void hideProgressBarAnimation(final Activity activity) { | |
View root = activity.findViewById(android.R.id.content); | |
for (ProgressBar progressBar : Iterables.filter(TreeIterables.breadthFirstViewTraversal(root), ProgressBar.class)) { | |
removeAnimation(progressBar); | |
} | |
} | |
private static class RemoveProgressBarAnimation implements ViewAction { | |
@Override | |
public Matcher<View> getConstraints() { | |
return CoreMatchers.instanceOf(ProgressBar.class); | |
} | |
@Override | |
public String getDescription() { | |
return null; | |
} | |
@Override | |
public void perform(UiController uiController, View view) { | |
if (view instanceof ProgressBar) { | |
removeAnimation((ProgressBar) view); | |
} | |
} | |
} | |
private static void removeAnimation(ProgressBar progressBar) { | |
Drawable nullDrawable = ContextCompat.getDrawable(progressBar.getContext(), android.R.color.black); | |
progressBar.setIndeterminateDrawable(nullDrawable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment