List of usage examples for android.view.accessibility AccessibilityEvent TYPE_VIEW_FOCUSED
int TYPE_VIEW_FOCUSED
To view the source code for android.view.accessibility AccessibilityEvent TYPE_VIEW_FOCUSED.
Click Source Link
From source file:com.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java
/** * Sends the specified text to the {@link AccessibilityManager} to be * spoken.//from ww w . j a va2 s. co 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.managedprovisioning.DeviceOwnerProvisioningActivity.java
private void progressUpdate(int progressMessage) { mProgressTextView.setText(progressMessage); mProgressTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); }
From source file:com.android.inputmethod.accessibility.AccessibilityUtils.java
/** * Sends the specified text to the {@link AccessibilityManager} to be * spoken.// w w w.jav a 2 s . c om * * @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); }
From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessor.java
public void onAccessibilityEvent(AccessibilityEvent event) { if (mTestingListener != null) { mTestingListener.onAccessibilityEvent(event); }//from w w w .ja va 2s . co m if ((mDumpEventMask & event.getEventType()) != 0) { Log.v(DUMP_EVNET_LOG_TAG, event.toString()); } if (shouldDropRefocusEvent(event)) { return; } if (shouldDropEvent(event)) { return; } maintainExplorationState(event); if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || event.getEventType() == AccessibilityEvent.TYPE_WINDOWS_CHANGED) { mService.setRootDirty(true); } // We need to save the last focused event so that we can filter out related selected events. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { if (mLastFocusedEvent != null) { mLastFocusedEvent.recycle(); } mLastFocusedEvent = AccessibilityEvent.obtain(event); } if (AccessibilityEventUtils.eventMatchesAnyType(event, MASK_DELAYED_EVENT_TYPES)) { mHandler.postProcessEvent(event); } else { processEvent(event); } if (mTestingListener != null) { mTestingListener.afterAccessibilityEvent(event); } }
From source file:com.aboveware.common.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>// w w w. j ava 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> * * 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.screenspeak.eventprocessor.AccessibilityEventProcessor.java
/** * Helper method for {@link #shouldDropEvent} that handles events that * automatically occur immediately after a window state change. * * @param event The automatically generated event to consider retaining. * @return Whether to retain the event./* w w w . ja v a 2 s.c o m*/ */ private boolean shouldKeepAutomaticEvent(AccessibilityEvent event) { final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); // Don't drop focus events from EditTexts. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { AccessibilityNodeInfoCompat node = null; try { node = record.getSource(); if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, EditText.class)) { return true; } } finally { AccessibilityNodeInfoUtils.recycleNodes(node); } } return false; }
From source file:com.prashant.custom.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>//from w w w . j av a 2s .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.partynetwork.iparty.app.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>/*from w w w . ja va 2 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> * <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.elephant.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>/*www . j a v a 2s .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); } }
From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java
private void tryFocusCachedRecord() { if (mCachedPotentiallyFocusableRecordQueue.isEmpty()) { return;/* w w w. j a v a 2 s . c o m*/ } Iterator<Pair<AccessibilityRecordCompat, Integer>> iterator = mCachedPotentiallyFocusableRecordQueue .descendingIterator(); while (iterator.hasNext()) { Pair<AccessibilityRecordCompat, Integer> focusableRecord = iterator.next(); AccessibilityRecordCompat record = focusableRecord.first; int eventType = focusableRecord.second; if (setFocusOnView(record, eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED)) { emptyCachedPotentialFocusQueue(); return; } } }