-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor setting of touch actions options
- Loading branch information
Mykola Mokhnach
committed
Oct 16, 2017
1 parent
6882bc8
commit 55039ab
Showing
14 changed files
with
820 additions
and
123 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/main/java/io/appium/java_client/android/AndroidTouchAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.android; | ||
|
||
import io.appium.java_client.PerformsTouchActions; | ||
import io.appium.java_client.TouchAction; | ||
|
||
|
||
public class AndroidTouchAction extends TouchAction<AndroidTouchAction> { | ||
|
||
public AndroidTouchAction(PerformsTouchActions performsTouchActions) { | ||
super(performsTouchActions); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/io/appium/java_client/ios/touch/DoubleTapOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.ios.touch; | ||
|
||
import io.appium.java_client.touch.OptionsWithAbsolutePositioning; | ||
|
||
/** | ||
* @deprecated this class will be removed | ||
*/ | ||
@Deprecated | ||
public class DoubleTapOptions extends OptionsWithAbsolutePositioning<DoubleTapOptions> { | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/io/appium/java_client/touch/ActionOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public abstract class ActionOptions<T extends ActionOptions<T>> { | ||
/** | ||
* This method is automatically called before building | ||
* options map to verify the consistency of the instance. | ||
* | ||
* @throws IllegalArgumentException if there are problems with this options map. | ||
*/ | ||
protected abstract void verify(); | ||
|
||
/** | ||
* Creates a map based on the provided options. | ||
* | ||
* @return options mapping. | ||
*/ | ||
public Map<String, Object> build() { | ||
verify(); | ||
return new HashMap<>(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/io/appium/java_client/touch/LongPressOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class LongPressOptions extends OptionsWithAbsolutePositioning<LongPressOptions> { | ||
protected Duration duration = null; | ||
|
||
/** | ||
* Set the long press duration. | ||
* | ||
* @param duration the duration value to set. | ||
* Time resolution unit is 1 ms. | ||
* @return this instance for chaining. | ||
*/ | ||
public LongPressOptions withDuration(Duration duration) { | ||
checkNotNull(duration); | ||
checkArgument(duration.toMillis() >= 0, | ||
"Duration value should be greater or equal to zero"); | ||
this.duration = duration; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> build() { | ||
final Map<String, Object> result = super.build(); | ||
if (duration != null) { | ||
result.put("duration", this.duration.toMillis()); | ||
} | ||
return result; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/io/appium/java_client/touch/MoveToOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
public class MoveToOptions extends OptionsWithRelativePositioning<MoveToOptions> { | ||
} |
107 changes: 107 additions & 0 deletions
107
src/main/java/io/appium/java_client/touch/OptionsWithAbsolutePositioning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
import org.openqa.selenium.Point; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.internal.HasIdentity; | ||
|
||
import java.util.Map; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public abstract class OptionsWithAbsolutePositioning<T extends OptionsWithAbsolutePositioning<T>> | ||
extends ActionOptions<T> { | ||
private String elementId = null; | ||
private Point absoluteOffset = null; | ||
private Point relativeOffset = null; | ||
|
||
/** | ||
* Set the destination element for the corresponding action. | ||
* | ||
* @param element the destination element. | ||
* @return this instance for chaining. | ||
*/ | ||
public T withElement(WebElement element) { | ||
checkNotNull(element); | ||
this.elementId = ((HasIdentity) element).getId(); | ||
//noinspection unchecked | ||
return (T) this; | ||
} | ||
|
||
/** | ||
* Set the absolute offset for the corresponding action. | ||
* | ||
* @param xOffset the absolute distance from the left screen corner (the element must not be set). | ||
* @param yOffset the absolute distance from the top screen corner. | ||
* @return this instance for chaining. | ||
*/ | ||
public T withAbsoluteOffset(int xOffset, int yOffset) { | ||
this.absoluteOffset = new Point(xOffset, yOffset); | ||
//noinspection unchecked | ||
return (T) this; | ||
} | ||
|
||
/** | ||
* Set the relative offset for the corresponding action. | ||
* | ||
* @param xOffset the relative distance from the left element corner (the element must be set). | ||
* @param yOffset the relative distance from the top element corner (the element must be set). | ||
* @return this instance for chaining. | ||
*/ | ||
public T withRelativeOffset(int xOffset, int yOffset) { | ||
this.relativeOffset = new Point(xOffset, yOffset); | ||
//noinspection unchecked | ||
return (T) this; | ||
} | ||
|
||
@Override | ||
protected void verify() { | ||
if (elementId == null) { | ||
if (absoluteOffset != null) { | ||
throw new IllegalArgumentException("Absolute offset must not be defined if 'element' option is set"); | ||
} | ||
if (relativeOffset == null) { | ||
throw new IllegalArgumentException("Relative offset must be defined if 'element' option is set"); | ||
} | ||
} else { | ||
if (absoluteOffset == null) { | ||
throw new IllegalArgumentException("Absolute offset must be defined if 'element' option not set"); | ||
} | ||
if (relativeOffset != null) { | ||
throw new IllegalArgumentException("Relative offset must not be defined if 'element' option not set"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Object> build() { | ||
final Map<String, Object> result = super.build(); | ||
if (absoluteOffset != null) { | ||
result.put("x", absoluteOffset.x); | ||
result.put("y", absoluteOffset.y); | ||
} | ||
if (relativeOffset != null) { | ||
result.put("x", relativeOffset.x); | ||
result.put("y", relativeOffset.y); | ||
} | ||
if (elementId != null) { | ||
result.put("element", elementId); | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.