1717package io .appium .java_client ;
1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
20- import static io .appium .java_client .touch .AbsoluteOffsetOption .useAbsolute ;
2120import static io .appium .java_client .touch .LongPressOptions .longPressOptions ;
22- import static io .appium .java_client .touch .RelativeOffsetOption .useRelative ;
21+ import static io .appium .java_client .touch .PositionOffsetOption .positionOffsetOption ;
22+ import static io .appium .java_client .touch .WebElementOption .elementOption ;
2323
2424import com .google .common .collect .ImmutableList ;
2525import com .google .common .collect .ImmutableMap ;
2626
27- import io .appium .java_client .touch .AbsoluteOffsetOption ;
2827import io .appium .java_client .touch .ActionOptions ;
2928import io .appium .java_client .touch .LongPressOptions ;
30- import io .appium .java_client .touch .RelativeOffsetOption ;
29+ import io .appium .java_client .touch .PositionOffsetOption ;
3130import io .appium .java_client .touch .TapOptions ;
3231import io .appium .java_client .touch .WaitOptions ;
32+ import io .appium .java_client .touch .WebElementOption ;
3333import org .openqa .selenium .WebElement ;
3434
3535import java .time .Duration ;
@@ -55,24 +55,12 @@ public TouchAction(PerformsTouchActions performsTouchActions) {
5555 }
5656
5757 /**
58- * Press on an element .
58+ * Press action on the screen .
5959 *
60- * @param pressOptions see {@link RelativeOffsetOption }.
60+ * @param pressOptions see {@link WebElementOption} and {@link PositionOffsetOption }.
6161 * @return this TouchAction, for chaining.
6262 */
63- public T press (RelativeOffsetOption pressOptions ) {
64- parameterBuilder .add (new ActionParameter ("press" , pressOptions ));
65- //noinspection unchecked
66- return (T ) this ;
67- }
68-
69- /**
70- * Press on an element.
71- *
72- * @param pressOptions see {@link AbsoluteOffsetOption}.
73- * @return this TouchAction, for chaining.
74- */
75- public T press (AbsoluteOffsetOption pressOptions ) {
63+ public <S extends PositionOffsetOption > T press (S pressOptions ) {
7664 parameterBuilder .add (new ActionParameter ("press" , pressOptions ));
7765 //noinspection unchecked
7866 return (T ) this ;
@@ -83,11 +71,11 @@ public T press(AbsoluteOffsetOption pressOptions) {
8371 *
8472 * @param el element to press on.
8573 * @return this TouchAction, for chaining.
86- * @deprecated use {@link #press(RelativeOffsetOption )} instead
74+ * @deprecated use {@link #press(PositionOffsetOption )} instead
8775 */
8876 @ Deprecated
8977 public T press (WebElement el ) {
90- return press (useRelative (el ));
78+ return press (elementOption (el ));
9179 }
9280
9381 /**
@@ -96,11 +84,11 @@ public T press(WebElement el) {
9684 * @param x x coordinate.
9785 * @param y y coordinate.
9886 * @return this TouchAction, for chaining.
99- * @deprecated use {@link #press(AbsoluteOffsetOption )} instead
87+ * @deprecated use {@link #press(PositionOffsetOption )} instead
10088 */
10189 @ Deprecated
10290 public T press (int x , int y ) {
103- return press (useAbsolute (x , y ));
91+ return ( T ) press (positionOffsetOption (x , y ));
10492 }
10593
10694 /**
@@ -110,11 +98,11 @@ public T press(int x, int y) {
11098 * @param x x offset.
11199 * @param y y offset.
112100 * @return this TouchAction, for chaining.
113- * @deprecated use {@link #press(RelativeOffsetOption )} instead
101+ * @deprecated use {@link #press(PositionOffsetOption )} instead
114102 */
115103 @ Deprecated
116104 public T press (WebElement el , int x , int y ) {
117- return press (useRelative (el , x , y ));
105+ return press (elementOption (el , x , y ));
118106 }
119107
120108 /**
@@ -130,25 +118,12 @@ public T release() {
130118 }
131119
132120 /**
133- * Move current touch to center of an element.
134- *
135- * @param moveToOptions see {@link AbsoluteOffsetOption}.
136- * @return this TouchAction, for chaining.
137- */
138- public T moveTo (AbsoluteOffsetOption moveToOptions ) {
139- ActionParameter action = new ActionParameter ("moveTo" , moveToOptions );
140- parameterBuilder .add (action );
141- //noinspection unchecked
142- return (T ) this ;
143- }
144-
145- /**
146- * Move current touch to center of an element.
121+ * Moves current touch to a new position.
147122 *
148- * @param moveToOptions see {@link RelativeOffsetOption }.
123+ * @param moveToOptions see {@link WebElementOption} and {@link PositionOffsetOption }.
149124 * @return this TouchAction, for chaining.
150125 */
151- public T moveTo (RelativeOffsetOption moveToOptions ) {
126+ public < S extends PositionOffsetOption > T moveTo (S moveToOptions ) {
152127 ActionParameter action = new ActionParameter ("moveTo" , moveToOptions );
153128 parameterBuilder .add (action );
154129 //noinspection unchecked
@@ -160,11 +135,11 @@ public T moveTo(RelativeOffsetOption moveToOptions) {
160135 *
161136 * @param el element to move to.
162137 * @return this TouchAction, for chaining.
163- * @deprecated {@link #moveTo(RelativeOffsetOption )} instead
138+ * @deprecated {@link #moveTo(PositionOffsetOption )} instead
164139 */
165140 @ Deprecated
166141 public T moveTo (WebElement el ) {
167- return moveTo (useRelative (el ));
142+ return moveTo (elementOption (el ));
168143 }
169144
170145 /**
@@ -175,11 +150,11 @@ public T moveTo(WebElement el) {
175150 * @param x change in x coordinate to move through.
176151 * @param y change in y coordinate to move through.
177152 * @return this TouchAction, for chaining.
178- * @deprecated {@link #moveTo(AbsoluteOffsetOption )} instead
153+ * @deprecated {@link #moveTo(PositionOffsetOption )} instead
179154 */
180155 @ Deprecated
181156 public T moveTo (int x , int y ) {
182- return moveTo (useAbsolute (x , y ));
157+ return ( T ) moveTo (positionOffsetOption (x , y ));
183158 }
184159
185160 /**
@@ -189,11 +164,11 @@ public T moveTo(int x, int y) {
189164 * @param x x offset.
190165 * @param y y offset.
191166 * @return this TouchAction, for chaining.
192- * @deprecated {@link #moveTo(RelativeOffsetOption )} instead
167+ * @deprecated {@link #moveTo(PositionOffsetOption )} instead
193168 */
194169 @ Deprecated
195170 public T moveTo (WebElement el , int x , int y ) {
196- return moveTo (useRelative (el , x , y ));
171+ return moveTo (elementOption (el , x , y ));
197172 }
198173
199174 /**
@@ -209,24 +184,12 @@ public TouchAction tap(TapOptions tapOptions) {
209184 }
210185
211186 /**
212- * Tap on an element.
213- *
214- * @param tapOptions see {@link RelativeOffsetOption}.
215- * @return this TouchAction, for chaining.
216- */
217- public T tap (RelativeOffsetOption tapOptions ) {
218- ActionParameter action = new ActionParameter ("tap" , tapOptions );
219- parameterBuilder .add (action );
220- return (T ) this ;
221- }
222-
223- /**
224- * Tap on an element.
187+ * Tap on a position.
225188 *
226- * @param tapOptions see {@link AbsoluteOffsetOption }.
189+ * @param tapOptions see {@link WebElementOption} and {@link PositionOffsetOption }.
227190 * @return this TouchAction, for chaining.
228191 */
229- public T tap (AbsoluteOffsetOption tapOptions ) {
192+ public < S extends PositionOffsetOption > T tap (S tapOptions ) {
230193 ActionParameter action = new ActionParameter ("tap" , tapOptions );
231194 parameterBuilder .add (action );
232195 return (T ) this ;
@@ -237,11 +200,11 @@ public T tap(AbsoluteOffsetOption tapOptions) {
237200 *
238201 * @param el element to tap.
239202 * @return this TouchAction, for chaining.
240- * @deprecated use {@link #tap(RelativeOffsetOption )} instead.
203+ * @deprecated use {@link #tap(PositionOffsetOption )} instead.
241204 */
242205 @ Deprecated
243206 public T tap (WebElement el ) {
244- return tap (useRelative (el ));
207+ return tap (elementOption (el ));
245208 }
246209
247210 /**
@@ -250,11 +213,11 @@ public T tap(WebElement el) {
250213 * @param x x coordinate.
251214 * @param y y coordinate.
252215 * @return this TouchAction, for chaining.
253- * @deprecated use {@link #tap(AbsoluteOffsetOption )} instead.
216+ * @deprecated use {@link #tap(PositionOffsetOption )} instead.
254217 */
255218 @ Deprecated
256219 public T tap (int x , int y ) {
257- return tap (useAbsolute (x , y ));
220+ return ( T ) tap (positionOffsetOption (x , y ));
258221 }
259222
260223 /**
@@ -264,11 +227,11 @@ public T tap(int x, int y) {
264227 * @param x x offset.
265228 * @param y y offset.
266229 * @return this TouchAction, for chaining.
267- * @deprecated use {@link #tap(RelativeOffsetOption )} instead.
230+ * @deprecated use {@link #tap(PositionOffsetOption )} instead.
268231 */
269232 @ Deprecated
270233 public T tap (WebElement el , int x , int y ) {
271- return tap (useRelative (el , x , y ));
234+ return tap (elementOption (el , x , y ));
272235 }
273236
274237 /**
@@ -329,23 +292,10 @@ public T longPress(LongPressOptions longPressOptions) {
329292 /**
330293 * Press and hold the at the center of an element until the context menu event has fired.
331294 *
332- * @param longPressOptions see {@link RelativeOffsetOption}.
333- * @return this TouchAction, for chaining.
334- */
335- public T longPress (RelativeOffsetOption longPressOptions ) {
336- ActionParameter action = new ActionParameter ("longPress" , longPressOptions );
337- parameterBuilder .add (action );
338- //noinspection unchecked
339- return (T ) this ;
340- }
341-
342- /**
343- * Press and hold the at the center of an element until the context menu event has fired.
344- *
345- * @param longPressOptions see {@link AbsoluteOffsetOption}.
295+ * @param longPressOptions see {@link WebElementOption} and {@link PositionOffsetOption}.
346296 * @return this TouchAction, for chaining.
347297 */
348- public T longPress (AbsoluteOffsetOption longPressOptions ) {
298+ public < S extends PositionOffsetOption > T longPress (S longPressOptions ) {
349299 ActionParameter action = new ActionParameter ("longPress" , longPressOptions );
350300 parameterBuilder .add (action );
351301 //noinspection unchecked
@@ -357,11 +307,11 @@ public T longPress(AbsoluteOffsetOption longPressOptions) {
357307 *
358308 * @param el element to long-press.
359309 * @return this TouchAction, for chaining.
360- * @deprecated use {@link #longPress(RelativeOffsetOption )} instead
310+ * @deprecated use {@link #longPress(PositionOffsetOption )} instead
361311 */
362312 @ Deprecated
363313 public T longPress (WebElement el ) {
364- return longPress (useRelative (el ));
314+ return longPress (elementOption (el ));
365315 }
366316
367317 /**
@@ -375,7 +325,7 @@ public T longPress(WebElement el) {
375325 @ Deprecated
376326 public T longPress (WebElement el , Duration duration ) {
377327 return longPress (longPressOptions ()
378- .withDuration (duration ).withOffset (useRelative (el )));
328+ .withDuration (duration ).withOffset (elementOption (el )));
379329 }
380330
381331 /**
@@ -385,11 +335,11 @@ public T longPress(WebElement el, Duration duration) {
385335 * @param x x coordinate.
386336 * @param y y coordinate.
387337 * @return this TouchAction, for chaining.
388- * @deprecated use {@link #longPress(AbsoluteOffsetOption )} instead
338+ * @deprecated use {@link #longPress(PositionOffsetOption )} instead
389339 */
390340 @ Deprecated
391341 public T longPress (int x , int y ) {
392- return longPress (useAbsolute (x , y ));
342+ return ( T ) longPress (positionOffsetOption (x , y ));
393343 }
394344
395345 /**
@@ -404,8 +354,8 @@ public T longPress(int x, int y) {
404354 */
405355 @ Deprecated
406356 public T longPress (int x , int y , Duration duration ) {
407- return longPress (longPressOptions ()
408- .withDuration (duration ).withOffset (useAbsolute (x , y )));
357+ return ( T ) longPress (longPressOptions ()
358+ .withDuration (duration ).withOffset (positionOffsetOption (x , y )));
409359 }
410360
411361 /**
@@ -416,11 +366,11 @@ public T longPress(int x, int y, Duration duration) {
416366 * @param x x offset.
417367 * @param y y offset.
418368 * @return this TouchAction, for chaining.
419- * @deprecated use {@link #longPress(RelativeOffsetOption )} instead
369+ * @deprecated use {@link #longPress(PositionOffsetOption )} instead
420370 */
421371 @ Deprecated
422372 public T longPress (WebElement el , int x , int y ) {
423- return longPress (useRelative (el , x , y ));
373+ return longPress (elementOption (el , x , y ));
424374 }
425375
426376 /**
@@ -437,7 +387,7 @@ public T longPress(WebElement el, int x, int y) {
437387 @ Deprecated
438388 public TouchAction longPress (WebElement el , int x , int y , Duration duration ) {
439389 return longPress (longPressOptions ()
440- .withOffset (useRelative (el , x , y )).withDuration (duration ));
390+ .withOffset (elementOption (el , x , y )).withDuration (duration ));
441391 }
442392
443393 /**
0 commit comments