android.support.v4.view.accessibility.AccessibilityNodeInfoCompat Java Examples

The following examples show how to use android.support.v4.view.accessibility.AccessibilityNodeInfoCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the current item is at the edge of a list by checking the
 * scrollable predecessors of the items on either or both sides.
 *
 * @param context The parent context.
 * @param node The node to check.
 * @param direction The direction in which to check, one of:
 *            <ul>
 *            <li>{@code -1} to check backward
 *            <li>{@code 0} to check both backward and forward
 *            <li>{@code 1} to check forward
 *            </ul>
 * @param filter (Optional) Filter used to validate list-type ancestors.
 * @return true if the current item is at the edge of a list.
 */
public static boolean isEdgeListItem(
        Context context, AccessibilityNodeInfoCompat node, int direction, NodeFilter filter) {
    if (node == null) {
        return false;
    }

    if ((direction <= 0) && isMatchingEdgeListItem(context, node,
            NodeFocusFinder.SEARCH_BACKWARD, FILTER_SCROLL_BACKWARD.and(filter))) {
        return true;
    }

    if ((direction >= 0) && isMatchingEdgeListItem(context, node,
            NodeFocusFinder.SEARCH_FORWARD, FILTER_SCROLL_FORWARD.and(filter))) {
        return true;
    }

    return false;
}
 
Example #2
Source File: DrawerLayout.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This should really be in AccessibilityNodeInfoCompat, but there unfortunately
 * seem to be a few elements that are not easily cloneable using the underlying API.
 * Leave it private here as it's not general-purpose useful.
 */
private void copyNodeInfoNoChildren(AccessibilityNodeInfoCompat dest,
        AccessibilityNodeInfoCompat src) {
    final Rect rect = mTmpRect;

    src.getBoundsInParent(rect);
    dest.setBoundsInParent(rect);

    src.getBoundsInScreen(rect);
    dest.setBoundsInScreen(rect);

    dest.setVisibleToUser(src.isVisibleToUser());
    dest.setPackageName(src.getPackageName());
    dest.setClassName(src.getClassName());
    dest.setContentDescription(src.getContentDescription());

    dest.setEnabled(src.isEnabled());
    dest.setClickable(src.isClickable());
    dest.setFocusable(src.isFocusable());
    dest.setFocused(src.isFocused());
    dest.setAccessibilityFocused(src.isAccessibilityFocused());
    dest.setSelected(src.isSelected());
    dest.setLongClickable(src.isLongClickable());

    dest.addAction(src.getActions());
}
 
Example #3
Source File: VerticalContainerBrailleRule.java    From brailleback with Apache License 2.0 6 votes vote down vote up
@Override
public void format(Editable result,
        Context context,
        AccessibilityNodeInfoCompat node) {
    boolean empty = (node.getChildCount() == 0);
    int res;
    if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(context, node,
                    GridView.class)) {
        res = empty ? R.string.type_emptygridview : R.string.type_gridview;
    } else if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(
        context, node, ScrollView.class)) {
        res = empty ? R.string.type_emptyscrollview
                : R.string.type_scrollview;
    } else {
        res = empty ? R.string.type_emptylistview : R.string.type_listview;
    }
    result.append(context.getString(res));
}
 
Example #4
Source File: ViewPager.java    From RxJavaApp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
    if (super.performAccessibilityAction(host, action, args)) {
        return true;
    }
    switch (action) {
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
            if (canScrollHorizontally(1)) {
                setCurrentItem(mCurItem + 1);
                return true;
            }
        } return false;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
            if (canScrollHorizontally(-1)) {
                setCurrentItem(mCurItem - 1);
                return true;
            }
        } return false;
    }
    return false;
}
 
Example #5
Source File: ViewPagerEx.java    From ImageSliderWithSwipes with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
    if (super.performAccessibilityAction(host, action, args)) {
        return true;
    }
    switch (action) {
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
            if (canScrollHorizontally(1)) {
                setCurrentItem(mCurItem + 1);
                return true;
            }
        } return false;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
            if (canScrollHorizontally(-1)) {
                setCurrentItem(mCurItem - 1);
                return true;
            }
        } return false;
    }
    return false;
}
 
Example #6
Source File: GridLayoutManager.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
        RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
    ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (!(lp instanceof LayoutParams)) {
        super.onInitializeAccessibilityNodeInfoForItem(host, info);
        return;
    }
    LayoutParams glp = (LayoutParams) lp;
    int spanGroupIndex = getSpanGroupIndex(recycler, state, glp.getViewPosition());
    if (mOrientation == HORIZONTAL) {
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                glp.getSpanIndex(), glp.getSpanSize(),
                spanGroupIndex, 1,
                mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false));
    } else { // VERTICAL
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                spanGroupIndex , 1,
                glp.getSpanIndex(), glp.getSpanSize(),
                mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false));
    }
}
 
Example #7
Source File: DefaultNavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private boolean handleIncrementalSearchAction() {
    AccessibilityNodeInfoCompat currentNode = getFocusedNode(true);
    try {
        if (currentNode != null
                && WebInterfaceUtils.hasLegacyWebContent(currentNode)
                && mFeedbackManager.emitOnFailure(
                    WebInterfaceUtils.performSpecialAction(currentNode,
                        ACTION_TOGGLE_INCREMENTAL_SEARCH),
                    FeedbackManager.TYPE_COMMAND_FAILED)) {
            return true;
        }
        return false;
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(currentNode);
    }
}
 
Example #8
Source File: DefaultNavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private boolean moveFocus(AccessibilityNodeInfoCompat from,
        int direction) {
    int searchDirection = (direction == DIRECTION_BACKWARD)
        ? FocusFinder.SEARCH_BACKWARD
        : FocusFinder.SEARCH_FORWARD;
    AccessibilityNodeInfoCompat next = null;
    next = mFocusFinder.linear(from, searchDirection);
    try {
        if (next != null) {
            return next.performAction(
                    AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
        }
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(next);
    }
    return false;
}
 
Example #9
Source File: MarginDrawerLayout.java    From something.apk with MIT License 6 votes vote down vote up
/**
 * This should really be in AccessibilityNodeInfoCompat, but there unfortunately
 * seem to be a few elements that are not easily cloneable using the underlying API.
 * Leave it private here as it's not general-purpose useful.
 */
private void copyNodeInfoNoChildren(AccessibilityNodeInfoCompat dest,
                                    AccessibilityNodeInfoCompat src) {
    final Rect rect = mTmpRect;

    src.getBoundsInParent(rect);
    dest.setBoundsInParent(rect);

    src.getBoundsInScreen(rect);
    dest.setBoundsInScreen(rect);

    dest.setVisibleToUser(src.isVisibleToUser());
    dest.setPackageName(src.getPackageName());
    dest.setClassName(src.getClassName());
    dest.setContentDescription(src.getContentDescription());

    dest.setEnabled(src.isEnabled());
    dest.setClickable(src.isClickable());
    dest.setFocusable(src.isFocusable());
    dest.setFocused(src.isFocused());
    dest.setAccessibilityFocused(src.isAccessibilityFocused());
    dest.setSelected(src.isSelected());
    dest.setLongClickable(src.isLongClickable());

    dest.addAction(src.getActions());
}
 
Example #10
Source File: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private static AccessibilityNodeInfoCompat refreshFromChild(
        AccessibilityNodeInfoCompat node) {
    if (node.getChildCount() > 0) {
        AccessibilityNodeInfoCompat firstChild = node.getChild(0);
        if (firstChild != null) {
            AccessibilityNodeInfoCompat parent = firstChild.getParent();
            firstChild.recycle();
            if (node.equals(parent)) {
                return parent;
            } else {
                recycleNodes(parent);
            }
        }
    }
    return null;
}
 
Example #11
Source File: VerticalViewPager.java    From ankihelper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
    if (super.performAccessibilityAction(host, action, args)) {
        return true;
    }
    switch (action) {
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
            if (internalCanScrollVertically(1)) {
                setCurrentItem(mCurItem + 1);
                return true;
            }
        }
        return false;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
            if (internalCanScrollVertically(-1)) {
                setCurrentItem(mCurItem - 1);
                return true;
            }
        }
        return false;
    }
    return false;
}
 
Example #12
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * This should really be in AccessibilityNodeInfoCompat, but there unfortunately
 * seem to be a few elements that are not easily cloneable using the underlying API.
 * Leave it private here as it's not general-purpose useful.
 */
private void copyNodeInfoNoChildren(AccessibilityNodeInfoCompat dest,
                                    AccessibilityNodeInfoCompat src) {
    final Rect rect = mTmpRect;

    src.getBoundsInParent(rect);
    dest.setBoundsInParent(rect);

    src.getBoundsInScreen(rect);
    dest.setBoundsInScreen(rect);

    dest.setVisibleToUser(src.isVisibleToUser());
    dest.setPackageName(src.getPackageName());
    dest.setClassName(src.getClassName());
    dest.setContentDescription(src.getContentDescription());

    dest.setEnabled(src.isEnabled());
    dest.setClickable(src.isClickable());
    dest.setFocusable(src.isFocusable());
    dest.setFocused(src.isFocused());
    dest.setAccessibilityFocused(src.isAccessibilityFocused());
    dest.setSelected(src.isSelected());
    dest.setLongClickable(src.isLongClickable());

    dest.addAction(src.getActions());
}
 
Example #13
Source File: DrawerLayout.java    From guideshow with MIT License 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);

    superNode.recycle();

    addChildrenForAccessibility(info, (ViewGroup) host);
}
 
Example #14
Source File: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPopulateNodeForVirtualView(
        int virtualViewId, AccessibilityNodeInfoCompat node) {
    if (mVirtualViews == null || mVirtualViews.size() <= virtualViewId) {
        // TODO(clholgat): Remove this work around when the Android bug is fixed.
        // crbug.com/420177
        node.setBoundsInParent(mPlaceHolderRect);
        node.setContentDescription(PLACE_HOLDER_STRING);
        return;
    }
    VirtualView view = mVirtualViews.get(virtualViewId);
    view.getTouchTarget(mTouchTarget);

    node.setBoundsInParent(rectToPx(mTouchTarget));
    node.setContentDescription(view.getAccessibilityDescription());
    node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
    node.addAction(AccessibilityNodeInfoCompat.ACTION_FOCUS);
    node.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK);
}
 
Example #15
Source File: RadialPickerLayout.java    From date_picker_converter with Apache License 2.0 6 votes vote down vote up
/**
 * Necessary for accessibility, to ensure we support "scrolling" forward and backward
 * in the circle.
 */
@Override
@SuppressWarnings("deprecation")
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    if (Build.VERSION.SDK_INT >= 21) {
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
    }
    else if (Build.VERSION.SDK_INT >= 16) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    } else {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
    }
}
 
Example #16
Source File: NestedScrollView.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    NestedScrollView nsvHost = (NestedScrollView) host;
    info.setClassName(ScrollView.class.getName());
    if (nsvHost.isEnabled()) {
        int scrollRange = nsvHost.getScrollRange();
        if (scrollRange > 0) {
            info.setScrollable(true);
            if (nsvHost.getScrollY() > 0) {
                info.addAction(8192);
            }
            if (nsvHost.getScrollY() < scrollRange) {
                info.addAction(4096);
            }
        }
    }
}
 
Example #17
Source File: DrawerLayout.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    if (DrawerLayout.CAN_HIDE_DESCENDANTS) {
        super.onInitializeAccessibilityNodeInfo(host, info);
    } else {
        AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
        super.onInitializeAccessibilityNodeInfo(host, superNode);
        info.setSource(host);
        ViewParent parent = ViewCompat.getParentForAccessibility(host);
        if (parent instanceof View) {
            info.setParent((View) parent);
        }
        copyNodeInfoNoChildren(info, superNode);
        superNode.recycle();
        addChildrenForAccessibility(info, (ViewGroup) host);
    }
    info.setClassName(DrawerLayout.class.getName());
    info.setFocusable(false);
    info.setFocused(false);
    info.removeAction(AccessibilityActionCompat.ACTION_FOCUS);
    info.removeAction(AccessibilityActionCompat.ACTION_CLEAR_FOCUS);
}
 
Example #18
Source File: VelocityViewPager.java    From Muzesto with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
    if (super.performAccessibilityAction(host, action, args)) {
        return true;
    }
    switch (action) {
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
            if (canScrollHorizontally(1)) {
                setCurrentItem(mCurItem + 1);
                return true;
            }
        } return false;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
            if (canScrollHorizontally(-1)) {
                setCurrentItem(mCurItem - 1);
                return true;
            }
        } return false;
    }
    return false;
}
 
Example #19
Source File: DrawerLayout.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);

    superNode.recycle();

    addChildrenForAccessibility(info, (ViewGroup) host);
}
 
Example #20
Source File: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether a node is actionable. That is, the node supports one of
 * the following actions:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#isClickable()}
 * <li>{@link AccessibilityNodeInfoCompat#isFocusable()}
 * <li>{@link AccessibilityNodeInfoCompat#isLongClickable()}
 * </ul>
 * This parities the system method View#isActionableForAccessibility(), which
 * was added in JellyBean.
 *
 * @param node The node to examine.
 * @return {@code true} if node is actionable.
 */
public static boolean isActionableForAccessibility(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return false;
    }

    // Nodes that are clickable are always actionable.
    if (isClickable(node) || isLongClickable(node)) {
        return true;
    }

    if (node.isFocusable()) {
        return true;
    }

    return supportsAnyAction(node, AccessibilityNodeInfoCompat.ACTION_FOCUS,
            AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT,
            AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT);
}
 
Example #21
Source File: VerticalViewPager.java    From DoubleViewPager with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
    if (super.performAccessibilityAction(host, action, args)) {
        return true;
    }
    switch (action) {
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
            if (canScrollHorizontally(1)) {
                setCurrentItem(mCurItem + 1);
                return true;
            }
        } return false;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
            if (canScrollHorizontally(-1)) {
                setCurrentItem(mCurItem - 1);
                return true;
            }
        } return false;
    }
    return false;
}
 
Example #22
Source File: MarginDrawerLayout.java    From something.apk with MIT License 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);

    superNode.recycle();

    addChildrenForAccessibility(info, (ViewGroup) host);
}
 
Example #23
Source File: DefaultBrailleRule.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private CharSequence getFallbackText(
    Context context,
    AccessibilityNodeInfoCompat node) {
    // Order is important below because of class inheritance.
    if (matchesAny(context, node, Button.class, ImageButton.class)) {
        return context.getString(R.string.type_button);
    }
    if (matchesAny(context, node, QuickContactBadge.class)) {
        return context.getString(R.string.type_quickcontact);
    }
    if (matchesAny(context, node, ImageView.class)) {
        return context.getString(R.string.type_image);
    }
    if (matchesAny(context, node, EditText.class)) {
        return context.getString(R.string.type_edittext);
    }
    if (matchesAny(context, node, AbsSeekBar.class)) {
        return context.getString(R.string.type_seekbar);
    }
    return "";
}
 
Example #24
Source File: AutomationUtils.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether a node matches the class specified by
 * {@code className} and exactly match the text or content description
 * specified by {@code text}.
 */
private static boolean nodeMatchesFilter(Context context, AccessibilityNodeInfoCompat node,
        CharSequence referenceClassName, String findText) {
    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence nodeClass = node.getClassName();
    final CharSequence nodePackage = node.getPackageName();

    if (!loader.checkInstanceOf(context, nodeClass, nodePackage, referenceClassName)) {
        return false;
    }

    final CharSequence nodeText = node.getText();
    if (TextUtils.equals(findText, nodeText)) {
        return true;
    }

    final CharSequence nodeDesc = node.getContentDescription();
    if (TextUtils.equals(findText, nodeDesc)) {
        return true;
    }

    return false;
}
 
Example #25
Source File: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 5 votes vote down vote up
private static boolean isSpeakingNode(Context context, AccessibilityNodeInfoCompat node) {
    if (hasText(node)) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE,
                "Speaking, has text");
        return true;
    }

    // Special case for check boxes.
    if (node.isCheckable()) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE,
                "Speaking, is checkable");
        return true;
    }

    // Special case for web content.
    if (WebInterfaceUtils.supportsWebActions(node)) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE,
                "Speaking, has web content");
        return true;
    }

    // Special case for containers with non-focusable content.
    if (hasNonActionableSpeakingChildren(context, node)) {
        LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE,
                "Speaking, has non-actionable speaking children");
        return true;
    }

    return false;
}
 
Example #26
Source File: RecyclerViewAccessibilityDelegate.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    if (mRecyclerView.getLayoutManager() != null) {
        mRecyclerView.getLayoutManager().
                onInitializeAccessibilityNodeInfoForItem(host, info);
    }
}
 
Example #27
Source File: MonthView.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
public void clearFocusedVirtualView() {
    final int focusedVirtualView = getFocusedVirtualView();
    if (focusedVirtualView != ExploreByTouchHelper.INVALID_ID) {
        getAccessibilityNodeProvider(MonthView.this).performAction(
                focusedVirtualView,
                AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
                null);
    }
}
 
Example #28
Source File: SearchNavigationMode.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Syncs accessibility focus back to the node focused when search mode
 * first activated.
 */
private void syncBackToInitial() {
    AccessibilityNodeInfoCompat focused = FocusFinder.getFocusedNode(
                    mAccessibilityService, false);
    if (focused == null) {
        return;
    }
    try {
        mInitialNode.reset(AccessibilityNodeInfoUtils.refreshNode(
                    mInitialNode.get()));
        if (!AccessibilityNodeInfoRef.isNull(mInitialNode)) {
            if (mInitialNode.get().isAccessibilityFocused()) {
                return;
            }
            mFeedbackManager.emitOnFailure(
                mInitialNode.get().performAction(
                    AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS),
                    FeedbackManager.TYPE_COMMAND_FAILED);
        } else {
            mFeedbackManager.emitOnFailure(
                focused.performAction(AccessibilityNodeInfoCompat.
                        ACTION_CLEAR_ACCESSIBILITY_FOCUS),
                FeedbackManager.TYPE_COMMAND_FAILED);
        }
    } finally {
        focused.recycle();
    }
}
 
Example #29
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
private AccessibilityNodeInfoCompat createNode(int virtualViewId) {
    switch (virtualViewId) {
        case -1:
            return createNodeForHost();
        default:
            return createNodeForChild(virtualViewId);
    }
}
 
Example #30
Source File: ViewPager.java    From android-movies-demo with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    info.setClassName(ViewPager.class.getName());
    info.setScrollable(canScroll());
    if (canScrollHorizontally(1)) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
    }
    if (canScrollHorizontally(-1)) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
    }
}