本文整理汇总了Java中android.support.test.espresso.util.TreeIterables.breadthFirstViewTraversal方法的典型用法代码示例。如果您正苦于以下问题:Java TreeIterables.breadthFirstViewTraversal方法的具体用法?Java TreeIterables.breadthFirstViewTraversal怎么用?Java TreeIterables.breadthFirstViewTraversal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.test.espresso.util.TreeIterables
的用法示例。
在下文中一共展示了TreeIterables.breadthFirstViewTraversal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResume
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
@Override
protected void onResume(){
super.onResume();
View root = this.getWindow().getDecorView();
for(View v : TreeIterables.breadthFirstViewTraversal(root)){
if(v.getId() != -1) {
System.out.println("View: " + v.getResources().getResourceEntryName(v.getId()) + " " + v.isClickable());
} else if(v.getContentDescription() != null){
System.out.println("View: " + v.getContentDescription().toString() + " " + v.isClickable());
} else{
System.out.println("View: " + v.toString() + " No Des, No Id " + v.isClickable());
}
}
}
示例2: getAllViews
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
protected ArrayList<View> getAllViews() {
View root = getDecorView();
ArrayList<View> views = new ArrayList<>();
for (View v : TreeIterables.breadthFirstViewTraversal(root)) {
// Log.i("Chimp-needs-to-know","Active View: " + v.toString());
views.add(v);
}
/*
View focus = getActivityInstance().getCurrentFocus();
if (focus != null) {
for (View v : TreeIterables.breadthFirstViewTraversal(focus)) {
Log.i("Chimp-needs-to-know", "In focus View: " + v.toString());
}
} */
return views;
}
示例3: matchView
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
private View matchView(View view, Matcher<View> matcher) {
if (view == null) {
return null;
}
if (matcher.matches(view)) {
return view;
}
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
if (matcher.matches(child)) {
return child;
}
}
return null;
}
示例4: waitForMatch
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
public static ViewAction waitForMatch(final Matcher<View> aViewMatcher, final long timeout) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "Waiting for view matching " + aViewMatcher;
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + timeout;
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
if (aViewMatcher.matches(child)) {
// found
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
//The action has timed out.
throw new PerformException.Builder()
.withActionDescription(getDescription())
.withViewDescription("")
.withCause(new TimeoutException())
.build();
}
};
}
示例5: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例6: isConditionMet
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
@Override
protected boolean isConditionMet(View view) {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
if (matcher.matches(child)) {
return true;
}
}
return false;
}
示例7: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/**
* Perform action of waiting for a specific view id.
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例8: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/** Perform action of waiting for a specific view id. */
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例9: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/**
* Looks for a view with the given ID for a given millis
* @param viewId ID of the view you are looking for
* @param millis Millis trying to find it
* @return ViewAction so you can use like any other EspressoAction
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例10: waitInvisibleGoneId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
public static ViewAction waitInvisibleGoneId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait view id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
// Log.e("test", "waitInvisibleGoneId view id:" + viewId);
uiController.loopMainThreadForAtLeast(200);
do {
View find = null;
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// if (viewMatcher.matches(child) && child.getVisibility() == View.VISIBLE) {
// Log.e("test","original view id:"+viewId+" child view id:"+child.getId());
if (viewMatcher.matches(child)) {
find = child;
Log.e("test", "macthch visible: " + child.getVisibility());
}
}
if (find != null && find.getVisibility() == View.VISIBLE) {
// Log.e("test", "find startTime:" + startTime);
// Log.e("test","find endTime:"+endTime);
// Log.e("test","find System.currentTimeMillis():"+System.currentTimeMillis());
} else {
Log.e("test", "waitInvisibleGoneId wait time :" + (System.currentTimeMillis() - startTime) / 1000 + " id:" + viewId);
return;
}
// Log.e("test","startTime:"+startTime);
// Log.e("test","endTime:"+endTime);
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
Log.e("test", "waitInvisibleGoneId time out :" + (System.currentTimeMillis() - startTime) / 1000 + " id:" + viewId);
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例11: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait view id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
Log.e("test", "waitId original view id:" + viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// if (viewMatcher.matches(child) && child.getVisibility() == View.VISIBLE) {
// Log.e("test","original view id:"+viewId+" child view id:"+child.getId());
if (viewMatcher.matches(child) && child.getVisibility() == View.VISIBLE) {
// Log.e("test", "find startTime:" + startTime);
// Log.e("test","find endTime:"+endTime);
// Log.e("test","find System.currentTimeMillis():"+System.currentTimeMillis());
Log.e("test", "waitId wait time :" + (System.currentTimeMillis() - startTime) / 1000 + " id:" + viewId);
return;
}
}
// Log.e("test","startTime:"+startTime);
// Log.e("test","endTime:"+endTime);
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
Log.e("test", "waitId time out :" + (System.currentTimeMillis() - startTime) / 1000 + " id:" + viewId);
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例12: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/**
* Perform action of waiting for a specific view id.
* <p/>
* E.g.:
* onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
*
* @param viewId
* @param millis
* @return
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例13: screenshot
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/**
* Performs screenshot of activity with specified view
* use like onView(isRoot()).perform(screenshot(R.id.MainActivity));
* @param viewId view to look at
* @param testTag description of screenshoshot
* @return
*/
public static ViewAction screenshot(final int viewId, final String testTag) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "screenshoting current activity with root id <" + viewId + "> .";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final Matcher<View> viewMatcher = withId(viewId);
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
Activity host=(Activity) child.getContext();
try {
Screenshot.capture(testTag+"_"+host.getLocalClassName().toString(),host);
} catch (IOException e) {
//something bad happened.no screenshot.
Log.d(TAG,e.toString());
e.printStackTrace();
throw new RuntimeException(e);
}
return;
}
}
// nothing found
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new NoRootViewFoundWithIdException())
.build();
}
};
}
示例14: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/**
* Perform action of waiting for a specific view id
* based off https://stackoverflow.com/questions/21417954/espresso-thread-sleep
* @param viewId - view to look for
* @param millis - how long to wait for in milliseconds
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
示例15: waitId
import android.support.test.espresso.util.TreeIterables; //导入方法依赖的package包/类
/**
* Perform action of waiting for a specific view id.
* <p/>
* E.g.:
* onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
*
* @param viewId
* @param millis
* @return
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}