Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove unused helpers #617

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,134 +16,24 @@
package io.appium.uiautomator2.core;

import android.view.InputEvent;
import android.view.MotionEvent.PointerCoords;

import io.appium.uiautomator2.common.exceptions.UiAutomator2Exception;
import io.appium.uiautomator2.model.settings.Settings;
import io.appium.uiautomator2.model.settings.TrackScrollEvents;
import io.appium.uiautomator2.utils.Logger;

import static io.appium.uiautomator2.utils.ReflectionUtils.getMethod;
import static io.appium.uiautomator2.utils.ReflectionUtils.invoke;

public class InteractionController {

public static final String METHOD_PERFORM_MULTI_POINTER_GESTURE = "performMultiPointerGesture";
private static final String CLASS_INTERACTION_CONTROLLER = "androidx.test.uiautomator.InteractionController";
private static final String METHOD_SEND_KEY = "sendKey";
private static final String METHOD_INJECT_EVENT_SYNC = "injectEventSync";
private static final String METHOD_TOUCH_DOWN = "touchDown";
private static final String METHOD_TOUCH_UP = "touchUp";
private static final String METHOD_TOUCH_MOVE = "touchMove";
private static final String METHOD_CLICK_NO_SYNC = "clickNoSync";
private final Object interactionController;

public InteractionController(Object interactionController) {
this.interactionController = interactionController;
}

public boolean sendKey(int keyCode, int metaState) throws UiAutomator2Exception {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER, METHOD_SEND_KEY, int.class, int.class),
interactionController, keyCode, metaState);
}

public boolean injectEventSync(final InputEvent event, boolean shouldRegister) throws UiAutomator2Exception {
if (!shouldRegister) {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER,
METHOD_INJECT_EVENT_SYNC, InputEvent.class), interactionController, event);
}
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() {
@Override
public void run() {
Boolean result = (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER,
METHOD_INJECT_EVENT_SYNC, InputEvent.class), interactionController, event);
setResult(result);
}
});
}

public boolean injectEventSync(final InputEvent event) throws UiAutomator2Exception {
return injectEventSync(event, true);
}

public boolean shouldTrackScrollEvents() {
final TrackScrollEvents trackScrollEventsSetting = Settings.get(TrackScrollEvents.class);
Boolean trackScrollEvents = trackScrollEventsSetting.getValue();
Logger.error(String.format("Setting '%s' is set to %b",
trackScrollEventsSetting.getName(), trackScrollEvents));

return trackScrollEvents;
}

private boolean doTouchDown(final int x, final int y) {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER,
METHOD_TOUCH_DOWN, int.class, int.class), interactionController, x, y);
}

public boolean touchDown(final int x, final int y) throws UiAutomator2Exception {
return shouldTrackScrollEvents()
? EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() {
@Override
public void run() {
setResult(doTouchDown(x, y));
}
})
: doTouchDown(x, y);
}

private boolean doTouchUp(final int x, final int y) {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER, METHOD_TOUCH_UP,
int.class, int.class), interactionController, x, y);
}

public boolean touchUp(final int x, final int y) throws UiAutomator2Exception {
return shouldTrackScrollEvents()
? EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() {
@Override
public void run() {
setResult(doTouchUp(x, y));
}
})
: doTouchUp(x, y);
}

private boolean doTouchMove(final int x, final int y) {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER,
METHOD_TOUCH_MOVE, int.class, int.class), interactionController, x, y);
}

public boolean touchMove(final int x, final int y) throws UiAutomator2Exception {
return shouldTrackScrollEvents()
? EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() {
@Override
public void run() {
setResult(doTouchMove(x, y));
}
})
: doTouchMove(x, y);
}

private boolean doPerformMultiPointerGesture(final PointerCoords[][] pcs) {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER,
METHOD_PERFORM_MULTI_POINTER_GESTURE, PointerCoords[][].class),
interactionController, (Object) pcs);
}

public boolean clickNoSync(int x, int y) {
return (Boolean) invoke(getMethod(CLASS_INTERACTION_CONTROLLER,
METHOD_CLICK_NO_SYNC, int.class, int.class), interactionController, x, y);
}

public Boolean performMultiPointerGesture(final PointerCoords[][] pcs) throws UiAutomator2Exception {
if (shouldTrackScrollEvents()) {
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() {
@Override
public void run() {
setResult(doPerformMultiPointerGesture(pcs));
}
});
} else {
return doPerformMultiPointerGesture(pcs);
}
METHOD_INJECT_EVENT_SYNC, InputEvent.class), interactionController, event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.app.Service;
import android.app.UiAutomation;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.view.Display;
import android.view.accessibility.AccessibilityNodeInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.appium.uiautomator2.core.AxNodeInfoHelper;
import io.appium.uiautomator2.model.internal.CustomUiDevice;
import io.appium.uiautomator2.utils.Attribute;
import io.appium.uiautomator2.utils.ContentSizeHelpers;
import io.appium.uiautomator2.utils.ElementHelpers;
import io.appium.uiautomator2.utils.Logger;
import io.appium.uiautomator2.utils.PositionHelper;
Expand Down Expand Up @@ -93,7 +94,7 @@ public String getAttribute(String attr) throws UiObjectNotFoundException {
result = element.getResourceName();
break;
case CONTENT_SIZE:
result = ElementHelpers.getContentSize(this);
result = ContentSizeHelpers.getContentSize(this);
break;
case ENABLED:
result = element.isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.appium.uiautomator2.model.internal.CustomUiDevice;
import io.appium.uiautomator2.utils.Attribute;
import io.appium.uiautomator2.utils.ByUiAutomatorFinder;
import io.appium.uiautomator2.utils.ContentSizeHelpers;
import io.appium.uiautomator2.utils.ElementHelpers;
import io.appium.uiautomator2.utils.Logger;
import io.appium.uiautomator2.utils.PositionHelper;
Expand Down Expand Up @@ -85,7 +86,7 @@ public String getAttribute(String attr) throws UiObjectNotFoundException {
result = toAxNodeInfo(element).getViewIdResourceName();
break;
case CONTENT_SIZE:
result = ElementHelpers.getContentSize(this);
result = ContentSizeHelpers.getContentSize(this);
break;
case ENABLED:
result = element.isEnabled();
Expand Down
Loading
Loading