-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwipeShellCommand.java
More file actions
229 lines (209 loc) · 4.05 KB
/
SwipeShellCommand.java
File metadata and controls
229 lines (209 loc) · 4.05 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import java.lang.Thread;
import java.util.concurrent.TimeUnit;
import se.vidstige.jadb.JadbDevice;
/**
* Data Structure for ADB Shell swipe command. <br>
*
*/
public class SwipeShellCommand
{
/**
* Returns a formatted shell swipe command.
*
* @param x1
* @param y1
* @param x2
* @param y2
* @param time Time in Milliseconds.
* @return Shell swipe command.
*/
public static String toString (int x1, int y1, int x2, int y2, long time)
{
return String.format("input touchscreen swipe %d %d %d %d %d", x1, y1, x2, y2, time);
}
private int x1, x2, y1, y2;
private long time;
/**
* Default constructor. Initializes everything to 0;
*/
public SwipeShellCommand ()
{
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
time = 0l;
}
/**
* Parameterized Constructor.
*
* @param x1
* @param x2
* @param y1
* @param y2
* @param time
*/
public SwipeShellCommand (int x1, int y1, int x2, int y2, long time)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.time = time;
}
/**
* Gets x1.
*
* @return
*/
public int getX1 ()
{
return this.x1;
}
/**
* Sets x1.
*
* @param x1
*/
public void setX1 (int x1)
{
this.x1 = x1;
}
/**
* Gets x2.
*
* @return
*/
public int getX2 ()
{
return this.x2;
}
/**
* Sets x2.
*
* @param x2
*/
public void setX2 (int x2)
{
this.x2 = x2;
}
/**
* Gets y1.
*
* @return
*/
public int getY1 ()
{
return this.y1;
}
/**
* Sets y1.
*
* @param y1
*/
public void setY1 (int y1)
{
this.y1 = y1;
}
/**
* Gets y2.
*
* @return
*/
public int getY2 ()
{
return this.y2;
}
/**
* Sets y2.
*
* @param y2
*/
public void setY2 (int y2)
{
this.y2 = y2;
}
/**
* Gets time.
*
* @return
*/
public long getTime()
{
return this.time;
}
/**
* Sets time.
* @param time
*/
public void setTime(long time)
{
this.time = time;
}
/**
* Creates an unsafe thread to run a Shell Swipe command on a given device.
*
* @param device
* @param threadName
* @return Unsafe Thread
*/
public Thread GetShellCommand (JadbDevice device, String threadName)
{
Thread ret = new Thread(threadName)
{
@Override
public void run ()
{
try
{
device.executeShell(toString());
TimeUnit.MILLISECONDS.sleep(time);
}
catch (Exception e)
{
//do nothing
}
}
};
return ret;
}
/**
* Runs a shell command and waits until touch command finishes before returning.
* Will return true if the method successfully ran. Will return false if an error was thrown.
*
* @param device
* @return
*/
public boolean RunShellCommand (JadbDevice device)
{
boolean ret = true;
try
{
device.execute(toString());
TimeUnit.MILLISECONDS.sleep(time);
}
catch (Exception e)
{
ret = false;
}
return ret;
}
/**
* Returns a data string that is used for building scripts for ADB_Clicker.
*
* @return
*/
public String extractData ()
{
return String.format("%d|%d|%d|%d|%d");
}
/**
* toString() returns a formatted Shell Swipe command for use with any device.
*
* @return
*/
public String toString ()
{
return String.format("input touchscreen swipe %d %d %d %d %d", x1, y1, x2, y2, time);
}
}