From 4eef7728156483c5e23b19f4d807d0456619fb12 Mon Sep 17 00:00:00 2001 From: diye Date: Thu, 14 Apr 2022 15:01:41 +0800 Subject: [PATCH] feat: add actions - Wechat scan - Alipay scan - Headset hook --- app/build.gradle | 4 ++-- .../ws/diye/statusbarplus/ActionCardView.kt | 5 +++++ .../statusbarplus/CoreAccessibilityService.kt | 19 +++++++++++++++++++ .../main/java/ws/diye/statusbarplus/Models.kt | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index af5d393..cc0ee8c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "ws.diye.statusbarplus" minSdk 21 targetSdk 31 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/ws/diye/statusbarplus/ActionCardView.kt b/app/src/main/java/ws/diye/statusbarplus/ActionCardView.kt index 7a92d96..6655454 100644 --- a/app/src/main/java/ws/diye/statusbarplus/ActionCardView.kt +++ b/app/src/main/java/ws/diye/statusbarplus/ActionCardView.kt @@ -177,12 +177,17 @@ class ActionCardView(context: Context, attrs: AttributeSet): FrameLayout(context if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { put("Screenshot", AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT) } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + put("Headset Hook", AccessibilityService.GLOBAL_ACTION_KEYCODE_HEADSETHOOK) + } putAll( mapOf( "Volume Up" to CustomSwipeAction.VOLUME_UP, "Volume Down" to CustomSwipeAction.VOLUME_DOWN, "Mute Music" to CustomSwipeAction.MUTE_MUSIC_STREAM, "Keep Screen On" to CustomSwipeAction.TOGGLE_KEEP_SCREEN_ON, + "Wechat Scan" to CustomSwipeAction.WECHAT_SCAN, + "Alipay Scan" to CustomSwipeAction.ALIPAY_SCAN, ) ) } diff --git a/app/src/main/java/ws/diye/statusbarplus/CoreAccessibilityService.kt b/app/src/main/java/ws/diye/statusbarplus/CoreAccessibilityService.kt index 952ba1d..8685b3e 100644 --- a/app/src/main/java/ws/diye/statusbarplus/CoreAccessibilityService.kt +++ b/app/src/main/java/ws/diye/statusbarplus/CoreAccessibilityService.kt @@ -3,6 +3,7 @@ package ws.diye.statusbarplus import android.accessibilityservice.AccessibilityService import android.annotation.SuppressLint import android.content.Context +import android.content.Intent import android.content.SharedPreferences import android.content.res.Configuration import android.graphics.Color @@ -10,6 +11,7 @@ import android.view.accessibility.AccessibilityEvent import android.graphics.PixelFormat import android.media.AudioManager +import android.net.Uri import android.os.Build import android.util.DisplayMetrics import android.view.* @@ -199,6 +201,8 @@ class CoreAccessibilityService : AccessibilityService() { CustomSwipeAction.VOLUME_DOWN -> updateVolumeByStep(-1) CustomSwipeAction.MUTE_MUSIC_STREAM -> muteStream() CustomSwipeAction.TOGGLE_KEEP_SCREEN_ON -> toggleKeepScreenOn() + CustomSwipeAction.WECHAT_SCAN -> wechatScan() + CustomSwipeAction.ALIPAY_SCAN -> alipayScan() else -> performGlobalAction(actionData.actionValue) } } @@ -323,6 +327,21 @@ private fun CoreAccessibilityService.toggleKeepScreenOn() { toast.show() } +private fun CoreAccessibilityService.wechatScan() { + val itx = applicationContext.packageManager.getLaunchIntentForPackage("com.tencent.mm") + if (itx != null) { + itx.putExtra("LauncherUI.From.Scaner.Shortcut", true) + applicationContext.startActivity(itx) + } +} + +private fun CoreAccessibilityService.alipayScan() { + val uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007") + val intent = Intent(Intent.ACTION_VIEW, uri) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + applicationContext.startActivity(intent) +} + private class TouchGestureDetect(var x: Float = 0F, var y: Float = 0F) { var processed = false var maxDistanceX = 0F diff --git a/app/src/main/java/ws/diye/statusbarplus/Models.kt b/app/src/main/java/ws/diye/statusbarplus/Models.kt index 0e59694..b83f9ce 100644 --- a/app/src/main/java/ws/diye/statusbarplus/Models.kt +++ b/app/src/main/java/ws/diye/statusbarplus/Models.kt @@ -32,5 +32,7 @@ class CustomSwipeAction { const val VOLUME_DOWN = 100002 const val MUTE_MUSIC_STREAM = 100003 const val TOGGLE_KEEP_SCREEN_ON = 100004 + const val WECHAT_SCAN = 100101 + const val ALIPAY_SCAN = 100102 } } \ No newline at end of file