Java Code Examples for android.view.ViewParent#requestSendAccessibilityEvent()

The following examples show how to use android.view.ViewParent#requestSendAccessibilityEvent() . 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: AccessibilityUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.
 *
 * @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);
}
 
Example 2
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 3
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param view the View to trigger the accessibility event
 * @param msg text that will be read aloud (if accessibility enabled)
 */
public static void announceForAccessibility(View view, String msg)
{
    if (view != null && msg != null)
    {
        if (Build.VERSION.SDK_INT >= 16)
        {
            view.announceForAccessibility(msg);

        } else {
            Context context = view.getContext();
            if (context != null)
            {
                AccessibilityManager accesibility = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
                if (accesibility != null && accesibility.isEnabled())
                {
                    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
                    event.getText().add(msg);
                    event.setEnabled(view.isEnabled());
                    event.setClassName(view.getClass().getName());
                    event.setPackageName(context.getPackageName());

                    ViewParent parent = view.getParent();
                    if (Build.VERSION.SDK_INT >= 14 && parent != null)
                    {
                        parent.requestSendAccessibilityEvent(view, event);

                    } else {
                        accesibility.sendAccessibilityEvent(event);
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: AccessibilityUtils.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.
 *
 * @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);
}
 
Example 5
Source File: KeyboardAccessibilityDelegate.java    From Indic-Keyboard 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 6
Source File: ViewParentCompatICS.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public static boolean requestSendAccessibilityEvent(ViewParent viewparent, View view, AccessibilityEvent accessibilityevent)
{
    return viewparent.requestSendAccessibilityEvent(view, accessibilityevent);
}
 
Example 7
Source File: ViewParentCompatICS.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static boolean requestSendAccessibilityEvent(
        ViewParent parent, View child, AccessibilityEvent event) {
    return parent.requestSendAccessibilityEvent(child, event);
}
 
Example 8
Source File: ViewParentCompatICS.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static boolean requestSendAccessibilityEvent(
        ViewParent parent, View child, AccessibilityEvent event) {
    return parent.requestSendAccessibilityEvent(child, event);
}
 
Example 9
Source File: ViewParentCompatICS.java    From guideshow with MIT License 4 votes vote down vote up
public static boolean requestSendAccessibilityEvent(
        ViewParent parent, View child, AccessibilityEvent event) {
    return parent.requestSendAccessibilityEvent(child, event);
}