Skip to content

Commit

Permalink
1.修改应用配色,删掉无用的代码和文件
Browse files Browse the repository at this point in the history
  • Loading branch information
LisPig committed May 20, 2024
1 parent 69cace8 commit 2bc9af5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8,935 deletions.
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
android:supportsRtl="true"
android:theme="@style/Theme.WordUnlock"
tools:targetApi="31">
<service
android:name=".FloatingWordInputService"
android:enabled="true"
android:exported="true"
android:theme="@style/Theme.Transparent" />
<service
android:name=".WordUnlockForegroundService"
android:enabled="true"
Expand Down
56 changes: 18 additions & 38 deletions app/src/main/java/com/example/wordunlock/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,25 @@ class MainActivity : AppCompatActivity() {
supportActionBar?.setDisplayShowHomeEnabled(false)
}
}

if (!isAccessibilityServiceEnabled()) {
// 如果辅助功能未开启,在这里处理逻辑,比如弹窗提示或直接finish()
// 注意:此处处理逻辑需谨慎,避免无限循环或用户体验不佳的情况
// 示例代码可能需要根据实际情况调整
AlertDialog.Builder(this)
.setTitle("辅助功能未开启")
.setMessage("请确保辅助功能已开启以正常使用应用。")
.setPositiveButton("前往设置") { dialog, _ ->
dialog.dismiss()
openAccessibilitySettings()
}
.setCancelable(false) // 避免用户点击外部关闭而不做处理
.show()
}
bottomNavView.setupWithNavController(navController)



// 检查并请求 SYSTEM_ALERT_WINDOW 权限
if (!Settings.canDrawOverlays(this)) {
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Expand Down Expand Up @@ -97,7 +113,7 @@ class MainActivity : AppCompatActivity() {
// 检查权限是否已授予
if (Settings.canDrawOverlays(this)) {
// 权限已授予,执行相关操作
val intent = Intent(this, WordUnlockForegroundService::class.java)
val intent = Intent(this, WordUnlockService::class.java)
startService(intent)
} else {
// 权限未授予,提示用户或执行其他操作
Expand All @@ -106,11 +122,6 @@ class MainActivity : AppCompatActivity() {
}
}

fun getRawFileNames(context: Context): List<String> {
val rawClass = R.raw::class.java
return rawClass.fields.map { it.name }
}

//}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
Expand All @@ -130,38 +141,7 @@ class MainActivity : AppCompatActivity() {

override fun onResume() {
super.onResume()
// 在Activity变为可见时检查辅助功能状态
if (!isAccessibilityServiceEnabled()) {
// 如果辅助功能未开启,在这里处理逻辑,比如弹窗提示或直接finish()
// 注意:此处处理逻辑需谨慎,避免无限循环或用户体验不佳的情况
// 示例代码可能需要根据实际情况调整
AlertDialog.Builder(this)
.setTitle("辅助功能未开启")
.setMessage("请确保辅助功能已开启以正常使用应用。")
.setPositiveButton("前往设置") { dialog, _ ->
dialog.dismiss()
openAccessibilitySettings()
}
.setCancelable(false) // 避免用户点击外部关闭而不做处理
.show()
} else {
// 辅助功能已开启,执行其他逻辑
//setContentView(R.layout.activity_main)
val navController = findNavController(R.id.frame_layout_container)
val bottomNavView = findViewById<BottomNavigationView>(R.id.bottom_nav_view)
bottomNavView.setupWithNavController(navController)
// val fileList = assets.list("raw")
/*val raw_read_string = applicationContext.resources.openRawResource(R.raw.sixlevel).bufferedReader().use{
it.readText()
}*/
/*recyclerView = this.findViewById(R.id.recycler_view)
val layoutManager = LinearLayoutManager(this)
recyclerView.layoutManager = layoutManager
val fileNames = getRawFileNames(this)
jsonFileListAdapter = JsonFileListAdapter(this, fileNames)
recyclerView.adapter = jsonFileListAdapter*/
}

}

}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/example/wordunlock/WordUnlockService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ class WordUnlockService : AccessibilityService() {
val intent = Intent(this, WordUnlockForegroundService::class.java)
val randomWordDefinition = getRandomWordDefinitionFromJson(this)
randomWordDefinition?.let {
intent.putExtra("wordDefinition", it) // 传递单词数据
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startService(intent)
if(it != null) {
intent.putExtra("wordDefinition", it) // 传递单词数据
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startService(intent)
}
}
// }
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/color/custom_primary_color.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#ADD8E6"></item>
<item android:color="#00B0FF"></item>
</selector>
Loading

0 comments on commit 2bc9af5

Please sign in to comment.