Example usage for android.text SpannableStringBuilder clear

List of usage examples for android.text SpannableStringBuilder clear

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder clear.

Prototype

public void clear() 

Source Link

Usage

From source file:com.google.android.marvin.mytalkback.speechrules.NodeSpeechRuleProcessor.java

/**
 * If the supplied node has a label, replaces the builder text with a
 * version formatted with the label.//w  ww . java 2  s. co  m
 */
private void formatTextWithLabel(AccessibilityNodeInfoCompat node, SpannableStringBuilder builder) {
    final AccessibilityNodeInfoCompat labelNode = AccessibilityNodeInfoCompatUtils.getLabeledBy(node);
    if (labelNode == null) {
        return;
    }

    final SpannableStringBuilder labelDescription = new SpannableStringBuilder();
    appendDescriptionForTree(labelNode, labelDescription, null, null);
    if (TextUtils.isEmpty(labelDescription)) {
        return;
    }

    final String labeled = mContext.getString(R.string.template_labeled_item, builder, labelDescription);

    // Replace the text of the builder.
    builder.clear();
    builder.append(labeled);
}

From source file:com.android.screenspeak.speechrules.NodeSpeechRuleProcessor.java

/**
 * If the supplied node has a label, replaces the builder text with a
 * version formatted with the label./*w  ww  . j  a va2  s.co  m*/
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void formatTextWithLabel(AccessibilityNodeInfoCompat node, SpannableStringBuilder builder) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        return;

    // TODO(KM): add getLabeledBy to support lib
    AccessibilityNodeInfo info = (AccessibilityNodeInfo) node.getInfo();
    if (info == null)
        return;
    AccessibilityNodeInfo labeledBy = info.getLabeledBy();
    if (labeledBy == null)
        return;
    AccessibilityNodeInfoCompat labelNode = new AccessibilityNodeInfoCompat(labeledBy);

    final SpannableStringBuilder labelDescription = new SpannableStringBuilder();
    Set<AccessibilityNodeInfoCompat> visitedNodes = new HashSet<>();
    appendDescriptionForTree(labelNode, labelDescription, null, null, visitedNodes);
    AccessibilityNodeInfoUtils.recycleNodes(visitedNodes);
    if (TextUtils.isEmpty(labelDescription)) {
        return;
    }

    final String labeled = mContext.getString(R.string.template_labeled_item, builder, labelDescription);
    Spannable spannableLabeledText = StringBuilderUtils.createSpannableFromTextWithTemplate(labeled, builder);

    // Replace the text of the builder.
    builder.clear();
    builder.append(spannableLabeledText);
}

From source file:com.android.talkback.speechrules.NodeSpeechRuleProcessor.java

/**
 * If the supplied node has a label, replaces the builder text with a
 * version formatted with the label.//from   w ww  .ja  v  a  2 s .com
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void formatTextWithLabel(AccessibilityNodeInfoCompat node, SpannableStringBuilder builder) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        return;

    // TODO: add getLabeledBy to support lib
    AccessibilityNodeInfo info = (AccessibilityNodeInfo) node.getInfo();
    if (info == null)
        return;
    AccessibilityNodeInfo labeledBy = info.getLabeledBy();
    if (labeledBy == null)
        return;
    AccessibilityNodeInfoCompat labelNode = new AccessibilityNodeInfoCompat(labeledBy);

    final SpannableStringBuilder labelDescription = new SpannableStringBuilder();
    Set<AccessibilityNodeInfoCompat> visitedNodes = new HashSet<>();
    appendDescriptionForTree(labelNode, labelDescription, null, null, visitedNodes);
    AccessibilityNodeInfoUtils.recycleNodes(visitedNodes);
    if (TextUtils.isEmpty(labelDescription)) {
        return;
    }

    final String labeled = mContext.getString(R.string.template_labeled_item, builder, labelDescription);
    Spannable spannableLabeledText = StringBuilderUtils.createSpannableFromTextWithTemplate(labeled, builder);

    // Replace the text of the builder.
    builder.clear();
    builder.append(spannableLabeledText);
}