在自定义视图实现可访问性没有给出口头反馈 [英] Implementing accessability on custom view gives no verbal feedback

查看:101
本文介绍了在自定义视图实现可访问性没有给出口头反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经打开可访问性,和我的设备说话,因为我浏览周围。

I have turned accessability on, and my device speaks as I navigate around.

我有一个自定义的搜索栏,并实施了folllowing:

I have a custom seekbar and have implemented the folllowing:

的onTouchEvent 节选:

...
case MotionEvent.ACTION_MOVE:

    getParent().requestDisallowInterceptTouchEvent(true);

    setTouchAngle(pointToAngle(touchX, touchY));
    score = getScoreFromAngle(angleStart,touchAngle);
    if (onScoreSetListener != null) {
        onScoreSetListener.onScorePoll(this, score);
        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
    }
    break;
...

onPopulateAccessibilityEvent 方法:

    @Override
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        super.onPopulateAccessibilityEvent(event);

        LogUtils.i(TAG,"onPopulateAccessibilityEvent()",null);

        switch (event.getEventType()) {
            case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:

                LogUtils.d(TAG,"dispatchPopulateAccessibilityEvent() TYPE_VIEW_TEXT_CHANGED",null);

                event.getText().add(String.valueOf(getScore()));
                break;
            }
    }

我可以看到 onPopulateAccessibilityEvent 被称为 LogCat中成功,但该设备不给任何反馈。我希望目前的比分被读回,但没有。

I can see onPopulateAccessibilityEvent being called in LogCat successfully, but the device is not giving any feedback. I expect the current score to be read back, but nothing.

没有人有任何见解?

推荐答案

如果您正在扩展进度,您可以设置文字传出 TYPE_VIEW_SELECTED 事件。当用户调整搜索栏,这些将被自动发送。

If you're extending ProgressBar, you can set the text for outgoing TYPE_VIEW_SELECTED events. These are sent automatically as the user adjusts the seek bar.

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.getText().add(...);
}

不过,它看起来像你可能已经扩展查看。在这种情况下,你需要使用一个微小的变通方法,并通过发送对ICS一个 VIEW_FOCUSED 事件触发的公告,或使用 announceForAccessibility API的软糖及以上。这将需要支持-V4磁带库和是这样的:

However, it looks like you may have extended View. In this case, you will need to use a slight workaround and trigger an announcement by sending a VIEW_FOCUSED event on ICS, or use the announceForAccessibility API on JellyBean and above. Which would require the support-v4 library and would look like this:

/** The parent context. Used to obtain string resources. */
private final Context mContext;

/**
 * The accessibility manager for this context. This is used to check the
 * accessibility enabled state, as well as to send raw accessibility events.
 */
private final AccessibilityManager mA11yManager;

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 *
 * @param text The text to announce.
 */
private void announceForAccessibilityCompat(CharSequence text) {
    if (!mA11yManager.isEnabled()) {
        return;
    }

    // Prior to SDK 16, announcements could only be made through FOCUSED
    // events. Jelly Bean (SDK 16) added support for speaking text verbatim
    // using the ANNOUNCEMENT event type.
    final int eventType;
    if (Build.VERSION.SDK_INT < 16) {
        eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
    } else {
        eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
    }

    // Construct an accessibility event with the minimum recommended
    // attributes. An event without a class name or package may be dropped.
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.getText().add(text);
    event.setEnabled(isEnabled());
    event.setClassName(getClass().getName());
    event.setPackageName(mContext.getPackageName());

    // JellyBean MR1 requires a source view to set the window ID.
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(this);

    // Sends the event directly through the accessibility manager. If your
    // application only targets SDK 14+, you should just call
    // getParent().requestSendAccessibilityEvent(this, event);
    mA11yManager.sendAccessibilityEvent(event);
}

这篇关于在自定义视图实现可访问性没有给出口头反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆