Skip to content

Commit

Permalink
refactor(automator): 转换为kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
hyb1996 committed Nov 26, 2018
1 parent 39de832 commit 306762a
Show file tree
Hide file tree
Showing 134 changed files with 4,258 additions and 4,845 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
apply plugin: 'com.android.application'
def AAVersion = '4.4.0'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def AAVersion = '4.5.2'
def SupportLibVersion = '28.0.0'

configurations.all {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/autojs/autojs/autojs/AutoJs.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String println(int level, CharSequence charSequence) {
}

public void ensureAccessibilityServiceEnabled() {
if (AccessibilityService.getInstance() != null) {
if (AccessibilityService.Companion.getInstance() != null) {
return;
}
String errorMessage = null;
Expand All @@ -149,7 +149,7 @@ public void ensureAccessibilityServiceEnabled() {

@Override
public void waitForAccessibilityServiceEnabled() {
if (AccessibilityService.getInstance() != null) {
if (AccessibilityService.Companion.getInstance() != null) {
return;
}
String errorMessage = null;
Expand All @@ -166,7 +166,7 @@ public void waitForAccessibilityServiceEnabled() {
}
if (errorMessage != null) {
AccessibilityServiceTool.goToAccessibilitySetting();
if (!org.autojs.autojs.accessibility.AccessibilityService.waitForEnabled(-1)) {
if (!org.autojs.autojs.accessibility.AccessibilityService.Companion.waitForEnabled(-1)) {
throw new ScriptInterruptedException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface OnVolumeDownListener {
private boolean mVolumeUpFromShell, mVolumeUpFromAccessibility;

GlobalKeyObserver() {
AccessibilityService.getStickOnKeyObserver()
AccessibilityService.Companion.getStickOnKeyObserver()
.addListener(this);
ShellKeyObserver observer = new ShellKeyObserver();
observer.setKeyListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onClick() {
super.onClick();
Log.d(getClass().getName(), "onClick");
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
if (AccessibilityService.getInstance() == null) {
if (AccessibilityService.Companion.getInstance() == null) {
Toast.makeText(this, R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
AccessibilityServiceTool.goToAccessibilitySetting();
inactive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void goToAccessibilitySetting() {
GlobalAppContext.toast(context.getString(R.string.text_please_choose) + context.getString(R.string._app_name));
}
try {
AccessibilityServiceUtils.goToAccessibilitySetting(context);
AccessibilityServiceUtils.INSTANCE.goToAccessibilitySetting(context);
} catch (ActivityNotFoundException e) {
GlobalAppContext.toast(context.getString(R.string.go_to_accessibility_settings) + context.getString(R.string._app_name));
}
Expand Down Expand Up @@ -66,19 +66,19 @@ public static boolean enableAccessibilityServiceByRoot(Class<? extends android.a

public static boolean enableAccessibilityServiceByRootAndWaitFor(long timeOut) {
if (enableAccessibilityServiceByRoot(sAccessibilityServiceClass)) {
return AccessibilityService.waitForEnabled(timeOut);
return AccessibilityService.Companion.waitForEnabled(timeOut);
}
return false;
}

public static void enableAccessibilityServiceByRootIfNeeded() {
if (AccessibilityService.getInstance() == null)
if (AccessibilityService.Companion.getInstance() == null)
if (Pref.shouldEnableAccessibilityServiceByRoot()) {
AccessibilityServiceTool.enableAccessibilityServiceByRoot(sAccessibilityServiceClass);
}
}

public static boolean isAccessibilityServiceEnabled(Context context) {
return AccessibilityServiceUtils.isAccessibilityServiceEnabled(context, sAccessibilityServiceClass);
return AccessibilityServiceUtils.INSTANCE.isAccessibilityServiceEnabled(context, sAccessibilityServiceClass);
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/autojs/autojs/tool/CrashHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void uncaughtException(Thread thread, Throwable ex) {
}
return;
}
AccessibilityService service = AccessibilityService.getInstance();
AccessibilityService service = AccessibilityService.Companion.getInstance();
if (service != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.d(TAG, "disable service: " + service);
service.disableSelf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private void inspectLayout(Func1<NodeInfo, FloatyWindow> windowCreator) {
mLayoutInspectDialog.dismiss();
mLayoutInspectDialog = null;
}
if (AccessibilityService.getInstance() == null) {
if (AccessibilityService.Companion.getInstance() == null) {
Toast.makeText(mContext, R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
AccessibilityServiceTool.goToAccessibilitySetting();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public View getViewForObject(Object object, View convertView, ItemInfo itemInfo)
viewHolder = (ViewHolder) convertView.getTag();
}

viewHolder.nameView.setText(simplifyClassName(nodeInfo.className));
viewHolder.nameView.setText(simplifyClassName(nodeInfo.getClassName()));
viewHolder.nodeInfo = nodeInfo;
if (viewHolder.infoView.getVisibility() == VISIBLE)
viewHolder.infoView.setText(getItemInfoDsc(itemInfo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void enableOrDisableAccessibilityService(DrawerMenuItemViewHolder holder) {
if (checked && !isAccessibilityServiceEnabled) {
enableAccessibilityService();
} else if (!checked && isAccessibilityServiceEnabled) {
if (!AccessibilityService.disable()) {
if (!AccessibilityService.Companion.disable()) {
AccessibilityServiceTool.goToAccessibilitySetting();
}
}
Expand All @@ -216,7 +216,7 @@ void goToNotificationServiceSettings(DrawerMenuItemViewHolder holder) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
return;
}
boolean enabled = NotificationListenerService.getInstance() != null;
boolean enabled = NotificationListenerService.Companion.getInstance() != null;
boolean checked = holder.getSwitchCompat().isChecked();
if ((checked && !enabled) || (!checked && enabled)) {
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
Expand Down Expand Up @@ -390,7 +390,7 @@ public void onResourceReady(Drawable resource, Transition<? super Drawable> tran
private void syncSwitchState() {
setChecked(mAccessibilityServiceItem, AccessibilityServiceTool.isAccessibilityServiceEnabled(getActivity()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
setChecked(mNotificationPermissionItem, NotificationListenerService.getInstance() != null);
setChecked(mNotificationPermissionItem, NotificationListenerService.Companion.getInstance() != null);
}

}
Expand Down
2 changes: 2 additions & 0 deletions autojs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion versions.compile
Expand Down
8 changes: 4 additions & 4 deletions autojs/src/main/java/com/stardust/autojs/AutoJs.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public void onActivityResumed(Activity activity) {


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() {
Expand Down Expand Up @@ -225,7 +225,7 @@ public void waitForServiceEnabled() {
@Nullable
@Override
public AccessibilityService getService() {
return AccessibilityService.getInstance();
return AccessibilityService.Companion.getInstance();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -35,7 +35,7 @@ public UiObject child(int i) {
@Nullable
@Override
public UiObject parent() {
return mNodeInfo.parent == null ? null : new ReadOnlyUiObject(mNodeInfo.parent);
return mNodeInfo.getParent() == null ? null : new ReadOnlyUiObject(mNodeInfo.getParent());
}

@Override
Expand All @@ -50,7 +50,7 @@ public int getChildCount() {

@Override
public String className() {
return mNodeInfo.className;
return mNodeInfo.getClassName();
}

@Override
Expand All @@ -60,7 +60,7 @@ public CharSequence getClassName() {

@Override
public String packageName() {
return mNodeInfo.packageName;
return mNodeInfo.getPackageName();
}

@Override
Expand All @@ -70,12 +70,12 @@ public CharSequence getPackageName() {

@Override
public String id() {
return mNodeInfo.id;
return mNodeInfo.getId();
}

@Override
public String desc() {
return mNodeInfo.desc;
return mNodeInfo.getDesc();
}

@Override
Expand All @@ -101,13 +101,13 @@ public Rect boundsInParent() {

@Override
public int drawingOrder() {
return mNodeInfo.drawingOrder;
return mNodeInfo.getDrawingOrder();
}

@NonNull
@Override
public String text() {
return mNodeInfo.text;
return mNodeInfo.getText();
}

@Override
Expand Down Expand Up @@ -138,62 +138,62 @@ public void getBoundsInScreen(Rect outBounds) {

@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
Expand Down Expand Up @@ -259,47 +259,47 @@ public boolean isScrollable() {

@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
Expand Down
Loading

0 comments on commit 306762a

Please sign in to comment.