Search in sources :

Example 1 with AccessibilityNodeInfoCompat

use of androidx.core.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.

the class AccessibilityNodeInfoWrapper method getDescription.

@Nullable
public static CharSequence getDescription(View view) {
    AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
    try {
        CharSequence contentDescription = node.getContentDescription();
        CharSequence nodeText = node.getText();
        boolean hasNodeText = !TextUtils.isEmpty(nodeText);
        boolean isEditText = view instanceof EditText;
        // EditText's prioritize their own text content over a contentDescription
        if (!TextUtils.isEmpty(contentDescription) && (!isEditText || !hasNodeText)) {
            return contentDescription;
        }
        if (hasNodeText) {
            return nodeText;
        }
        // comma separated, becomes the description.
        if (view instanceof ViewGroup) {
            final StringBuilder concatChildDescription = new StringBuilder();
            final String separator = ", ";
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
                final View child = viewGroup.getChildAt(i);
                AccessibilityNodeInfoCompat childNodeInfo = AccessibilityNodeInfoCompat.obtain();
                ViewCompat.onInitializeAccessibilityNodeInfo(child, childNodeInfo);
                CharSequence childNodeDescription = null;
                if (AccessibilityUtil.isSpeakingNode(childNodeInfo, child) && !AccessibilityUtil.isAccessibilityFocusable(childNodeInfo, child)) {
                    childNodeDescription = getDescription(child);
                }
                if (!TextUtils.isEmpty(childNodeDescription)) {
                    if (concatChildDescription.length() > 0) {
                        concatChildDescription.append(separator);
                    }
                    concatChildDescription.append(childNodeDescription);
                }
                childNodeInfo.recycle();
            }
            return concatChildDescription.length() > 0 ? concatChildDescription.toString() : null;
        }
        return null;
    } finally {
        node.recycle();
    }
}
Also used : EditText(android.widget.EditText) ViewGroup(android.view.ViewGroup) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) View(android.view.View) Nullable(androidx.annotation.Nullable)

Example 2 with AccessibilityNodeInfoCompat

use of androidx.core.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.

the class AccessibilityNodeInfoWrapper method getIgnored.

public static boolean getIgnored(View view) {
    int important = ViewCompat.getImportantForAccessibility(view);
    if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO || important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
        return true;
    }
    // Go all the way up the tree to make sure no parent has hidden its descendants
    ViewParent parent = view.getParent();
    while (parent instanceof View) {
        if (ViewCompat.getImportantForAccessibility((View) parent) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
            return true;
        }
        parent = parent.getParent();
    }
    AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
    try {
        if (!node.isVisibleToUser()) {
            return true;
        }
        if (AccessibilityUtil.isAccessibilityFocusable(node, view)) {
            if (node.getChildCount() <= 0) {
                // speakable description
                return false;
            } else if (AccessibilityUtil.isSpeakingNode(node, view)) {
                // Node is focusable and has something to speak
                return false;
            }
            // Node is focusable and has nothing to speak
            return true;
        }
        // then it should receive focus from navigation and be read aloud.
        if (!AccessibilityUtil.hasFocusableAncestor(node, view) && AccessibilityUtil.hasText(node)) {
            return false;
        }
        return true;
    } finally {
        node.recycle();
    }
}
Also used : ViewParent(android.view.ViewParent) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) View(android.view.View)

Example 3 with AccessibilityNodeInfoCompat

use of androidx.core.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.

the class AccessibilityNodeInfoWrapper method getIsAccessibilityFocused.

public static boolean getIsAccessibilityFocused(View view) {
    AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
    boolean isAccessibilityFocused = node.isAccessibilityFocused();
    node.recycle();
    return isAccessibilityFocused;
}
Also used : AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat)

Example 4 with AccessibilityNodeInfoCompat

use of androidx.core.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.

the class AccessibilityUtil method hasFocusableAncestor.

/**
 * Determines if any of the provided {@link View}'s and {@link AccessibilityNodeInfoCompat}'s
 * ancestors can receive accessibility focus
 *
 * @param view The {@link View} to evaluate
 * @param node The {@link AccessibilityNodeInfoCompat} to evaluate
 * @return {@code true} if an ancestor of may receive accessibility focus
 */
public static boolean hasFocusableAncestor(@Nullable AccessibilityNodeInfoCompat node, @Nullable View view) {
    if (node == null || view == null) {
        return false;
    }
    ViewParent parentView = ViewCompat.getParentForAccessibility(view);
    if (!(parentView instanceof View)) {
        return false;
    }
    AccessibilityNodeInfoCompat parentNode = AccessibilityNodeInfoCompat.obtain();
    try {
        ViewCompat.onInitializeAccessibilityNodeInfo((View) parentView, parentNode);
        if (parentNode == null) {
            return false;
        }
        if (isAccessibilityFocusable(parentNode, (View) parentView)) {
            return true;
        }
        if (hasFocusableAncestor(parentNode, (View) parentView)) {
            return true;
        }
    } finally {
        parentNode.recycle();
    }
    return false;
}
Also used : ViewParent(android.view.ViewParent) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) HorizontalScrollView(android.widget.HorizontalScrollView) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 5 with AccessibilityNodeInfoCompat

use of androidx.core.view.accessibility.AccessibilityNodeInfoCompat in project android_packages_apps_Settings by omnirom.

the class SliceContextualCardRenderer method initDismissalActions.

private void initDismissalActions(RecyclerView.ViewHolder holder, ContextualCard card) {
    final Button btnKeep = holder.itemView.findViewById(R.id.keep);
    btnKeep.setOnClickListener(v -> {
        mFlippedCardSet.remove(holder);
        resetCardView(holder);
    });
    final Button btnRemove = holder.itemView.findViewById(R.id.remove);
    btnRemove.setOnClickListener(v -> {
        mControllerRendererPool.getController(mContext, card.getCardType()).onDismissed(card);
        mFlippedCardSet.remove(holder);
        resetCardView(holder);
        mSliceLiveDataMap.get(card.getSliceUri()).removeObservers(mLifecycleOwner);
    });
    ViewCompat.setAccessibilityDelegate(getInitialView(holder), new AccessibilityDelegateCompat() {

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.addAction(AccessibilityNodeInfoCompat.ACTION_DISMISS);
            info.setDismissable(true);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (action == AccessibilityNodeInfoCompat.ACTION_DISMISS) {
                mControllerRendererPool.getController(mContext, card.getCardType()).onDismissed(card);
            }
            return super.performAccessibilityAction(host, action, args);
        }
    });
}
Also used : Button(android.widget.Button) Bundle(android.os.Bundle) AccessibilityDelegateCompat(androidx.core.view.AccessibilityDelegateCompat) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

AccessibilityNodeInfoCompat (androidx.core.view.accessibility.AccessibilityNodeInfoCompat)18 View (android.view.View)13 AccessibilityDelegateCompat (androidx.core.view.AccessibilityDelegateCompat)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 Bundle (android.os.Bundle)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 PendingIntent (android.app.PendingIntent)3 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Intent (android.content.Intent)3 ViewGroup (android.view.ViewGroup)3 ViewParent (android.view.ViewParent)3 Button (android.widget.Button)3 DateTimeView (android.widget.DateTimeView)3 Nullable (androidx.annotation.Nullable)3 AdapterView (android.widget.AdapterView)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 ScrollView (android.widget.ScrollView)2 SuppressLint (android.annotation.SuppressLint)1 MotionEvent (android.view.MotionEvent)1