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

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

Introduction

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

Prototype

public boolean isFocused() 

Source Link

Document

Gets whether this node is focused.

Usage

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

@Override
public CharSequence getHintText(Context context, AccessibilityNodeInfoCompat node) {
    int inputMode = InputModeManager.INPUT_MODE_TOUCH;
    KeyComboManager keyComboManager = null;

    // If the EditText already has the input focus, then we should not tell the user "double-tap
    // to activate", nor "double-tap and hold to long press".
    boolean skipClickHints = false;
    TalkBackService service = TalkBackService.getInstance();
    if (service != null) {
        CursorController cursorController = service.getCursorController();
        AccessibilityNodeInfoCompat cursor = cursorController.getCursorOrInputCursor();
        if (cursor != null && cursor.isFocused() && node.equals(cursor)) {
            skipClickHints = true;/*from  ww w. ja va 2s.  c o  m*/
        }

        inputMode = service.getInputModeManager().getInputMode();
        keyComboManager = service.getKeyComboManager();
    }

    final CharSequence customClickHint = NodeHintHelper.getHintForInputMode(context, inputMode, keyComboManager,
            context.getString(R.string.keycombo_shortcut_perform_click), R.string.template_hint_edit_text,
            R.string.template_hint_edit_text_keyboard, null /* label */);
    final CharSequence customHint = NodeHintHelper.getCustomHintString(context, node, customClickHint,
            null /* customLongClickHint */, skipClickHints, inputMode, keyComboManager);

    return customHint;
}

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

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    final CharSequence text = getText(context, node);
    String formattedText;//from  w  ww . j a  va 2s. c om
    boolean isCurrentlyEditing = node.isFocused();
    if (hasWindowSupport()) {
        isCurrentlyEditing = isCurrentlyEditing && isInputWindowOnScreen();
    }

    if (isCurrentlyEditing) {
        formattedText = context.getString(R.string.template_edit_box_current, text);
    } else {
        formattedText = context.getString(R.string.template_edit_box, text);
    }

    return StringBuilderUtils.createSpannableFromTextWithTemplate(formattedText, text);
}

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

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    final CharSequence text = getText(context, node);
    boolean isCurrentlyEditing = node.isFocused();
    if (hasWindowSupport()) {
        isCurrentlyEditing = isCurrentlyEditing && isInputWindowOnScreen();
    }//from  w  ww  .j av  a 2s.c om

    SpannableStringBuilder output = new SpannableStringBuilder();

    CharSequence roleText = Role.getRoleDescriptionOrDefault(context, node);
    StringBuilderUtils.append(output, roleText);

    if (isCurrentlyEditing) {
        CharSequence editing = context.getString(R.string.value_edit_box_editing);
        StringBuilderUtils.append(output, editing);
    }
    if (TalkBackService.getInstance() != null
            && TalkBackService.getInstance().getCursorController().isSelectionModeActive()) {
        StringBuilderUtils.append(output, context.getString(R.string.notification_type_selection_mode_on));
    }

    StringBuilderUtils.append(output, text);

    return output;
}

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

private boolean shouldDropEvent(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    final AccessibilityNodeInfoCompat source = record.getSource();

    // Don't drop if we're on pre-ICS or the event was generated (e.g.
    // missing a node).
    if (source == null) {
        return false;
    }// www  .  j a va 2 s.co  m

    // Don't drop if the node is currently focused or accessibility focused.
    if (source.isFocused() || source.isAccessibilityFocused()) {
        return false;
    }

    // Don't drop if the node was recently explored.
    return true;
}

From source file:com.google.android.marvin.mytalkback.formatter.ProgressBarFormatter.java

private boolean shouldDropEvent(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final AccessibilityNodeInfoCompat source = record.getSource();

    // Don't drop if we're on pre-ICS or the event was generated (e.g.
    // missing a node).
    if (source == null) {
        return false;
    }/*  w  ww .j ava 2  s  .co m*/

    // Don't drop if the node is currently focused or accessibility focused.
    if (source.isFocused() || source.isAccessibilityFocused()) {
        return false;
    }

    // Don't drop if the node was recently explored.
    if (source.equals(sRecentlyExplored)) {
        return false;
    }

    return true;
}

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  v  a 2 s.  c  o m
        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;
}

From source file:com.googlecode.eyesfree.brailleback.IMENavigationMode.java

/** Returns true if a field suitable for modal editing is focused. */
private boolean isModalFieldFocused() {
    // Only instances of EditText with both input and accessibility focus
    // should be edited modally.
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    try {/*from www .j a v a  2s  .  c  om*/
        root = AccessibilityServiceCompatUtils.getRootInActiveWindow(mAccessibilityService);
        if (root == null) {
            return false;
        }
        accessibilityFocused = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        return (accessibilityFocused != null && accessibilityFocused.isFocused() && AccessibilityNodeInfoUtils
                .nodeMatchesClassByType(mAccessibilityService, accessibilityFocused, EditText.class));
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(root, accessibilityFocused);
    }
}

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

/**
 * Gets a description of the properties of a node.
 *//*  www .j  a v  a 2 s .c  o 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.controller.CursorControllerApp.java

public AccessibilityNodeInfoCompat getAccessibilityFocusedOrInputFocusedEditableNode() {
    final AccessibilityNodeInfoCompat compatRoot = AccessibilityServiceCompatUtils
            .getRootInAccessibilityFocusedWindow(mService);

    if (compatRoot == null) {
        return null;
    }/*from   w w w .j  a  v a 2 s . co  m*/

    AccessibilityNodeInfoCompat focusedNode = getAccessibilityFocusedNode(compatRoot);

    // TODO: If there's no focused node, we should either mimic following
    // focus from new window or try to be smart for things like list views.
    if (focusedNode == null) {
        AccessibilityNodeInfoCompat inputFocusedNode = getInputFocusedNode();
        if (inputFocusedNode != null && inputFocusedNode.isFocused() && inputFocusedNode.isEditable()) {
            focusedNode = inputFocusedNode;
        }
    }

    // If we can't find the focused node but the keyboard is showing, return the last editable.
    // This will occur if the input-focused view is actually a virtual view (e.g. in WebViews).
    // Note: need to refresh() in order to verify that the node is still available on-screen.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && focusedNode == null && mLastEditable != null
            && mLastEditable.refresh()) {
        WindowManager windowManager = new WindowManager(false); // RTL state doesn't matter.
        windowManager.setWindows(mService.getWindows());
        if (windowManager.isInputWindowOnScreen()) {
            focusedNode = AccessibilityNodeInfoCompat.obtain(mLastEditable);
        }
    }

    return focusedNode;
}

From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java

private void followScrollEvent(AccessibilityNodeInfoCompat source, AccessibilityRecordCompat record,
        int movingDirection, boolean wasScrollAction) {
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;

    try {/*  ww w.j  a v a 2  s .  com*/
        // First, see if we've already placed accessibility focus.
        root = AccessibilityServiceCompatUtils.getRootInAccessibilityFocusedWindow(mService);
        if (root == null) {
            return;
        }

        accessibilityFocused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
        boolean validAccessibilityFocus = AccessibilityNodeInfoUtils.shouldFocusNode(accessibilityFocused);
        // there are cases when scrollable container was scrolled and application set
        // focus on node that is on new container page. We should keep this focus
        boolean hasInputFocus = accessibilityFocused != null && accessibilityFocused.isFocused();

        if (validAccessibilityFocus && (hasInputFocus || !wasScrollAction)) {
            // focused on valid node and scrolled not by scroll action
            // keep focus
            return;
        }

        if (validAccessibilityFocus) {
            // focused on valid node and scrolled by scroll action
            // focus on next focusable node
            if (source == null) {
                source = record.getSource();
                if (source == null)
                    return;
            }
            if (!AccessibilityNodeInfoUtils.hasAncestor(accessibilityFocused, source)) {
                return;
            }
            TraversalStrategy traversal = new OrderedTraversalStrategy(root);
            try {
                focusNextFocusedNode(traversal, accessibilityFocused, movingDirection);
            } finally {
                traversal.recycle();
            }
        } else {
            if (mLastFocusedItem == null) {
                // there was no focus - don't set focus
                return;
            }

            if (source == null) {
                source = record.getSource();
                if (source == null)
                    return;
            }
            if (mLastFocusedItem.equals(source)
                    || AccessibilityNodeInfoUtils.hasAncestor(mLastFocusedItem, source)) {

                // There is no focus now, but it was on source node's child before
                // Try focusing the appropriate child node.
                if (tryFocusingChild(source, movingDirection)) {
                    return;
                }

                // Finally, try focusing the scrollable node itself.
                tryFocusing(source);
            }
        }
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(root, accessibilityFocused);
    }
}