Java Code Examples for android.view.accessibility.AccessibilityEvent#setEnabled()
The following examples show how to use
android.view.accessibility.AccessibilityEvent#setEnabled() .
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 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 2
Source File: ExploreByTouchHelper.java From android-recipes-app with Apache License 2.0 | 6 votes |
/** * Constructs and returns an {@link AccessibilityEvent} populated with * information about the specified item. * * @param virtualViewId The virtual view id for the item for which to * construct an event. * @param eventType The type of event to construct. * @return An {@link AccessibilityEvent} populated with information about * the specified item. */ private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) { final AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setEnabled(true); event.setClassName(DEFAULT_CLASS_NAME); // Allow the client to populate the event. onPopulateEventForVirtualView(virtualViewId, event); // Make sure the developer is following the rules. if (event.getText().isEmpty() && (event.getContentDescription() == null)) { throw new RuntimeException("Callbacks must add text or a content description in " + "populateEventForVirtualViewId()"); } // Don't allow the client to override these properties. event.setPackageName(mView.getContext().getPackageName()); final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); record.setSource(mView, virtualViewId); return event; }
Example 3
Source File: ExploreByTouchHelper.java From V.FlyoutTest with MIT License | 6 votes |
/** * Constructs and returns an {@link AccessibilityEvent} populated with * information about the specified item. * * @param virtualViewId The virtual view id for the item for which to * construct an event. * @param eventType The type of event to construct. * @return An {@link AccessibilityEvent} populated with information about * the specified item. */ private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) { final AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setEnabled(true); event.setClassName(DEFAULT_CLASS_NAME); // Allow the client to populate the event. onPopulateEventForVirtualView(virtualViewId, event); // Make sure the developer is following the rules. if (event.getText().isEmpty() && (event.getContentDescription() == null)) { throw new RuntimeException("Callbacks must add text or a content description in " + "populateEventForVirtualViewId()"); } // Don't allow the client to override these properties. event.setPackageName(mView.getContext().getPackageName()); final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); record.setSource(mView, virtualViewId); return event; }
Example 4
Source File: IcsAdapterView.java From android-apps with MIT License | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setScrollable(isScrollableForAccessibility()); View selectedView = getSelectedView(); if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setCurrentItemIndex(getSelectedItemPosition()); event.setFromIndex(getFirstVisiblePosition()); event.setToIndex(getLastVisiblePosition()); event.setItemCount(getCount()); }
Example 5
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 6
Source File: BrowserAccessibilityManager.java From 365browser with Apache License 2.0 | 5 votes |
@CalledByNative private void setAccessibilityEventBooleanAttributes(AccessibilityEvent event, boolean checked, boolean enabled, boolean password, boolean scrollable) { event.setChecked(checked); event.setEnabled(enabled); event.setPassword(password); event.setScrollable(scrollable); }
Example 7
Source File: TextPicker.java From GifAssistant with Apache License 2.0 | 5 votes |
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType, String text) { if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setClassName(Button.class.getName()); event.setPackageName(getContext().getPackageName()); event.getText().add(text); event.setEnabled(TextPicker.this.isEnabled()); event.setSource(TextPicker.this, virtualViewId); requestSendAccessibilityEvent(TextPicker.this, event); } }
Example 8
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 9
Source File: NumberPicker.java From NewXmPluginSDK with Apache License 2.0 | 5 votes |
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType, String text) { AccessibilityManager acm = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (acm.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setClassName(Button.class.getName()); event.setPackageName(getContext().getPackageName()); event.getText().add(text); event.setEnabled(NumberPicker.this.isEnabled()); event.setSource(NumberPicker.this, virtualViewId); requestSendAccessibilityEvent(NumberPicker.this, event); } }
Example 10
Source File: IcsAdapterView.java From Libraries-for-Android-Developers with MIT License | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setScrollable(isScrollableForAccessibility()); View selectedView = getSelectedView(); if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setCurrentItemIndex(getSelectedItemPosition()); event.setFromIndex(getFirstVisiblePosition()); event.setToIndex(getLastVisiblePosition()); event.setItemCount(getCount()); }
Example 11
Source File: NumberPicker.java From DateTimePicker with Apache License 2.0 | 5 votes |
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType, String text) { //if (AccessibilityManager.getInstance(mContext).isEnabled()) { if (accessibilityManager != null && accessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setClassName(Button.class.getName()); event.setPackageName(getContext().getPackageName()); event.getText().add(text); event.setEnabled(NumberPicker.this.isEnabled()); AccessibilityRecordCompat.setSource(event, NumberPicker.this, virtualViewId); //event.setSource(NumberPicker.this, virtualViewId); requestSendAccessibilityEvent(NumberPicker.this, 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: AdapterView.java From letv with Apache License 2.0 | 5 votes |
@TargetApi(14) public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setClassName(AdapterView.class.getName()); event.setScrollable(isScrollableForAccessibility()); View selectedView = getSelectedView(); if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setCurrentItemIndex(getSelectedItemPosition()); event.setFromIndex(getFirstVisiblePosition()); event.setToIndex(getLastVisiblePosition()); event.setItemCount(getCount()); }
Example 14
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 15
Source File: KeyboardAccessibilityNodeProvider.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
/** * Creates and populates an {@link AccessibilityEvent} for the specified key * and event type. * * @param key A key on the host keyboard view. * @param eventType The event type to create. * @return A populated {@link AccessibilityEvent} for the key. * @see AccessibilityEvent */ public AccessibilityEvent createAccessibilityEvent(final Key key, final int eventType) { final int virtualViewId = getVirtualViewIdOf(key); final String keyDescription = getKeyDescription(key); final AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setPackageName(mKeyboardView.getContext().getPackageName()); event.setClassName(key.getClass().getName()); event.setContentDescription(keyDescription); event.setEnabled(true); final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); record.setSource(mKeyboardView, virtualViewId); return event; }
Example 16
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); }
Example 17
Source File: AdapterView.java From android-tv-launcher with MIT License | 5 votes |
public void onInitializeAccessibilityEvent(AccessibilityEvent paramAccessibilityEvent) { super.onInitializeAccessibilityEvent(paramAccessibilityEvent); paramAccessibilityEvent.setScrollable(isScrollableForAccessibility()); View localView = getSelectedView(); if (localView != null) paramAccessibilityEvent.setEnabled(localView.isEnabled()); paramAccessibilityEvent.setCurrentItemIndex(getSelectedItemPosition()); paramAccessibilityEvent.setFromIndex(getFirstVisiblePosition()); paramAccessibilityEvent.setToIndex(getLastVisiblePosition()); paramAccessibilityEvent.setItemCount(getCount()); }
Example 18
Source File: AdapterView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ @Override public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { super.onInitializeAccessibilityEventInternal(event); event.setScrollable(isScrollableForAccessibility()); View selectedView = getSelectedView(); if (selectedView != null) { event.setEnabled(selectedView.isEnabled()); } event.setCurrentItemIndex(getSelectedItemPosition()); event.setFromIndex(getFirstVisiblePosition()); event.setToIndex(getLastVisiblePosition()); event.setItemCount(getCount()); }
Example 19
Source File: BrowserAccessibilityManager.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@CalledByNative private void setAccessibilityEventBooleanAttributes(AccessibilityEvent event, boolean checked, boolean enabled, boolean password, boolean scrollable) { event.setChecked(checked); event.setEnabled(enabled); event.setPassword(password); event.setScrollable(scrollable); }
Example 20
Source File: RadialMenuView.java From talkback with Apache License 2.0 | 4 votes |
@Override protected void populateEventForItem(RadialMenuItem item, AccessibilityEvent event) { event.setContentDescription(item.getTitle()); event.setChecked(item.isChecked()); event.setEnabled(item.isEnabled()); }