List of usage examples for android.view.accessibility AccessibilityEvent setEventType
public void setEventType(@EventType int eventType)
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
protected void waitForEventQueueSync() throws Throwable { startRecordingEvents();/*w ww. ja v a2 s .c om*/ final AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEnabled(false); event.setEventType(SYNC_EVENT_TYPE); event.setParcelableData(SYNC_PARCELABLE); // Sending the event through the manager sets the event time and // may clear the source node. Only certain event types can be // dispatched (see the framework's AccessibilityManagerService // canDispatchAccessibilityEvent() method). mManager.sendAccessibilityEvent(event); final AccessibilityEvent syncedEvent = stopRecordingEventsAfter(mSyncEventFilter); assertNotNull("Synchronized event queue", syncedEvent); }
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
/** * Finds an {@link android.view.accessibility.AccessibilityNodeInfo} by View id in the active window. * The search is performed from the root node. * * @param viewId The id of a View./*from ww w . j a v a2s. co m*/ * @return An {@link android.view.accessibility.AccessibilityNodeInfo} if found, null otherwise. */ protected final AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId) { startRecordingEvents(); final View view = getViewForId(viewId); assertNotNull("Obtain view from activity", view); final AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEnabled(false); event.setEventType(NODE_INFO_EVENT_TYPE); event.setParcelableData(SYNC_PARCELABLE); event.setSource(view); // Sending the event through the manager sets the event time and // may clear the source node. Only certain event types can be // dispatched (see the framework's AccessibilityManagerService // canDispatchAccessibilityEvent() method). mManager.sendAccessibilityEvent(event); final AccessibilityEvent syncedEvent = stopRecordingEventsAfter(mNodeInfoEventFilter); assertNotNull("Synchronized event queue", syncedEvent); final AccessibilityNodeInfo sourceNode = syncedEvent.getSource(); assertNotNull("Obtained source node from event", sourceNode); return sourceNode; }
From source file:com.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java
/** * Sends the specified text to the {@link AccessibilityManager} to be * spoken.//w w w . java 2 s. c o 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.inputmethod.accessibility.AccessibilityUtils.java
/** * Sends the specified text to the {@link AccessibilityManager} to be * spoken.// ww w. j a va 2 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()) { 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.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "modal editor" mode. *///from 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.android.tv.MainActivity.java
/** * Says {@code text} when accessibility is turned on. *///from ww w . j av a2 s .c o m public void sendAccessibilityText(String text) { if (mAccessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(); event.setClassName(getClass().getName()); event.setPackageName(getPackageName()); event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); event.getText().add(text); mAccessibilityManager.sendAccessibilityEvent(event); } }
From source file:com.android.tv.MainActivity.java
private void tune() { if (DEBUG)/*w w w. j a v a2 s . com*/ Log.d(TAG, "tune()"); mTuneDurationTimer.start(); lazyInitializeIfNeeded(LAZY_INITIALIZATION_DELAY); // Prerequisites to be able to tune. if (mInputIdUnderSetup != null) { mTunePending = true; return; } mTunePending = false; final Channel channel = mChannelTuner.getCurrentChannel(); if (!mChannelTuner.isCurrentChannelPassthrough()) { if (mTvInputManagerHelper.getTunerTvInputSize() == 0) { Toast.makeText(this, R.string.msg_no_input, Toast.LENGTH_SHORT).show(); // TODO: Direct the user to a Play Store landing page for TvInputService apps. finish(); return; } SetupUtils setupUtils = SetupUtils.getInstance(this); if (setupUtils.isFirstTune()) { if (!mChannelTuner.areAllChannelsLoaded()) { // tune() will be called, once all channels are loaded. stopTv("tune()", false); return; } if (mChannelDataManager.getChannelCount() > 0) { mOverlayManager.showIntroDialog(); } else if (!Features.ONBOARDING_EXPERIENCE.isEnabled(this)) { mOverlayManager.showSetupFragment(); return; } } if (!TvCommonUtils.isRunningInTest() && mShowNewSourcesFragment && setupUtils.hasUnrecognizedInput(mTvInputManagerHelper)) { // Show new channel sources fragment. runAfterAttachedToWindow(new Runnable() { @Override public void run() { mOverlayManager.runAfterOverlaysAreClosed(new Runnable() { @Override public void run() { mOverlayManager.showNewSourcesFragment(); } }); } }); } mShowNewSourcesFragment = false; if (mChannelTuner.getBrowsableChannelCount() == 0 && mChannelDataManager.getChannelCount() > 0 && !mOverlayManager.getSideFragmentManager().isActive()) { if (!mChannelTuner.areAllChannelsLoaded()) { return; } if (mTvInputManagerHelper.getTunerTvInputSize() == 1) { mOverlayManager.getSideFragmentManager().show(new CustomizeChannelListFragment()); } else { showSettingsFragment(); } return; } // TODO: need to refactor the following code to put in startTv. if (channel == null) { // There is no channel to tune to. stopTv("tune()", false); if (!mChannelDataManager.isDbLoadFinished()) { // Wait until channel data is loaded in order to know the number of channels. // tune() will be retried, once the channel data is loaded. return; } if (mOverlayManager.getSideFragmentManager().isActive()) { return; } mOverlayManager.showSetupFragment(); return; } setupUtils.onTuned(); if (mTuneParams != null) { Long initChannelId = mTuneParams.getLong(KEY_INIT_CHANNEL_ID); if (initChannelId == channel.getId()) { mTuneParams.remove(KEY_INIT_CHANNEL_ID); } else { mTuneParams = null; } } } mIsCurrentChannelUnblockedByUser = false; if (!isUnderShrunkenTvView()) { mLastAllowedRatingForCurrentChannel = null; } mHandler.removeMessages(MSG_UPDATE_CHANNEL_BANNER_BY_INFO_UPDATE); if (mAccessibilityManager.isEnabled()) { // For every tune, we need to inform the tuned channel or input to a user, // if Talkback is turned on. AccessibilityEvent event = AccessibilityEvent.obtain(); event.setClassName(getClass().getName()); event.setPackageName(getPackageName()); event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); if (TvContract.isChannelUriForPassthroughInput(channel.getUri())) { TvInputInfo input = mTvInputManagerHelper.getTvInputInfo(channel.getInputId()); event.getText().add(Utils.loadLabel(this, input)); } else if (TextUtils.isEmpty(channel.getDisplayName())) { event.getText().add(channel.getDisplayNumber()); } else { event.getText().add(channel.getDisplayNumber() + " " + channel.getDisplayName()); } mAccessibilityManager.sendAccessibilityEvent(event); } boolean success = mTvView.tuneTo(channel, mTuneParams, mOnTuneListener); mOnTuneListener.onTune(channel, isUnderShrunkenTvView()); mTuneParams = null; if (!success) { Toast.makeText(this, R.string.msg_tune_failed, Toast.LENGTH_SHORT).show(); return; } // Explicitly make the TV view main to make the selected input an HDMI-CEC active source. mTvView.setMain(); scheduleRestoreMainTvView(); if (!isUnderShrunkenTvView()) { if (!channel.isPassthrough()) { addToRecentChannels(channel.getId()); } Utils.setLastWatchedChannel(this, channel); TvApplication.getSingletons(this).getMainActivityWrapper().notifyCurrentChannelChange(this, channel); } checkChannelLockNeeded(mTvView); updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_TUNE); if (mActivityResumed) { // requestVisibleBehind should be called after onResume() is called. But, when // launcher is over the TV app and the screen is turned off and on, tune() can // be called during the pause state by mBroadcastReceiver (Intent.ACTION_SCREEN_ON). requestVisibleBehind(true); } updateMediaSession(); }
From source file:org.nekC.android.support.widget.RecyclerView.java
private void dispatchContentChangedIfNecessary() { final int flags = mEatenAccessibilityChangeFlags; mEatenAccessibilityChangeFlags = 0;//w w w . jav a 2s. c o m if (flags != 0 && mAccessibilityManager != null && mAccessibilityManager.isEnabled()) { final AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED); AccessibilityEventCompat.setContentChangeTypes(event, flags); sendAccessibilityEventUnchecked(event); } }
From source file:android.support.v71.widget.RecyclerView.java
private void dispatchContentChangedIfNecessary() { final int flags = mEatenAccessibilityChangeFlags; mEatenAccessibilityChangeFlags = 0;// www. jav a 2 s . com if (flags != 0 && isAccessibilityEnabled()) { final AccessibilityEvent event = AccessibilityEvent.obtain(); event.setEventType(AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED); AccessibilityEventCompat.setContentChangeTypes(event, flags); sendAccessibilityEventUnchecked(event); } }