GIT 提交信息:
增强无障碍设置集成和布局调整 - 通过改进结构和对齐增强主活动布局。 - 在 MainActivity 中实现无障碍服务检查和设置管理。 - 集成日志记录,以更好地跟踪服务可用性和 GAID 检索。
This commit is contained in:
parent
9afcb2ef27
commit
4cff1bfad1
@ -1,10 +1,14 @@
|
||||
package io.sixminutes.ridicule
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
@ -13,8 +17,16 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private val gaidHelper by lazy { GAIDHelper(this) }
|
||||
private val TAG = "ridicule"
|
||||
|
||||
private val gaidHelper by lazy { GAIDHelper(this) }
|
||||
private var accessibilityService: MyAccessibilityService? = null
|
||||
// ActivityResultLauncher 用于启动无障碍设置页面
|
||||
private lateinit var enableAccessibilityLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@ -25,6 +37,19 @@ class MainActivity : AppCompatActivity() {
|
||||
insets
|
||||
}
|
||||
|
||||
getGAID()
|
||||
|
||||
// 初始化 ActivityResultLauncher
|
||||
enableAccessibilityLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
// 用户从设置页面返回后,再次检查无障碍服务是否可用
|
||||
checkAccessibilityService()
|
||||
}
|
||||
|
||||
// 检查无障碍服务是否可用
|
||||
checkAccessibilityService()
|
||||
}
|
||||
|
||||
private fun getGAID() {
|
||||
// 获取 TextView 的引用
|
||||
val gaidTextView: TextView = findViewById(R.id.gaid)
|
||||
|
||||
@ -50,4 +75,45 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.e(TAG, "Google Play services are not available.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查无障碍服务是否可用,如果不可用则打开设置页面
|
||||
*/
|
||||
private fun checkAccessibilityService() {
|
||||
accessibilityService = MyAccessibilityService.getInstance()
|
||||
if (accessibilityService == null) {
|
||||
Log.e(TAG, "Accessibility service is not available")
|
||||
openAccessibilitySettings()
|
||||
} else {
|
||||
Log.d(TAG, "Accessibility service is available: $accessibilityService")
|
||||
continueMainActivityExecution()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开无障碍设置页面
|
||||
*/
|
||||
private fun openAccessibilitySettings() {
|
||||
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
|
||||
enableAccessibilityLauncher.launch(intent)
|
||||
Log.d(TAG, "Opening accessibility settings")
|
||||
}
|
||||
|
||||
/**
|
||||
* 无障碍服务可用后继续执行 MainActivity 的逻辑
|
||||
*/
|
||||
private fun continueMainActivityExecution() {
|
||||
// 在这里添加 MainActivity 的后续操作,例如更新 UI 或执行其他任务
|
||||
Log.d(TAG, "Continuing MainActivity execution after accessibility service is enabled.")
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
// 调用点击功能的方法
|
||||
fun simulateTap(x: Int, y: Int) {
|
||||
accessibilityService?.simulateTap(x, y)
|
||||
}
|
||||
|
||||
}
|
@ -7,19 +7,25 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gaid"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:text="GAID:"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="729dp"
|
||||
tools:layout_editor_absoluteX="1dp"
|
||||
tools:layout_editor_absoluteY="1dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gaid"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="GAID:"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user