List of usage examples for android.view.accessibility AccessibilityEvent getEventType
public @EventType int getEventType()
From source file:com.android.screenspeak.formatter.CheckableClickedFormatter.java
@Override public boolean accept(AccessibilityEvent event, ScreenSpeakService context) { int type = event.getEventType(); if (type == AccessibilityEvent.TYPE_VIEW_CLICKED) { mClickedNode = null;/*from w w w. j a v a2s . co m*/ mClickedTime = -1; if (event.isChecked()) { return true; } AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); AccessibilityNodeInfoCompat source = record.getSource(); if (source != null) { if (source.isCheckable()) { return true; } // it is bug in settings application that does not include clicked state on node // so we need to restore it later from TYPE_WINDOW_CONTENT_CHANGED event if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mClickedNode = source; mClickedTime = System.currentTimeMillis(); } } return false; } if (type == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false; if (mClickedTime == -1 || mClickedNode == null) return false; long now = System.currentTimeMillis(); if ((mClickedTime + 1000) < now) { mClickedTime = -1; if (mClickedNode != null) { mClickedNode.recycle(); mClickedNode = null; } return false; } AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); AccessibilityNodeInfoCompat source = record.getSource(); return findClickedCheckableNode(source); } return false; }
From source file:com.android.screenspeak.eventprocessor.ProcessorEventQueue.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { final int eventType = event.getEventType(); if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { mLastWindowStateChanged = SystemClock.uptimeMillis(); }// w w w . j a v a2 s .com synchronized (mEventQueue) { mEventQueue.enqueue(event); mHandler.postSpeak(); } }
From source file:com.google.android.marvin.mytalkback.ProcessorLongHover.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { final int eventType = event.getEventType(); if ((eventType == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) || (eventType == AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START)) { mIsTouchExploring = true;// w w w . j a v a 2 s. c o m } if (eventType == AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END) { mIsTouchExploring = false; cacheEnteredNode(null); cancelLongHover(); return; } if (!mIsTouchExploring || ((eventType != TRIGGER_ACTION) && (eventType != AccessibilityEvent.TYPE_VIEW_HOVER_EXIT))) { return; } final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event); final AccessibilityNodeInfoCompat source = record.getSource(); if (source == null) { return; } if (eventType == TRIGGER_ACTION) { cacheEnteredNode(source); postLongHoverRunnable(event); } else if (eventType == AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT) { if (source.equals(mWaitingForExit)) { cancelLongHover(); } } source.recycle(); }
From source file:com.android.screenspeak.formatter.CheckableClickedFormatter.java
@Override public boolean format(AccessibilityEvent event, ScreenSpeakService context, Utterance utterance) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) { if (sCachedCheckableNode == null) return false; utterance.addAuditory(R.raw.tick); utterance.addHaptic(R.array.view_clicked_pattern); utterance.addSpoken(context.getString( sCachedCheckableNode.isChecked() ? R.string.value_checked : R.string.value_not_checked)); sCachedCheckableNode.recycle();//from ww w .j a va2 s . c om sCachedCheckableNode = null; return true; } AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); AccessibilityNodeInfoCompat source = record.getSource(); utterance.addAuditory(R.raw.tick); utterance.addHaptic(R.array.view_clicked_pattern); CharSequence eventText = AccessibilityEventUtils.getEventTextOrDescription(event); if (!TextUtils.isEmpty(eventText)) { utterance.addSpoken(eventText); } // Switch and ToggleButton state is sent along with the event, so only // append checked / not checked state for other types of controls. if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(source, ToggleButton.class) || AccessibilityNodeInfoUtils.nodeMatchesClassByType(source, Switch.class)) { return true; } if (source == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (event.isChecked()) { utterance.addSpoken(context.getString(R.string.value_checked)); } else { utterance.addSpoken(context.getString(R.string.value_not_checked)); } return true; } if (source.isCheckable()) { if (source.isChecked()) { utterance.addSpoken(context.getString(R.string.value_checked)); } else { utterance.addSpoken(context.getString(R.string.value_not_checked)); } } return true; }
From source file:com.android.screenspeak.formatter.TouchExplorationFormatter.java
/** * Formatter that returns an utterance to announce touch exploration. *///from ww w. ja va 2 s .com @Override public boolean format(AccessibilityEvent event, ScreenSpeakService context, Utterance utterance) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED && EventState.getInstance().hasEvent(EventState.EVENT_SKIP_FOCUS_PROCESSING_AFTER_GRANULARITY_MOVE, SKIP_GRANULARITY_MOVE_FOCUS_TIMEOUT)) { EventState.getInstance().clearEvent(EventState.EVENT_SKIP_FOCUS_PROCESSING_AFTER_GRANULARITY_MOVE); return true; } final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); final AccessibilityNodeInfoCompat sourceNode = record.getSource(); final AccessibilityNodeInfoCompat focusedNode = getFocusedNode(event.getEventType(), sourceNode); // Drop the event if the source node was non-null, but the focus // algorithm decided to drop the event by returning null. if ((sourceNode != null) && (focusedNode == null)) { AccessibilityNodeInfoUtils.recycleNodes(sourceNode); return false; } LogUtils.log(this, Log.VERBOSE, "Announcing node: %s", focusedNode); // Populate the utterance. addDescription(utterance, focusedNode, event, sourceNode); addFeedback(utterance, focusedNode); // By default, touch exploration flushes all other events. utterance.getMetadata().putInt(Utterance.KEY_METADATA_QUEUING, DEFAULT_QUEUING_MODE); // Events formatted by this class should always advance continuous // reading, if active. utterance.addSpokenFlag(FeedbackItem.FLAG_ADVANCE_CONTINUOUS_READING); AccessibilityNodeInfoUtils.recycleNodes(sourceNode, focusedNode); return true; }
From source file:com.android.talkback.formatter.CheckableClickedFormatter.java
@Override public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) { if (sCachedCheckableNode == null) return false; // Need to get latest state of cached node before accessing. sCachedCheckableNode.refresh();//from w w w . j av a 2s. co m utterance.addAuditory(R.raw.tick); utterance.addHaptic(R.array.view_clicked_pattern); utterance.addSpoken(context.getString( sCachedCheckableNode.isChecked() ? R.string.value_checked : R.string.value_not_checked)); sCachedCheckableNode.recycle(); sCachedCheckableNode = null; return true; } AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); AccessibilityNodeInfoCompat source = record.getSource(); utterance.addAuditory(R.raw.tick); utterance.addHaptic(R.array.view_clicked_pattern); CharSequence eventText = AccessibilityEventUtils.getEventTextOrDescription(event); if (!TextUtils.isEmpty(eventText)) { utterance.addSpoken(eventText); } // Switch and ToggleButton state is sent along with the event, so only // append checked / not checked state for other types of controls. // TODO: node.isTwoState() if (Role.getRole(source) == Role.ROLE_TOGGLE_BUTTON || Role.getRole(source) == Role.ROLE_SWITCH) { return true; } if (source == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (event.isChecked()) { utterance.addSpoken(context.getString(R.string.value_checked)); } else { utterance.addSpoken(context.getString(R.string.value_not_checked)); } return true; } if (source.isCheckable()) { if (source.isChecked()) { utterance.addSpoken(context.getString(R.string.value_checked)); } else { utterance.addSpoken(context.getString(R.string.value_not_checked)); } } return true; }
From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java
private boolean isCharacterTraversalEvent(AccessibilityEvent event) { return (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY && event.getMovementGranularity() == AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER); }
From source file:com.android.screenspeak.eventprocessor.EventQueue.java
/** * Removes and returns an AccessibilityEvent from the front of the event queue. * * @return The event at the front of the queue. *//*from w ww . j a va2 s . co m*/ public AccessibilityEvent dequeue() { if (mEventQueue.isEmpty()) { return null; } final AccessibilityEvent event = mEventQueue.remove(0); if (event != null && AccessibilityEventUtils.eventMatchesAnyType(event, MASK_LIMITED_EVENT_TYPES)) { final int eventType = event.getEventType(); final int eventCountOfType = mQualifyingEvents.get(eventType, 0); mQualifyingEvents.put(eventType, (eventCountOfType - 1)); } return event; }
From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java
/** * Returns true if a pending phonetic letter should be interrupted. *///from w ww . j av a 2 s. co m private boolean shouldCancelPhoneticLetter(AccessibilityEvent event) { return event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED && event.getEventType() != AccessibilityEvent.TYPE_VIEW_LONG_CLICKED && event.getEventType() != AccessibilityEvent.TYPE_ANNOUNCEMENT; }
From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java
private boolean isKeyboardEvent(AccessibilityEvent event) { if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { return false; }/* w w w.ja v a 2 s.c o m*/ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { // For platform since lollipop, check that the current window is an // Input Method. final AccessibilityNodeInfo source = event.getSource(); if (source == null) { return false; } int windowId = source.getWindowId(); WindowManager manager = new WindowManager(); manager.setWindows(mService.getWindows()); return manager.getWindowType(windowId) == AccessibilityWindowInfo.TYPE_INPUT_METHOD; } else { // For old platforms, we can't check the window type directly, so just // manually check the classname. return event.getClassName().equals("com.android.inputmethod.keyboard.Key"); } }