|
1 |
| -package io.appium.java_client; |
2 |
| - |
3 |
| -import org.openqa.selenium.Dimension; |
4 |
| -import org.openqa.selenium.Point; |
5 |
| - |
6 |
| -public enum SwipeElementDirection { |
7 |
| - /** |
8 |
| - * Up from the center of the lower |
9 |
| - */ |
10 |
| - UP{ |
11 |
| - @Override |
12 |
| - void swipe(AppiumDriver driver, MobileElement element, int duration){ |
13 |
| - Point p = element.getCenter(); |
14 |
| - Point location = element.getLocation(); |
15 |
| - Dimension size = element.getSize(); |
16 |
| - driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration); |
17 |
| - } |
18 |
| - }, |
19 |
| - /** |
20 |
| - * Down from the center of the upper |
21 |
| - */ |
22 |
| - DOWN{ |
23 |
| - @Override |
24 |
| - void swipe(AppiumDriver driver, MobileElement element, int duration){ |
25 |
| - Point p = element.getCenter(); |
26 |
| - Point location = element.getLocation(); |
27 |
| - Dimension size = element.getSize(); |
28 |
| - driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration); |
29 |
| - } |
30 |
| - }, |
31 |
| - /** |
32 |
| - * To the left from the center of the rightmost |
33 |
| - */ |
34 |
| - LEFT{ |
35 |
| - @Override |
36 |
| - void swipe(AppiumDriver driver, MobileElement element, int duration){ |
37 |
| - Point p = element.getCenter(); |
38 |
| - Point location = element.getLocation(); |
39 |
| - Dimension size = element.getSize(); |
40 |
| - driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration); |
41 |
| - } |
42 |
| - }, |
43 |
| - /** |
44 |
| - * To the right from the center of the leftmost |
45 |
| - */ |
46 |
| - RIGHT{ |
47 |
| - @Override |
48 |
| - void swipe(AppiumDriver driver, MobileElement element, int duration){ |
49 |
| - Point p = element.getCenter(); |
50 |
| - Point location = element.getLocation(); |
51 |
| - Dimension size = element.getSize(); |
52 |
| - driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration); |
53 |
| - } |
54 |
| - }; |
55 |
| - |
56 |
| - void swipe(AppiumDriver driver, MobileElement element, int duration){} |
57 |
| -} |
| 1 | +package io.appium.java_client; |
| 2 | + |
| 3 | +import org.openqa.selenium.Dimension; |
| 4 | +import org.openqa.selenium.Point; |
| 5 | + |
| 6 | +public enum SwipeElementDirection { |
| 7 | + /** |
| 8 | + * Up from the center of the lower |
| 9 | + */ |
| 10 | + UP{ |
| 11 | + @Override |
| 12 | + void swipe(AppiumDriver driver, MobileElement element, |
| 13 | + int xOffsetStart, int xOffsetEnd, int yOffsetStart, |
| 14 | + int yOffsetEnd, int duration) throws IllegalCoordinatesException { |
| 15 | + Point p = element.getCenter(); |
| 16 | + Point location = element.getLocation(); |
| 17 | + Dimension size = element.getSize(); |
| 18 | + driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration); |
| 19 | + } |
| 20 | + }, |
| 21 | + /** |
| 22 | + * Down from the center of the upper |
| 23 | + */ |
| 24 | + DOWN{ |
| 25 | + @Override |
| 26 | + void swipe(AppiumDriver driver, MobileElement element, |
| 27 | + int xOffsetStart, int xOffsetEnd, int yOffsetStart, |
| 28 | + int yOffsetEnd, int duration) throws IllegalCoordinatesException { |
| 29 | + Point p = element.getCenter(); |
| 30 | + Point location = element.getLocation(); |
| 31 | + Dimension size = element.getSize(); |
| 32 | + driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration); |
| 33 | + } |
| 34 | + }, |
| 35 | + /** |
| 36 | + * To the left from the center of the rightmost |
| 37 | + */ |
| 38 | + LEFT{ |
| 39 | + @Override |
| 40 | + void swipe(AppiumDriver driver, MobileElement element, |
| 41 | + int xOffsetStart, int xOffsetEnd, int yOffsetStart, |
| 42 | + int yOffsetEnd, int duration) throws IllegalCoordinatesException { |
| 43 | + Point p = element.getCenter(); |
| 44 | + Point location = element.getLocation(); |
| 45 | + Dimension size = element.getSize(); |
| 46 | + driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration); |
| 47 | + } |
| 48 | + }, |
| 49 | + /** |
| 50 | + * To the right from the center of the leftmost |
| 51 | + */ |
| 52 | + RIGHT{ |
| 53 | + @Override |
| 54 | + void swipe(AppiumDriver driver, MobileElement element, |
| 55 | + int xOffsetStart, int xOffsetEnd, int yOffsetStart, |
| 56 | + int yOffsetEnd, int duration) throws IllegalCoordinatesException { |
| 57 | + Point p = element.getCenter(); |
| 58 | + Point location = element.getLocation(); |
| 59 | + Dimension size = element.getSize(); |
| 60 | + driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration); |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + abstract void swipe(AppiumDriver driver, MobileElement element, |
| 65 | + int xOffsetStart, int xOffsetEnd, int yOffsetStart, |
| 66 | + int yOffsetEnd, int duration) throws IllegalCoordinatesException; |
| 67 | +} |
0 commit comments