当前位置: 首页>>代码示例>>Java>>正文


Java AccessibilityRecord.getContentDescription方法代码示例

本文整理汇总了Java中android.view.accessibility.AccessibilityRecord.getContentDescription方法的典型用法代码示例。如果您正苦于以下问题:Java AccessibilityRecord.getContentDescription方法的具体用法?Java AccessibilityRecord.getContentDescription怎么用?Java AccessibilityRecord.getContentDescription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.accessibility.AccessibilityRecord的用法示例。


在下文中一共展示了AccessibilityRecord.getContentDescription方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAccessibilityEvent

import android.view.accessibility.AccessibilityRecord; //导入方法依赖的package包/类
/**
 * Processes an AccessibilityEvent, by traversing the View's tree and
 * putting together a message to speak to the user.
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (!mTextToSpeechInitialized) {
        Log.e(LOG_TAG, "Text-To-Speech engine not ready.  Bailing out.");
        return;
    }

    // This AccessibilityNodeInfo represents the view that fired the
    // AccessibilityEvent. The following code will use it to traverse the
    // view hierarchy, using this node as a starting point.
    //
    // NOTE: Every method that returns an AccessibilityNodeInfo may return null,
    // because the explored window is in another process and the
    // corresponding View might be gone by the time your request reaches the
    // view hierarchy.
    AccessibilityNodeInfo source = event.getSource();
    if (source == null) {
        return;
    }

    // Grab the parent of the view that fired the event.
    AccessibilityNodeInfo rowNode = getListItemNodeInfo(source);
    if (rowNode == null) {
        return;
    }

    // Using this parent, get references to both child nodes, the label and the checkbox.
    AccessibilityNodeInfo labelNode = rowNode.getChild(0);
    if (labelNode == null) {
        rowNode.recycle();
        return;
    }

    AccessibilityNodeInfo completeNode = rowNode.getChild(1);
    if (completeNode == null) {
        rowNode.recycle();
        return;
    }

    // Determine what the task is and whether or not it's complete, based on
    // the text inside the label, and the state of the check-box.
    if (rowNode.getChildCount() < 2 || !rowNode.getChild(1).isCheckable()) {
        rowNode.recycle();
        return;
    }

    CharSequence taskLabel = labelNode.getText();
    final boolean isComplete = completeNode.isChecked();

    String completeStr = null;
    if (isComplete) {
        completeStr = getString(R.string.task_complete);
    } else {
        completeStr = getString(R.string.task_not_complete);
    }

    String taskStr = getString(R.string.task_complete_template, taskLabel, completeStr);
    StringBuilder utterance = new StringBuilder(taskStr);

    // The custom ListView added extra context to the event by adding an
    // AccessibilityRecord to it. Extract that from the event and read it.
    final int records = event.getRecordCount();
    for (int i = 0; i < records; i++) {
        AccessibilityRecord record = event.getRecord(i);
        CharSequence contentDescription = record.getContentDescription();
        if (!TextUtils.isEmpty(contentDescription )) {
            utterance.append(SEPARATOR);
            utterance.append(contentDescription);
        }
    }

    // Announce the utterance.
    mTts.speak(utterance.toString(), TextToSpeech.QUEUE_FLUSH, null);
    Log.d(LOG_TAG, utterance.toString());
}
 
开发者ID:luoqii,项目名称:ApkLauncher,代码行数:80,代码来源:TaskBackService.java


注:本文中的android.view.accessibility.AccessibilityRecord.getContentDescription方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。