Search in sources :

Example 11 with AccessibilityNodeInfoCompat

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();
    }
}
Also used : ViewParent(android.view.ViewParent) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) View(android.view.View)

Example 12 with AccessibilityNodeInfoCompat

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;
}
Also used : AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)

Example 13 with AccessibilityNodeInfoCompat

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();
    }
}
Also used : AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) AccessibilityActionCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat) Nullable(android.support.annotation.Nullable)

Example 14 with AccessibilityNodeInfoCompat

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;
}
Also used : AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)

Example 15 with AccessibilityNodeInfoCompat

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);
}
Also used : Selection(com.android.documentsui.dirlist.MultiSelectManager.Selection) ActivityManager(android.app.ActivityManager) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) Context(android.content.Context) Bundle(android.os.Bundle) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) TextView(android.widget.TextView) Recycler(android.support.v7.widget.RecyclerView.Recycler) Point(android.graphics.Point) SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) DocumentClipper(com.android.documentsui.DocumentClipper) GridLayoutManager(android.support.v7.widget.GridLayoutManager) State(com.android.documentsui.State) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)20 View (android.view.View)11 Bundle (android.os.Bundle)6 ActivityManager (android.app.ActivityManager)5 Context (android.content.Context)5 Point (android.graphics.Point)5 GridLayoutManager (android.support.v7.widget.GridLayoutManager)5 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)5 RecyclerView (android.support.v7.widget.RecyclerView)5 Recycler (android.support.v7.widget.RecyclerView.Recycler)5 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 DocumentClipper (com.android.documentsui.DocumentClipper)5 State (com.android.documentsui.State)5 Selection (com.android.documentsui.dirlist.MultiSelectManager.Selection)5 Nullable (android.support.annotation.Nullable)3 ViewParent (android.view.ViewParent)3 ViewGroup (android.view.ViewGroup)2 AdapterView (android.widget.AdapterView)2