本文整理汇总了Java中android.text.Editable.getSpanStart方法的典型用法代码示例。如果您正苦于以下问题:Java Editable.getSpanStart方法的具体用法?Java Editable.getSpanStart怎么用?Java Editable.getSpanStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Editable
的用法示例。
在下文中一共展示了Editable.getSpanStart方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleIgnoredTag
import android.text.Editable; //导入方法依赖的package包/类
/**
* When we come upon an ignored tag, we mark it with an Annotation object with a specific key
* and value as above. We don't really need to be checking these values since Html.fromHtml()
* doesn't use Annotation spans, but we should do it now to be safe in case they do start using
* it in the future.
* @param opening If this is an opening tag or not.
* @param output Spannable string that we're working with.
*/
private void handleIgnoredTag(boolean opening, Editable output) {
int len = output.length();
if (opening) {
output.setSpan(new Annotation(IGNORED_ANNOTATION_KEY, IGNORED_ANNOTATION_VALUE), len,
len, Spannable.SPAN_MARK_MARK);
} else {
Object start = getOpeningAnnotation(output);
if (start != null) {
int where = output.getSpanStart(start);
// Remove the temporary Annotation span.
output.removeSpan(start);
// Delete everything between the start of the Annotation and the end of the string
// (what we've generated so far).
output.delete(where, len);
}
}
}
示例2: handleTag
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {
if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
if (opening) {
mListParents.add(tag);
} else mListParents.remove(tag);
mListItemCount = 0;
} else if (tag.equals("li") && !opening) {
handleListTag(output);
}
else if(tag.equalsIgnoreCase("code")) {
if(opening) {
output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
} else {
Log.d("COde Tag","Code tag encountered");
Object obj = getLast(output, TypefaceSpan.class);
int where = output.getSpanStart(obj);
output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
}
}
}
示例3: onSelectionChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
protected void onSelectionChanged(int handle, int selEnd) {
super.onSelectionChanged(handle, selEnd);
Editable text = getText();
MathSpannable[] spans = text.getSpans(0, text.length(), MathSpannable.class);
for (MathSpannable span : spans) {
log("onSelectionChanged " + handle + " " + selEnd);
int start = text.getSpanStart(span);
int end = text.getSpanEnd(span);
if (handle > start && handle < end) {
log("notifying span(" + span.getEquation() + ") that its cursor is " + (handle - start));
span.setCursor(handle - start);
} else {
log("removing span(" + span.getEquation() + ")'s cursor");
span.setCursor(-1);
}
}
}
示例4: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
final RichEditText.TagSpan span = willDelSpan;
log("TagSpanTextWatcher#willRemove#span:" + (span == null ? "null" : span.toString()));
if (span != null && span.willRemove) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
// Remove the span
s.removeSpan(span);
// Remove the remaining emoticon text.
if (start != end) {
s.delete(start, end);
}
}
}
示例5: removeAutocomplete
import android.text.Editable; //导入方法依赖的package包/类
/**
* Remove any autocomplete text
*
* @param text Current text content that may include autocomplete text
*/
private boolean removeAutocomplete(final Editable text) {
final int start = text.getSpanStart(AUTOCOMPLETE_SPAN);
if (start < 0) {
// No autocomplete text
return false;
}
beginSettingAutocomplete();
// When we call delete() here, the autocomplete spans we set are removed as well.
text.delete(start, text.length());
// Keep mAutoCompletePrefixLength the same because the prefix has not changed.
// Clear mAutoCompleteResult to make sure we get fresh autocomplete text next time.
mAutoCompleteResult = AutocompleteResult.emptyResult();
// Reshow the cursor.
setCursorVisible(true);
endSettingAutocomplete();
return true;
}
示例6: onSelectionChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void onSelectionChanged(final int selStart, final int selEnd) {
// The user has repositioned the cursor somewhere. We need to adjust
// the autocomplete text depending on where the new cursor is.
final Editable text = getText();
final int start = text.getSpanStart(AUTOCOMPLETE_SPAN);
if (mSettingAutoComplete || start < 0 || (start == selStart && start == selEnd)) {
// Do not commit autocomplete text if there is no autocomplete text
// or if selection is still at start of autocomplete text
return;
}
if (selStart <= start && selEnd <= start) {
// The cursor is in user-typed text; remove any autocomplete text.
removeAutocomplete(text);
} else {
// The cursor is in the autocomplete text; commit it so it becomes regular text.
commitAutocomplete(text);
}
}
示例7: backspace
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void backspace() {
final int selectionHandle = getSelectionStart();
final Editable editable = getText();
if (selectionHandle > 0) {
MathSpannable[] spans = editable.getSpans(selectionHandle, selectionHandle, MathSpannable.class);
if (spans.length != 0) {
String text = editable.toString();
String textBeforeInsertionHandle = text.substring(0, selectionHandle);
String textAfterInsertionHandle = text.substring(selectionHandle, text.length());
int deletionLength = -1;
if (selectionHandle == editable.getSpanEnd(spans[0]) && spans[0].removeOnBackspace()) {
deletionLength = spans[0].getEquation().length();
} else if (selectionHandle != editable.getSpanStart(spans[0])) {
deletionLength = spans[0].backspace();
}
if (deletionLength != -1) {
String newText = textBeforeInsertionHandle.substring(0, textBeforeInsertionHandle.length() - deletionLength) + textAfterInsertionHandle;
setText(newText);
setSelection(selectionHandle - deletionLength);
return;
}
}
}
super.backspace();
}
示例8: end
import android.text.Editable; //导入方法依赖的package包/类
/**
* Modified from {@link android.text.Html}
*/
private void end(Editable output, Class kind, boolean paragraphStyle, Object... replaces) {
Object obj = getLast(output, kind);
// start of the tag
int where = output.getSpanStart(obj);
// end of the tag
int len = output.length();
// If we're in a table, then we need to store the raw HTML for later
if (tableTagLevel > 0) {
final CharSequence extractedSpanText = extractSpanText(output, kind);
tableHtmlBuilder.append(extractedSpanText);
}
output.removeSpan(obj);
if (where != len) {
int thisLen = len;
// paragraph styles like AlignmentSpan need to end with a new line!
if (paragraphStyle) {
output.append("\n");
thisLen++;
}
for (Object replace : replaces) {
output.setSpan(replace, where, thisLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (HtmlTextView.DEBUG) {
Log.d(HtmlTextView.TAG, "where: " + where);
Log.d(HtmlTextView.TAG, "thisLen: " + thisLen);
}
}
}
示例9: extractSpanText
import android.text.Editable; //导入方法依赖的package包/类
/**
* Returns the text contained within a span and deletes it from the output string
*/
private CharSequence extractSpanText(Editable output, Class kind) {
final Object obj = getLast(output, kind);
// start of the tag
final int where = output.getSpanStart(obj);
// end of the tag
final int len = output.length();
final CharSequence extractedSpanText = output.subSequence(where, len);
output.delete(where, len);
return extractedSpanText;
}
示例10: changeRemoveState
import android.text.Editable; //导入方法依赖的package包/类
void changeRemoveState(boolean willRemove, Editable message) {
if (this.willRemove == willRemove)
return;
this.willRemove = willRemove;
int cacheSpanStart = message.getSpanStart(this);
int cacheSpanEnd = message.getSpanEnd(this);
if (cacheSpanStart >= 0 && cacheSpanEnd >= cacheSpanStart) {
message.setSpan(this, cacheSpanStart, cacheSpanEnd,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
示例11: getNonAutocompleteText
import android.text.Editable; //导入方法依赖的package包/类
/**
* Get the portion of text that is not marked as autocomplete text.
*
* @param text Current text content that may include autocomplete text
*/
private static String getNonAutocompleteText(final Editable text) {
final int start = text.getSpanStart(AUTOCOMPLETE_SPAN);
if (start < 0) {
// No autocomplete text; return the whole string.
return text.toString();
}
// Only return the portion that's not autocomplete text
return TextUtils.substring(text, 0, start);
}
示例12: commitAutocomplete
import android.text.Editable; //导入方法依赖的package包/类
/**
* Convert any autocomplete text to regular text
*
* @param text Current text content that may include autocomplete text
*/
private boolean commitAutocomplete(final Editable text) {
final int start = text.getSpanStart(AUTOCOMPLETE_SPAN);
if (start < 0) {
// No autocomplete text
return false;
}
beginSettingAutocomplete();
// Remove all spans here to convert from autocomplete text to regular text
for (final Object span : mAutoCompleteSpans) {
text.removeSpan(span);
}
// Keep mAutoCompleteResult the same because the result has not changed.
// Reset mAutoCompletePrefixLength because the prefix now includes the autocomplete text.
mAutoCompletePrefixLength = text.length();
// Reshow the cursor.
setCursorVisible(true);
endSettingAutocomplete();
// Filter on the new text
if (mFilterListener != null) {
mFilterListener.onFilter(text.toString(), null);
}
return true;
}
示例13: commitText
import android.text.Editable; //导入方法依赖的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;
}
示例14: setComposingText
import android.text.Editable; //导入方法依赖的package包/类
@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
Editable currentText = getText();
int autoCompleteSpanStart = currentText.getSpanStart(mAutocompleteSpan);
if (autoCompleteSpanStart >= 0) {
int composingEnd = BaseInputConnection.getComposingSpanEnd(currentText);
// On certain device/keyboard combinations, the composing regions are specified
// with a noticeable delay after the initial character is typed, and in certain
// circumstances it does not check that the current state of the text matches the
// expectations of it's composing region.
// For example, you can be typing:
// chrome://f
// Chrome will autocomplete to:
// chrome://f[lags]
// And after the autocomplete has been set, the keyboard will set the composing
// region to the last character and it assumes it is 'f' as it was the last
// character the keyboard sent. If we commit this composition, the text will
// look like:
// chrome://flag[f]
// And if we use the autocomplete clearing logic below, it will look like:
// chrome://f[f]
// To work around this, we see if the composition matches all the characters prior
// to the autocomplete and just readjust the composing region to be that subset.
//
// See crbug.com/366732
if (composingEnd == currentText.length()
&& autoCompleteSpanStart >= text.length()
&& TextUtils.equals(
currentText.subSequence(
autoCompleteSpanStart - text.length(),
autoCompleteSpanStart),
text)) {
setComposingRegion(
autoCompleteSpanStart - text.length(), autoCompleteSpanStart);
}
// Once composing text is being modified, the autocomplete text has been accepted
// or has to be deleted.
mAutocompleteSpan.clearSpan();
Selection.setSelection(currentText, autoCompleteSpanStart);
currentText.delete(autoCompleteSpanStart, currentText.length());
}
return super.setComposingText(text, newCursorPosition);
}