Java Code Examples for android.view.accessibility.AccessibilityEvent#getAddedCount()
The following examples show how to use
android.view.accessibility.AccessibilityEvent#getAddedCount() .
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: TextEventInterpreter.java From talkback with Apache License 2.0 | 6 votes |
private static boolean passesSanityCheck(AccessibilityEvent event) { final List<CharSequence> afterTexts = event.getText(); final CharSequence afterText = (afterTexts == null || afterTexts.isEmpty()) ? null : afterTexts.get(0); final CharSequence beforeText = event.getBeforeText(); // Special case for deleting all the text in an EditText with a // hint, since the event text will contain the hint rather than an // empty string. int beforeTextLength = (beforeText == null) ? 0 : beforeText.length(); if ((event.getAddedCount() == 0) && (event.getRemovedCount() == beforeTextLength)) { return true; } if (afterText == null || beforeText == null) { return false; } final int diff = (event.getAddedCount() - event.getRemovedCount()); return ((beforeText.length() + diff) == afterText.length()); }
Example 2
Source File: DigitsEditText.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@Override public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) { // Since we're replacing the text every time we add or remove a // character, only read the difference. (issue 5337550) final int added = event.getAddedCount(); final int removed = event.getRemovedCount(); final int length = event.getBeforeText().length(); if (added > removed) { event.setRemovedCount(0); event.setAddedCount(1); event.setFromIndex(length); } else if (removed > added) { event.setRemovedCount(1); event.setAddedCount(0); event.setFromIndex(length - 1); } else { return; } } else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) { // The parent EditText class lets tts read "edit box" when this View // has a focus, which // confuses users on app launch (issue 5275935). return; } super.sendAccessibilityEventUnchecked(event); }
Example 3
Source File: TextEventInterpreter.java From talkback with Apache License 2.0 | 5 votes |
/** * Returns {@code true} if it's a junky {@link AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED} when * typing pin code in unlock screen. * * <p>Starting from P, pin entry at lock screen files text changed event when the digit typed in * is visually replaced by bullet. We don't want to announce this change. * * <p>Fortunately, password field at lock screen doesn't have this issue. */ private static boolean isJunkyCharacterReplacedByBulletInUnlockPinEntry( AccessibilityEvent event) { if (!BuildVersionUtils.isAtLeastP() || (event.getAddedCount() != 1) || (event.getRemovedCount() != 1)) { return false; } AccessibilityNodeInfo source = event.getSource(); try { return AccessibilityNodeInfoUtils.isPinEntry(source); } finally { AccessibilityNodeInfoUtils.recycleNodes(source); } }
Example 4
Source File: TextEventInterpreter.java From talkback with Apache License 2.0 | 5 votes |
/** * Returns {@code null}, empty string or the added text depending on the event. * * <p>For cases where event.getText() is null or bad size, text interpretation is expected to be * set invalid with "addedText is null" in interpretTextChange(). Hence where event.getText() is * null or bad size, we return null as returning an empty string here would bypass this condition * and the text interpretation would be incorrect. * * @param event * @return the added text. */ private static @Nullable CharSequence getAddedText(AccessibilityEvent event) { final List<CharSequence> textList = event.getText(); // noinspection ConstantConditions if (textList == null || textList.size() > 1) { LogUtils.w(TAG, "getAddedText: Text list was null or bad size"); return null; } // If the text was empty, the list will be empty. See the // implementation for TextView.onPopulateAccessibilityEvent(). if (textList.size() == 0) { return ""; } final CharSequence text = textList.get(0); if (text == null) { LogUtils.w(TAG, "getAddedText: First text entry was null"); return null; } final int addedBegIndex = event.getFromIndex(); final int addedEndIndex = addedBegIndex + event.getAddedCount(); if (areInvalidIndices(text, addedBegIndex, addedEndIndex)) { LogUtils.w( TAG, "getAddedText: Invalid indices (%d,%d) for \"%s\"", addedBegIndex, addedEndIndex, text); return ""; } return getSubsequenceWithSpans(text, addedBegIndex, addedEndIndex); }
Example 5
Source File: AccessibilityEventUtils.java From brailleback with Apache License 2.0 | 4 votes |
/** * @return If the <code>first</code> event is equal to the <code>second</code>. */ public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) { // TODO: The framework should implement AccessibilityEvent#equals() if (first == null || second == null) { return false; } if (first.getEventType() != second.getEventType()) { return false; } if (first.getPackageName() == null) { if (second.getPackageName() != null) { return false; } } else if (!first.getPackageName().equals(second.getPackageName())) { return false; } if (first.getClassName() == null) { if (second.getClassName() != null) { return false; } } else if (!first.getClassName().equals(second.getClassName())) { return false; } if (!first.getText().equals(second.getText())) { // The result of getText() is never null. return false; } if (first.getContentDescription() == null) { if (second.getContentDescription() != null) { return false; } } else if (!first.getContentDescription().equals(second.getContentDescription())) { return false; } if (first.getBeforeText() == null) { if (second.getBeforeText() != null) { return false; } } else if (!first.getBeforeText().equals(second.getBeforeText())) { return false; } if (first.getParcelableData() != null) { // Parcelable data may not implement equals() correctly. return false; } if (first.getAddedCount() != second.getAddedCount()) { return false; } if (first.isChecked() != second.isChecked()) { return false; } if (first.isEnabled() != second.isEnabled()) { return false; } if (first.getFromIndex() != second.getFromIndex()) { return false; } if (first.isFullScreen() != second.isFullScreen()) { return false; } if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) { return false; } if (first.getItemCount() != second.getItemCount()) { return false; } if (first.isPassword() != second.isPassword()) { return false; } if (first.getRemovedCount() != second.getRemovedCount()) { return false; } if (first.getEventTime() != second.getEventTime()) { return false; } return true; }