List of usage examples for android.view.accessibility AccessibilityManager sendAccessibilityEvent
public void sendAccessibilityEvent(AccessibilityEvent 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 ww w . ja v a 2 s . com*/ 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.aboveware.common.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>//from w ww .j a va2 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> * * 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.elephant.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>//from w ww .jav a2s.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 = (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.arta.lib.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>//from ww w . ja v a2s . 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 = 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.partynetwork.iparty.app.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>/*from w w w . java 2s. com*/ * 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:cc.flydev.launcher.Folder.java
private void sendCustomAccessibilityEvent(int type, String text) { AccessibilityManager accessibilityManager = (AccessibilityManager) getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(type); onInitializeAccessibilityEvent(event); event.getText().add(text);/* w w w . j a va 2 s. com*/ accessibilityManager.sendAccessibilityEvent(event); } }
From source file:com.android.launcher3.Utilities.java
public static void sendCustomAccessibilityEvent(View target, int type, String text) { AccessibilityManager accessibilityManager = (AccessibilityManager) target.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(type); target.onInitializeAccessibilityEvent(event); event.getText().add(text);/* w ww . j a v a 2 s. co m*/ accessibilityManager.sendAccessibilityEvent(event); } }
From source file:com.llf.android.launcher3.Folder.java
private void sendCustomAccessibilityEvent(int type, String text) { AccessibilityManager accessibilityManager = (AccessibilityManager) getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(type); // XXX onInitializeAccessibilityEvent(event); event.getText().add(text);/*from w ww . j av a 2s.com*/ accessibilityManager.sendAccessibilityEvent(event); } }
From source file:org.mozilla.gecko.GeckoAppShell.java
public static void emitGeckoAccessibilityEvent(int eventType, String role, String text, String description, boolean enabled, boolean checked, boolean password) { AccessibilityManager accessibilityManager = (AccessibilityManager) GeckoApp.mAppContext .getSystemService(Context.ACCESSIBILITY_SERVICE); if (!accessibilityManager.isEnabled()) return;/*www . j ava 2s. c om*/ LayerController layerController = GeckoApp.mAppContext.getLayerController(); LayerView layerView = layerController.getView(); AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setClassName(layerView.getClass().getName() + "$" + role); event.setPackageName(GeckoApp.mAppContext.getPackageName()); event.setEnabled(enabled); event.setChecked(checked); event.setPassword(password); event.setContentDescription(description); event.getText().add(text); accessibilityManager.sendAccessibilityEvent(event); }
From source file:com.klinker.deskclock.widget.multiwaveview.GlowPadView.java
private void announceTargets() { StringBuilder utterance = new StringBuilder(); final int targetCount = mTargetDrawables.size(); for (int i = 0; i < targetCount; i++) { String targetDescription = getTargetDescription(i); String directionDescription = getDirectionDescription(i); if (!TextUtils.isEmpty(targetDescription) && !TextUtils.isEmpty(directionDescription)) { String text = String.format(directionDescription, targetDescription); utterance.append(text);//from w w w .j a v a2 s .c om } } if (utterance.length() > 0) { final AccessibilityManager accessibilityManager = (AccessibilityManager) getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { if (Build.VERSION.SDK_INT >= 16) { announceForAccessibility(utterance.toString()); } else { AccessibilityEvent acc_event = AccessibilityEvent .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); AccessibilityRecordCompat arc = new AccessibilityRecordCompat(acc_event); arc.setSource(this); acc_event.setClassName(this.getClass().getName()); acc_event.setPackageName(this.getContext().getPackageName()); acc_event.setEnabled(this.isEnabled()); acc_event.getText().add(utterance.toString()); accessibilityManager.sendAccessibilityEvent(acc_event); } } } }