
com.jayway.android.robotium.solo.DialogUtils Maven / Gradle / Ivy
package com.jayway.android.robotium.solo;
/**
* This class contains the waitForDialogToClose() method.
*
* @author Renas Reda, [email protected]
*
*/
class DialogUtils {
private final ViewFetcher viewFetcher;
private final Sleeper sleeper;
/**
* Constructs this object.
*
* @param viewFetcher the {@code ViewFetcher} instance.
* @param sleeper the {@code Sleeper} instance.
*
*/
public DialogUtils(ViewFetcher viewFetcher, Sleeper sleeper) {
this.viewFetcher = viewFetcher;
this.sleeper = sleeper;
}
/**
* Waits for a {@link android.app.Dialog} to close.
*
* @param timeout the amount of time in milliseconds to wait
* @return {@code true} if the {@code Dialog} is closed before the timeout and {@code false} if it is not closed.
*/
public boolean waitForDialogToClose(long timeout) {
sleeper.sleepMini();
int elementsBefore = viewFetcher.getWindowDecorViews().length;
long now = System.currentTimeMillis();
final long endTime = now + timeout;
int elementsNow;
while (now < endTime) {
elementsNow = viewFetcher.getWindowDecorViews().length;
if(elementsBefore < elementsNow){
elementsBefore = elementsNow;
}
if(elementsBefore > elementsNow)
break;
sleeper.sleepMini();
now = System.currentTimeMillis();
}
if (now > endTime)
return false;
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy