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

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

Introduction

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

Prototype

public boolean isCheckable() 

Source Link

Document

Gets whether this node is checkable.

Usage

From source file:com.facebook.stetho.inspector.elements.android.AccessibilityNodeInfoWrapper.java

@Nullable
public static String getFocusableReasons(AccessibilityNodeInfoCompat node, View view) {
    boolean hasText = AccessibilityUtil.hasText(node);
    boolean isCheckable = node.isCheckable();
    boolean hasNonActionableSpeakingDescendants = AccessibilityUtil.hasNonActionableSpeakingDescendants(node,
            view);/*www  . j a  v a 2s.co  m*/

    if (AccessibilityUtil.isActionableForAccessibility(node)) {
        if (node.getChildCount() <= 0) {
            return "View is actionable and has no children.";
        } else if (hasText) {
            return "View is actionable and has a description.";
        } else if (isCheckable) {
            return "View is actionable and checkable.";
        } else if (hasNonActionableSpeakingDescendants) {
            return "View is actionable and has non-actionable descendants with descriptions.";
        }
    }

    if (AccessibilityUtil.isTopLevelScrollItem(node, view)) {
        if (hasText) {
            return "View is a direct child of a scrollable container and has a description.";
        } else if (isCheckable) {
            return "View is a direct child of a scrollable container and is checkable.";
        } else if (hasNonActionableSpeakingDescendants) {
            return "View is a direct child of a scrollable container and has non-actionable "
                    + "descendants with descriptions.";
        }
    }

    if (hasText) {
        return "View has a description and is not actionable, but has no actionable ancestor.";
    }

    return null;
}

From source file:Main.java

/**
 * Returns whether the supplied {@link View} and {@link AccessibilityNodeInfoCompat} would
 * produce spoken feedback if it were accessibility focused.  NOTE: not all speaking nodes are
 * focusable./*  w w w .  j a va  2s  .co  m*/
 *
 * @param view The {@link View} to evaluate
 * @param node The {@link AccessibilityNodeInfoCompat} to evaluate
 * @return {@code true} if it meets the criterion for producing spoken feedback
 */
public static boolean isSpeakingNode(@Nullable AccessibilityNodeInfoCompat node, @Nullable View view) {
    if (node == null || view == null) {
        return false;
    }

    if (!node.isVisibleToUser()) {
        return false;
    }

    int important = ViewCompat.getImportantForAccessibility(view);
    if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
            || (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO && node.getChildCount() <= 0)) {
        return false;
    }

    return node.isCheckable() || hasText(node) || hasNonActionableSpeakingDescendants(node, view);
}

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

private boolean findCheckableNode(AccessibilityNodeInfoCompat source) {
    if (source.isCheckable()) {
        sCachedCheckableNode = source;/*from  ww  w . j  a v  a  2 s  . c o  m*/
        return true;
    }

    int children = source.getChildCount();
    for (int i = 0; i < children; i++) {
        AccessibilityNodeInfoCompat node = source.getChild(i);
        if (findCheckableNode(node)) {
            if (!sCachedCheckableNode.equals(node)) {
                node.recycle();
            }
            return true;
        }

        if (node != null) {
            node.recycle();
        }
    }

    return false;
}

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

private AccessibilityNodeInfoCompat findCheckableChild(AccessibilityNodeInfoCompat node) {
    return AccessibilityNodeInfoUtils.getSelfOrMatchingDescendant(node, new NodeFilter() {
        @Override/*  w w w  . j ava2s  . c  o m*/
        public boolean accept(AccessibilityNodeInfoCompat node) {
            return node.isCheckable();
        }
    });
}

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

private boolean findCheckableNode(AccessibilityNodeInfoCompat source) {
    if (source == null) {
        return false;
    }/* w w  w.ja va  2  s .c o  m*/
    if (source.isCheckable()) {
        sCachedCheckableNode = source;
        return true;
    }

    int children = source.getChildCount();
    for (int i = 0; i < children; i++) {
        AccessibilityNodeInfoCompat node = source.getChild(i);
        if (findCheckableNode(node)) {
            if (!sCachedCheckableNode.equals(node)) {
                node.recycle();
            }
            return true;
        }

        if (node != null) {
            node.recycle();
        }
    }

    return false;
}

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

@Override
public boolean accept(AccessibilityEvent event, ScreenSpeakService context) {
    int type = event.getEventType();

    if (type == AccessibilityEvent.TYPE_VIEW_CLICKED) {
        mClickedNode = null;//from   w  w  w.j  a  v a 2  s.  c o  m
        mClickedTime = -1;

        if (event.isChecked()) {
            return true;
        }

        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat source = record.getSource();
        if (source != null) {
            if (source.isCheckable()) {
                return true;
            }

            // it is bug in settings application that does not include clicked state on node
            // so we need to restore it later from TYPE_WINDOW_CONTENT_CHANGED event
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mClickedNode = source;
                mClickedTime = System.currentTimeMillis();
            }
        }

        return false;
    }

    if (type == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            return false;
        if (mClickedTime == -1 || mClickedNode == null)
            return false;

        long now = System.currentTimeMillis();
        if ((mClickedTime + 1000) < now) {
            mClickedTime = -1;
            if (mClickedNode != null) {
                mClickedNode.recycle();
                mClickedNode = null;
            }
            return false;
        }

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

    return false;
}

From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java

private static boolean isSpeakingNode(Context context, AccessibilityNodeInfoCompat node) {
    if (hasText(node)) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Speaking, has text");
        return true;
    }/*  ww  w.j a v  a  2  s.com*/

    // Special case for check boxes.
    if (node.isCheckable()) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Speaking, is checkable");
        return true;
    }

    // Special case for web content.
    if (WebInterfaceUtils.hasWebContent(node)) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Speaking, has web content");
        return true;
    }

    // Special case for containers with non-focusable content.
    if (hasNonActionableSpeakingChildren(context, node)) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE,
                "Speaking, has non-actionable speaking children");
        return true;
    }

    return false;
}

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

@Override
public boolean accept(AccessibilityEvent event, TalkBackService context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return false;

    int type = event.getEventType();

    if (type == AccessibilityEvent.TYPE_VIEW_CLICKED) {
        mClickedNode = null;//w w  w  .ja v  a2 s.  c  om
        mClickedTime = -1;

        if (event.isChecked()) {
            return true;
        }

        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat source = record.getSource();
        if (source != null) {
            if (source.isCheckable()) {
                return true;
            }

            // it is bug in settings application that does not include clicked state on node
            // so we need to restore it later from TYPE_WINDOW_CONTENT_CHANGED event
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mClickedNode = source;
                mClickedTime = System.currentTimeMillis();
            }
        }

        return false;
    }

    if (type == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            return false;
        if (mClickedTime == -1 || mClickedNode == null)
            return false;

        long now = System.currentTimeMillis();
        if ((mClickedTime + 1000) < now) {
            mClickedTime = -1;
            if (mClickedNode != null) {
                mClickedNode.recycle();
                mClickedNode = null;
            }
            return false;
        }

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

    return false;
}

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 w ww  .  j a  v a2s.  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.android.talkback.formatter.ClickFormatter.java

@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    AccessibilityNodeInfoCompat source = record.getSource();
    AccessibilityNodeInfoCompat refreshedSource = AccessibilityNodeInfoUtils.refreshNode(source);

    try {//  w  w  w  .j a  va 2s  .  com
        if (refreshedSource == null) {
            // Node no longer exists.
            return false;
        }

        // Is source directly checkable?
        if (refreshedSource.isCheckable()) {
            utterance.addSpoken(getStateText(refreshedSource, context));
            return true;
        }

        // Does source contain non-focusable checkable child?
        if (refreshedSource.isAccessibilityFocused() || refreshedSource.isFocused()) {
            AccessibilityNodeInfoCompat checkableChild = findCheckableChild(refreshedSource);
            if (checkableChild != null) {
                utterance.addSpoken(getStateText(checkableChild, context));
                checkableChild.recycle();
                return true;
            }
        }
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(source, refreshedSource);
    }

    utterance.addSpokenFlag(FeedbackItem.FLAG_NO_SPEECH);
    return true;
}