Example usage for android.view.accessibility AccessibilityEvent setClassName

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

Introduction

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

Prototype

public void setClassName(CharSequence className) 

Source Link

Document

Sets the class name of the source.

Usage

From source file:com.arta.lib.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/*from w w  w. j  av  a  2s  .c  om*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
 * via https://github.com/coreform/android-formidable-validation
 *
 * @param context
 *     Used to get {@link AccessibilityManager}
 * @param text
 *     The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = null;
        if (null != context) {
            accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
        }
        if (null == accessibilityManager || !accessibilityManager.isEnabled()) {
            return;
        }

        // Prior to SDK 16, announcements could only be made through FOCUSED
        // events. Jelly Bean (SDK 16) added support for speaking text verbatim
        // using the ANNOUNCEMENT event type.
        final int eventType;
        if (Build.VERSION.SDK_INT < 16) {
            eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
        } else {
            eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
        }

        // Construct an accessibility event with the minimum recommended
        // attributes. An event without a class name or package may be dropped.
        final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.getText().add(text);
        event.setClassName(Manager.class.getName());
        event.setPackageName(context.getPackageName());

        // Sends the event directly through the accessibility manager. If your
        // application only targets SDK 14+, you should just call
        // getParent().requestSendAccessibilityEvent(this, event);
        accessibilityManager.sendAccessibilityEvent(event);
    }
}

From source file:com.coreform.open.android.formidablevalidation.ValidationManager.java

/**
  * Generates and dispatches an SDK-specific spoken announcement.
  * <p>// w  ww .jav  a2 s . co m
  * For backwards compatibility, we're constructing an event from scratch
  * using the appropriate event type. If your application only targets SDK
  * 16+, you can just call View.announceForAccessibility(CharSequence).
  * </p>
  * 
  * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
  *
  * @param text The text to announce.
  */
public static void announceForAccessibilityCompat(CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // Prior to SDK 16, announcements could only be made through FOCUSED
    // events. Jelly Bean (SDK 16) added support for speaking text verbatim
    // using the ANNOUNCEMENT event type.
    final int eventType;
    if (Build.VERSION.SDK_INT < 16) {
        eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
    } else {
        eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
    }

    // Construct an accessibility event with the minimum recommended
    // attributes. An event without a class name or package may be dropped.
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.getText().add(text);
    event.setClassName(SetErrorHandler.class.getName());
    event.setPackageName(mContext.getPackageName());

    // Sends the event directly through the accessibility manager. If your
    // application only targets SDK 14+, you should just call
    // getParent().requestSendAccessibilityEvent(this, event);
    mAccessibilityManager.sendAccessibilityEvent(event);
}

From source file:com.android.datetimepicker.AccessibleTextView.java

private void installAccessibilityDelegate() {
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        @Override//from   w  w  w .  j  a v a 2s .  c  om
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            event.setClassName(Button.class.getName());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setClassName(Button.class.getName());
        }
    });
}

From source file:android.support.v7.widget.RecyclerViewAccessibilityDelegateEx.java

@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(host, event);
    event.setClassName(RecyclerView.class.getName());
    if (host instanceof RecyclerView) {
        RecyclerView rv = (RecyclerView) host;
        if (rv.getLayoutManager() != null) {
            rv.getLayoutManager().onInitializeAccessibilityEvent(event);
        }//from   w w  w.  j ava  2s . com
    }
}

From source file:android.support.v7.widget.RecyclerViewAccessibilityDelegate.java

@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(host, event);
    event.setClassName(RecyclerView.class.getName());
    if (host instanceof RecyclerView && !shouldIgnore()) {
        RecyclerView rv = (RecyclerView) host;
        if (rv.getLayoutManager() != null) {
            rv.getLayoutManager().onInitializeAccessibilityEvent(event);
        }//from  www.ja va2  s .  c o m
    }
}

From source file:android.support.v7.widget.AppCompatButton.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setClassName(Button.class.getName());
}

From source file:com.fenlisproject.elf.core.widget.ExtendedEditText.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setClassName(EditText.class.getName());
}

From source file:com.albedinsky.android.ui.widget.ActionTextButton.java

/**
 *//*  ww  w  .j  a va 2 s .  co  m*/
@Override
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void onInitializeAccessibilityEvent(@NonNull AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setClassName(ActionTextButton.class.getName());
}

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

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