输入法中的光标移动和文本检索

发布于 2024-10-10 05:06:51 字数 994 浏览 3 评论 0原文

我正在设计我的第一个 Android IME,有点不知所措。我的目标与可访问性相关,因此我想知道我是否正在使用 IME 框架尝试一些不可能的事情。我已经采用了默认的软键盘示例,并让它与我的一些修改一起工作,所以我肯定至少理解了其中的一些内容,但是对于我正在尝试的一些事情,没有大量的文档。我的意思是:

目前,带有纯触摸屏键盘的 Android 手机无法访问。我目前有一个可访问的触摸屏键盘,使用类似于 IOS/VoiceOver 中使用的方法,因此项目的这一部分已经完成,并且在 IME 框架中相当简单地完成。

目前,Android 的辅助功能 API 不提供用于导航文本字段的可访问反馈。也就是说,在加载了 Android 屏幕阅读器的情况下,如果您键入单词“this”,您会在键入时听到各个字符的发音,但如果您随后尝试在“s”上向左箭头移动,则不会朗读该字符。因此,我想捕捉动作并为导航过去的元素提供语音反馈。这就是我开始遇到问题的地方。

我目前有向左和向右箭头的语音反馈,使用 getCurrentInputConnection.getTextBeforeCursor(1, 0) 向左箭头,以及向右箭头的类似调用。处理完移动后,这将获取当前光标下的字符,一切都很好。

不过,我的挑战是在线条之间上下移动箭头时出现的。理想情况下,我想抓住当前的文本行并说出该内容,但我看不到任何方法可以做到这一点。我唯一能想到的是 getTextBefore/AfterCursor(Integer.MAX_VALUE, 0) 的某种组合并组合这些值,通过过滤上一个和下一个 \n 来确定当前行。是否有另一种方法 - 将字段的整个文本内容作为单个文本块获取,并使用光标位置来确定该文本的哪一部分代表当前行?我在各种输入法类中看到一些有关提取文本的信息,似乎可能有一种方法可以监视它,但我不知道这对我是否有用(即返回整个字段)内容?)

我的下一个目标是提供标准文本导航功能。 Android 辅助功能目前不包括触摸屏探索,因此不可能滚动大块文本。我不一定期望人们在手机上写小说,但我想提供快速手势或命令来向上/向下移动段落,以及较长字段的顶部/底部。 IMF 是否提供了光标移动的方法,或者这超出了其权限?

I'm designing my first Android IME and am a bit overwhelmed. My goals are accessibility-related, and as such I wonder if perhaps I'm trying things with the IME framework that just aren't possible. I've taken the default softkeyboard example and have it working along with some of my modifications, so I've definitely understood at least some of this, but there isn't a whole lot of documentation on some of the things I'm attempting. Here's what I mean:

Currently, Android phones with touchscreen-only keyboards are inaccessible. I currently have an accessible touchscreen keyboard using methods similar to those used in IOS/VoiceOver, so that part of the project is done and fairly straight-forward to accomplish in the IME framework.

Currently, Android's accessibility API doesn't provide accessible feedback for navigating text fields. That is, with an Android screen reader loaded, if you type the word "this", you'll hear individual characters spoken as you type them, but if you then try left-arrowing over the "s", that isn't spoken. So I want to trap movements and provide spoken feedback for the elements navigated past. Here's where I start encountering problems.

I currently have speech feedback for left and right arrowing, using getCurrentInputConnection.getTextBeforeCursor(1, 0) for arrowing left, and a similar call for arrowing right. This gets the character currently under the cursor after the movement is processed, and all is good.

My challenge, though, comes when arrowing up and down between lines. Ideally, I'd like to grab the current line of text and speak that, but I don't see any way to do that. The only thing I can think of is some combination of getTextBefore/AfterCursor(Integer.MAX_VALUE, 0) and combining those values, determining the current line by filtering for the previous and next \n. Is there another way--getting the entire text content of the field as a single block of text and using the cursor position to determine which piece of that text represents the current line? I'm seeing something about extracted text in the various input method classes, and it seems like there may be a way to monitor that, but I don't know if that is at all useful to me (I.e. would that return the entire field content?)

My next goal is providing standard text navigation capabilities. Android accessibility doesn't currently include touchscreen exploration, so it is impossible to otherwise scroll a large block of text. I don't necessarily expect folks to write novels on their phones, but I'd like to provide quick gestures or commands to move up/down paragraphs, and to the top/bottom of longer fields. Does the IMF provide methods for cursor movement, or is that outside of its authority?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2024-10-17 05:06:51

老实说,我没有得到第一部分:(

对于你的第二个问题,你需要手动处理。
例如,要添加具有向下绘制的键并使其工作,您需要:

  • onKey 方法中检查代码。
  • 如果是 20,您应该对该按键事件执行 sendDownUpKeyEvents

Honestly, I didn't get the first part :(

For your second question, you will need to handle it by hand.
For instance, to add a key with a down drawable and make it work you will need to:

  • In the onKey method check for the code.
  • If it's 20, you should do a sendDownUpKeyEvents of that key event.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文