Java Code Examples for android.view.accessibility.AccessibilityEvent#setEventType()
The following examples show how to use
android.view.accessibility.AccessibilityEvent#setEventType() .
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: 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 2
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 3
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 4
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 5
Source File: SwitchAccessHighlightFeedbackController.java From talkback with Apache License 2.0 | 6 votes |
private void speakFeedbackForGlobalMenuButton(boolean speakHints) { // Manually construct an AccessibilityEvent and an AccessibilityNodeInfoCompat, which will be // used by the compositor to compose spoken feedback, for the global Switch Access menu button. final AccessibilityEvent event = AccessibilityEvent.obtain(); final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(); event.setEventType(TYPE_VIEW_FOCUSED); node.setEnabled(true); node.setContentDescription( context.getString(R.string.option_scanning_menu_button_content_description)); node.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK); node.setClassName(OverlayActionNode.class.getName()); CompatUtils.invoke( node, null, CompatUtils.getMethod(AccessibilityNodeInfo.class, "setSealed", boolean.class), true); SwitchAccessNodeCompat nodeInfoCompat = new SwitchAccessNodeCompat(node); hintsManager.postHintForNode(event, nodeInfoCompat); compositor.handleEvent( AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, nodeInfoCompat, EVENT_ID_UNTRACKED); isLastSpeech = !speakHints; }
Example 6
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 7
Source File: RecyclerView.java From kripton with Apache License 2.0 | 5 votes |
private void dispatchContentChangedIfNecessary() { final int flags = mEatenAccessibilityChangeFlags; mEatenAccessibilityChangeFlags = 0; if (flags != 0 && isAccessibilityEnabled()) { final AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); sendAccessibilityEventUnchecked(event); } }
Example 8
Source File: PLA_AdapterView.java From EverMemo with MIT License | 5 votes |
@Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = false; // This is an exceptional case which occurs when a window gets the // focus and sends a focus event via its focused child to announce // current focus/selection. AdapterView fires selection but not focus // events so we change the event type here. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED); } // we send selection events only from AdapterView to avoid // generation of such event for each child View selectedView = getSelectedView(); if (selectedView != null) { populated = selectedView.dispatchPopulateAccessibilityEvent(event); } if (!populated) { if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setItemCount(getCount()); event.setCurrentItemIndex(getSelectedItemPosition()); } return populated; }
Example 9
Source File: AndroidUtilities.java From Telegram with GNU General Public License v2.0 | 5 votes |
public static void makeAccessibilityAnnouncement(CharSequence what) { AccessibilityManager am = (AccessibilityManager) ApplicationLoader.applicationContext.getSystemService(Context.ACCESSIBILITY_SERVICE); if (am.isEnabled()) { AccessibilityEvent ev = AccessibilityEvent.obtain(); ev.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); ev.getText().add(what); am.sendAccessibilityEvent(ev); } }
Example 10
Source File: AndroidUtilities.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public static void makeAccessibilityAnnouncement(CharSequence what) { AccessibilityManager am = (AccessibilityManager) ApplicationLoader.applicationContext.getSystemService(Context.ACCESSIBILITY_SERVICE); if (am.isEnabled()) { AccessibilityEvent ev = AccessibilityEvent.obtain(); ev.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); ev.getText().add(what); am.sendAccessibilityEvent(ev); } }
Example 11
Source File: AccessibilityUtils.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
/** * Sends the specified text to the {@link AccessibilityManager} to be * spoken. * * @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); }
Example 12
Source File: PLAAdapterView.java From Lay-s with MIT License | 5 votes |
@Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = false; // This is an exceptional case which occurs when a window gets the // focus and sends a focus event via its focused child to announce // current focus/selection. AdapterView fires selection but not focus // events so we change the event type here. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED); } // we send selection events only from AdapterView to avoid // generation of such event for each child View selectedView = getSelectedView(); if (selectedView != null) { populated = selectedView.dispatchPopulateAccessibilityEvent(event); } if (!populated) { if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setItemCount(getCount()); event.setCurrentItemIndex(getSelectedItemPosition()); } return populated; }
Example 13
Source File: CustomVirtualViewCompatMode.java From input-samples with Apache License 2.0 | 5 votes |
private void sendAccessibilityEvent(int eventType, int virtualId) { AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(eventType); event.setSource(this, virtualId); event.setEnabled(true); event.setPackageName(getContext().getPackageName()); if (VERBOSE) { Log.v(TAG, "sendAccessibilityEvent(" + eventType + ", " + virtualId + "): " + event); } getContext().getSystemService(AccessibilityManager.class).sendAccessibilityEvent(event); }
Example 14
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 15
Source File: PLAAdapterView.java From SimplifyReader with Apache License 2.0 | 5 votes |
@Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = false; // This is an exceptional case which occurs when a window gets the // focus and sends a focus event via its focused child to announce // current focus/selection. AdapterView fires selection but not focus // events so we change the event type here. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED); } // we send selection events only from AdapterView to avoid // generation of such event for each child View selectedView = getSelectedView(); if (selectedView != null) { populated = selectedView.dispatchPopulateAccessibilityEvent(event); } if (!populated) { if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setItemCount(getCount()); event.setCurrentItemIndex(getSelectedItemPosition()); } return populated; }
Example 16
Source File: EcoGalleryAdapterView.java From samples with Apache License 2.0 | 5 votes |
@Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = false; // This is an exceptional case which occurs when a window gets the // focus and sends a focus event via its focused child to announce // current focus/selection. AdapterView fires selection but not focus // events so we change the event type here. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED); } // we send selection events only from AdapterView to avoid // generation of such event for each child View selectedView = getSelectedView(); if (selectedView != null) { populated = selectedView.dispatchPopulateAccessibilityEvent(event); } if (!populated) { if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setItemCount(getCount()); event.setCurrentItemIndex(getSelectedItemPosition()); } return populated; }
Example 17
Source File: AccessibilityUtils.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
/** * Sends the specified text to the {@link AccessibilityManager} to be * spoken. * * @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); }
Example 18
Source File: CustomVirtualViewCompatMode.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
private void sendAccessibilityEvent(int eventType, int virtualId) { AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(eventType); event.setSource(this, virtualId); event.setEnabled(true); event.setPackageName(getContext().getPackageName()); if (VERBOSE) { Log.v(TAG, "sendAccessibilityEvent(" + eventType + ", " + virtualId + "): " + event); } getContext().getSystemService(AccessibilityManager.class).sendAccessibilityEvent(event); }