use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.
the class AccessibilityNodeInfoWrapper method getIgnoredReasons.
public static String getIgnoredReasons(View view) {
int important = ViewCompat.getImportantForAccessibility(view);
if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO) {
return "View has importantForAccessibility set to 'NO'.";
}
if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
return "View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
}
ViewParent parent = view.getParent();
while (parent instanceof View) {
if (ViewCompat.getImportantForAccessibility((View) parent) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
return "An ancestor View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
}
parent = parent.getParent();
}
AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
try {
if (!node.isVisibleToUser()) {
return "View is not visible.";
}
if (AccessibilityUtil.isAccessibilityFocusable(node, view)) {
return "View is actionable, but has no description.";
}
if (AccessibilityUtil.hasText(node)) {
return "View is not actionable, and an ancestor View has co-opted its description.";
}
return "View is not actionable and has no description.";
} finally {
node.recycle();
}
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.
the class AccessibilityNodeInfoWrapper method createNodeInfoFromView.
public static AccessibilityNodeInfoCompat createNodeInfoFromView(View view) {
AccessibilityNodeInfoCompat nodeInfo = AccessibilityNodeInfoCompat.obtain();
ViewCompat.onInitializeAccessibilityNodeInfo(view, nodeInfo);
return nodeInfo;
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project stetho by facebook.
the class AccessibilityNodeInfoWrapper method getActions.
@Nullable
public static String getActions(View view) {
AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
try {
final StringBuilder actionLabels = new StringBuilder();
final String separator = ", ";
for (AccessibilityActionCompat action : node.getActionList()) {
if (actionLabels.length() > 0) {
actionLabels.append(separator);
}
switch(action.getId()) {
case AccessibilityNodeInfoCompat.ACTION_FOCUS:
actionLabels.append("focus");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS:
actionLabels.append("clear-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_SELECT:
actionLabels.append("select");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
actionLabels.append("clear-selection");
break;
case AccessibilityNodeInfoCompat.ACTION_CLICK:
actionLabels.append("click");
break;
case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
actionLabels.append("long-click");
break;
case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
actionLabels.append("accessibility-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
actionLabels.append("clear-accessibility-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
actionLabels.append("next-at-movement-granularity");
break;
case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
actionLabels.append("previous-at-movement-granularity");
break;
case AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT:
actionLabels.append("next-html-element");
break;
case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT:
actionLabels.append("previous-html-element");
break;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
actionLabels.append("scroll-forward");
break;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
actionLabels.append("scroll-backward");
break;
case AccessibilityNodeInfoCompat.ACTION_CUT:
actionLabels.append("cut");
break;
case AccessibilityNodeInfoCompat.ACTION_COPY:
actionLabels.append("copy");
break;
case AccessibilityNodeInfoCompat.ACTION_PASTE:
actionLabels.append("paste");
break;
case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
actionLabels.append("set-selection");
break;
default:
CharSequence label = action.getLabel();
if (label != null) {
actionLabels.append(label);
} else {
actionLabels.append("unknown");
}
break;
}
}
return actionLabels.length() > 0 ? actionLabels.toString() : null;
} finally {
node.recycle();
}
}
use of android.support.v4.view.accessibility.AccessibilityNodeInfoCompat in project android-betterpickers by code-troopers.
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 platform_frameworks_base by android.
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);
}
Aggregations