-
Notifications
You must be signed in to change notification settings - Fork 787
/
DialogUtils.java
executable file
·65 lines (49 loc) · 1.5 KB
/
DialogUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.jayway.android.robotium.solo;
/**
* This class contains dialog related methods. Examples are:
* getCurrentDialog(), getDialogList(), isDialogShown(), etc.
*
* @author Renas Reda, renas.reda@jayway.com
*
*/
class DialogUtils {
private final ViewFetcher viewFetcher;
private final Sleeper sleeper;
/**
* Constructs this object.
*
* @param viewFetcher the {@code ViewFetcher} instance.
* @param sleeper the {@code RobotiumUtils} 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 elements = viewFetcher.getWindowDecorViews().length;
long now = System.currentTimeMillis();
final long endTime = now + timeout;
while (now < endTime) {
if(elements < viewFetcher.getWindowDecorViews().length){
elements = viewFetcher.getWindowDecorViews().length;
}
if(elements > viewFetcher.getWindowDecorViews().length)
break;
if(!viewFetcher.getActiveDecorView().isEnabled())
break;
sleeper.sleepMini();
now = System.currentTimeMillis();
}
if (now > endTime)
return false;
return true;
}
}