use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project HoloEverywhere by Prototik.
the class TouchExplorationHelper method createAccessibilityNodeInfo.
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) {
if (virtualViewId == View.NO_ID) {
return getNodeForParent();
}
final T item = getItemForId(virtualViewId);
if (item == null) {
return null;
}
final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();
populateNodeForItemInternal(item, node);
return node;
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project android-betterpickers by code-troopers.
the class TouchExplorationHelper method getNodeForParent.
private AccessibilityNodeInfoCompat getNodeForParent() {
final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(mParentView);
ViewCompat.onInitializeAccessibilityNodeInfo(mParentView, info);
final LinkedList<T> items = new LinkedList<T>();
getVisibleItems(items);
for (T item : items) {
final int virtualDescendantId = getIdForItem(item);
info.addChild(mParentView, virtualDescendantId);
}
return info;
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project android_frameworks_base by ResurrectionRemix.
the class DirectoryFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Context context = getActivity();
final State state = getDisplayState();
// Read arguments when object created for the first time.
// Restore state if fragment recreated.
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
mRoot = args.getParcelable(Shared.EXTRA_ROOT);
mDocument = args.getParcelable(Shared.EXTRA_DOC);
mStateKey = buildStateKey(mRoot, mDocument);
mQuery = args.getString(Shared.EXTRA_QUERY);
mType = args.getInt(Shared.EXTRA_TYPE);
final Selection selection = args.getParcelable(Shared.EXTRA_SELECTION);
mSelection = selection != null ? selection : new Selection();
mSearchMode = args.getBoolean(Shared.EXTRA_SEARCH_MODE);
mIconHelper = new IconHelper(context, MODE_GRID);
mAdapter = new SectionBreakDocumentsAdapterWrapper(this, new ModelBackedDocumentsAdapter(this, mIconHelper));
mRecView.setAdapter(mAdapter);
// Switch Access Accessibility API needs an {@link AccessibilityDelegate} to know the proper
// route when user selects an UI element. It usually guesses this if the element has an
// {@link OnClickListener}, but since we do not have one for itemView, we will need to
// manually route it to the right behavior. RecyclerView has its own AccessibilityDelegate,
// and routes it to its LayoutManager; so we must override the LayoutManager's accessibility
// methods to route clicks correctly.
mLayout = new GridLayoutManager(getContext(), mColumnCount) {
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
info.addAction(AccessibilityActionCompat.ACTION_CLICK);
}
@Override
public boolean performAccessibilityActionForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View view, int action, Bundle args) {
// We are only handling click events; route all other to default implementation
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(view);
if (vh instanceof DocumentHolder) {
DocumentHolder dh = (DocumentHolder) vh;
if (dh.mEventListener != null) {
dh.mEventListener.onActivate(dh);
return true;
}
}
}
return super.performAccessibilityActionForItem(recycler, state, view, action, args);
}
};
SpanSizeLookup lookup = mAdapter.createSpanSizeLookup();
if (lookup != null) {
mLayout.setSpanSizeLookup(lookup);
}
mRecView.setLayoutManager(mLayout);
mGestureDetector = new ListeningGestureDetector(this.getContext(), mDragHelper, new GestureListener());
mRecView.addOnItemTouchListener(mGestureDetector);
// TODO: instead of inserting the view into the constructor, extract listener-creation code
// and set the listener on the view after the fact. Then the view doesn't need to be passed
// into the selection manager.
mSelectionManager = new MultiSelectManager(mRecView, mAdapter, state.allowMultiple ? MultiSelectManager.MODE_MULTIPLE : MultiSelectManager.MODE_SINGLE, null);
mSelectionManager.addCallback(new SelectionModeListener());
mModel = new Model();
mModel.addUpdateListener(mAdapter);
mModel.addUpdateListener(mModelUpdateListener);
// Make sure this is done after the RecyclerView is set up.
mFocusManager = new FocusManager(context, mRecView, mModel);
mTuner = FragmentTuner.pick(getContext(), state);
mClipper = new DocumentClipper(context);
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
boolean svelte = am.isLowRamDevice() && (mType == TYPE_RECENT_OPEN);
mIconHelper.setThumbnailsEnabled(!svelte);
// Kick off loader at least once
getLoaderManager().restartLoader(LOADER_ID, null, this);
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.
the class AccessibilityUtil method hasNonActionableSpeakingDescendants.
/**
* Determines if the supplied {@link View} and {@link AccessibilityNodeInfoCompat} has any
* children which are not independently accessibility focusable and also have a spoken
* description.
* <p>
* NOTE: Accessibility services will include these children's descriptions in the closest
* focusable ancestor.
*
* @param view The {@link View} to evaluate
* @param node The {@link AccessibilityNodeInfoCompat} to evaluate
* @return {@code true} if it has any non-actionable speaking descendants within its subtree
*/
public static boolean hasNonActionableSpeakingDescendants(@Nullable AccessibilityNodeInfoCompat node, @Nullable View view) {
if (node == null || view == null || !(view instanceof ViewGroup)) {
return false;
}
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
View childView = viewGroup.getChildAt(i);
if (childView == null) {
continue;
}
AccessibilityNodeInfoCompat childNode = AccessibilityNodeInfoCompat.obtain();
try {
ViewCompat.onInitializeAccessibilityNodeInfo(childView, childNode);
if (isAccessibilityFocusable(childNode, childView)) {
continue;
}
if (isSpeakingNode(childNode, childView)) {
return true;
}
} finally {
childNode.recycle();
}
}
return false;
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.
the class AccessibilityNodeInfoWrapper method getFocusableReasons.
@Nullable
public static String getFocusableReasons(View view) {
AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
try {
boolean hasText = AccessibilityUtil.hasText(node);
boolean isCheckable = node.isCheckable();
boolean hasNonActionableSpeakingDescendants = AccessibilityUtil.hasNonActionableSpeakingDescendants(node, view);
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;
} finally {
node.recycle();
}
}
Aggregations