Example usage for android.view.accessibility AccessibilityEvent getText

List of usage examples for android.view.accessibility AccessibilityEvent getText

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent getText.

Prototype

public List<CharSequence> getText() 

Source Link

Document

Gets the text of the event.

Usage

From source file:com.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.//from w  ww . j a  v  a2  s.c om
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

From source file:com.android.inputmethod.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken./*from   w  w w.  j ava  2s  .  co  m*/
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        Log.e(TAG, "Attempted to speak when accessibility was disabled!");
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 *///  w w w .  j  a  va 2s.  com
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);
    }
}

From source file:com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        super.onPopulateAccessibilityEvent(event);
    }//from w w  w.  ja  va2  s .  c  om
    final CharSequence cdesc = getContentDescription();
    if (!TextUtils.isEmpty(cdesc)) {
        event.getText().add(cdesc);
    }
}

From source file:com.onyx.latinime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 */// ww  w  .  j  av  a  2 s.c  o m
private void sendWindowStateChanged(final String text) {
    final AccessibilityEvent stateChange = AccessibilityEvent
            .obtain(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    mView.onInitializeAccessibilityEvent(stateChange);
    stateChange.getText().add(text);
    stateChange.setContentDescription(null);

    final ViewParent parent = mView.getParent();
    if (parent != null) {
        parent.requestSendAccessibilityEvent(mView, stateChange);
    }
}

From source file:com.android.talkback.eventprocessor.ProcessorScreen.java

private CharSequence getWindowTitleFromEvent(AccessibilityEvent event, boolean useContentDescription) {
    if (useContentDescription && !TextUtils.isEmpty(event.getContentDescription())) {
        return event.getContentDescription();
    }//w  w w .  j av a  2 s .  c om

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

    return null;
}

From source file:com.android.yijiang.kzx.widget.betterpickers.TouchExplorationHelper.java

private AccessibilityEvent getEventForItem(T item, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    event.setEnabled(true);// ww  w  . ja v a 2s. c om

    // Allow the client to populate the event.
    populateEventForItem(item, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setClassName(item.getClass().getName());
    event.setPackageName(mParentView.getContext().getPackageName());
    record.setSource(mParentView, virtualDescendantId);

    return event;
}

From source file:com.deange.datetimepicker.TouchExplorationHelper.java

private AccessibilityEvent getEventForItem(T item, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    event.setEnabled(true);//from   w ww.j  a  v  a  2s . c o m

    // Allow the client to populate the event.
    populateEventForItem(item, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don&#39;t allow the client to override these properties.
    event.setClassName(item.getClass().getName());
    event.setPackageName(mParentView.getContext().getPackageName());
    record.setSource(mParentView, virtualDescendantId);

    return event;
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

/**
 * ??//from   www  . j  a  va 2 s. c o  m
 *
 * @param event
 * @param className
 * @param sourceText
 */
private void processAlertDialogEvent(AccessibilityEvent event, String className, String sourceText) {
    Timber.d("");
    String eventText = event.getText().toString();

    if (eventText.contains(getString(R.string.str_accessibility_error))) {
        onInstallFail(event);
    } else if (!eventText.contains(getString(R.string.str_accessibility_uninstall))) {
        AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event,
                getString(R.string.btn_accessibility_ok));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            nodeInfo.recycle();
        }
    } else if (eventText.contains(getString(R.string.str_accessibility_replace))
            || eventText.contains(getString(R.string.str_accessibility_replace1))) {
        AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event,
                getString(R.string.btn_accessibility_ok));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            nodeInfo.recycle();
        }
    }
}

From source file:com.android.utils.ExploreByTouchHelper.java

/**
 * 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.//ww  w. j  a va2 s. co m
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);

    // Ensure the client has good defaults.
    event.setEnabled(true);
    event.setClassName(mHost.getClass().getName() + DEFAULT_CLASS_NAME);

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

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

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

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

    return event;
}