@@ -2,26 +2,55 @@ package com.ven.assists
22
33import android.accessibilityservice.AccessibilityService
44import android.accessibilityservice.GestureDescription
5+ import android.app.Activity
6+ import android.app.Application
57import android.content.ClipData
68import android.content.ClipboardManager
79import android.content.Context
810import android.content.Intent
911import android.graphics.Path
1012import android.graphics.Rect
13+ import android.media.projection.MediaProjectionManager
14+ import android.os.Bundle
1115import android.provider.Settings
1216import android.text.TextUtils
1317import android.util.Log
1418import android.view.accessibility.AccessibilityNodeInfo
19+ import androidx.activity.ComponentActivity
20+ import androidx.activity.result.ActivityResultLauncher
21+ import androidx.activity.result.contract.ActivityResultContracts
22+ import androidx.appcompat.app.AppCompatActivity
1523import com.blankj.utilcode.util.ActivityUtils
1624import com.blankj.utilcode.util.LogUtils
1725import com.blankj.utilcode.util.ScreenUtils
1826import com.blankj.utilcode.util.ThreadUtils
27+ import com.ven.assists.stepper.StepManager
28+ import kotlinx.coroutines.CoroutineScope
29+ import kotlinx.coroutines.Dispatchers
30+ import kotlinx.coroutines.Job
1931
2032object Assists {
2133
2234 // 日志TAG
2335 var LOG_TAG = " assists_log"
2436
37+ // 手势执行延迟回调
38+ var gestureBeginDelay = 0L
39+
40+ val screenRequestLaunchers: HashMap <Activity , ActivityResultLauncher <Intent >> = hashMapOf()
41+
42+ private var job = Job ()
43+ var coroutine: CoroutineScope = CoroutineScope (job + Dispatchers .IO )
44+ private set
45+ get() {
46+ if (job.isCancelled || ! job.isActive) {
47+ job = Job ()
48+ field = CoroutineScope (job + Dispatchers .IO )
49+ }
50+ return field
51+ }
52+
53+
2554 /* *
2655 * 无障碍服务,未开启前为null,使用注意判空
2756 */
@@ -33,11 +62,76 @@ object Assists {
3362 // 手势监听
3463 val gestureListeners: ArrayList <GestureListener > = arrayListOf ()
3564
36- // 手势执行延迟回调
37- var gestureBeginDelay = 0L
3865
39- fun init () {
66+ var screenCaptureService: ScreenCaptureService ? = null
67+ set(value) {
68+ if (value != null ) {
69+ serviceListeners.forEach { it.screenCaptureEnable() }
70+ }
71+ field = value
72+ }
73+
74+ private val activityLifecycleCallbacks = object : Application .ActivityLifecycleCallbacks {
75+ override fun onActivityCreated (activity : Activity , savedInstanceState : Bundle ? ) {
76+ if (activity is ComponentActivity ) {
77+ val screenRequestLauncher = activity.registerForActivityResult(ActivityResultContracts .StartActivityForResult ()) { result ->
78+ if (result.resultCode == Activity .RESULT_OK ) {
79+ val service = Intent (activity, ScreenCaptureService ::class .java)
80+ service.putExtra(" rCode" , result.resultCode)
81+ service.putExtra(" rData" , result.data)
82+ activity.startService(service)
83+ }
84+ }
85+ screenRequestLaunchers[activity] = screenRequestLauncher
86+ }
87+ }
88+
89+ override fun onActivityStarted (activity : Activity ) {
90+ }
91+
92+ override fun onActivityResumed (activity : Activity ) {
93+ }
94+
95+ override fun onActivityPaused (activity : Activity ) {
96+ }
97+
98+ override fun onActivityStopped (activity : Activity ) {
99+ }
100+
101+ override fun onActivitySaveInstanceState (activity : Activity , outState : Bundle ) {
102+ }
103+
104+ override fun onActivityDestroyed (activity : Activity ) {
105+ screenRequestLaunchers.remove(activity)
106+ }
107+ }
108+
109+ /* *
110+ * 请求录屏权限
111+ * @param isAutoEnable 是否自动通过,如果设置自动通过前提需要先开启无障碍服务(当前仅测试小米系统通过,其他机型系统未测试)
112+ */
113+ fun requestScreenCapture (isAutoEnable : Boolean ) {
114+ screenCaptureService ? : let {
115+ screenRequestLaunchers[ActivityUtils .getTopActivity()]?.launch(
116+ (ActivityUtils .getTopActivity().getSystemService(AppCompatActivity .MEDIA_PROJECTION_SERVICE ) as MediaProjectionManager )
117+ .createScreenCaptureIntent()
118+ )
119+ if (isAutoEnable && service != null ) {
120+ }
121+ }
122+ }
123+
124+ /* *
125+ * 是否拥有录屏权限
126+ */
127+ fun isOwnScreenCapture (): Boolean {
128+ return screenCaptureService == null
129+ }
130+
131+ fun init (application : Application ) {
132+ application.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
40133 LogUtils .getConfig().globalTag = LOG_TAG
134+ OpencvWrapper .init ()
41135 }
42136
43137 /* *
0 commit comments