Skip to content

Commit

Permalink
feat: 通知栏快捷捕获快照
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 20, 2023
1 parent d1c04e2 commit a2a6834
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 18 deletions.
14 changes: 13 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
android:usesCleartextTraffic="true">

<activity
android:name="li.songe.gkd.MainActivity"
android:name=".MainActivity"
android:configChanges="uiMode|screenSize|orientation|keyboardHidden|touchscreen|smallestScreenSize|screenLayout|navigation|mnc|mcc|locale|layoutDirection|keyboard|fontWeightAdjustment|fontScale|density|colorMode"
android:exported="true"
android:theme="@style/SplashScreenTheme">
Expand Down Expand Up @@ -132,6 +132,18 @@
android:exported="false"
android:foregroundServiceType="dataSync"
android:process=":remote" />
<service
android:name=".debug.SnapshotTileService"
android:exported="true"
android:icon="@drawable/ic_capture"
android:label="@string/capture_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:process=":remote">

<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>


</application>
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/li/songe/gkd/debug/SnapshotExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.core.graphics.set
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.ZipUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand Down Expand Up @@ -66,15 +67,16 @@ object SnapshotExt {
private val captureLoading = MutableStateFlow(false)

suspend fun captureSnapshot(): ComplexSnapshot {
if (!GkdAbService.isRunning()) {
throw RpcError("无障碍不可用")
}
if (captureLoading.value) {
throw RpcError("正在截屏,不可重复截屏")
}
captureLoading.value = true
ToastUtils.showShort("正在捕获快照...")

try {
if (!GkdAbService.isRunning()) {
throw RpcError("无障碍不可用")
}

val snapshotDef = coroutineScope { async(Dispatchers.IO) { createComplexSnapshot() } }
val bitmapDef = coroutineScope {
Expand Down Expand Up @@ -114,6 +116,7 @@ object SnapshotExt {
File(getSnapshotPath(snapshot.id)).writeText(text)
DbSet.snapshotDao.insert(snapshot.toSnapshot())
}
ToastUtils.showShort("快照捕获成功")
return snapshot
} finally {
captureLoading.value = false
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/li/songe/gkd/debug/SnapshotTileService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package li.songe.gkd.debug

import android.accessibilityservice.AccessibilityService
import android.service.quicksettings.TileService
import com.blankj.utilcode.util.ToastUtils
import kotlinx.coroutines.delay
import li.songe.gkd.appScope
import li.songe.gkd.debug.SnapshotExt.captureSnapshot
import li.songe.gkd.service.GkdAbService
import li.songe.gkd.service.topActivityFlow
import li.songe.gkd.util.launchTry

class SnapshotTileService : TileService() {
override fun onClick() {
super.onClick()
if (!GkdAbService.isRunning()) {
ToastUtils.showShort("无障碍没有开启")
return
}
val service = GkdAbService.service ?: return
val oldAppId = topActivityFlow.value?.appId
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
appScope.launchTry {
var i = 0
while (topActivityFlow.value?.appId == oldAppId) {
delay(100)
i++
if (i * 100 > 3000) {
ToastUtils.showShort("没有检测到界面切换,捕获失败")
return@launchTry
}
}
captureSnapshot()
}
}

}
1 change: 0 additions & 1 deletion app/src/main/java/li/songe/gkd/notif/NotifManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fun createNotif(context: Service, channelId: String, notif: Notif) {
.setAutoCancel(notif.autoCancel)

val notification = builder.build()
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
context.startForeground(
notif.id, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values-en/strings.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/values-zh/strings.xml

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<resources>
<string name="app_name">GKD</string>
<string name="ab_label">GKD</string>
<string name="ab_desc">Cabin -free speed point service based on rules -based matching</string>
<string name="ab_desc">基于规则匹配的无障碍速点服务\n强大的自定义规则能帮助你实现点击关闭各种广告\n自定义快捷操作等高级功能</string>
<string name="capture_label">捕获快照</string>
</resources>

0 comments on commit a2a6834

Please sign in to comment.