Skip to content

Commit

Permalink
feat: add actions
Browse files Browse the repository at this point in the history
- Wechat scan
- Alipay scan
- Headset hook
  • Loading branch information
diyews committed Apr 14, 2022
1 parent 7fe44e4 commit 4eef772
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/ws/diye/statusbarplus/ActionCardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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
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.*
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/ws/diye/statusbarplus/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 4eef772

Please sign in to comment.