Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DAJIBA committed Jun 17, 2021
1 parent 9d1d496 commit bc71a24
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 21 deletions.
22 changes: 14 additions & 8 deletions abllib/src/main/java/com/levine/abllib/AblService.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package com.levine.abllib;

import android.accessibilityservice.AccessibilityService;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.view.accessibility.AccessibilityEvent;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

import java.util.List;

/**
* 2019/4/21
Expand Down Expand Up @@ -40,15 +34,27 @@ private void init() {

}

@Override
protected boolean onGesture(int gestureId) {
return super.onGesture(gestureId);
}


@Override
protected void onServiceConnected() {
super.onServiceConnected();
LogUtils.v("onServiceConnected");
AccessibilityServiceInfo config = new AccessibilityServiceInfo();
//配置监听的事件类型为界面变化|点击事件
config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_VIEW_CLICKED;
config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
config.flags = AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
setServiceInfo(config);
}

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
LogUtils.v(event.getPackageName() + "");
// LogUtils.v(event.getPackageName() + "");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion abllib/src/main/java/com/levine/abllib/AblStepHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class AblStepHandler extends Handler {

private static AblStepHandler instance;
private static AblStepHandler instance;
private List<StepListener> mStepListeners = new ArrayList<>();
private boolean isStop = true;//是否停止
private String[] mDatas;//数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.view.accessibility.AccessibilityNodeInfo;

import java.util.List;

/**
* 2019/4/21
* 13:05
Expand Down
60 changes: 54 additions & 6 deletions abllib/src/main/java/com/levine/abllib/utils/AblUtil.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.levine.abllib.utils;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.provider.Settings;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.levine.abllib.AblConfig;
import com.levine.abllib.AblService;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

import static com.blankj.utilcode.util.ActivityUtils.startActivity;
Expand All @@ -32,6 +33,48 @@
*/
public class AblUtil {

/***
* 检查悬浮窗开启权限
* @param context
* @return
*/
public static boolean checkFloatPermission(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
return true;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
try {
Class cls = Class.forName("android.content.Context");
Field declaredField = cls.getDeclaredField("APP_OPS_SERVICE");
declaredField.setAccessible(true);
Object obj = declaredField.get(cls);
if (!(obj instanceof String)) {
return false;
}
String str2 = (String) obj;
obj = cls.getMethod("getSystemService", String.class).invoke(context, str2);
cls = Class.forName("android.app.AppOpsManager");
Field declaredField2 = cls.getDeclaredField("MODE_ALLOWED");
declaredField2.setAccessible(true);
Method checkOp = cls.getMethod("checkOp", Integer.TYPE, Integer.TYPE, String.class);
int result = (Integer) checkOp.invoke(obj, 24, Binder.getCallingUid(), context.getPackageName());
return result == declaredField2.getInt(cls);
} catch (Exception e) {
return false;
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AppOpsManager appOpsMgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
if (appOpsMgr == null)
return false;
int mode = appOpsMgr.checkOpNoThrow("android:system_alert_window", android.os.Process.myUid(), context
.getPackageName());
return Settings.canDrawOverlays(context) || mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED;
} else {
return Settings.canDrawOverlays(context);
}
}
}

/**
* 添加悬浮界面
*
Expand All @@ -50,6 +93,11 @@ public static void addSuspensionWindowView(Context context, View view) {
}
}

public static void removeSuspensionWindowView(Context context, View view) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.removeView(view);
}

/**
* 添加悬浮界面
*
Expand All @@ -65,9 +113,9 @@ private static void addSuspensionView(Context context, View view) {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
}
layoutParams.format = PixelFormat.TRANSLUCENT;// 支持透明
layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;// 焦点
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;//窗口的宽和高
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
// layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;// 焦点
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;//窗口的宽和高
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.x = 0;//窗口位置的偏移量
layoutParams.y = 0;
layoutParams.gravity = Gravity.CENTER;
Expand Down
33 changes: 29 additions & 4 deletions abllib/src/main/java/com/levine/abllib/utils/AblViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.levine.abllib.AblService;
import com.levine.abllib.callback.AniCallBack;
Expand Down Expand Up @@ -118,7 +116,7 @@ public static List<AccessibilityNodeInfo> findById(String id, AnisCallBack anisC
* @return
*/
public static AccessibilityNodeInfo findByText(AccessibilityNodeInfo parent, String text, int position) {
if (parent != null ) {
if (parent != null) {
List<AccessibilityNodeInfo> accessibilityNodeInfos =
parent.findAccessibilityNodeInfosByText(text);
if (accessibilityNodeInfos != null &&
Expand All @@ -135,7 +133,7 @@ public static AccessibilityNodeInfo findByText(String text, int position) {
}

public static List<AccessibilityNodeInfo> findByText(AccessibilityNodeInfo parent, String text) {
if (parent != null ) {
if (parent != null) {
List<AccessibilityNodeInfo> accessibilityNodeInfos =
parent.findAccessibilityNodeInfosByText(text);
if (accessibilityNodeInfos != null &&
Expand Down Expand Up @@ -368,6 +366,33 @@ public static void clickScreen(
);
}

public static void clickScreen(
float x,
float y
) {
dispatch_gesture(
new float[]{x, y},
new float[]{x, y},
100,
2000,
null
);
}

public static void clickScreen(
float x,
float y,
long duration
) {
dispatch_gesture(
new float[]{x, y},
new float[]{x, y},
100,
duration,
null
);
}

/**
* 点击屏幕
*
Expand Down

0 comments on commit bc71a24

Please sign in to comment.