Java Code Examples for android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#setBoundsInParent()
The following examples show how to use
android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#setBoundsInParent() .
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: KlyphDrawerLayout.java From Klyph with MIT License | 6 votes |
/** * 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 2
Source File: CompositorViewHolder.java From 365browser with Apache License 2.0 | 6 votes |
@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 3
Source File: RadialTimePickerView.java From SublimePicker with Apache License 2.0 | 6 votes |
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { node.setClassName(getClass().getName()); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); final int type = getTypeFromId(virtualViewId); final int value = getValueFromId(virtualViewId); final CharSequence description = getVirtualViewDescription(type, value); node.setContentDescription(description); getBoundsForVirtualView(virtualViewId, mTempRect); node.setBoundsInParent(mTempRect); final boolean selected = isVirtualViewSelected(type, value); node.setSelected(selected); final int nextId = getVirtualViewIdAfter(type, value); if (nextId != INVALID_ID) { node.setTraversalBefore(RadialTimePickerView.this, nextId); } }
Example 4
Source File: MarginDrawerLayout.java From something.apk with MIT License | 6 votes |
/** * 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 5
Source File: CompositorViewHolder.java From delion with Apache License 2.0 | 6 votes |
@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 6
Source File: DebugDrawerLayout.java From u2020 with Apache License 2.0 | 6 votes |
/** * 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 7
Source File: DrawerLayout.java From adt-leanback-support with Apache License 2.0 | 6 votes |
/** * 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 8
Source File: SlidingPaneLayout.java From letv with Apache License 2.0 | 6 votes |
private void copyNodeInfoNoChildren(AccessibilityNodeInfoCompat dest, AccessibilityNodeInfoCompat src) { Rect rect = this.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()); dest.setMovementGranularities(src.getMovementGranularities()); }
Example 9
Source File: MonthView.java From narrate-android with Apache License 2.0 | 5 votes |
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { getItemBounds(virtualViewId, mTempRect); node.setContentDescription(getItemDescription(virtualViewId)); node.setBoundsInParent(mTempRect); node.addAction(AccessibilityNodeInfo.ACTION_CLICK); if (virtualViewId == mSelectedDay) { node.setSelected(true); } }
Example 10
Source File: SimpleMonthView.java From AppCompat-Extension-Library with Apache License 2.0 | 5 votes |
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { final boolean hasBounds = getBoundsForDay(virtualViewId, mTempRect); if (!hasBounds) { // The day is invalid, kill the node. mTempRect.setEmpty(); node.setContentDescription(""); node.setBoundsInParent(mTempRect); node.setVisibleToUser(false); return; } node.setText(getDayText(virtualViewId)); node.setContentDescription(getDayDescription(virtualViewId)); node.setBoundsInParent(mTempRect); final boolean isDayEnabled = isDayEnabled(virtualViewId); if (isDayEnabled) { node.addAction(AccessibilityActionCompat.ACTION_CLICK); } node.setEnabled(isDayEnabled); if (virtualViewId == mActivatedDay) { // TODO: This should use activated once that's supported. node.setChecked(true); } }
Example 11
Source File: SlidingPaneLayout.java From adt-leanback-support with Apache License 2.0 | 5 votes |
/** * 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()); dest.setMovementGranularities(src.getMovementGranularities()); }
Example 12
Source File: SlidingPaneLayout.java From V.FlyoutTest with MIT License | 5 votes |
/** * 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()); dest.setMovementGranularities(src.getMovementGranularities()); }
Example 13
Source File: MonthView.java From date_picker_converter with Apache License 2.0 | 5 votes |
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { getItemBounds(virtualViewId, mTempRect); node.setContentDescription(getItemDescription(virtualViewId)); node.setBoundsInParent(mTempRect); node.addAction(AccessibilityNodeInfo.ACTION_CLICK); if (virtualViewId == mSelectedDay) { node.setSelected(true); } }
Example 14
Source File: SlidingPaneLayout.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * 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()); dest.setMovementGranularities(src.getMovementGranularities()); }
Example 15
Source File: SlidingPaneLayout.java From android-recipes-app with Apache License 2.0 | 5 votes |
/** * 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()); dest.setMovementGranularities(src.getMovementGranularities()); }
Example 16
Source File: ExploreByTouchHelper.java From android-recipes-app with Apache License 2.0 | 4 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * specified item. Automatically manages accessibility focus actions. * <p> * Allows the implementing class to specify most node properties, but * overrides the following: * <ul> * <li>{@link AccessibilityNodeInfoCompat#setPackageName} * <li>{@link AccessibilityNodeInfoCompat#setClassName} * <li>{@link AccessibilityNodeInfoCompat#setParent(View)} * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)} * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser} * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)} * </ul> * <p> * Uses the bounds of the parent view and the parent-relative bounding * rectangle specified by * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically * update the following properties: * <ul> * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser} * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent} * </ul> * * @param virtualViewId The virtual view id for item for which to construct * a node. * @return An {@link AccessibilityNodeInfoCompat} for the specified item. */ private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); // Ensure the client has good defaults. node.setEnabled(true); node.setClassName(DEFAULT_CLASS_NAME); // Allow the client to populate the node. onPopulateNodeForVirtualView(virtualViewId, node); // Make sure the developer is following the rules. if ((node.getText() == null) && (node.getContentDescription() == null)) { throw new RuntimeException("Callbacks must add text or a content description in " + "populateNodeForVirtualViewId()"); } node.getBoundsInParent(mTempParentRect); if (mTempParentRect.isEmpty()) { throw new RuntimeException("Callbacks must set parent bounds in " + "populateNodeForVirtualViewId()"); } final int actions = node.getActions(); if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) { throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) { throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()"); } // Don't allow the client to override these properties. node.setPackageName(mView.getContext().getPackageName()); node.setSource(mView, virtualViewId); node.setParent(mView); // Manage internal accessibility focus state. if (mFocusedVirtualViewId == virtualViewId) { node.setAccessibilityFocused(true); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { node.setAccessibilityFocused(false); node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } // Set the visibility based on the parent bound. if (intersectVisibleToUser(mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(mTempParentRect); } // Calculate screen-relative bound. mView.getLocationOnScreen(mTempGlobalRect); final int offsetX = mTempGlobalRect[0]; final int offsetY = mTempGlobalRect[1]; mTempScreenRect.set(mTempParentRect); mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(mTempScreenRect); return node; }
Example 17
Source File: TouchExplorationHelper.java From DateTimepicker with Apache License 2.0 | 4 votes |
private AccessibilityNodeInfoCompat populateNodeForItemInternal( T item, AccessibilityNodeInfoCompat node) { final int virtualDescendantId = getIdForItem(item); // Ensure the client has good defaults. node.setEnabled(true); // Allow the client to populate the node. populateNodeForItem(item, node); if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) { throw new RuntimeException( "You must add text or a content description in populateNodeForItem()"); } // Don't allow the client to override these properties. node.setPackageName(mParentView.getContext().getPackageName()); node.setClassName(item.getClass().getName()); node.setParent(mParentView); node.setSource(mParentView, virtualDescendantId); if (mFocusedItemId == virtualDescendantId) { node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } node.getBoundsInParent(mTempParentRect); if (mTempParentRect.isEmpty()) { throw new RuntimeException("You must set parent bounds in populateNodeForItem()"); } // Set the visibility based on the parent bound. if (intersectVisibleToUser(mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(mTempParentRect); } // Calculate screen-relative bound. mParentView.getLocationOnScreen(mTempGlobalRect); final int offsetX = mTempGlobalRect[0]; final int offsetY = mTempGlobalRect[1]; mTempScreenRect.set(mTempParentRect); mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(mTempScreenRect); return node; }
Example 18
Source File: ExploreByTouchHelper.java From V.FlyoutTest with MIT License | 4 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * specified item. Automatically manages accessibility focus actions. * <p> * Allows the implementing class to specify most node properties, but * overrides the following: * <ul> * <li>{@link AccessibilityNodeInfoCompat#setPackageName} * <li>{@link AccessibilityNodeInfoCompat#setClassName} * <li>{@link AccessibilityNodeInfoCompat#setParent(View)} * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)} * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser} * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)} * </ul> * <p> * Uses the bounds of the parent view and the parent-relative bounding * rectangle specified by * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically * update the following properties: * <ul> * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser} * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent} * </ul> * * @param virtualViewId The virtual view id for item for which to construct * a node. * @return An {@link AccessibilityNodeInfoCompat} for the specified item. */ private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); // Ensure the client has good defaults. node.setEnabled(true); node.setClassName(DEFAULT_CLASS_NAME); // Allow the client to populate the node. onPopulateNodeForVirtualView(virtualViewId, node); // Make sure the developer is following the rules. if ((node.getText() == null) && (node.getContentDescription() == null)) { throw new RuntimeException("Callbacks must add text or a content description in " + "populateNodeForVirtualViewId()"); } node.getBoundsInParent(mTempParentRect); if (mTempParentRect.isEmpty()) { throw new RuntimeException("Callbacks must set parent bounds in " + "populateNodeForVirtualViewId()"); } final int actions = node.getActions(); if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) { throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) { throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()"); } // Don't allow the client to override these properties. node.setPackageName(mView.getContext().getPackageName()); node.setSource(mView, virtualViewId); node.setParent(mView); // Manage internal accessibility focus state. if (mFocusedVirtualViewId == virtualViewId) { node.setAccessibilityFocused(true); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { node.setAccessibilityFocused(false); node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } // Set the visibility based on the parent bound. if (intersectVisibleToUser(mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(mTempParentRect); } // Calculate screen-relative bound. mView.getLocationOnScreen(mTempGlobalRect); final int offsetX = mTempGlobalRect[0]; final int offsetY = mTempGlobalRect[1]; mTempScreenRect.set(mTempParentRect); mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(mTempScreenRect); return node; }
Example 19
Source File: ExploreByTouchHelper.java From letv with Apache License 2.0 | 4 votes |
private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) { AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); node.setEnabled(true); node.setClassName(DEFAULT_CLASS_NAME); onPopulateNodeForVirtualView(virtualViewId, node); if (node.getText() == null && node.getContentDescription() == null) { throw new RuntimeException("Callbacks must add text or a content description in populateNodeForVirtualViewId()"); } node.getBoundsInParent(this.mTempParentRect); if (this.mTempParentRect.isEmpty()) { throw new RuntimeException("Callbacks must set parent bounds in populateNodeForVirtualViewId()"); } int actions = node.getActions(); if ((actions & 64) != 0) { throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()"); } else if ((actions & 128) != 0) { throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()"); } else { node.setPackageName(this.mView.getContext().getPackageName()); node.setSource(this.mView, virtualViewId); node.setParent(this.mView); if (this.mFocusedVirtualViewId == virtualViewId) { node.setAccessibilityFocused(true); node.addAction(128); } else { node.setAccessibilityFocused(false); node.addAction(64); } if (intersectVisibleToUser(this.mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(this.mTempParentRect); } this.mView.getLocationOnScreen(this.mTempGlobalRect); int offsetX = this.mTempGlobalRect[0]; int offsetY = this.mTempGlobalRect[1]; this.mTempScreenRect.set(this.mTempParentRect); this.mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(this.mTempScreenRect); return node; } }
Example 20
Source File: ExploreByTouchHelper.java From adt-leanback-support with Apache License 2.0 | 4 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * specified item. Automatically manages accessibility focus actions. * <p> * Allows the implementing class to specify most node properties, but * overrides the following: * <ul> * <li>{@link AccessibilityNodeInfoCompat#setPackageName} * <li>{@link AccessibilityNodeInfoCompat#setClassName} * <li>{@link AccessibilityNodeInfoCompat#setParent(View)} * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)} * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser} * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)} * </ul> * <p> * Uses the bounds of the parent view and the parent-relative bounding * rectangle specified by * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically * update the following properties: * <ul> * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser} * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent} * </ul> * * @param virtualViewId The virtual view id for item for which to construct * a node. * @return An {@link AccessibilityNodeInfoCompat} for the specified item. */ private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); // Ensure the client has good defaults. node.setEnabled(true); node.setClassName(DEFAULT_CLASS_NAME); // Allow the client to populate the node. onPopulateNodeForVirtualView(virtualViewId, node); // Make sure the developer is following the rules. if ((node.getText() == null) && (node.getContentDescription() == null)) { throw new RuntimeException("Callbacks must add text or a content description in " + "populateNodeForVirtualViewId()"); } node.getBoundsInParent(mTempParentRect); if (mTempParentRect.isEmpty()) { throw new RuntimeException("Callbacks must set parent bounds in " + "populateNodeForVirtualViewId()"); } final int actions = node.getActions(); if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) { throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) { throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()"); } // Don't allow the client to override these properties. node.setPackageName(mView.getContext().getPackageName()); node.setSource(mView, virtualViewId); node.setParent(mView); // Manage internal accessibility focus state. if (mFocusedVirtualViewId == virtualViewId) { node.setAccessibilityFocused(true); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { node.setAccessibilityFocused(false); node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } // Set the visibility based on the parent bound. if (intersectVisibleToUser(mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(mTempParentRect); } // Calculate screen-relative bound. mView.getLocationOnScreen(mTempGlobalRect); final int offsetX = mTempGlobalRect[0]; final int offsetY = mTempGlobalRect[1]; mTempScreenRect.set(mTempParentRect); mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(mTempScreenRect); return node; }