// Note this comparator is not consistent with equals in Label, we should just implement // compareTo there, but will wait for BrailleBack to be merged with TalkBack @Override public int compare(Label first, Label second) { if (first == null) { if (second == null) { return 0; } else { return -1; } } if (second == null) return 1; int ret = first.getPackageName().compareTo(second.getPackageName()); if (ret != 0) return ret; return first.getViewName().compareTo(second.getViewName()); }
/** * Retrieves a {@link Label} from the label cache given a fully-qualified resource identifier * name. * * @param resourceName The fully-qualified resource identifier, such as * "com.android.deskclock:id/analog_appwidget", as provided by {@link * AccessibilityNodeInfo#getViewIdResourceName()} * @return The {@link Label} matching the provided identifier, or {@code null} if no such label * exists or has not yet been fetched from storage */ public Label getLabelForViewIdFromCache(String resourceName) { if (!isInitialized()) { return null; } Pair<String, String> parsedId = splitResourceName(resourceName); if (parsedId == null) { return null; } Label search = new Label(parsedId.first, null, parsedId.second, null, null, 0, null, 0); Label result = mLabelCache.ceiling(search); // TODO: This can be done much simplier with modifying equals in Label but want to wait // until BrailleBack is integrate to ensure compatibility if (result != null && search.getViewName() != null && search.getViewName().equals(result.getViewName()) && search.getPackageName() != null && search.getPackageName().equals(result.getPackageName())) { return result; } return null; }