本文整理汇总了Java中android.view.accessibility.AccessibilityEvent.setBeforeText方法的典型用法代码示例。如果您正苦于以下问题:Java AccessibilityEvent.setBeforeText方法的具体用法?Java AccessibilityEvent.setBeforeText怎么用?Java AccessibilityEvent.setBeforeText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.accessibility.AccessibilityEvent
的用法示例。
在下文中一共展示了AccessibilityEvent.setBeforeText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commitText
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
Editable currentText = getText();
if (currentText == null) return super.commitText(text, newCursorPosition);
int selectionStart = Selection.getSelectionStart(currentText);
int selectionEnd = Selection.getSelectionEnd(currentText);
int autocompleteIndex = currentText.getSpanStart(mAutocompleteSpan);
// If the text being committed is a single character that matches the next character
// in the selection (assumed to be the autocomplete text), we only move the text
// selection instead clearing the autocomplete text causing flickering as the
// autocomplete text will appear once the next suggestions are received.
//
// To be confident that the selection is an autocomplete, we ensure the selection
// is at least one character and the end of the selection is the end of the
// currently entered text.
if (newCursorPosition == 1 && selectionStart > 0 && selectionStart != selectionEnd
&& selectionEnd >= currentText.length()
&& autocompleteIndex == selectionStart
&& text.length() == 1) {
currentText.getChars(selectionStart, selectionStart + 1, mTempSelectionChar, 0);
if (mTempSelectionChar[0] == text.charAt(0)) {
// Since the text isn't changing, TalkBack won't read out the typed characters.
// To work around this, explicitly send an accessibility event. crbug.com/416595
if (mAccessibilityManager != null && mAccessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(
AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
event.setFromIndex(selectionStart);
event.setRemovedCount(0);
event.setAddedCount(1);
event.setBeforeText(currentText.toString().substring(0, selectionStart));
sendAccessibilityEventUnchecked(event);
}
setAutocompleteText(
currentText.subSequence(0, selectionStart + 1),
currentText.subSequence(selectionStart + 1, selectionEnd));
if (!mInBatchEditMode) {
notifyAutocompleteTextStateChanged(false);
}
return true;
}
}
boolean retVal = super.commitText(text, newCursorPosition);
// Ensure the autocomplete span is removed if it is no longer valid after committing the
// text.
if (getText().getSpanStart(mAutocompleteSpan) >= 0) clearAutocompleteSpanIfInvalid();
return retVal;
}