Example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat isChecked

List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat isChecked

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat isChecked.

Prototype

public boolean isChecked() 

Source Link

Document

Gets whether this node is checked.

Usage

From source file:com.android.talkback.formatter.ClickFormatter.java

private String getStateText(AccessibilityNodeInfoCompat node, Context context) {
    switch (Role.getRole(node)) {
    case Role.ROLE_SWITCH:
    case Role.ROLE_TOGGLE_BUTTON:
        if (node.isChecked()) {
            return context.getString(R.string.value_on);
        } else {//  w  ww .j ava  2s  . c  o  m
            return context.getString(R.string.value_off);
        }
    default:
        if (node.isChecked()) {
            return context.getString(R.string.value_checked);
        } else {
            return context.getString(R.string.value_not_checked);
        }
    }
}

From source file:com.googlecode.eyesfree.brailleback.rule.DefaultBrailleRule.java

@Override
public void format(Editable result, Context context, AccessibilityNodeInfoCompat node) {
    int oldLength = result.length();
    CharSequence text = LabelingUtils.getNodeText(node, getLabelManager());
    if (text == null) {
        text = "";
    }/*from   ww  w.j av  a 2  s.  c o  m*/

    result.append(text);

    if (node.isCheckable() || node.isChecked()) {
        CharSequence mark;
        if (node.isChecked()) {
            mark = context.getString(R.string.checkmark_checked);
        } else {
            mark = context.getString(R.string.checkmark_not_checked);
        }
        StringUtils.appendWithSpaces(result, mark);
    }

    if (oldLength == result.length() && AccessibilityNodeInfoUtils.isActionableForAccessibility(node)) {
        result.append(getFallbackText(context, node));
    }
}

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

/**
 * Appends meta-data about the node's checked (if checkable) states.
 * <p>/*from   w ww. j a  va2 s .c o m*/
 * This should be applied to all nodes in a tree, including the root.
 */
private void appendMetadataToBuilder(AccessibilityNodeInfoCompat node,
        SpannableStringBuilder descriptionBuilder) {
    // Append the control's checked state, if applicable. Ignore nodes that
    // were accepted by the switch rule, since they already include the
    // checkable state.
    if (node.isCheckable() && !mRuleSwitch.accept(mContext, node)) {
        final int res = node.isChecked() ? R.string.value_checked : R.string.value_not_checked;
        StringBuilderUtils.appendWithSeparator(descriptionBuilder, mContext.getString(res));
    }
}

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

/**
 * Appends meta-data about the node's checked (if checkable) states.
 * <p>//w w  w  .  ja va  2  s  .c o m
 * This should be applied to all nodes in a tree, including the root.
 */
private void appendCheckedStatus(AccessibilityNodeInfoCompat node, AccessibilityEvent event,
        SpannableStringBuilder descriptionBuilder) {
    // Append the control's checked state, if applicable. Ignore nodes that
    // were accepted by the switch rule, since they already include the
    // checkable state.
    if (node.isCheckable() && !mRuleSwitch.accept(node, event)) {
        CharSequence checkedString = mContext
                .getString(node.isChecked() ? R.string.value_checked : R.string.value_not_checked);
        StringBuilderUtils.appendWithSeparator(descriptionBuilder, checkedString);
    }
}

From source file:com.googlecode.eyesfree.utils.TreeDebug.java

/**
 * Gets a description of the properties of a node.
 *//*  w  ww.j a v  a 2  s  .co  m*/
public static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());

    if (node.getClassName() != null) {
        appendSimpleName(sb, node.getClassName());
    } else {
        sb.append("??");
    }

    if (!node.isVisibleToUser()) {
        sb.append(":invisible");
    }

    if (node.getText() != null) {
        sb.append(":");
        sb.append(node.getText().toString().trim());
    }

    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription().toString().trim());
    }

    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) != 0) {
            sb.append("+");
        }
    }

    if (node.isCheckable()) {
        sb.append(":");
        if (node.isChecked()) {
            sb.append("(X)");
        } else {
            sb.append("( )");
        }
    }

    if (node.isFocusable()) {
        sb.append(":focusable");
    }

    if (node.isFocused()) {
        sb.append(":focused");
    }

    if (node.isSelected()) {
        sb.append(":selected");
    }

    if (node.isClickable()) {
        sb.append(":clickable");
    }

    if (node.isLongClickable()) {
        sb.append(":longClickable");
    }

    if (node.isAccessibilityFocused()) {
        sb.append(":accessibilityFocused");
    }

    if (!node.isEnabled()) {
        sb.append(":disabled");
    }

    return sb.toString();
}

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

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    final SpannableStringBuilder output = new SpannableStringBuilder();
    final CharSequence text = (!TextUtils.isEmpty(node.getText())) ? node.getText()
            : AccessibilityEventUtils.getEventAggregateText(event);
    final CharSequence contentDescription = node.getContentDescription();
    final CharSequence roleText = Role.getRoleDescriptionOrDefault(context, node);

    // Prepend any contentDescription, if present
    StringBuilderUtils.appendWithSeparator(output, contentDescription);

    // Append node or event text
    StringBuilderUtils.append(output, text, roleText);

    // The text should contain the current state.  Explicitly speak state for ToggleButtons.
    if (TextUtils.isEmpty(text) || Role.getRole(node) == Role.ROLE_TOGGLE_BUTTON) {
        final CharSequence state = context
                .getString(node.isChecked() ? R.string.value_checked : R.string.value_not_checked);
        StringBuilderUtils.appendWithSeparator(output, state);
    }// w  ww  .j a v  a2  s. c o m

    return output;
}

From source file:com.android.talkback.controller.CursorControllerAppTest.java

@MediumTest
public void testClickCurrent() {
    setContentView(R.layout.cursor_test);

    AccessibilityNodeInfoCompat checkBox = getNodeForId(R.id.check_me);
    assertFalse(checkBox.isChecked());

    mCursorController.setCursor(checkBox);
    waitForAccessibilityIdleSync();/*from  w  ww.  j  a  v  a  2 s. co  m*/

    mCursorController.clickCurrent();
    waitForAccessibilityIdleSync();

    checkBox.refresh();
    assertTrue(checkBox.isChecked());
}

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

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    final SpannableStringBuilder output = new SpannableStringBuilder();
    final CharSequence text = (!TextUtils.isEmpty(node.getText())) ? node.getText()
            : AccessibilityEventUtils.getEventAggregateText(event);
    final CharSequence contentDescription = node.getContentDescription();

    // Prepend any contentDescription, if present
    StringBuilderUtils.appendWithSeparator(output, contentDescription);

    // Append node or event text
    final CharSequence switchDescription = context.getString(R.string.template_switch,
            (!TextUtils.isEmpty(text)) ? text : "");
    StringBuilderUtils.appendWithSeparator(output, switchDescription);

    // The text should contain the current state.  Explicitly speak state for ToggleButtons.
    if (TextUtils.isEmpty(text) || AccessibilityNodeInfoUtils.nodeMatchesClassByType(context, node,
            android.widget.ToggleButton.class)) {
        final CharSequence state = context
                .getString(node.isChecked() ? R.string.value_checked : R.string.value_not_checked);
        StringBuilderUtils.appendWithSeparator(output, state);
    }/*w ww.ja  v  a2s .  c  o m*/

    return output;
}

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

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    final SpannableStringBuilder output = new SpannableStringBuilder();
    final CharSequence text = (!TextUtils.isEmpty(node.getText())) ? node.getText()
            : AccessibilityEventUtils.getEventAggregateText(event);
    final CharSequence contentDescription = node.getContentDescription();

    // Prepend any contentDescription, if present
    StringBuilderUtils.appendWithSeparator(output, contentDescription);

    // Append node or event text
    final String switchDescription = context.getString(R.string.template_switch,
            (!TextUtils.isEmpty(text)) ? text : "");
    final Spannable spannableSwitchDescription = StringBuilderUtils
            .createSpannableFromTextWithTemplate(switchDescription, text);
    StringBuilderUtils.appendWithSeparator(output, spannableSwitchDescription);

    // The text should contain the current state.  Explicitly speak state for ToggleButtons.
    if (TextUtils.isEmpty(text)
            || AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, ToggleButton.class)) {
        final CharSequence state = context
                .getString(node.isChecked() ? R.string.value_checked : R.string.value_not_checked);
        StringBuilderUtils.appendWithSeparator(output, state);
    }/*from w  w w  . j  a  v  a  2s  . c om*/

    return output;
}

From source file:com.android.talkback.formatter.CheckableClickedFormatter.java

@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (sCachedCheckableNode == null)
            return false;

        // Need to get latest state of cached node before accessing.
        sCachedCheckableNode.refresh();/*from  w w  w . ja v a2  s. c o  m*/

        utterance.addAuditory(R.raw.tick);
        utterance.addHaptic(R.array.view_clicked_pattern);
        utterance.addSpoken(context.getString(
                sCachedCheckableNode.isChecked() ? R.string.value_checked : R.string.value_not_checked));
        sCachedCheckableNode.recycle();
        sCachedCheckableNode = null;
        return true;
    }

    AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    AccessibilityNodeInfoCompat source = record.getSource();

    utterance.addAuditory(R.raw.tick);
    utterance.addHaptic(R.array.view_clicked_pattern);

    CharSequence eventText = AccessibilityEventUtils.getEventTextOrDescription(event);
    if (!TextUtils.isEmpty(eventText)) {
        utterance.addSpoken(eventText);
    }

    // Switch and ToggleButton state is sent along with the event, so only
    // append checked / not checked state for other types of controls.
    // TODO: node.isTwoState()
    if (Role.getRole(source) == Role.ROLE_TOGGLE_BUTTON || Role.getRole(source) == Role.ROLE_SWITCH) {
        return true;
    }

    if (source == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        if (event.isChecked()) {
            utterance.addSpoken(context.getString(R.string.value_checked));
        } else {
            utterance.addSpoken(context.getString(R.string.value_not_checked));
        }

        return true;
    }

    if (source.isCheckable()) {
        if (source.isChecked()) {
            utterance.addSpoken(context.getString(R.string.value_checked));
        } else {
            utterance.addSpoken(context.getString(R.string.value_not_checked));
        }
    }

    return true;
}