本文整理汇总了Java中android.text.Spannable.getSpanEnd方法的典型用法代码示例。如果您正苦于以下问题:Java Spannable.getSpanEnd方法的具体用法?Java Spannable.getSpanEnd怎么用?Java Spannable.getSpanEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Spannable
的用法示例。
在下文中一共展示了Spannable.getSpanEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dealUnderLinesData
import android.text.Spannable; //导入方法依赖的package包/类
/**
* 解析link
*
* @param tv_content
* @param context
*/
private static void dealUnderLinesData(TextView tv_content, Context context) {
CharSequence charSequence = tv_content.getText();
if (charSequence instanceof Spannable) {
tv_content.setText("");
Spannable s = EmojiDisplay.spannableFilter(tv_content.getContext(),
new SpannableStringBuilder(charSequence),
charSequence,
EmoticonsKeyboardUtils.getFontHeight(tv_content));
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
String clickText = s.subSequence(start, end).toString();
URLSpanNoUnderline urlSpanNoUnderline = new URLSpanNoUnderline(context, span.getURL(), clickText);
s.setSpan(urlSpanNoUnderline, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tv_content.append(s);
}
}
示例2: dealAILink
import android.text.Spannable; //导入方法依赖的package包/类
/**
* 解析机器人对话link
*
* @param textView
*/
private static void dealAILink(TextView textView, String type) {
CharSequence charSequence = textView.getText();
if (charSequence instanceof Spannable) {
textView.setText("");
Spannable s = (Spannable) charSequence;
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
String clickContent = s.subSequence(start, end).toString();
AIURLSpan myURLSpan = new AIURLSpan(span.getURL(), type, clickContent, textView.getContext());
s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
textView.append(s);
}
}
示例3: dealCustomLink
import android.text.Spannable; //导入方法依赖的package包/类
/**
* 解析富文本link
*
* @param textView
*/
private static void dealCustomLink(TextView textView) {
CharSequence charSequence = textView.getText();
if (charSequence instanceof Spannable) {
textView.setText("");
Spannable s = (Spannable) charSequence;
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
CustomClickSpan myURLSpan = new CustomClickSpan(textView.getContext(), span.getURL());
s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
textView.append(s);
}
}
示例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: 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);
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: highlightUrl
import android.text.Spannable; //导入方法依赖的package包/类
private void highlightUrl(TextView textView, BetterLinkMovementExtended.ClickableSpanWithText spanWithText, Spannable text) {
if (!this.isUrlHighlighted) {
this.isUrlHighlighted = true;
int spanStart = text.getSpanStart(spanWithText.span());
int spanEnd = text.getSpanEnd(spanWithText.span());
Selection.removeSelection(text);
text.setSpan(new BackgroundColorSpan(textView.getHighlightColor()), spanStart, spanEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(text);
Selection.setSelection(text, spanStart, spanEnd);
}
}
示例10: a
import android.text.Spannable; //导入方法依赖的package包/类
private boolean a(Spannable spannable, ClickableSpan clickablespan) {
boolean flag = false;
int i = spannable.getSpanStart(clickablespan);
int j = spannable.getSpanEnd(clickablespan);
if (i >= 0 && j > i)
flag = true;
return flag;
}
示例11: addCustomTabUrlHandler
import android.text.Spannable; //导入方法依赖的package包/类
private static void addCustomTabUrlHandler(Activity activity, TextView textView) {
CharSequence text = textView.getText();
Spannable s = new SpannableString(text);
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 CustomTabUrlSpan(activity, span.getURL());
s.setSpan(span, start, end, 0);
}
textView.setText(s);
}
示例12: 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);
}
示例13: getQueryRange
import android.text.Spannable; //导入方法依赖的package包/类
/**
* Returns the current query out of the given Spannable.
* @param text the anchor text
* @return an int[] with query start and query end positions
*/
@Nullable
public static int[] getQueryRange(Spannable text) {
QuerySpan[] span = text.getSpans(0, text.length(), QuerySpan.class);
if (span == null || span.length == 0) return null;
if (span.length > 1) {
// Won't happen
log("getQueryRange: ERR: MORE THAN ONE QuerySpan.");
}
QuerySpan sp = span[0];
return new int[]{text.getSpanStart(sp), text.getSpanEnd(sp)};
}
示例14: 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);
}
示例15: onTouchEvent
import android.text.Spannable; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
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);
LongClickableSpan[] link = buffer.getSpans(off, off, LongClickableSpan.class);
if (link.length != 0) {
long currTime = System.currentTimeMillis();
LongClickableSpan l = link[0];
int ls = buffer.getSpanStart(l);
int le = buffer.getSpanEnd(l);
// 判断点击的点是否在Image范围内
ClickableImageSpan[] is = buffer.getSpans(ls, le, ClickableImageSpan.class);
if (is.length > 0) {
if (!is[0].clicked(x)) {
Selection.removeSelection(buffer);
return false;
}
} else if (off < layout.getOffsetToLeftOf(ls) || off > layout.getOffsetToLeftOf(le + 1)) {
// 判断点击位置是否在链接范围内
Selection.removeSelection(buffer);
return false;
}
if (action == MotionEvent.ACTION_UP) {
// 如果按下时间超过500毫秒,触发长按事件
if (currTime - lastTime > MIN_INTERVAL) {
if (!l.onLongClick(widget)) {
// onLongClick返回false代表事件未处理,交由onClick处理
l.onClick(widget);
}
} else {
l.onClick(widget);
}
} else {
Selection.setSelection(buffer,
ls, le);
}
lastTime = currTime;
return true;
} else {
Selection.removeSelection(buffer);
return false;
}
}
return super.onTouchEvent(widget, buffer, event);
}