Java Code Examples for android.view.accessibility.AccessibilityManager#sendAccessibilityEvent()
The following examples show how to use
android.view.accessibility.AccessibilityManager#sendAccessibilityEvent() .
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 SuperToasts with Apache License 2.0 | 6 votes |
/** * Try to send an {@link AccessibilityEvent} * for a {@link View}. * * @param view The View that will dispatch the AccessibilityEvent * @return true if the AccessibilityEvent was dispatched */ @SuppressWarnings("UnusedReturnValue") public static boolean sendAccessibilityEvent(View view) { final AccessibilityManager accessibilityManager = (AccessibilityManager) view.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (!accessibilityManager.isEnabled()) return false; final AccessibilityEvent accessibilityEvent = AccessibilityEvent .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); accessibilityEvent.setClassName(view.getClass().getName()); accessibilityEvent.setPackageName(view.getContext().getPackageName()); view.dispatchPopulateAccessibilityEvent(accessibilityEvent); accessibilityManager.sendAccessibilityEvent(accessibilityEvent); return true; }
Example 2
Source File: SwitchPreference.java From holoaccent with Apache License 2.0 | 6 votes |
/** As defined in TwoStatePreference source */ void sendAccessibilityEvent(View view) { // Since the view is still not attached we create, populate, // and send the event directly since we do not know when it // will be attached and posting commands is not as clean. AccessibilityManager accessibilityManager = (AccessibilityManager)getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager == null) return; if (mSendClickAccessibilityEvent && accessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEvent.TYPE_VIEW_CLICKED); view.onInitializeAccessibilityEvent(event); view.dispatchPopulateAccessibilityEvent(event); accessibilityManager.sendAccessibilityEvent(event); } mSendClickAccessibilityEvent = false; }
Example 3
Source File: NumberPicker.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void onScrollStateChange(int scrollState) { if (mScrollState == scrollState) { return; } mScrollState = scrollState; if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChange(this, scrollState); } if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { AccessibilityManager am = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (am.isTouchExplorationEnabled()) { String text = (mDisplayedValues == null) ? formatNumber(mValue) : mDisplayedValues[mValue - mMinValue]; AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); event.getText().add(text); am.sendAccessibilityEvent(event); } } }
Example 4
Source File: AccessibilityUtils.java From SublimePicker with Apache License 2.0 | 6 votes |
public static void makeAnnouncement(View view, CharSequence announcement) { if (view == null) return; 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); } }
Example 5
Source File: NumberPicker.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void onScrollStateChange(int scrollState) { if (mScrollState == scrollState) { return; } mScrollState = scrollState; if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChange(this, scrollState); } if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { AccessibilityManager am = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (am.isTouchExplorationEnabled()) { String text = (mDisplayedValues == null) ? formatNumber(mValue) : mDisplayedValues[mValue - mMinValue]; AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); event.getText().add(text); am.sendAccessibilityEvent(event); } } }
Example 6
Source File: TalkBackHelper.java From libcommon with Apache License 2.0 | 6 votes |
/** * 指定したテキストをTalkBackで読み上げる(TalkBackが有効な場合) * @param context * @param text * @throws IllegalStateException */ public static void announceText(@NonNull final Context context, @Nullable final CharSequence[] text) throws IllegalStateException { if ((text == null) || (text.length == 0) || (context == null)) return; final AccessibilityManager manager = ContextUtils.requireSystemService(context, AccessibilityManager.class); if ((manager != null) && manager.isEnabled()) { final AccessibilityEvent event = AccessibilityEvent.obtain(); if (event != null) { event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT); event.setClassName(TalkBackHelper.class.getName()); event.setPackageName(context.getPackageName()); for (final CharSequence t: text) { event.getText().add(t); } manager.sendAccessibilityEvent(event); } else { throw new IllegalStateException("failed to obtain AccessibilityEvent"); } } else { throw new IllegalStateException("AccessibilityManager is not available/or disabled"); } }
Example 7
Source File: TalkBackHelper.java From libcommon with Apache License 2.0 | 6 votes |
/** * 指定したテキストをTalkBackで読み上げる(TalkBackが有効な場合) * @param context * @param text * @throws IllegalStateException */ public static void announceText(@NonNull final Context context, @Nullable final CharSequence text) throws IllegalStateException { if (TextUtils.isEmpty(text) || (context == null)) return; final AccessibilityManager manager = ContextUtils.requireSystemService(context, AccessibilityManager.class); if ((manager != null) && manager.isEnabled()) { final AccessibilityEvent event = AccessibilityEvent.obtain(); if (event != null) { event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT); event.setClassName(TalkBackHelper.class.getName()); event.setPackageName(context.getPackageName()); event.getText().add(text); manager.sendAccessibilityEvent(event); } else { throw new IllegalStateException("failed to obtain AccessibilityEvent"); } } else { throw new IllegalStateException("AccessibilityManager is not available/or disabled"); } }
Example 8
Source File: DragLayer.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) { AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close; AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_VIEW_FOCUSED); onInitializeAccessibilityEvent(event); event.getText().add(getContext().getString(stringId)); accessibilityManager.sendAccessibilityEvent(event); } }
Example 9
Source File: Folder.java From TurboLauncher with Apache License 2.0 | 5 votes |
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); accessibilityManager.sendAccessibilityEvent(event); } }
Example 10
Source File: DragLayer.java From TurboLauncher with Apache License 2.0 | 5 votes |
private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) { AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close; AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_VIEW_FOCUSED); onInitializeAccessibilityEvent(event); event.getText().add(getContext().getString(stringId)); accessibilityManager.sendAccessibilityEvent(event); } }
Example 11
Source File: DimScreenControllerApp.java From talkback with Apache License 2.0 | 5 votes |
private void announceScreenDimChanged(int announcementTextResId) { AccessibilityManager manager = (AccessibilityManager) service.getSystemService(Context.ACCESSIBILITY_SERVICE); if (manager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); event.setClassName(getClass().getName()); event.setPackageName(service.getPackageName()); event.getText().add(service.getString(announcementTextResId)); manager.sendAccessibilityEvent(event); } }
Example 12
Source File: TalkBackKeyboardShortcutPreferencesActivity.java From talkback with Apache License 2.0 | 5 votes |
/** Utility method for announcing text via accessibility event. */ public static void announceText(String text, Context context) { AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT); event.setContentDescription(text); accessibilityManager.sendAccessibilityEvent(event); } }
Example 13
Source File: SuntimesUtils.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
/** * @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 14
Source File: Utilities.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
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); accessibilityManager.sendAccessibilityEvent(event); } }
Example 15
Source File: Folder.java From LB-Launcher with Apache License 2.0 | 5 votes |
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); accessibilityManager.sendAccessibilityEvent(event); } }
Example 16
Source File: DragLayer.java From LB-Launcher with Apache License 2.0 | 5 votes |
private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) { AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled()) { int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close; AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_VIEW_FOCUSED); onInitializeAccessibilityEvent(event); event.getText().add(getContext().getString(stringId)); accessibilityManager.sendAccessibilityEvent(event); } }
Example 17
Source File: ViewParentCompat.java From adt-leanback-support with Apache License 2.0 | 5 votes |
@Override public boolean requestSendAccessibilityEvent( ViewParent parent, View child, AccessibilityEvent event) { // Emulate what ViewRootImpl does in ICS and above. if (child == null) { return false; } final AccessibilityManager manager = (AccessibilityManager) child.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); manager.sendAccessibilityEvent(event); return true; }
Example 18
Source File: ViewParentCompat.java From android-recipes-app with Apache License 2.0 | 5 votes |
@Override public boolean requestSendAccessibilityEvent( ViewParent parent, View child, AccessibilityEvent event) { // Emulate what ViewRootImpl does in ICS and above. if (child == null) { return false; } final AccessibilityManager manager = (AccessibilityManager) child.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); manager.sendAccessibilityEvent(event); return true; }
Example 19
Source File: ViewParentCompat.java From V.FlyoutTest with MIT License | 5 votes |
@Override public boolean requestSendAccessibilityEvent( ViewParent parent, View child, AccessibilityEvent event) { // Emulate what ViewRootImpl does in ICS and above. if (child == null) { return false; } final AccessibilityManager manager = (AccessibilityManager) child.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); manager.sendAccessibilityEvent(event); return true; }
Example 20
Source File: Toast.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void trySendAccessibilityEvent() { AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(mView.getContext()); if (!accessibilityManager.isEnabled()) { return; } // treat toasts as notifications since they are used to // announce a transient piece of information to the user AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); event.setClassName(getClass().getName()); event.setPackageName(mView.getContext().getPackageName()); mView.dispatchPopulateAccessibilityEvent(event); accessibilityManager.sendAccessibilityEvent(event); }