本文整理汇总了Java中android.text.Spannable.removeSpan方法的典型用法代码示例。如果您正苦于以下问题:Java Spannable.removeSpan方法的具体用法?Java Spannable.removeSpan怎么用?Java Spannable.removeSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Spannable
的用法示例。
在下文中一共展示了Spannable.removeSpan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findStartPosition
import android.text.Spannable; //导入方法依赖的package包/类
/**
* 检查当前位置是否命中在spannable上, 如果是, 返回spannable的start position
*/
private int findStartPosition(Spannable spannable, int startWidthPosition) {
CharacterStyle[] oldSpans = spannable.getSpans(startWidthPosition, spannable.length(), CharacterStyle.class);
int position = startWidthPosition;
for (CharacterStyle oldSpan : oldSpans) {
int spanStart = spannable.getSpanStart(oldSpan);
int spanEnd = spannable.getSpanEnd(oldSpan);
if (spanStart <= startWidthPosition && spanEnd > startWidthPosition) {
position = spanStart;
}
if (spanStart >= startWidthPosition) {
spannable.removeSpan(oldSpan);
}
}
//L.e("call: findStartPosition([spannable, startWidthPosition]) " + startWidthPosition + " -> " + position);
return position;
}
示例2: setAndMergeSpans
import android.text.Spannable; //导入方法依赖的package包/类
public static void setAndMergeSpans(Spannable text, Object what, int start, int end, int flags) {
Object[] spans = text.getSpans(Math.max(start - 1, 0), Math.min(end + 1, 0), what.getClass());
for (Object span : spans) {
if (!areSpansEqual(span, what))
continue;
int sFlags = text.getSpanFlags(span);
if ((sFlags & Spanned.SPAN_COMPOSING) != 0)
continue;
int sStart = text.getSpanStart(span);
int sEnd = text.getSpanEnd(span);
if (sEnd < start || sStart > end)
continue;
text.removeSpan(span);
if (sStart < start)
start = sStart;
if (sEnd > end)
end = sEnd;
}
text.setSpan(what, start, end, flags);
}
示例3: invalidateSpannables
import android.text.Spannable; //导入方法依赖的package包/类
public void invalidateSpannables() {
log("invalidating all spannables -- consider everything nullified");
final Spannable spans = getText();
final String text = spans.toString();
// Remove existing spans
for (CharacterStyle style : mSpans) {
spans.removeSpan(style);
}
// Loop over the text, looking for new spans
for (int i = 0; i < text.length(); i++) {
for (SpanComponent component : mComponents) {
String equation = component.parse(text.substring(i));
if (equation != null) {
MathSpannable span = component.getSpan(equation);
spans.setSpan(span, i, i + equation.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
i += equation.length();
break;
}
}
}
setSelection(getSelectionStart());
}
示例4: replaceQuoteSpans
import android.text.Spannable; //导入方法依赖的package包/类
/**
* Replaces the blue line produced by <blockquote>s with something more visible
*
* @param spannable parsed comment text #fromHtml
*/
private void replaceQuoteSpans(Spannable spannable) {
QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
final int start = spannable.getSpanStart(quoteSpan);
final int end = spannable.getSpanEnd(quoteSpan);
final int flags = spannable.getSpanFlags(quoteSpan);
spannable.removeSpan(quoteSpan);
//If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
final int barColor =
(SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
? ContextCompat.getColor(getContext(), R.color.md_blue_600)
: ContextCompat.getColor(getContext(), R.color.md_blue_400);
final int BAR_WIDTH = 4;
final int GAP = 5;
spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
barColor, //bar color
BAR_WIDTH, //bar width
GAP), //bar + text gap
start, end, flags);
}
}
示例5: onDismiss
import android.text.Spannable; //导入方法依赖的package包/类
@Override
public void onDismiss(Spannable text) {
// Remove any span added by shouldShow. Should be useless, but anyway.
QuerySpan[] span = text.getSpans(0, text.length(), QuerySpan.class);
for (QuerySpan s : span) {
text.removeSpan(s);
}
}
示例6: setSpanFromMark
import android.text.Spannable; //导入方法依赖的package包/类
private void setSpanFromMark(String tag, Spannable text, Object mark, Object... spans) {
int where = text.getSpanStart(mark);
text.removeSpan(mark);
int len = text.length();
if (where != len) {
for (Object span : spans) {
if (mSpanCallback != null) {
span = mSpanCallback.onSpanCreated(tag, span);
}
text.setSpan(span, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
示例7: clearSpan
import android.text.Spannable; //导入方法依赖的package包/类
private void clearSpan(Spannable spannable, int start, int end) {
if (start == end) {
return;
}
EmoticonSpan[] oldSpans = spannable.getSpans(start, end, EmoticonSpan.class);
for (int i = 0; i < oldSpans.length; i++) {
spannable.removeSpan(oldSpans[i]);
}
}
示例8: addEmojis
import android.text.Spannable; //导入方法依赖的package包/类
public static void addEmojis(Context context, Spannable text, int emojiSize, int index, int
length, boolean useSystemDefault) {
if (!useSystemDefault) {
int textLength = text.length();
int textLengthToProcess = (length < 0 || length >= textLength - index) ? textLength :
length + index;
EmojiconSpan[] oldSpans = (EmojiconSpan[]) text.getSpans(0, textLength, EmojiconSpan
.class);
for (Object removeSpan : oldSpans) {
text.removeSpan(removeSpan);
}
int i = index;
while (i < textLengthToProcess) {
int skip = 0;
int icon = 0;
char c = text.charAt(i);
if (isSoftBankEmoji(c)) {
icon = getSoftbankEmojiResource(c);
skip = icon == 0 ? 0 : 1;
}
if (icon == 0) {
int unicode = Character.codePointAt(text, i);
skip = Character.charCount(unicode);
if (unicode > 255) {
icon = getEmojiResource(context, unicode);
}
if (icon == 0 && i + skip < textLengthToProcess) {
Character.codePointAt(text, i + skip);
}
}
if (icon > 0) {
text.setSpan(new EmojiconSpan(context, icon, emojiSize), i, i + skip, 33);
}
i += skip;
}
}
}
示例9: removeOldHighlightedSpans
import android.text.Spannable; //导入方法依赖的package包/类
@Override
public void removeOldHighlightedSpans() {
Spannable spannableString = (Spannable) payloadTextView.getText();
BackgroundColorSpan[] backgroundSpans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
for (BackgroundColorSpan span : backgroundSpans) {
spannableString.removeSpan(span);
}
}
示例10: stripUnderlines
import android.text.Spannable; //导入方法依赖的package包/类
public static void stripUnderlines(TextView textView) {
Spannable s = new SpannableString(textView.getText());
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span: spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
s.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
s.setSpan(span, start, end, 0);
}
textView.setText(s);
}
示例11: addSmiles
import android.text.Spannable; //导入方法依赖的package包/类
/**
* replace existing spannable with smiles
* @param context
* @param spannable
* @return
*/
public static boolean addSmiles(Context context, Spannable spannable) {
boolean hasChanges = false;
for (Entry<Pattern, Object> entry : emoticons.entrySet()) {
Matcher matcher = entry.getKey().matcher(spannable);
while (matcher.find()) {
boolean set = true;
for (ImageSpan span : spannable.getSpans(matcher.start(),
matcher.end(), ImageSpan.class))
if (spannable.getSpanStart(span) >= matcher.start()
&& spannable.getSpanEnd(span) <= matcher.end())
spannable.removeSpan(span);
else {
set = false;
break;
}
if (set) {
hasChanges = true;
Object value = entry.getValue();
if(value instanceof String && !((String) value).startsWith("http")){
File file = new File((String) value);
if(!file.exists() || file.isDirectory()){
return false;
}
spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}else{
spannable.setSpan(new ImageSpan(context, (Integer)value),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
return hasChanges;
}
示例12: replaceSpan
import android.text.Spannable; //导入方法依赖的package包/类
/**
* Add {@code newSpan} at the same start and end indices as {@code oldSpan} and remove
* {@code oldSpan} from the {@code spannable}.
*/
public static void replaceSpan(Spannable spannable, Object oldSpan, Object newSpan) {
final int spanStart = spannable.getSpanStart(oldSpan);
final int spanEnd = spannable.getSpanEnd(oldSpan);
spannable.removeSpan(oldSpan);
spannable.setSpan(newSpan, spanStart, spanEnd, 0);
}
示例13: addSmiles
import android.text.Spannable; //导入方法依赖的package包/类
/**
* replace existing spannable with smiles
* @param context
* @param spannable
* @return
*/
public static boolean addSmiles(Context context, Spannable spannable) {
boolean hasChanges = false;
for (Map.Entry<Pattern, Object> entry : emoticons.entrySet()) {
Matcher matcher = entry.getKey().matcher(spannable);
while (matcher.find()) {
boolean set = true;
for (ImageSpan span : spannable.getSpans(matcher.start(),
matcher.end(), ImageSpan.class))
if (spannable.getSpanStart(span) >= matcher.start()
&& spannable.getSpanEnd(span) <= matcher.end())
spannable.removeSpan(span);
else {
set = false;
break;
}
if (set) {
hasChanges = true;
Object value = entry.getValue();
if(value instanceof String && !((String) value).startsWith("http")){
File file = new File((String) value);
if(!file.exists() || file.isDirectory()){
return false;
}
spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}else{
spannable.setSpan(new ImageSpan(context, (Integer)value),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
return hasChanges;
}
示例14: removeUrlHighlightColor
import android.text.Spannable; //导入方法依赖的package包/类
private void removeUrlHighlightColor(TextView textView) {
if (this.isUrlHighlighted) {
this.isUrlHighlighted = false;
Spannable text = (Spannable) textView.getText();
BackgroundColorSpan[] highlightSpans = text.getSpans(0, text.length(), BackgroundColorSpan.class);
for (BackgroundColorSpan highlightSpan : highlightSpans) {
text.removeSpan(highlightSpan);
}
try {
textView.setText(text);
Selection.removeSelection(text);
} catch (Exception ignored) {}
}
}
示例15: onTouchEvent
import android.text.Spannable; //导入方法依赖的package包/类
public boolean onTouchEvent(TextView widget, Spannable buffer,
MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
if(mClickLinks.length > 0){
// 点击的是Span区域,不要把点击事件传递
setPassToTv(false);
Selection.setSelection(buffer,
buffer.getSpanStart(mClickLinks[0]),
buffer.getSpanEnd(mClickLinks[0]));
//设置点击区域的背景色
mBgSpan = new BackgroundColorSpan(AppApplication.getAppResources().getColor(mClickableSpanBgClorId));
buffer.setSpan(mBgSpan,
buffer.getSpanStart(mClickLinks[0]),
buffer.getSpanEnd(mClickLinks[0]),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}else{
setPassToTv(true);
// textview选中效果
widget.setBackgroundResource(mTextViewBgColorId);
}
}else if(action == MotionEvent.ACTION_UP){
if(mClickLinks.length > 0){
mClickLinks[0].onClick(widget);
if(mBgSpan != null){
buffer.removeSpan(mBgSpan);
}
}else{
if(mBgSpan != null){
buffer.removeSpan(mBgSpan);
}
}
Selection.removeSelection(buffer);
widget.setBackgroundResource(DEFAULT_COLOR);
}else if(action == MotionEvent.ACTION_MOVE){
}else{
if(mBgSpan != null){
buffer.removeSpan(mBgSpan);
}
widget.setBackgroundResource(DEFAULT_COLOR);
}
return Touch.onTouchEvent(widget, buffer, event);
}