List of usage examples for android.view.accessibility AccessibilityEvent getText
public List<CharSequence> getText()
From source file:Main.java
/** * Announce text through the AccessibilityManager for a view. * * @param text//from ww w. ja v a 2 s .co m * @param view * @param manager */ public static void announceText(String text, View view, AccessibilityManager manager) { // Only announce text if the accessibility service is enabled if (!manager.isEnabled()) { return; } AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEventCompat.TYPE_ANNOUNCEMENT); event.getText().add(text); event.setEnabled(true); // Tie the event to the view event.setClassName(view.getClass().getName()); event.setPackageName(view.getContext().getPackageName()); AccessibilityEventCompat.asRecord(event).setSource(view); // Send the announcement manager.sendAccessibilityEvent(event); }
From source file:com.android.messaging.util.AccessibilityUtil.java
public static void announceForAccessibilityCompat(final View view, @Nullable AccessibilityManager accessibilityManager, final CharSequence text) { final Context context = view.getContext().getApplicationContext(); if (accessibilityManager == null) { accessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); }//from w w w . j a va2s. c o m if (!accessibilityManager.isEnabled()) { return; } // Jelly Bean added support for speaking text verbatim final int eventType = OsUtil.isAtLeastJB() ? AccessibilityEvent.TYPE_ANNOUNCEMENT : AccessibilityEvent.TYPE_VIEW_FOCUSED; // 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.setEnabled(view.isEnabled()); event.setClassName(view.getClass().getName()); event.setPackageName(context.getPackageName()); // JellyBean MR1 requires a source view to set the window ID. final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); record.setSource(view); // Sends the event directly through the accessibility manager. If we only supported SDK 14+ // we could have done: // getParent().requestSendAccessibilityEvent(this, event); accessibilityManager.sendAccessibilityEvent(event); }
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./*from w ww . jav a2 s . com*/ */ 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.utils.AccessibilityEventUtils.java
/** * Gets the text of an <code>event</code> by concatenating the text members * (regardless of their priority) using space as a delimiter. * * @param event The event./*from w ww . jav a 2s.c o m*/ * @return The event text. */ public static CharSequence getEventAggregateText(AccessibilityEvent event) { if (event == null) { return null; } final SpannableStringBuilder aggregator = new SpannableStringBuilder(); for (CharSequence text : event.getText()) { StringBuilderUtils.appendWithSeparator(aggregator, text); } return aggregator; }
From source file:com.aboveware.common.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>/* w ww. ja va2s . 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> * * note: AccessibilityManager is only available from API lvl 4. * * 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 = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); if (!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.android.gallery3d.util.AccessibilityUtils.java
public static void makeAnnouncement(View view, CharSequence announcement) { if (view == null) return;// w w w . j ava 2 s .c om if (ApiHelper.HAS_ANNOUNCE_FOR_ACCESSIBILITY) { view.announceForAccessibility(announcement); } else { // For API 15 and earlier, we need to construct an accessibility event Context ctx = view.getContext(); AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE); if (!am.isEnabled()) return; AccessibilityEvent event = AccessibilityEvent .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); AccessibilityRecordCompat arc = new AccessibilityRecordCompat(event); arc.setSource(view); event.setClassName(view.getClass().getName()); event.setPackageName(view.getContext().getPackageName()); event.setEnabled(view.isEnabled()); event.getText().add(announcement); am.sendAccessibilityEvent(event); } }
From source file:com.android.fastergallery.util.AccessibilityUtils.java
public static void makeAnnouncement(View view, CharSequence announcement) { if (view == null) return;// ww w . ja va 2 s . c om if (ApiHelper.HAS_ANNOUNCE_FOR_ACCESSIBILITY) { view.announceForAccessibility(announcement); } else { // For API 15 and earlier, we need to construct an accessibility // event Context ctx = view.getContext(); AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE); if (!am.isEnabled()) return; AccessibilityEvent event = AccessibilityEvent .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); AccessibilityRecordCompat arc = new AccessibilityRecordCompat(event); arc.setSource(view); event.setClassName(view.getClass().getName()); event.setPackageName(view.getContext().getPackageName()); event.setEnabled(view.isEnabled()); event.getText().add(announcement); am.sendAccessibilityEvent(event); } }
From source file:com.appeaser.sublimepickerlibrary.utilities.AccessibilityUtils.java
public static void makeAnnouncement(View view, CharSequence announcement) { if (view == null) return;//from w w w.j a v a 2 s . c om if (SUtils.isApi_16_OrHigher()) { view.announceForAccessibility(announcement); } else { // For API 15 and earlier, we need to construct an accessibility event Context ctx = view.getContext(); AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE); if (!am.isEnabled()) return; AccessibilityEvent event = AccessibilityEvent .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); AccessibilityRecordCompat arc = AccessibilityEventCompat.asRecord(event); arc.setSource(view); event.setClassName(view.getClass().getName()); event.setPackageName(view.getContext().getPackageName()); event.setEnabled(view.isEnabled()); event.getText().add(announcement); am.sendAccessibilityEvent(event); } }
From source file:com.prashant.custom.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>//from w w w .jav a 2 s . c o 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> * <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 = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); if (!accessibilityManager.isEnabled()) { return; } final int eventType; eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED; // 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.elephant.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>/*from w ww .jav a2 s . c o 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> * <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 = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); if (!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); } }