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();
}
}
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();
}
}
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;
}
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;
}
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);
}
});
}
Aggregations