List of usage examples for android.view.accessibility AccessibilityWindowInfo getId
public int getId()
From source file:com.android.utils.WindowManager.java
public int getWindowType(int windowId) { if (mWindows != null) { for (AccessibilityWindowInfo window : mWindows) { if (window != null && window.getId() == windowId) { return window.getType(); }/*from w w w. ja va2 s .c o m*/ } } return WRONG_WINDOW_TYPE; }
From source file:com.android.screenspeak.eventprocessor.ProcessorVolumeStream.java
private boolean attemptNavigation(int button) { AccessibilityNodeInfoCompat node = mCursorController.getCursor(); // Clear focus if it is on an IME if (node != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { for (AccessibilityWindowInfo awi : mService.getWindows()) { if (awi.getId() == node.getWindowId()) { if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) { node.recycle();//from ww w . j av a 2 s .co m node = null; } break; } } } } if (node == null) { node = findInputFocus(); } if (node == null) return false; try { if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, SeekBar.class)) { navigateSlider(button); return true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (((AccessibilityNodeInfo) node.getInfo()).isEditable()) { navigateEditText(button, node); return true; } } else { if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, EditText.class) || AccessibilityNodeInfoUtils.nodeMatchesClassByName(node, "com.google.android.search.searchplate.SimpleSearchText")) { navigateEditText(button, node); return true; } } return false; } finally { AccessibilityNodeInfoUtils.recycleNodes(node); } }
From source file:com.android.talkback.eventprocessor.ProcessorVolumeStream.java
private boolean attemptNavigation(int button) { AccessibilityNodeInfoCompat node = mCursorController.getCursorOrInputCursor(); // Clear focus if it is on an IME if (node != null) { if (API_LEVEL_SUPPORTS_WINDOW_NAVIGATION) { for (AccessibilityWindowInfo awi : mService.getWindows()) { if (awi.getId() == node.getWindowId()) { if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) { node.recycle();/*from ww w .j a v a 2 s . co m*/ node = null; } break; } } } } // If we cleared the focus before it is on an IME, try to get the current node again. if (node == null) { node = mCursorController.getCursorOrInputCursor(); } if (node == null) return false; try { if (Role.getRole(node) == Role.ROLE_SEEK_CONTROL) { navigateSlider(button, node); return true; } // In general, do not allow volume key navigation when the a11y focus is placed but // it is not on the edit field that the keyboard is currently editing. // // Example 1: // EditText1 has input focus and EditText2 has accessibility focus. // getCursorOrInputCursor() will return EditText2 based on its priority order. // EditText2.isFocused() = false, so we should not allow volume keys to control text. // // Example 2: // EditText1 in Window1 has input focus. EditText2 in Window2 has input focus as well. // If Window1 is input-focused but Window2 has the accessibility focus, don't allow // the volume keys to control the text. boolean nodeWindowFocused; if (API_LEVEL_SUPPORTS_WINDOW_NAVIGATION) { nodeWindowFocused = node.getWindow() != null && node.getWindow().isFocused(); } else { nodeWindowFocused = true; } if (node.isFocused() && nodeWindowFocused && AccessibilityNodeInfoUtils.isEditable(node)) { navigateEditText(button, node); return true; } return false; } finally { AccessibilityNodeInfoUtils.recycleNodes(node); } }
From source file:com.android.talkback.eventprocessor.ProcessorScreen.java
private boolean isSystemWindow(int windowId) { if (mSystemWindowIdsSet.contains(windowId)) { return true; }// ww w.j av a 2s .c o m if (!mIsSplitScreenModeAvailable) { return false; } for (AccessibilityWindowInfo window : mService.getWindows()) { if (window.getId() == windowId && window.getType() == AccessibilityWindowInfo.TYPE_SYSTEM) { return true; } } return false; }
From source file:com.android.talkback.eventprocessor.ProcessorScreen.java
private CharSequence getWindowTitle(int windowId) { // Try to get window title from the map. CharSequence windowTitle = mWindowTitlesMap.get(windowId); if (windowTitle != null) { return windowTitle; }// w ww.jav a 2 s .co m if (!BuildCompat.isAtLeastN()) { return null; } // Do not try to get system window title from AccessibilityWindowInfo.getTitle, it can // return non-translated value. if (isSystemWindow(windowId)) { return null; } // Try to get window title from AccessibilityWindowInfo. for (AccessibilityWindowInfo window : mService.getWindows()) { if (window.getId() == windowId) { return window.getTitle(); } } return null; }
From source file:com.android.talkback.eventprocessor.ProcessorScreen.java
private CharSequence getWindowTitleForFeedback(int windowId) { CharSequence title = getWindowTitle(windowId); // Try to fall back to application label if window title is not available. if (title == null) { CharSequence packageName = mWindowToPackageName.get(windowId); // Try to get package name from accessibility window info if it's not in the map. if (packageName == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { for (AccessibilityWindowInfo window : mService.getWindows()) { if (window.getId() == windowId) { AccessibilityNodeInfo rootNode = window.getRoot(); if (rootNode != null) { packageName = rootNode.getPackageName(); rootNode.recycle(); }//w ww . ja v a2 s .co m } } } if (packageName != null) { title = mService.getApplicationLabel(packageName); } } title = WindowManager.formatWindowTitleForFeedback(title, mService); if (isAlertDialog(windowId)) { title = mService.getString(R.string.template_alert_dialog_template, title); } return title; }
From source file:com.android.talkback.eventprocessor.ProcessorScreen.java
private void updateWindowTitlesMap(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: { // If split screen mode is NOT available, we only need to care single window. if (!mIsSplitScreenModeAvailable) { mWindowTitlesMap.clear();//from w w w . ja va2 s .c om } int windowId = getWindowId(event); boolean shouldAnnounceEvent = shouldAnnounceEvent(event, windowId); CharSequence title = getWindowTitleFromEvent(event, shouldAnnounceEvent /* useContentDescription */); if (title != null) { if (shouldAnnounceEvent) { // When software keyboard is shown or hidden, TYPE_WINDOW_STATE_CHANGED // is dispatched with text describing the visibility of the keyboard. speakWithFeedback(title); } else { mWindowTitlesMap.put(windowId, title); if (getWindowType(event) == AccessibilityWindowInfo.TYPE_SYSTEM) { mSystemWindowIdsSet.add(windowId); } CharSequence eventWindowClassName = event.getClassName(); mWindowToClassName.put(windowId, eventWindowClassName); mWindowToPackageName.put(windowId, event.getPackageName()); } } } break; case AccessibilityEvent.TYPE_WINDOWS_CHANGED: { HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>(mWindowTitlesMap.keySet()); List<AccessibilityWindowInfo> windows = mService.getWindows(); for (AccessibilityWindowInfo window : windows) { windowIdsToBeRemoved.remove(window.getId()); } for (Integer windowId : windowIdsToBeRemoved) { mWindowTitlesMap.remove(windowId); mSystemWindowIdsSet.remove(windowId); mWindowToClassName.remove(windowId); mWindowToPackageName.remove(windowId); } } break; } }
From source file:com.android.talkback.formatter.TouchExplorationFormatter.java
/** * Resets cached scrollable state when touch exploration after window state * changes./*from ww w . j a v a 2 s . c o m*/ */ @Override public void onAccessibilityEvent(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: // Reset cached scrollable state. mLastNodeWasScrollable = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Store window title in the map. List<CharSequence> titles = event.getText(); if (titles.size() > 0) { AccessibilityNodeInfo node = event.getSource(); if (node != null) { int windowType = getWindowType(node); if (windowType == AccessibilityWindowInfo.TYPE_APPLICATION || windowType == AccessibilityWindowInfo.TYPE_SYSTEM) { mWindowTitlesMap.put(node.getWindowId(), titles.get(0)); } node.recycle(); } } } break; case AccessibilityEvent.TYPE_WINDOWS_CHANGED: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Copy key set not to modify original map. HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>(); windowIdsToBeRemoved.addAll(mWindowTitlesMap.keySet()); // Enumerate window ids to be removed. List<AccessibilityWindowInfo> windows = mService.getWindows(); for (AccessibilityWindowInfo window : windows) { windowIdsToBeRemoved.remove(window.getId()); } // Delete titles of non-existing window ids. for (Integer windowId : windowIdsToBeRemoved) { mWindowTitlesMap.remove(windowId); } } break; } }
From source file:com.android.talkback.eventprocessor.ProcessorScreen.java
private void updateScreenState(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: // Do nothing if split screen mode is available since it can be covered by // TYPE_WINDOWS_CHANGED events. if (mIsSplitScreenModeAvailable) { return; }/*from w ww. j ava2 s .co m*/ mWindowIdA = getWindowId(event); break; case AccessibilityEvent.TYPE_WINDOWS_CHANGED: // Do nothing if split screen mode is NOT available since it can be covered by // TYPE_WINDOW_STATE_CHANGED events. if (!mIsSplitScreenModeAvailable) { return; } ArrayList<AccessibilityWindowInfo> applicationWindows = new ArrayList<>(); ArrayList<AccessibilityWindowInfo> systemWindows = new ArrayList<>(); ArrayList<AccessibilityWindowInfo> accessibilityOverlayWindows = new ArrayList<>(); List<AccessibilityWindowInfo> windows = mService.getWindows(); // If there are no windows available, clear the cached IDs. if (windows.isEmpty()) { mAccessibilityOverlayWindowId = WINDOW_ID_NONE; mWindowIdA = WINDOW_ID_NONE; mWindowIdB = WINDOW_ID_NONE; return; } for (int i = 0; i < windows.size(); i++) { AccessibilityWindowInfo window = windows.get(i); switch (window.getType()) { case AccessibilityWindowInfo.TYPE_APPLICATION: if (window.getParent() == null) { applicationWindows.add(window); } break; case AccessibilityWindowInfo.TYPE_SYSTEM: systemWindows.add(window); break; case AccessibilityWindowInfo.TYPE_ACCESSIBILITY_OVERLAY: accessibilityOverlayWindows.add(window); break; } } if (accessibilityOverlayWindows.size() == windows.size()) { // TODO: investigate whether there is a case where we have more than one // accessibility overlay, and add a logic for it if there is. mAccessibilityOverlayWindowId = accessibilityOverlayWindows.get(0).getId(); return; } mAccessibilityOverlayWindowId = WINDOW_ID_NONE; if (applicationWindows.size() == 0) { mWindowIdA = WINDOW_ID_NONE; mWindowIdB = WINDOW_ID_NONE; // If there is no application window but a system window, consider it as a // current window. This logic handles notification shade and lock screen. if (systemWindows.size() > 0) { Collections.sort(systemWindows, new WindowManager.WindowPositionComparator(mService.isScreenLayoutRTL())); mWindowIdA = systemWindows.get(0).getId(); } } else if (applicationWindows.size() == 1) { mWindowIdA = applicationWindows.get(0).getId(); mWindowIdB = WINDOW_ID_NONE; } else if (applicationWindows.size() == 2) { Collections.sort(applicationWindows, new WindowManager.WindowPositionComparator(mService.isScreenLayoutRTL())); mWindowIdA = applicationWindows.get(0).getId(); mWindowIdB = applicationWindows.get(1).getId(); } else { // If there are more than 2 windows, report the active window as the current // window. for (AccessibilityWindowInfo applicationWindow : applicationWindows) { if (applicationWindow.isActive()) { mWindowIdA = applicationWindow.getId(); mWindowIdB = WINDOW_ID_NONE; return; } } } break; } }
From source file:com.android.talkback.controller.CursorControllerApp.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { int eventType = event.getEventType(); if (eventType == AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { final AccessibilityNodeInfo node = event.getSource(); if (node == null) { if (LogUtils.LOG_LEVEL <= Log.WARN) { Log.w(LOGTAG, "TYPE_VIEW_ACCESSIBILITY_FOCUSED event without a source."); }/* www . j a v a 2 s . c o m*/ return; } // When a new view gets focus, clear the state of the granularity // manager if this event came from a different node than the locked // node but from the same window. final AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node); mGranularityManager.onNodeFocused(nodeCompat); if (mSwitchNodeWithGranularityDirection == AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY) { mGranularityManager.navigate(AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY); } else if (mSwitchNodeWithGranularityDirection == AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY) { mGranularityManager.startFromLastNode(); mGranularityManager.navigate(AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); } mSwitchNodeWithGranularityDirection = 0; nodeCompat.recycle(); mReachedEdge = false; mGranularityNavigationReachedEdge = false; } else if (eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED) { final AccessibilityNodeInfo node = event.getSource(); if (node != null) { final AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node); // Note: we also need to check ROLE_EDIT_TEXT for JB MR1 and lower and for // Chrome/WebView 51 and lower. We should check isEditable() first because it's // more semantically appropriate for what we want. if (nodeCompat.isEditable() || Role.getRole(nodeCompat) == Role.ROLE_EDIT_TEXT) { AccessibilityNodeInfoUtils.recycleNodes(mLastEditable); mLastEditable = nodeCompat; } else { nodeCompat.recycle(); } } } else if (mIsWindowNavigationAvailable && eventType == AccessibilityEvent.TYPE_WINDOWS_CHANGED) { // Remove last focused nodes of non-existing windows. Set<Integer> windowIdsToBeRemoved = new HashSet(mLastFocusedNodeMap.keySet()); for (AccessibilityWindowInfo window : mService.getWindows()) { windowIdsToBeRemoved.remove(window.getId()); } for (Integer windowIdToBeRemoved : windowIdsToBeRemoved) { AccessibilityNodeInfoCompat removedNode = mLastFocusedNodeMap.remove(windowIdToBeRemoved); if (removedNode != null) { removedNode.recycle(); } } } }