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.arta.lib.widget.crouton.Manager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>//from ww w .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> * <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:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java
private void setInitialFocus() { InputMethodManager imm = (InputMethodManager) mDialog.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); View view = mShouldRequestExpirationDate ? mMonthInput : mCardUnmaskInput; imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); if (sObserverForTest != null) { sObserverForTest.onCardUnmaskPromptReadyForInput(this); }//w w w. j a v a 2 s . c om }
From source file:com.android.talkback.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.j av a 2 s . c om */ 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 (Role.getRole(node) == Role.ROLE_EDIT_TEXT) { return true; } } finally { AccessibilityNodeInfoUtils.recycleNodes(node); } } return false; }
From source file:com.xandy.calendar.month.SimpleDayPickerFragment.java
/** * Sets the month displayed at the top of this view based on time. Override * to add custom events when the title is changed. * * @param time A day in the new focus month. * @param updateHighlight TODO(epastern): *//*from w w w. ja va 2s . c o m*/ protected void setMonthDisplayed(Time time, boolean updateHighlight) { CharSequence oldMonth = mMonthName.getText(); mMonthName.setText(Utils.formatMonthYear(mContext, time)); mMonthName.invalidate(); if (!TextUtils.equals(oldMonth, mMonthName.getText())) { mMonthName.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); } mCurrentMonthDisplayed = time.month; if (updateHighlight) { mAdapter.updateFocusMonth(mCurrentMonthDisplayed); } }
From source file:com.android.calendar.month.SimpleDayPickerFragment.java
/** * Sets the month displayed at the top of this view based on time. Override * to add custom events when the title is changed. * * @param time//www .j a va2s . c om * A day in the new focus month. * @param updateHighlight * TODO(epastern): */ protected void setMonthDisplayed(Time time, int jMonth, boolean updateHighlight) { CharSequence oldMonth = mMonthName.getText(); mMonthName.setText(Utils.formatMonthYear(mContext, time)); mMonthName.invalidate(); if (!TextUtils.equals(oldMonth, mMonthName.getText())) { mMonthName.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); } mCurrentMonthDisplayed = jMonth; if (updateHighlight) { mAdapter.updateFocusMonth(mCurrentMonthDisplayed); } }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void announceForAccessibilityCompat(final Context context, final View view, final CharSequence text, final Class<?> cls) { final AccessibilityManager accessibilityManager = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); if (!accessibilityManager.isEnabled()) return;// ww w .j ava2 s. c o m // 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 < Build.VERSION_CODES.JELLY_BEAN) { 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(cls.getName()); event.setPackageName(context.getPackageName()); event.setSource(view); // 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.coreform.open.android.formidablevalidation.ValidationManager.java
/** * Generates and dispatches an SDK-specific spoken announcement. * <p>/* www.j a v a 2 s .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> * * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip * * @param text The text to announce. */ public static void announceForAccessibilityCompat(CharSequence text) { if (!mAccessibilityManager.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(SetErrorHandler.class.getName()); event.setPackageName(mContext.getPackageName()); // Sends the event directly through the accessibility manager. If your // application only targets SDK 14+, you should just call // getParent().requestSendAccessibilityEvent(this, event); mAccessibilityManager.sendAccessibilityEvent(event); }
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "modal editor" mode. *//* ww w. j av a2 s.c o m*/ public void testModalEditorMode() { mIMENavMode.onActivate(); verify(mNext).onActivate(); EditorInfo ei = new EditorInfo(); // Mock out the AccessibilityNodeInfo. // The class actually uses the compat variant, but on recent API // releases (including the test environment) they should call through. AccessibilityNodeInfo rawNode = mock(AccessibilityNodeInfo.class); when(mAccessibilityService.getRootInActiveWindow()).thenReturn(rawNode); when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY)).thenReturn(rawNode); when(rawNode.getClassName()).thenReturn(EditText.class.getName()); when(rawNode.isFocused()).thenReturn(true); mIMENavMode.onCreateIME(); mIMENavMode.onBindInput(); mIMENavMode.onStartInput(ei, false /* restarting */); mIMENavMode.onStartInputView(ei, false /* restarting */); verify(mNext, times(1)).onDeactivate(); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertEquals(mDisplayManager, mIMENavMode.getDisplayManager()); assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager()); AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext).onObserveAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onAccessibilityEvent(accessibilityEvent); verify(mNext, never()).onAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); try { mIMENavMode.onInvalidateAccessibilityNode(node); verify(mNext, never()).onInvalidateAccessibilityNode(node); } finally { node.recycle(); } // Move input focus away and back again. when(rawNode.isFocused()).thenReturn(false); accessibilityEvent = AccessibilityEvent.obtain(); accessibilityEvent.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext, times(2)).onActivate(); when(rawNode.isFocused()).thenReturn(true); mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext, times(2)).onDeactivate(); } finally { accessibilityEvent.recycle(); } DisplayManager.Content content = new DisplayManager.Content(""); mIMENavMode.onPanLeftOverflow(content); verify(mNext).onPanLeftOverflow(content); mIMENavMode.onPanRightOverflow(content); verify(mNext).onPanRightOverflow(content); BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).handleBrailleKey(0x1b); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).moveCursor(BrailleIME.DIRECTION_FORWARD, AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendDefaultAction(); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).route(0, content); // Finishing and unbinding the input should activate the next nav mode // again. mIMENavMode.onFinishInputView(true); mIMENavMode.onFinishInput(); mIMENavMode.onUnbindInput(); verify(mNext, times(3)).onActivate(); mIMENavMode.onDestroyIME(); // Deactivate, but make sure it didn't happen too early. verify(mNext, times(2)).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext, times(3)).onDeactivate(); }
From source file:com.xandy.calendar.AllInOneActivity.java
private void setTitleInActionBar(EventInfo event) { if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) { return;//from w ww . j a v a 2s .co m } final long start = event.startTime.toMillis(false /* use isDst */); final long end; if (event.endTime != null) { end = event.endTime.toMillis(false /* use isDst */); } else { end = start; } final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong); CharSequence oldDate = mDateRange.getText(); mDateRange.setText(msg); updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true) : start); if (!TextUtils.equals(oldDate, msg)) { mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); if (mShowWeekNum && mWeekTextView != null) { mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); } } }
From source file:com.google.android.marvin.mytalkback.TalkBackService.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.//from ww w . ja v a 2s . com */ private boolean shouldKeepAutomaticEvent(AccessibilityEvent event) { final AccessibilityRecordCompat record = new AccessibilityRecordCompat(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(this, node, android.widget.EditText.class)) { return true; } } finally { AccessibilityNodeInfoUtils.recycleNodes(node); } } return false; }