gpt4 book ai didi

android - 亚行可访问性重点变更

转载 作者:行者123 更新时间:2023-12-04 11:44:05 25 4
gpt4 key购买 nike

我想知道如何在 Talkback 开启时让 ADB 调整可访问性焦点。我努力了:

adb shell input trackball roll 0 1
adb shell input [stylusdpad|keyboard|mouse|touchpad|gamepad|touchnavigation|joystick|touchscreen|stylus|trackball] swipe 180 780 540 780
adb shell input keyboard keyevent KEYCODE_TAB
adb shell input keyevent KEYCODE_NAVIGATE_NEXT
adb shell "input keyevent KEYCODE_ALT_LEFT & input keyevent KEYCODE_DPAD_LEFT"
我还尝试使用 adb shell getevent 记录事件并在没有成功的情况下播放它们。
但是我总是必须物理地滑动屏幕(即 ADB 滑动不起作用 )才能改变可访问性焦点。有没有办法通过可访问性来做到这一点,只是下一个和上一个 Action ?
我找到了这个 article by Google :

Navigation

  • Move to next item: Alt + Right arrowNote: In continuous reading mode, this shortcut fast-forwards through the text.
  • Move to previous item: Alt + Left arrowNote: In continuous reading mode, this shortcut rewinds the text.

这意味着我只需要一次发送多个按键,对吗?我试过这个, based on another SO answer :
device="/dev/input/event3"
ALT_KEY=57#18 #KEYCODE_ALT_LEFT
LEFT_KEY=21#37 #KEYCODE_DPAD_RIGHT
RIGHT_KEY=22#39 #KEYCODE_DPAD_RIGHT

device="/dev/input/event0"
adb shell "sendevent $device 1 $ALT_KEY 1 & sendevent $device 0 0 0 & sendevent $device 1 $RIGHT_KEY 1 & sendevent $device 0 0 0"
device="/dev/input/event1"
adb shell "sendevent $device 1 $ALT_KEY 1 & sendevent $device 0 0 0 & sendevent $device 1 $RIGHT_KEY 1 & sendevent $device 0 0 0"
device="/dev/input/event2"
adb shell "sendevent $device 1 $ALT_KEY 1 & sendevent $device 0 0 0 & sendevent $device 1 $RIGHT_KEY 1 & sendevent $device 0 0 0"
device="/dev/input/event3"
adb shell "sendevent $device 1 $ALT_KEY 1 & sendevent $device 0 0 0 & sendevent $device 1 $RIGHT_KEY 1 & sendevent $device 0 0 0"

device="/dev/input/event0"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 0 0 0 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
device="/dev/input/event1"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 0 0 0 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
device="/dev/input/event2"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 0 0 0 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
device="/dev/input/event3"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 0 0 0 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"

device="/dev/input/event0"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
device="/dev/input/event1"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
device="/dev/input/event2"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
device="/dev/input/event3"
adb shell "sendevent $device 1 $ALT_KEY 1 && sendevent $device 1 $RIGHT_KEY 1 && sendevent $device 0 0 0"
(虽然我知道 device0 实际上是键盘设备,但我还是想尝试一下)

最佳答案

我在这里的回答将尽可能简洁。我的完整代码可在 GitHub 上获得.
据我所知,开发人员无法通过 ADB 执行可访问性操作,他们必须创建 Accessibility service为了act on behalf of an Accessibility user并创建一个 Broadcast Receiver这样它就可以通过亚行接受输入。这是答案的三分之二,需要多一个组件,因为开发人员无法通过 ADB 激活无障碍服务!这必须手动完成 每次切换可访问性 或通过accessibility shortcuts - 其中只能有一个。 编辑 我也想通了这一点:)
无障碍服务
开发者文档为 Accessibility Service 提供了一种机制。 :

An accessibility service is an application that provides user interface enhancements to assist users with disabilities, or who may temporarily be unable to fully interact with a device. For example, users who are driving, taking care of a young child or attending a very loud party might need additional or alternative interface feedback.


我关注了 Google Codelab构建一个可以对用户采取行动的服务。这是该服务的一个 fragment ,用于左右滑动(用户导航):
    fun swipeHorizontal(leftToRight: Boolean) {
val swipePath = Path()
if (leftToRight) {
swipePath.moveTo(halfWidth - quarterWidth, halfHeight)
swipePath.lineTo(halfWidth + quarterWidth, halfHeight)
} else {
swipePath.moveTo(halfWidth + quarterWidth, halfHeight)
swipePath.lineTo(halfWidth - quarterWidth, halfHeight)
}
val gestureBuilder = GestureDescription.Builder()
gestureBuilder.addStroke(StrokeDescription(swipePath, 0, 500))
dispatchGesture(gestureBuilder.build(), GestureResultCallback(baseContext), null)
}
广播接收器。
需要注意的是,启用服务时会注册 Receiver:
    override fun onServiceConnected() {
IntentFilter().apply {
addAction(ACCESSIBILITY_CONTROL_BROADCAST_ACTION)

priority = 100

registerReceiver(accessibilityActionReceiver, this)
}
// REMEMBER TO DEREGISTER!
然后接收者可以响应 Intent 并调用服务:
    override fun onReceive(context: Context?, intent: Intent?) {
require(intent != null) { "Intent is required" }
val serviceReference = //get a reference to the service somehow

intent.getStringExtra(ACCESSIBILITY_ACTION)?.let {
serviceReference.apply {
when (it) {
ACTION_NEXT -> swipeHorizontal(true)
ACTION_PREV -> swipeHorizontal(false)
//...
adb 上的示例用法:
adb shell am broadcast -a com.balsdon.talkback.accessibility -e ACTION "ACTION_PREV"
编辑
通过 adb 启动服务:
感谢 this comment
TALKBACK="com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService"
ALLYDEV="com.balsdon.accessibilityBroadcastService/.AccessibilityBroadcastService"
adb shell settings put secure enabled_accessibility_services $TALKBACK:$ALLYDEV
辅助功能快捷方式
** 编辑:不再需要,但无论如何我都会把它留在这里 **
可能最烦人的事情是每次切换可访问性时,服务都会关闭。所以我添加了我的 service as a shortcut按下 VOLUME_UP 和 VOLUME_DOWN 键。 Thanks to this question .
  INPUT_DEVICE="/dev/input/event1" # VOLUME KEYS EVENT FILE
VOLUME_DOWN=114 #0x0072
VOLUME_UP=115 #0x0073
BLANK_EVENT="sendevent $INPUT_DEVICE 0 0 0"

INST_DN="sendevent $INPUT_DEVICE 1 $VOLUME_DOWN 1 && $BLANK_EVENT && sendevent $INPUT_DEVICE 1 $VOLUME_UP 1 && $BLANK_EVENT"
INST_UP="sendevent $INPUT_DEVICE 1 $VOLUME_DOWN 0 && $BLANK_EVENT && sendevent $INPUT_DEVICE 1 $VOLUME_UP 0 && $BLANK_EVENT"
adb shell "$INST_DN"
sleep 3
adb shell "$INST_UP"
我已经有了 toggling accessibility on/off 的脚本,所以我只是在此基础上添加了这一点,并且每次都可以运行我的服务。
编辑 2
我在 AOSP 上提出问题关于开发人员需要编写“滑动服务”而不是“导航服务”这一事实。这是有问题的,因为可以修改手势,然后我的系统将无法按预期运行。相反,我应该能够调用我想要执行的特定操作 NAVIGATE TO NEXT ELEMENTNAVIGATE TO PREVIOUS ELEMENT与“向右滑动”和“向左滑动”相反——阅读了 WCAG 指南后,我不认为这违反了原则。

关于android - 亚行可访问性重点变更,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66790141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com