Example usage for android.view ViewParent requestSendAccessibilityEvent

List of usage examples for android.view ViewParent requestSendAccessibilityEvent

Introduction

In this page you can find the example usage for android.view ViewParent requestSendAccessibilityEvent.

Prototype

public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event);

Source Link

Document

Called by a child to request from its parent to send an AccessibilityEvent .

Usage

From source file:com.android.mail.utils.ViewUtils.java

/**
 * Convenience method for sending a {@link android.view.accessibility.AccessibilityEvent#TYPE_ANNOUNCEMENT}
 * {@link android.view.accessibility.AccessibilityEvent} to make an announcement which is related to some
 * sort of a context change for which none of the events representing UI transitions
 * is a good fit. For example, announcing a new page in a book. If accessibility
 * is not enabled this method does nothing.
 *
 * @param view view to perform the accessibility announcement
 * @param text The announcement text./* www .  ja  v  a  2s . c  o m*/
 */
public static void announceForAccessibility(View view, CharSequence text) {
    final AccessibilityManager accessibilityManager = (AccessibilityManager) view.getContext()
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    final ViewParent parent = view.getParent();
    if (accessibilityManager.isEnabled() && parent != null) {
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        view.onInitializeAccessibilityEvent(event);
        event.getText().add(text);
        event.setContentDescription(null);
        parent.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.
 *///from   w  w  w .ja va 2 s.  c  om
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.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.//  www .j ava 2s .com
 *
 * @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.onyx.latinime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 */// w  ww .j a v  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.inputmethod.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken./*from  w  w  w. j a va 2 s . c  o  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);
}