Java Code Examples for android.view.accessibility.AccessibilityWindowInfo#getType()

The following examples show how to use android.view.accessibility.AccessibilityWindowInfo#getType() . 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: WindowManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** returns true if there is no window with windowType after baseWindow */
public boolean isLastWindow(AccessibilityWindowInfo baseWindow, int windowType) {
  int index = getWindowIndex(baseWindow);
  if (index == WRONG_INDEX) {
    return true;
  }

  int count = mWindows.size();
  for (int i = index + 1; i < count; i++) {
    AccessibilityWindowInfo window = mWindows.get(i);
    if (window != null && window.getType() == windowType) {
      return false;
    }
  }

  return true;
}
 
Example 2
Source File: WindowManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** returns true if there is no window with windowType before baseWindow */
public boolean isFirstWindow(AccessibilityWindowInfo baseWindow, int windowType) {
  int index = getWindowIndex(baseWindow);
  if (index <= 0) {
    return true;
  }

  for (int i = index - 1; i > 0; i--) {
    AccessibilityWindowInfo window = mWindows.get(i);
    if (window != null && window.getType() == windowType) {
      return false;
    }
  }

  return true;
}
 
Example 3
Source File: ScreenState.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Returns title of window with given window ID.
 *
 * <p><strong>Note: </strong> This method returns null if the window has no title, or the window
 * is not visible, or the window is IME or system window.
 */
@Nullable
public CharSequence getWindowTitle(int windowId) {
  AccessibilityWindowInfo window = idToWindowInfoMap.get(windowId);
  if ((window == null)
      || (window.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD)
      || (window.getType() == AccessibilityWindowInfo.TYPE_SYSTEM)
      || (window.getType() == AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER)) {
    // Only return title for application or accessibility windows.
    return null;
  }

  CharSequence eventTitle = overriddenWindowTitles.get(windowId);
  if (!TextUtils.isEmpty(eventTitle)) {
    return eventTitle;
  }

  if (BuildVersionUtils.isAtLeastN()) {
    // AccessibilityWindowInfo.getTitle() is available since API 24.
    CharSequence infoTitle = window.getTitle();
    if (!TextUtils.isEmpty(infoTitle)) {
      return infoTitle;
    }
  }
  return null;
}
 
Example 4
Source File: WindowEventInterpreter.java    From talkback with Apache License 2.0 6 votes vote down vote up
public boolean isSplitScreenMode() {
  if (!isSplitScreenModeAvailable) {
    return false;
  }

  // TODO: Update this state when receiving a TYPE_WINDOWS_CHANGED event if possible.
  List<AccessibilityWindowInfo> windows = AccessibilityServiceCompatUtils.getWindows(service);
  List<AccessibilityWindowInfo> applicationWindows = new ArrayList<>();
  for (AccessibilityWindowInfo window : windows) {
    if (window.getType() == AccessibilityWindowInfo.TYPE_APPLICATION) {
      if (window.getParent() == null
          && !AccessibilityWindowInfoUtils.isPictureInPicture(window)) {
        applicationWindows.add(window);
      }
    }
  }

  // We consider user to be in split screen mode if there are two non-parented
  // application windows.
  return applicationWindows.size() == 2;
}
 
Example 5
Source File: WindowEventInterpreter.java    From talkback with Apache License 2.0 6 votes vote down vote up
private boolean isSystemWindow(int windowId) {
  if (systemWindowIdsSet.contains(windowId)) {
    return true;
  }

  if (!isSplitScreenModeAvailable) {
    return false;
  }

  for (AccessibilityWindowInfo window : AccessibilityServiceCompatUtils.getWindows(service)) {
    if (window.getId() == windowId && window.getType() == AccessibilityWindowInfo.TYPE_SYSTEM) {
      return true;
    }
  }

  return false;
}
 
Example 6
Source File: SummaryOutput.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the SummaryActivity, passing it the application window which will be used to generate
 * the screen summary.
 */
public static void showOutput(AccessibilityService service) {
  List<AccessibilityWindowInfo> windows = AccessibilityServiceCompatUtils.getWindows(service);
  ArrayList<ArrayList<NodeData>> nodeDataList = new ArrayList<ArrayList<NodeData>>();
  for (int i = 0; i < TreeTraversal.ZONE_COUNT; i++) {
    nodeDataList.add(new ArrayList<NodeData>());
  }
  // Collect summary info from all windows of type application to account for split screen mode.
  // Also collect info if the window is an active system window, such as notification shade.
  for (AccessibilityWindowInfo window : windows) {
    int windowType = window.getType();
    if (windowType == AccessibilityWindowInfo.TYPE_APPLICATION
        || (window.getType() == AccessibilityWindowInfo.TYPE_SYSTEM && window.isActive())) {
      ArrayList<ArrayList<NodeData>> windowSummary = TreeTraversal.checkRootNode(window, service);
      for (int i = 0; i < TreeTraversal.ZONE_COUNT; i++) {
        nodeDataList.get(i).addAll(windowSummary.get(i));
      }
    }
  }
  // Attach summary elements to their location names in LocationData. Only add to the LocationData
  // list if the list of summary items is non empty.
  ArrayList<LocationData> locationDataList = new ArrayList<LocationData>();
  String[] locationNames = getLocationNames(service);
  for (int i = 0; i < TreeTraversal.ZONE_COUNT; i++) {
    ArrayList<NodeData> nodeDataSubList = nodeDataList.get(i);
    if (!nodeDataSubList.isEmpty()) {
      locationDataList.add(new LocationData(locationNames[i], nodeDataList.get(i)));
    }
  }

  showDialog(service, locationDataList);
}
 
Example 7
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private AccessibilityWindowInfo getWindowOfTypeIme() {
    try {
        List<AccessibilityWindowInfo> ww = getWindows();
        for (AccessibilityWindowInfo w : ww) {
            if (w.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) {
                return w;
            }
        }
    } catch (java.lang.SecurityException ex) {
        //This can only happen when switching users!
        Ln.e(ex, "failed to getWindows!");
    }
    return null;
}
 
Example 8
Source File: ScreenState.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Used by {@link #toString()}. */
private boolean isInSplitScreenMode() {
  for (AccessibilityWindowInfo window : idToWindowInfoMap.values()) {
    if ((window != null)
        && window.getType() == AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER) {
      return true;
    }
  }
  return false;
}
 
Example 9
Source File: ScreenState.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Used by {@link #toString()}. */
private String getWindowListString(int windowType) {
  StringBuilder sb = new StringBuilder();
  for (AccessibilityWindowInfo window : idToWindowInfoMap.values()) {
    if ((window != null)
        && (window.getType() == windowType)
        && !AccessibilityWindowInfoUtils.isPictureInPicture(window)) {
      sb.append(getWindowDescription(window));
    }
  }
  return sb.toString();
}
 
Example 10
Source File: AccessibilityWindowInfoUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Reorders the list of {@link AccessibilityWindowInfo} objects based on window positions on the
 * screen. Removes the {@link AccessibilityWindowInfo} for the split screen divider in
 * multi-window mode.
 */
public static void sortAndFilterWindows(List<AccessibilityWindowInfo> windows, boolean isInRTL) {
  if (windows == null) {
    return;
  }

  Collections.sort(windows, new WindowPositionComparator(isInRTL));
  for (AccessibilityWindowInfo window : windows) {
    if (window.getType() == AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER) {
      windows.remove(window);
      return;
    }
  }
}
 
Example 11
Source File: AccessibilityWindowInfoUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(AccessibilityWindowInfo window) {
  if (window == null) {
    return false;
  }
  int type = window.getType();
  return (type == AccessibilityWindowInfo.TYPE_APPLICATION)
      || (type == AccessibilityWindowInfo.TYPE_SYSTEM);
}
 
Example 12
Source File: AccessibilityWindowInfoUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(AccessibilityWindowInfo window) {
  if (window == null) {
    return false;
  }
  int type = window.getType();
  return (type == AccessibilityWindowInfoCompat.TYPE_APPLICATION)
      || (type == AccessibilityWindowInfoCompat.TYPE_SPLIT_SCREEN_DIVIDER);
}
 
Example 13
Source File: WindowManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
public int getWindowType(int windowId) {
  if (mWindows != null) {
    for (AccessibilityWindowInfo window : mWindows) {
      if (window != null && window.getId() == windowId) {
        return window.getType();
      }
    }
  }

  return WRONG_WINDOW_TYPE;
}
 
Example 14
Source File: WindowManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
public boolean isInputWindowOnScreen() {
  if (mWindows == null) {
    return false;
  }

  for (AccessibilityWindowInfo window : mWindows) {
    if (window != null && window.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) {
      return true;
    }
  }

  return false;
}
 
Example 15
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private void closeKeyboard() {
  for (AccessibilityWindowInfo w : getInstrumentation().getUiAutomation().getWindows()) {
    if (w.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) {
      device.pressBack();
      return;
    }
  }
}
 
Example 16
Source File: WindowManager.java    From talkback with Apache License 2.0 4 votes vote down vote up
private boolean isFocusedWindowType(int windowType) {
  AccessibilityWindowInfo info = getCurrentWindow(false /* useInputFocus */);
  return info != null && info.getType() == windowType;
}
 
Example 17
Source File: WindowHierarchyElementAndroid.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 4 votes vote down vote up
private WindowHierarchyElementAndroid construct(
    int id,
    @Nullable WindowHierarchyElementAndroid parent,
    AccessibilityWindowInfo fromWindow,
    Map<ViewHierarchyElementAndroid, AccessibilityNodeInfo> elementToNodeInfoMap) {
  // Bookkeeping
  this.parentId = (parent != null) ? parent.getId() : null;

  // Window properties
  this.windowId = fromWindow.getId();
  this.layer = fromWindow.getLayer();
  this.type = fromWindow.getType();
  this.focused = fromWindow.isFocused();
  this.accessibilityFocused = fromWindow.isAccessibilityFocused();
  this.active = fromWindow.isActive();

  android.graphics.Rect tempRect = new android.graphics.Rect();
  fromWindow.getBoundsInScreen(tempRect);
  this.boundsInScreen = new Rect(tempRect.left, tempRect.top, tempRect.right, tempRect.bottom);

  // Build the window's view hierarchy
  AccessibilityNodeInfo rootInfo = fromWindow.getRoot();
  this.viewHierarchyElements = new ArrayList<>(); // The ultimate size is unknown
  if (rootInfo != null) {
    buildViewHierarchy(
        rootInfo, viewHierarchyElements, null /* no parent */, elementToNodeInfoMap);
    rootInfo.recycle();
  } else {
    // This could occur in the case where the application state changes between the time that
    // the AccessibilityWindowInfo object is obtained and when its root AccessibilityNodeInfo is
    // extracted.
    LogUtils.w(TAG, "Constructed WindowHierarchyElement with no valid root.");
  }
  return new WindowHierarchyElementAndroid(
      id,
      parentId,
      childIds,
      windowId,
      layer,
      type,
      focused,
      accessibilityFocused,
      active,
      boundsInScreen,
      viewHierarchyElements);
}
 
Example 18
Source File: WindowTransitionInfo.java    From talkback with Apache License 2.0 4 votes vote down vote up
private static boolean isSystemOrImeWindow(AccessibilityWindowInfo window) {
  return (window.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD)
      || (window.getType() == AccessibilityWindowInfo.TYPE_SYSTEM);
}