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

The following examples show how to use android.view.accessibility.AccessibilityEvent#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: ActionBarContextView.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Action mode started
        //TODO event.setSource(this);
        event.setClassName(getClass().getName());
        event.setPackageName(getContext().getPackageName());
        event.setContentDescription(mTitle);
    } else {
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}
 
Example 2
Source File: RadialTimePickerView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setClassName(getClass().getName());

    final int type = getTypeFromId(virtualViewId);
    final int value = getValueFromId(virtualViewId);
    final CharSequence description = getVirtualViewDescription(type, value);
    event.setContentDescription(description);
}
 
Example 3
Source File: ActionBarContextView.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Action mode started
        //TODO event.setSource(this);
        event.setClassName(getClass().getName());
        event.setPackageName(getContext().getPackageName());
        event.setContentDescription(mTitle);
    } else {
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}
 
Example 4
Source File: DragAndDropAccessibilityDelegate.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int id, AccessibilityEvent event) {
    if (id == INVALID_ID) {
        throw new IllegalArgumentException("Invalid virtual view id");
    }
    event.setContentDescription(mContext.getString(R.string.action_move_here));
}
 
Example 5
Source File: RadialTimePickerView.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setClassName(getClass().getName());

    final int type = getTypeFromId(virtualViewId);
    final int value = getValueFromId(virtualViewId);
    final CharSequence description = getVirtualViewDescription(type, value);
    event.setContentDescription(description);
}
 
Example 6
Source File: RadialTimePickerView.java    From SublimePicker with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setClassName(getClass().getName());

    final int type = getTypeFromId(virtualViewId);
    final int value = getValueFromId(virtualViewId);
    final CharSequence description = getVirtualViewDescription(type, value);
    event.setContentDescription(description);
}
 
Example 7
Source File: KeyboardAccessibilityDelegate.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 */
protected void sendWindowStateChanged(final String text) {
    final AccessibilityEvent stateChange = AccessibilityEvent.obtain(
            AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    mKeyboardView.onInitializeAccessibilityEvent(stateChange);
    stateChange.getText().add(text);
    stateChange.setContentDescription(null);

    final ViewParent parent = mKeyboardView.getParent();
    if (parent != null) {
        parent.requestSendAccessibilityEvent(mKeyboardView, stateChange);
    }
}
 
Example 8
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    if (mVirtualViews == null || mVirtualViews.size() <= virtualViewId) {
        // TODO(clholgat): Remove this work around when the Android bug is fixed.
        // crbug.com/420177
        event.setContentDescription(PLACE_HOLDER_STRING);
        return;
    }
    VirtualView view = mVirtualViews.get(virtualViewId);

    event.setContentDescription(view.getAccessibilityDescription());
    event.setClassName(CompositorViewHolder.class.getName());
}
 
Example 9
Source File: DragAndDropAccessibilityDelegate.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int id, AccessibilityEvent event) {
    if (id == INVALID_ID) {
        throw new IllegalArgumentException("Invalid virtual view id");
    }
    event.setContentDescription(mContext.getString(R.string.action_move_here));
}
 
Example 10
Source File: TaskListView.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method will fire whenever a child event wants to send an AccessibilityEvent.  As a
 * result, it's a great place to add more AccessibilityRecords, if you want.  In this case,
 * the code is grabbing the position of the item in the list, and assuming that to be the
 * priority for the task.
 */
@Override
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
    // Add a record for ourselves as well.
    AccessibilityEvent record = AccessibilityEvent.obtain();
    super.onInitializeAccessibilityEvent(record);

    int priority = (Integer) child.getTag();
    String priorityStr = "Priority: " + priority;
    record.setContentDescription(priorityStr);

    event.appendRecord(record);
    return true;
}
 
Example 11
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    if (mVirtualViews == null || mVirtualViews.size() <= virtualViewId) {
        // TODO(clholgat): Remove this work around when the Android bug is fixed.
        // crbug.com/420177
        event.setContentDescription(PLACE_HOLDER_STRING);
        return;
    }
    VirtualView view = mVirtualViews.get(virtualViewId);

    event.setContentDescription(view.getAccessibilityDescription());
    event.setClassName(CompositorViewHolder.class.getName());
}
 
Example 12
Source File: TalkBackKeyboardShortcutPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Utility method for announcing text via accessibility event. */
public static void announceText(String text, Context context) {
  AccessibilityManager accessibilityManager =
      (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
  if (accessibilityManager.isEnabled()) {
    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
    event.setContentDescription(text);
    accessibilityManager.sendAccessibilityEvent(event);
  }
}
 
Example 13
Source File: RadialMenuView.java    From talkback with Apache License 2.0 4 votes vote down vote up
@Override
protected void populateEventForItem(RadialMenuItem item, AccessibilityEvent event) {
  event.setContentDescription(item.getTitle());
  event.setChecked(item.isChecked());
  event.setEnabled(item.isEnabled());
}
 
Example 14
Source File: MonthView.java    From StyleableDateTimePicker with MIT License 4 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setContentDescription(getItemDescription(virtualViewId));
}
 
Example 15
Source File: MonthView.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setContentDescription(getItemDescription(virtualViewId));
}
 
Example 16
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private void finishGranularityMove(String text, boolean extendSelection,
        int itemStartIndex, int itemEndIndex, boolean forwards) {
    if (mNativeObj == 0) return;

    // Prepare to send both a selection and a traversal event in sequence.
    AccessibilityEvent selectionEvent = buildAccessibilityEvent(mAccessibilityFocusId,
            AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
    if (selectionEvent == null) return;
    AccessibilityEvent traverseEvent = buildAccessibilityEvent(mAccessibilityFocusId,
            AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY);
    if (traverseEvent == null) {
        selectionEvent.recycle();
        return;
    }

    // Update the cursor or selection based on the traversal. If it's an editable
    // text node, set the real editing cursor too.
    if (forwards) {
        mSelectionEndIndex = itemEndIndex;
    } else {
        mSelectionEndIndex = itemStartIndex;
    }
    if (!extendSelection) {
        mSelectionStartIndex = mSelectionEndIndex;
    }
    if (nativeIsEditableText(mNativeObj, mAccessibilityFocusId)
            && nativeIsFocused(mNativeObj, mAccessibilityFocusId)) {
        nativeSetSelection(mNativeObj, mAccessibilityFocusId,
                mSelectionStartIndex, mSelectionEndIndex);
    }

    // The selection event's "from" and "to" indices are just a cursor at the focus
    // end of the movement, or a selection if extendSelection is true.
    selectionEvent.setFromIndex(mSelectionStartIndex);
    selectionEvent.setToIndex(mSelectionStartIndex);
    selectionEvent.setItemCount(text.length());

    // The traverse event's "from" and "to" indices surround the item (e.g. the word,
    // etc.) with no whitespace.
    traverseEvent.setFromIndex(itemStartIndex);
    traverseEvent.setToIndex(itemEndIndex);
    traverseEvent.setItemCount(text.length());
    traverseEvent.setMovementGranularity(mSelectionGranularity);
    traverseEvent.setContentDescription(text);

    // The traverse event needs to set its associated action that triggered it.
    if (forwards) {
        traverseEvent.setAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
    } else {
        traverseEvent.setAction(
                AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
    }

    mView.requestSendAccessibilityEvent(mView, selectionEvent);
    mView.requestSendAccessibilityEvent(mView, traverseEvent);
}
 
Example 17
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setContentDescription(getDayDescription(virtualViewId));
}
 
Example 18
Source File: MonthView.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, @NonNull AccessibilityEvent event) {
    event.setContentDescription(getItemDescription(virtualViewId));
}
 
Example 19
Source File: MonthView.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setContentDescription(getItemDescription(virtualViewId));
}
 
Example 20
Source File: SimpleMonthView.java    From AppCompat-Extension-Library with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
    event.setContentDescription(getDayDescription(virtualViewId));
}