Search in sources :

Example 6 with AccessibilityNodeInfoCompat

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

Example 7 with AccessibilityNodeInfoCompat

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

Example 8 with AccessibilityNodeInfoCompat

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

Example 9 with AccessibilityNodeInfoCompat

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;
}
Also used : ViewGroup(android.view.ViewGroup) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) HorizontalScrollView(android.widget.HorizontalScrollView) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 10 with AccessibilityNodeInfoCompat

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

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