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

The following examples show how to use android.view.accessibility.AccessibilityEvent#getContentDescription() . 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: ExploreByTouchHelper.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private AccessibilityEvent b(int l, int i1)
{
    AccessibilityEvent accessibilityevent = AccessibilityEvent.obtain(i1);
    accessibilityevent.setEnabled(true);
    accessibilityevent.setClassName(b);
    onPopulateEventForVirtualView(l, accessibilityevent);
    if (accessibilityevent.getText().isEmpty() && accessibilityevent.getContentDescription() == null)
    {
        throw new RuntimeException("Callbacks must add text or a content description in populateEventForVirtualViewId()");
    } else
    {
        accessibilityevent.setPackageName(h.getContext().getPackageName());
        AccessibilityEventCompat.asRecord(accessibilityevent).setSource(h, l);
        return accessibilityevent;
    }
}
 
Example 2
Source File: ExploreByTouchHelper.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);

    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateEventForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mView, virtualViewId);

    return event;
}
 
Example 3
Source File: ExploreByTouchHelper.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);

    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateEventForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mView, virtualViewId);

    return event;
}
 
Example 4
Source File: ExploreByTouchHelper.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);

    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateEventForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mView, virtualViewId);

    return event;
}
 
Example 5
Source File: ExploreByTouchHelper.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);

    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateEventForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mView, virtualViewId);

    return event;
}
 
Example 6
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);
    onPopulateEventForVirtualView(virtualViewId, event);
    if (event.getText().isEmpty() && event.getContentDescription() == null) {
        throw new RuntimeException("Callbacks must add text or a content description in populateEventForVirtualViewId()");
    }
    event.setPackageName(this.mView.getContext().getPackageName());
    AccessibilityEventCompat.asRecord(event).setSource(this.mView, virtualViewId);
    return event;
}
 
Example 7
Source File: AccessibilityEventUtils.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the text of an <code>event</code> by returning the content description
 * (if available) or by concatenating the text members (regardless of their
 * priority) using space as a delimiter.
 *
 * @param event The event.
 * @return The event text.
 */
public static CharSequence getEventTextOrDescription(AccessibilityEvent event) {
    if (event == null) {
        return null;
    }

    final CharSequence contentDescription = event.getContentDescription();

    if (!TextUtils.isEmpty(contentDescription)) {
        return contentDescription;
    }

    return getEventAggregateText(event);
}
 
Example 8
Source File: AccessibilityEventUtils.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the text of an <code>event</code> by returning the content description
 * (if available) or by concatenating the text members (regardless of their
 * priority) using space as a delimiter.
 * @param event The event.
 *
 * @return The event text.
 */
public static CharSequence getEventText(AccessibilityEvent event) {
    if (event == null) {
        return null;
    }

    final CharSequence contentDescription = event.getContentDescription();

    if (!TextUtils.isEmpty(contentDescription)) {
        return contentDescription;
    } else {
        return getEventAggregateText(event);
    }
}
 
Example 9
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the text of an <code>event</code> by returning the content description (if available) or
 * by concatenating the text members (regardless of their priority) using space as a delimiter.
 *
 * @param event The event.
 * @return The event text.
 */
public static CharSequence getEventTextOrDescription(AccessibilityEvent event) {
  if (event == null) {
    return null;
  }

  final CharSequence contentDescription = event.getContentDescription();

  if (!TextUtils.isEmpty(contentDescription)) {
    return contentDescription;
  }

  return getEventAggregateText(event);
}
 
Example 10
Source File: WindowEventInterpreter.java    From talkback with Apache License 2.0 5 votes vote down vote up
private CharSequence getWindowTitleFromWindowStateChange(
    AccessibilityEvent event, boolean useContentDescription) {
  if (useContentDescription && !TextUtils.isEmpty(event.getContentDescription())) {
    return event.getContentDescription();
  }

  List<CharSequence> titles = event.getText();
  if (!titles.isEmpty()) {
    return titles.get(0);
  }

  return null;
}
 
Example 11
Source File: ClockBackService.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Formats an utterance from an {@link AccessibilityEvent}.
 *
 * @param event The event from which to format an utterance.
 * @return The formatted utterance.
 */
private String formatUtterance(AccessibilityEvent event) {
    StringBuilder utterance = mUtterance;

    // Clear the utterance before appending the formatted text.
    utterance.setLength(0);

    List<CharSequence> eventText = event.getText();

    // We try to get the event text if such.
    if (!eventText.isEmpty()) {
        for (CharSequence subText : eventText) {
            // Make 01 pronounced as 1
            if (subText.charAt(0) =='0') {
                subText = subText.subSequence(1, subText.length());
            }
            utterance.append(subText);
            utterance.append(SPACE);
        }

        return utterance.toString();
    }

    // There is no event text but we try to get the content description which is
    // an optional attribute for describing a view (typically used with ImageView).
    CharSequence contentDescription = event.getContentDescription();
    if (contentDescription != null) {
        utterance.append(contentDescription);
        return utterance.toString();
    }

    return utterance.toString();
}
 
Example 12
Source File: AccessibilityEventUtils.java    From brailleback with Apache License 2.0 4 votes vote down vote up
/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 */
public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) {
    // TODO: The framework should implement AccessibilityEvent#equals()
    if (first == null || second == null) {
        return false;
    }
    if (first.getEventType() != second.getEventType()) {
        return false;
    }
    if (first.getPackageName() == null) {
        if (second.getPackageName() != null) {
            return false;
        }
    } else if (!first.getPackageName().equals(second.getPackageName())) {
        return false;
    }
    if (first.getClassName() == null) {
        if (second.getClassName() != null) {
            return false;
        }
    } else if (!first.getClassName().equals(second.getClassName())) {
        return false;
    }
    if (!first.getText().equals(second.getText())) {
        // The result of getText() is never null.
        return false;
    }
    if (first.getContentDescription() == null) {
        if (second.getContentDescription() != null) {
            return false;
        }
    } else if (!first.getContentDescription().equals(second.getContentDescription())) {
        return false;
    }
    if (first.getBeforeText() == null) {
        if (second.getBeforeText() != null) {
            return false;
        }
    } else if (!first.getBeforeText().equals(second.getBeforeText())) {
        return false;
    }
    if (first.getParcelableData() != null) {
        // Parcelable data may not implement equals() correctly.
        return false;
    }
    if (first.getAddedCount() != second.getAddedCount()) {
        return false;
    }
    if (first.isChecked() != second.isChecked()) {
        return false;
    }
    if (first.isEnabled() != second.isEnabled()) {
        return false;
    }
    if (first.getFromIndex() != second.getFromIndex()) {
        return false;
    }
    if (first.isFullScreen() != second.isFullScreen()) {
        return false;
    }
    if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
        return false;
    }
    if (first.getItemCount() != second.getItemCount()) {
        return false;
    }
    if (first.isPassword() != second.isPassword()) {
        return false;
    }
    if (first.getRemovedCount() != second.getRemovedCount()) {
        return false;
    }
    if (first.getEventTime() != second.getEventTime()) {
        return false;
    }
    return true;
}