use of com.yiw.circledemo.spannable.SpannableClickable in project CircleDemo by Naoki2015.
the class PraiseListView method setClickableSpan.
@NonNull
private SpannableString setClickableSpan(String textStr, final int position) {
SpannableString subjectSpanText = new SpannableString(textStr);
subjectSpanText.setSpan(new SpannableClickable(itemColor) {
@Override
public void onClick(View widget) {
if (onItemClickListener != null) {
onItemClickListener.onClick(position);
}
}
}, 0, subjectSpanText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return subjectSpanText;
}
use of com.yiw.circledemo.spannable.SpannableClickable in project CircleDemo by Naoki2015.
the class UrlUtils method formatUrlString.
public static SpannableStringBuilder formatUrlString(String contentStr) {
SpannableStringBuilder sp;
if (!TextUtils.isEmpty(contentStr)) {
sp = new SpannableStringBuilder(contentStr);
try {
//处理url匹配
Pattern urlPattern = Pattern.compile("(http|https|ftp|svn)://([a-zA-Z0-9]+[/?.?])" + "+[a-zA-Z0-9]*\\??([a-zA-Z0-9]*=[a-zA-Z0-9]*&?)*");
Matcher urlMatcher = urlPattern.matcher(contentStr);
while (urlMatcher.find()) {
final String url = urlMatcher.group();
if (!TextUtils.isEmpty(url)) {
sp.setSpan(new SpannableClickable() {
@Override
public void onClick(View widget) {
Uri uri = Uri.parse(url);
Context context = widget.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
context.startActivity(intent);
}
}, urlMatcher.start(), urlMatcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
//处理电话匹配
Pattern phonePattern = Pattern.compile("[1][34578][0-9]{9}");
Matcher phoneMatcher = phonePattern.matcher(contentStr);
while (phoneMatcher.find()) {
final String phone = phoneMatcher.group();
if (!TextUtils.isEmpty(phone)) {
sp.setSpan(new SpannableClickable() {
@Override
public void onClick(View widget) {
Context context = widget.getContext();
//用intent启动拨打电话
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}, phoneMatcher.start(), phoneMatcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
sp = new SpannableStringBuilder();
}
return sp;
}
use of com.yiw.circledemo.spannable.SpannableClickable in project CircleDemo by Naoki2015.
the class CommentListView method setClickableSpan.
@NonNull
private SpannableString setClickableSpan(final String textStr, final String id) {
SpannableString subjectSpanText = new SpannableString(textStr);
subjectSpanText.setSpan(new SpannableClickable(itemColor) {
@Override
public void onClick(View widget) {
Toast.makeText(MyApplication.getContext(), textStr + " &id = " + id, Toast.LENGTH_SHORT).show();
}
}, 0, subjectSpanText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return subjectSpanText;
}
Aggregations