refactor(automator): 转换为kotlin
This commit is contained in:
@@ -166,9 +166,9 @@ public abstract class AutoJs {
|
||||
|
||||
|
||||
private void addAccessibilityServiceDelegates() {
|
||||
AccessibilityService.addDelegate(100, mAccessibilityInfoProvider);
|
||||
AccessibilityService.addDelegate(200, mNotificationObserver);
|
||||
AccessibilityService.addDelegate(300, mAccessibilityActionRecorder);
|
||||
AccessibilityService.Companion.addDelegate(100, mAccessibilityInfoProvider);
|
||||
AccessibilityService.Companion.addDelegate(200, mNotificationObserver);
|
||||
AccessibilityService.Companion.addDelegate(300, mAccessibilityActionRecorder);
|
||||
}
|
||||
|
||||
public AccessibilityActionRecorder getAccessibilityActionRecorder() {
|
||||
@@ -225,7 +225,7 @@ public abstract class AutoJs {
|
||||
@Nullable
|
||||
@Override
|
||||
public AccessibilityService getService() {
|
||||
return AccessibilityService.getInstance();
|
||||
return AccessibilityService.Companion.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,12 +17,12 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
private NodeInfo mNodeInfo;
|
||||
|
||||
public ReadOnlyUiObject(NodeInfo info) {
|
||||
super(null, info.depth, -1);
|
||||
super(null, info.getDepth(), -1);
|
||||
mNodeInfo = info;
|
||||
}
|
||||
|
||||
public ReadOnlyUiObject(NodeInfo info, int indexInParent) {
|
||||
super(null, info.depth, indexInParent);
|
||||
super(null, info.getDepth(), indexInParent);
|
||||
mNodeInfo = info;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
@Nullable
|
||||
@Override
|
||||
public UiObject parent() {
|
||||
return mNodeInfo.parent == null ? null : new ReadOnlyUiObject(mNodeInfo.parent);
|
||||
return mNodeInfo.getParent() == null ? null : new ReadOnlyUiObject(mNodeInfo.getParent());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
|
||||
@Override
|
||||
public String className() {
|
||||
return mNodeInfo.className;
|
||||
return mNodeInfo.getClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +60,7 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
|
||||
@Override
|
||||
public String packageName() {
|
||||
return mNodeInfo.packageName;
|
||||
return mNodeInfo.getPackageName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,12 +70,12 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return mNodeInfo.id;
|
||||
return mNodeInfo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String desc() {
|
||||
return mNodeInfo.desc;
|
||||
return mNodeInfo.getDesc();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,13 +101,13 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
|
||||
@Override
|
||||
public int drawingOrder() {
|
||||
return mNodeInfo.drawingOrder;
|
||||
return mNodeInfo.getDrawingOrder();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String text() {
|
||||
return mNodeInfo.text;
|
||||
return mNodeInfo.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,62 +138,62 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
|
||||
@Override
|
||||
public int depth() {
|
||||
return mNodeInfo.depth;
|
||||
return mNodeInfo.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkable() {
|
||||
return mNodeInfo.checkable;
|
||||
return mNodeInfo.getCheckable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checked() {
|
||||
return mNodeInfo.checked;
|
||||
return mNodeInfo.getChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean focusable() {
|
||||
return mNodeInfo.focusable;
|
||||
return mNodeInfo.getFocusable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean focused() {
|
||||
return mNodeInfo.focused;
|
||||
return mNodeInfo.getFocused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visibleToUser() {
|
||||
return mNodeInfo.visibleToUser;
|
||||
return mNodeInfo.getVisibleToUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessibilityFocused() {
|
||||
return mNodeInfo.accessibilityFocused;
|
||||
return mNodeInfo.getAccessibilityFocused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selected() {
|
||||
return mNodeInfo.selected;
|
||||
return mNodeInfo.getSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clickable() {
|
||||
return mNodeInfo.clickable;
|
||||
return mNodeInfo.getClickable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longClickable() {
|
||||
return mNodeInfo.longClickable;
|
||||
return mNodeInfo.getLongClickable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabled() {
|
||||
return mNodeInfo.enabled;
|
||||
return mNodeInfo.getEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scrollable() {
|
||||
return mNodeInfo.scrollable;
|
||||
return mNodeInfo.getScrollable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,47 +259,47 @@ public class ReadOnlyUiObject extends UiObject {
|
||||
|
||||
@Override
|
||||
public boolean isContextClickable() {
|
||||
return mNodeInfo.contextClickable;
|
||||
return mNodeInfo.getContextClickable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDismissable() {
|
||||
return mNodeInfo.dismissable;
|
||||
return mNodeInfo.getDismissable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable() {
|
||||
return mNodeInfo.editable;
|
||||
return mNodeInfo.getEditable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int row() {
|
||||
return mNodeInfo.row;
|
||||
return mNodeInfo.getRow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int column() {
|
||||
return mNodeInfo.column;
|
||||
return mNodeInfo.getColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rowSpan() {
|
||||
return mNodeInfo.rowSpan;
|
||||
return mNodeInfo.getRowSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int columnSpan() {
|
||||
return mNodeInfo.columnSpan;
|
||||
return mNodeInfo.getColumnSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rowCount() {
|
||||
return mNodeInfo.rowCount;
|
||||
return mNodeInfo.getRowCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int columnCount() {
|
||||
return mNodeInfo.columnCount;
|
||||
return mNodeInfo.getColumnCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -82,22 +82,22 @@ public class SimpleActionAutomator {
|
||||
|
||||
@ScriptInterface
|
||||
public boolean scrollBackward(int i) {
|
||||
return performAction(ActionFactory.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, i));
|
||||
return performAction(ActionFactory.INSTANCE.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, i));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public boolean scrollForward(int i) {
|
||||
return performAction(ActionFactory.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, i));
|
||||
return performAction(ActionFactory.INSTANCE.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, i));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public boolean scrollMaxBackward() {
|
||||
return performAction(ActionFactory.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD));
|
||||
return performAction(ActionFactory.INSTANCE.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public boolean scrollMaxForward() {
|
||||
return performAction(ActionFactory.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD));
|
||||
return performAction(ActionFactory.INSTANCE.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
@@ -121,7 +121,7 @@ public class SimpleActionAutomator {
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean appendText(ActionTarget target, String text) {
|
||||
ScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP);
|
||||
return performAction(target.createAction(UiObject.ACTION_APPEND_TEXT, text));
|
||||
return performAction(target.createAction(UiObject.Companion.getACTION_APPEND_TEXT(), text));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
@@ -257,7 +257,7 @@ public class SimpleActionAutomator {
|
||||
if (root == null)
|
||||
return false;
|
||||
Log.v(TAG, "performAction: " + simpleAction + " root = " + root);
|
||||
return simpleAction.perform(UiObject.createRoot(root));
|
||||
return simpleAction.perform(UiObject.Companion.createRoot(root));
|
||||
}
|
||||
|
||||
private boolean isRunningPackageSelf() {
|
||||
|
||||
@@ -90,13 +90,13 @@ public class UiSelector extends UiGlobalSelector {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "find: root = " + root);
|
||||
if (root == null) {
|
||||
return UiObjectCollection.EMPTY;
|
||||
return UiObjectCollection.Companion.getEMPTY();
|
||||
}
|
||||
if (root.getPackageName() != null && mAccessibilityBridge.getConfig().whiteListContains(root.getPackageName().toString())) {
|
||||
Log.d(TAG, "package in white list, return null");
|
||||
return UiObjectCollection.EMPTY;
|
||||
return UiObjectCollection.Companion.getEMPTY();
|
||||
}
|
||||
return findOf(UiObject.createRoot(root, mAllocator));
|
||||
return findOf(UiObject.Companion.createRoot(root, mAllocator));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -78,7 +78,7 @@ public class AccessibilityActionConverter {
|
||||
AccessibilityNodeInfo source = event.getSource();
|
||||
if (source == null)
|
||||
return;
|
||||
String bounds = NodeInfo.boundsToString(AccessibilityNodeInfoHelper.getBoundsInScreen(source));
|
||||
String bounds = NodeInfo.Companion.boundsToString(AccessibilityNodeInfoHelper.INSTANCE.getBoundsInScreen(source));
|
||||
source.recycle();
|
||||
onAccessibilityEvent(event, bounds, sb);
|
||||
}
|
||||
@@ -122,8 +122,8 @@ public class AccessibilityActionConverter {
|
||||
AccessibilityNodeInfo source = event.getSource();
|
||||
if (source == null)
|
||||
return;
|
||||
UiObject uiObject = UiObject.createRoot(service.getRootInActiveWindow());
|
||||
List<UiObject> editableList = FilterAction.EditableFilter.findEditable(uiObject);
|
||||
UiObject uiObject = UiObject.Companion.createRoot(service.getRootInActiveWindow());
|
||||
List<UiObject> editableList = FilterAction.EditableFilter.Companion.findEditable(uiObject);
|
||||
int i = findInEditableList(editableList, source);
|
||||
sb.append("while(!input(").append(i).append(", \"").append(source.getText()).append("\"));");
|
||||
source.recycle();
|
||||
@@ -132,7 +132,7 @@ public class AccessibilityActionConverter {
|
||||
private static int findInEditableList(List<UiObject> editableList, AccessibilityNodeInfo editable) {
|
||||
int i = 0;
|
||||
for (UiObject nodeInfo : editableList) {
|
||||
if (AccessibilityNodeInfoHelper.getBoundsInScreen(nodeInfo).equals(AccessibilityNodeInfoHelper.getBoundsInScreen(editable))) {
|
||||
if (AccessibilityNodeInfoHelper.INSTANCE.getBoundsInScreen(nodeInfo).equals(AccessibilityNodeInfoHelper.INSTANCE.getBoundsInScreen(editable))) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
|
||||
@@ -204,13 +204,13 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
|
||||
mListeningNotification = true;
|
||||
ensureHandler();
|
||||
mLoopers.waitWhenIdle(true);
|
||||
if (NotificationListenerService.getInstance() == null) {
|
||||
if (NotificationListenerService.Companion.getInstance() == null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
mContext.startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
|
||||
}
|
||||
throw new ScriptException(mContext.getString(R.string.exception_notification_service_disabled));
|
||||
}
|
||||
NotificationListenerService.getInstance().addListener(this);
|
||||
NotificationListenerService.Companion.getInstance().addListener(this);
|
||||
}
|
||||
|
||||
public void observeToast() {
|
||||
@@ -250,8 +250,8 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
|
||||
mAccessibilityBridge.getNotificationObserver().removeNotificationListener(this);
|
||||
mAccessibilityBridge.getNotificationObserver().removeToastListener(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
|
||||
&& NotificationListenerService.getInstance() != null) {
|
||||
NotificationListenerService.getInstance().removeListener(this);
|
||||
&& NotificationListenerService.Companion.getInstance() != null) {
|
||||
NotificationListenerService.Companion.getInstance().removeListener(this);
|
||||
}
|
||||
}
|
||||
if (mKeyInterceptor != null) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import android.support.annotation.RequiresApi;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.R;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.enhancedfloaty.util.FloatingWindowPermissionUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
Reference in New Issue
Block a user