Java Code Examples for android.view.accessibility.AccessibilityNodeInfo#addAction()

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#addAction() . 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: GridView.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
/** @hide */
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfoInternal(info);

    final int columnsCount = getNumColumns();
    final int rowsCount = getCount() / columnsCount;
    final int selectionMode = getSelectionModeForAccessibility();
    final CollectionInfo collectionInfo = CollectionInfo.obtain(
            rowsCount, columnsCount, false, selectionMode);
    info.setCollectionInfo(collectionInfo);

    if (columnsCount > 0 || rowsCount > 0) {
        info.addAction(AccessibilityAction.ACTION_SCROLL_TO_POSITION);
    }
}
 
Example 2
Source File: PhotoAttachPhotoCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setEnabled(true);
    if (photoEntry != null && photoEntry.isVideo) {
        info.setText(LocaleController.getString("AttachVideo", R.string.AttachVideo) + ", " + LocaleController.formatCallDuration(photoEntry.duration));
    } else {
        info.setText(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
    }
    if (checkBox.isChecked()) {
        info.setSelected(true);
    }
    if (Build.VERSION.SDK_INT >= 21) {
        info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.acc_action_open_photo, LocaleController.getString("Open", R.string.Open)));
    }
}
 
Example 3
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
        int left, int top, int right, int bottom) {
    AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
    info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    info.setVisibleToUser(getVisibility() == View.VISIBLE);
    info.setBoundsInParent(boundsInParent);
    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    info.setBoundsInScreen(boundsInScreen);
    return info;
}
 
Example 4
Source File: SwitchAccessHighlightFeedbackController.java    From talkback with Apache License 2.0 6 votes vote down vote up
private void speakFeedbackForGlobalMenuButton(boolean speakHints) {
  // Manually construct an AccessibilityEvent and an AccessibilityNodeInfoCompat, which will be
  // used by the compositor to compose spoken feedback, for the global Switch Access menu button.
  final AccessibilityEvent event = AccessibilityEvent.obtain();
  final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();

  event.setEventType(TYPE_VIEW_FOCUSED);
  node.setEnabled(true);
  node.setContentDescription(
      context.getString(R.string.option_scanning_menu_button_content_description));
  node.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
  node.setClassName(OverlayActionNode.class.getName());
  CompatUtils.invoke(
      node,
      null,
      CompatUtils.getMethod(AccessibilityNodeInfo.class, "setSealed", boolean.class),
      true);
  SwitchAccessNodeCompat nodeInfoCompat = new SwitchAccessNodeCompat(node);

  hintsManager.postHintForNode(event, nodeInfoCompat);

  compositor.handleEvent(
      AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, nodeInfoCompat, EVENT_ID_UNTRACKED);

  isLastSpeech = !speakHints;
}
 
Example 5
Source File: RadialTimePickerView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo node) {
    node.setClassName(getClass().getName());
    node.addAction(AccessibilityAction.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 6
Source File: PagedView.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setScrollable(getPageCount() > 1);
    if (getCurrentPage() < getPageCount() - 1) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
    }
    if (getCurrentPage() > 0) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    }
    info.setClassName(getClass().getName());

    // Accessibility-wise, PagedView doesn't support long click, so disabling it.
    // Besides disabling the accessibility long-click, this also prevents this view from getting
    // accessibility focus.
    info.setLongClickable(false);
    info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
}
 
Example 7
Source File: NumberPicker.java    From zen4android with MIT License 5 votes vote down vote up
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText() {
    AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
    info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    return info;
}
 
Example 8
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected void addAction(AccessibilityNodeInfo node, int actionId) {
    // Before API level 21, it's not possible to expose actions other than the "legacy standard"
    // ones.
    if (actionId > AccessibilityNodeInfo.ACTION_SET_TEXT) return;

    node.addAction(actionId);
}
 
Example 9
Source File: PagingDayPickerView.java    From BottomSheetPickers with Apache License 2.0 5 votes vote down vote up
/**
 * Necessary for accessibility, to ensure we support "scrolling" forward and backward
 * in the month list.
 */
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
  info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
 
Example 10
Source File: DraggableCardFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(host, info);
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    return;
  }

  CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) card
      .getLayoutParams();
  int gravity = layoutParams.gravity;
  boolean isOnLeft = (gravity & Gravity.LEFT) == Gravity.LEFT;
  boolean isOnRight = (gravity & Gravity.RIGHT) == Gravity.RIGHT;
  boolean isOnTop = (gravity & Gravity.TOP) == Gravity.TOP;
  boolean isOnBottom = (gravity & Gravity.BOTTOM) == Gravity.BOTTOM;
  boolean isOnCenter = (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.CENTER_HORIZONTAL;

  if (!(isOnTop && isOnLeft)) {
    info.addAction(new AccessibilityAction(R.id.move_card_top_left_action,
        getString(R.string.cat_card_action_move_top_left)));
  }
  if (!(isOnTop && isOnRight)) {
    info.addAction(new AccessibilityAction(R.id.move_card_top_right_action,
        getString(R.string.cat_card_action_move_top_right)));
  }
  if (!(isOnBottom && isOnLeft)) {
    info.addAction(new AccessibilityAction(R.id.move_card_bottom_left_action,
        getString(R.string.cat_card_action_move_bottom_left)));
  }
  if (!(isOnBottom && isOnRight)) {
    info.addAction(new AccessibilityAction(
        R.id.move_card_bottom_right_action,
        getString(R.string.cat_card_action_move_bottom_right)));
  }
  if (!isOnCenter) {
    info.addAction(new AccessibilityAction(
        R.id.move_card_center_action,
        getString(R.string.cat_card_action_move_center)));
  }
}
 
Example 11
Source File: SeekBar.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfoInternal(info);

    if (canUserSetProgress()) {
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_PROGRESS);
    }
}
 
Example 12
Source File: RadialPickerLayout.java    From StyleableDateTimePicker with MIT License 5 votes vote down vote up
/**
 * Necessary for accessibility, to ensure we support "scrolling" forward and backward
 * in the circle.
 */
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
  info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
 
Example 13
Source File: DayPickerView.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
/**
 * Necessary for accessibility, to ensure we support "scrolling" forward and backward
 * in the month list.
 */
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
    info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
 
Example 14
Source File: RadialPickerLayout.java    From AlarmOn with Apache License 2.0 5 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 {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    }
}
 
Example 15
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setScrollable(getPageCount() > 1);
    if (getCurrentPage() < getPageCount() - 1) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
    }
    if (getCurrentPage() > 0) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    }
}
 
Example 16
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo 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(AccessibilityAction.ACTION_CLICK);
    }

    node.setEnabled(isDayEnabled);

    if (virtualViewId == mActivatedDay) {
        // TODO: This should use activated once that's supported.
        node.setChecked(true);
    }

}
 
Example 17
Source File: SdkCenteredViewPager.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info)
{
    super.onInitializeAccessibilityNodeInfo( host, info );
    info.setClassName( SdkCenteredViewPager.class.getName() );
    info.setScrollable( canScroll() );
    if ( canScrollHorizontally( 1 ) )
    {
        info.addAction( AccessibilityNodeInfo.ACTION_SCROLL_FORWARD );
    }
    if ( canScrollHorizontally( -1 ) )
    {
        info.addAction( AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD );
    }
}
 
Example 18
Source File: RadialPickerLayout.java    From DateTimepicker with Apache License 2.0 5 votes vote down vote up
/**
 * Necessary for accessibility, to ensure we support "scrolling" forward and backward
 * in the circle.
 */
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
  info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
 
Example 19
Source File: PersianRadialPickerLayout.java    From PersianDateRangePicker with Apache License 2.0 5 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 {
    info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
    info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
  }
}
 
Example 20
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
        int right, int bottom) {
    AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
    info.setClassName(NumberPicker.class.getName());
    info.setPackageName(mContext.getPackageName());
    info.setSource(NumberPicker.this);

    if (hasVirtualDecrementButton()) {
        info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
    }
    info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (hasVirtualIncrementButton()) {
        info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
    }

    info.setParent((View) getParentForAccessibility());
    info.setEnabled(NumberPicker.this.isEnabled());
    info.setScrollable(true);

    final float applicationScale =
        getContext().getResources().getCompatibilityInfo().applicationScale;

    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    boundsInParent.scale(applicationScale);
    info.setBoundsInParent(boundsInParent);

    info.setVisibleToUser(isVisibleToUser());

    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    boundsInScreen.scale(applicationScale);
    info.setBoundsInScreen(boundsInScreen);

    if (mAccessibilityFocusedView != View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    if (NumberPicker.this.isEnabled()) {
        if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        }
        if (getWrapSelectorWheel() || getValue() > getMinValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    }

    return info;
}