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

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#setContentDescription() . 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: DrawerLayout.java    From Dashchan with Apache License 2.0 7 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(AccessibilityNodeInfo dest, AccessibilityNodeInfo 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: 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 3
Source File: DefaultTimeBar.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(21)
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName(ACCESSIBILITY_CLASS_NAME);
    info.setContentDescription(getProgressText());
    if (duration <= 0) {
        return;
    }
    if (Util.SDK_INT >= 21) {
        info.addAction(AccessibilityAction.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityAction.ACTION_SCROLL_BACKWARD);
    } else {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    }
}
 
Example 4
Source File: BottomNavigationItemView.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  if (badgeDrawable != null && badgeDrawable.isVisible()) {
    CharSequence customContentDescription = itemData.getTitle();
    if (!TextUtils.isEmpty(itemData.getContentDescription())) {
      customContentDescription = itemData.getContentDescription();
    }
    info.setContentDescription(
        customContentDescription + ", " + badgeDrawable.getContentDescription());
  }
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionItemInfo(
      CollectionItemInfoCompat.obtain(
          /* rowIndex= */ 0,
          /* rowSpan= */ 1,
          /* columnIndex= */ getItemPosition(),
          /* columnSpan= */ 1,
          /* heading= */ false,
          /* selected= */ isSelected()));
  if (isSelected()) {
    infoCompat.setClickable(false);
    infoCompat.removeAction(AccessibilityActionCompat.ACTION_CLICK);
  }
  infoCompat.setRoleDescription(getResources().getString(R.string.item_view_role_description));
}
 
Example 5
Source File: TabLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  if (badgeDrawable != null && badgeDrawable.isVisible()) {
    CharSequence customContentDescription = getContentDescription();
    info.setContentDescription(
        customContentDescription + ", " + badgeDrawable.getContentDescription());
  }
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionItemInfo(
      CollectionItemInfoCompat.obtain(
          /* rowIndex= */ 0,
          /* rowSpan= */ 1,
          /* columnIndex= */ tab.getPosition(),
          /* columnSpan= */ 1,
          /* heading= */ false,
          /* selected= */ isSelected()));
  if (isSelected()) {
    infoCompat.setClickable(false);
    infoCompat.removeAction(AccessibilityActionCompat.ACTION_CLICK);
  }
  infoCompat.setRoleDescription("Tab");
}
 
Example 6
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 7
Source File: StickerEmojiCell.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);
    String descr = LocaleController.getString("AttachSticker", R.string.AttachSticker);
    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.alt != null && attribute.alt.length() > 0) {
                emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                descr = attribute.alt + " " + descr;
            }
            break;
        }
    }
    info.setContentDescription(descr);
    info.setEnabled(true);
}
 
Example 8
Source File: StickerEmojiCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    String descr = LocaleController.getString("AttachSticker", R.string.AttachSticker);
    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.alt != null && attribute.alt.length() > 0) {
                emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                descr = attribute.alt + " " + descr;
            }
            break;
        }
    }
    info.setContentDescription(descr);
    info.setEnabled(true);
}
 
Example 9
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 10
Source File: EditTextBoldCursor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName("android.widget.EditText");
    if (hintLayout != null) {
        info.setContentDescription(hintLayout.getText());
    }
}
 
Example 11
Source File: TextCheckCell2.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName("android.widget.Switch");
    info.setCheckable(true);
    info.setChecked(checkBox.isChecked());
    info.setContentDescription(checkBox.isChecked() ? LocaleController.getString("NotificationsOn", R.string.NotificationsOn) : LocaleController.getString("NotificationsOff", R.string.NotificationsOff));
}
 
Example 12
Source File: TextCheckCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName("android.widget.Switch");
    info.setCheckable(true);
    info.setChecked(checkBox.isChecked());
    info.setContentDescription(checkBox.isChecked() ? LocaleController.getString("NotificationsOn", R.string.NotificationsOn) : LocaleController.getString("NotificationsOff", R.string.NotificationsOff));
}
 
Example 13
Source File: EditTextBoldCursor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName("android.widget.EditText");
    if (hintLayout != null) {
        info.setContentDescription(hintLayout.getText());
    }
}
 
Example 14
Source File: TextCheckCell2.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName("android.widget.Switch");
    info.setCheckable(true);
    info.setChecked(checkBox.isChecked());
    info.setContentDescription(checkBox.isChecked() ? LocaleController.getString("NotificationsOn", R.string.NotificationsOn) : LocaleController.getString("NotificationsOff", R.string.NotificationsOff));
}
 
Example 15
Source File: TextCheckCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName("android.widget.Switch");
    info.setCheckable(true);
    info.setChecked(checkBox.isChecked());
    info.setContentDescription(checkBox.isChecked() ? LocaleController.getString("NotificationsOn", R.string.NotificationsOn) : LocaleController.getString("NotificationsOff", R.string.NotificationsOff));
}
 
Example 16
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@CalledByNative
private void setAccessibilityNodeInfoText(AccessibilityNodeInfo node, String text,
        boolean annotateAsLink, boolean isEditableText, String language) {
    CharSequence computedText = computeText(text, isEditableText, language);
    if (isEditableText) {
        node.setText(computedText);
    } else {
        node.setContentDescription(computedText);
    }
}
 
Example 17
Source File: MaterialTapTargetPrompt.java    From MaterialTapTargetPrompt with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info)
{
    super.onInitializeAccessibilityNodeInfo(host, info);

    @Nullable final Package viewPackage = PromptView.this.getClass().getPackage();
    if (viewPackage != null)
    {
        info.setPackageName(viewPackage.getName());
    }
    info.setSource(host);
    info.setClickable(true);
    info.setEnabled(true);
    info.setChecked(false);
    info.setFocusable(true);
    info.setFocused(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
    {
        info.setLabelFor(mPromptOptions.getTargetView());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        info.setDismissable(true);
    }

    info.setContentDescription(mPromptOptions.getContentDescription());
    info.setText(mPromptOptions.getContentDescription());
}
 
Example 18
Source File: MultiSlider.java    From MultiSlider with Apache License 2.0 4 votes vote down vote up
@Override
public AccessibilityNodeInfo createAccessibilityNodeInfo(int thumbId) {
    AccessibilityNodeInfo info = null;
    if (thumbId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree. Note that the
        // host View has an AccessibilityNodeProvider which means that this
        // provider is responsible for creating the node info for that root.
        info = AccessibilityNodeInfo.obtain(MultiSlider.this);
        onInitializeAccessibilityNodeInfo(info);
        // Add the virtual children of the root View.
        final int childCount = mThumbs.size();
        for (int i = 0; i < childCount; i++) {
            info.addChild(MultiSlider.this, i);
        }
        if (mThumbs.size() == 1) {
            info.setScrollable(true);
            if (Build.VERSION.SDK_INT >= 21) {
                info.addAction(ACTION_SET_PROGRESS);
                info.addAction(ACTION_SCROLL_BACKWARD);
                info.addAction(ACTION_SCROLL_FORWARD);
            } else {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }

        }

    } else {
        // Find the view that corresponds to the given id.
        Thumb thumb = mThumbs.get(thumbId);
        if (thumb == null) {
            return null;
        }
        // Obtain and initialize an AccessibilityNodeInfo with
        // information about the virtual view.
        info = AccessibilityNodeInfo.obtain(MultiSlider.this, thumbId);
        info.setClassName(thumb.getClass().getName());
        info.setParent(MultiSlider.this);
        info.setSource(MultiSlider.this, thumbId);
        info.setContentDescription("Multi-Slider thumb no:" + thumbId);

        if (Build.VERSION.SDK_INT >= 21) {
            info.addAction(ACTION_SET_PROGRESS);
            if (thumb.getPossibleMax() > thumb.value) {
                info.addAction(ACTION_SCROLL_BACKWARD);
            }
            if (thumb.getPossibleMax() > thumb.value) {
                info.addAction(ACTION_SCROLL_FORWARD);
            }

        } else {
            if (thumb.getPossibleMin() > thumb.value) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
            }
            if (thumb.getPossibleMax() > thumb.value) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
        }


        if (thumb.getThumb() != null) {
            int[] loc = new int[2];
            getLocationOnScreen(loc);
            Rect rect = thumb.getThumb().copyBounds();
            rect.top += loc[1];
            rect.left += loc[0];
            rect.right += loc[0];
            rect.bottom += loc[1];
            info.setBoundsInScreen(rect);
            //TODO somehow this resuls in [0,0][0,0]. wonder check why
            //info.setBoundsInParent(rect);

        }

        info.setText(thumb.tag + ": " + thumb.value);
        info.setEnabled(thumb.isEnabled());
        if (Build.VERSION.SDK_INT >= 24) {
            info.setImportantForAccessibility(true);
        }
        info.setVisibleToUser(true);
        info.setScrollable(true);
    }
    return info;
}
 
Example 19
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private void setAccessibilityNodeInfoStringAttributes(AccessibilityNodeInfo node,
        String className, String contentDescription) {
    node.setClassName(className);
    node.setContentDescription(contentDescription);
}
 
Example 20
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private void setAccessibilityNodeInfoStringAttributes(AccessibilityNodeInfo node,
        String className, String contentDescription) {
    node.setClassName(className);
    node.setContentDescription(contentDescription);
}