use of android.text.style.URLSpan in project WordPress-Android by wordpress-mobile.
the class StatsUIHelper method removeUnderlines.
/**
* Removes URL underlines in a string by replacing URLSpan occurrences by
* URLSpanNoUnderline objects.
*
* @param pText A Spannable object. For example, a TextView casted as
* Spannable.
*/
public static void removeUnderlines(Spannable pText) {
URLSpan[] spans = pText.getSpans(0, pText.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = pText.getSpanStart(span);
int end = pText.getSpanEnd(span);
pText.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
pText.setSpan(span, start, end, 0);
}
}
use of android.text.style.URLSpan in project apps-android-wikipedia by wikimedia.
the class LinkMovementMethodExt method onTouchEvent.
@Override
public boolean onTouchEvent(@NonNull final TextView widget, @NonNull final Spannable buffer, @NonNull final MotionEvent event) {
final int action = event.getAction();
if (action == MotionEvent.ACTION_UP) {
final int x = (int) event.getX() - widget.getTotalPaddingLeft() + widget.getScrollX();
final int y = (int) event.getY() - widget.getTotalPaddingTop() + widget.getScrollY();
final Layout layout = widget.getLayout();
final int line = layout.getLineForVertical(y);
final int off = layout.getOffsetForHorizontal(line, x);
final URLSpan[] links = buffer.getSpans(off, off, URLSpan.class);
if (links.length != 0) {
String url = decodeURL(links[0].getURL());
handler.onUrlClick(url, UriUtil.getTitleFromUrl(url));
return true;
}
}
return super.onTouchEvent(widget, buffer, event);
}
use of android.text.style.URLSpan in project apps-android-wikipedia by wikimedia.
the class RichTextUtil method removeUnderlinesFromLinksAndMakeBold.
public static void removeUnderlinesFromLinksAndMakeBold(@NonNull Spannable spannable, @NonNull URLSpan[] spans) {
for (URLSpan span : spans) {
int start = spannable.getSpanStart(span);
int end = spannable.getSpanEnd(span);
spannable.removeSpan(span);
span = new URLSpanBoldNoUnderline(span.getURL());
spannable.setSpan(span, start, end, 0);
}
}
use of android.text.style.URLSpan in project MusicVideoPlayer by MartingKing.
the class ArtistInfoActivity method setData.
private void setData(ArtistInfo artistInfo) {
String name = artistInfo.getName();
String avatarUri = artistInfo.getAvatar_s1000();
String country = artistInfo.getCountry();
String constellation = artistInfo.getConstellation();
float stature = artistInfo.getStature();
float weight = artistInfo.getWeight();
String birth = artistInfo.getBirth();
String intro = artistInfo.getIntro();
String url = artistInfo.getUrl();
if (!TextUtils.isEmpty(avatarUri)) {
ImageView ivAvatar = new ImageView(this);
ivAvatar.setScaleType(ImageView.ScaleType.FIT_START);
Glide.with(this).load(avatarUri).apply(new RequestOptions().placeholder(R.drawable.default_artist).error(R.drawable.default_artist)).into(ivAvatar);
llArtistInfoContainer.addView(ivAvatar);
}
if (!TextUtils.isEmpty(name)) {
setTitle(name);
TextView tvName = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvName.setText(getString(R.string.artist_info_name, name));
llArtistInfoContainer.addView(tvName);
}
if (!TextUtils.isEmpty(country)) {
TextView tvCountry = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvCountry.setText(getString(R.string.artist_info_country, country));
llArtistInfoContainer.addView(tvCountry);
}
if (!TextUtils.isEmpty(constellation) && !TextUtils.equals(constellation, "未知")) {
TextView tvConstellation = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvConstellation.setText(getString(R.string.artist_info_constellation, constellation));
llArtistInfoContainer.addView(tvConstellation);
}
if (stature != 0f) {
TextView tvStature = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvStature.setText(getString(R.string.artist_info_stature, String.valueOf(stature)));
llArtistInfoContainer.addView(tvStature);
}
if (weight != 0f) {
TextView tvWeight = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvWeight.setText(getString(R.string.artist_info_weight, String.valueOf(weight)));
llArtistInfoContainer.addView(tvWeight);
}
if (!TextUtils.isEmpty(birth) && !TextUtils.equals(birth, "0000-00-00")) {
TextView tvBirth = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvBirth.setText(getString(R.string.artist_info_birth, birth));
llArtistInfoContainer.addView(tvBirth);
}
if (!TextUtils.isEmpty(intro)) {
TextView tvIntro = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvIntro.setText(getString(R.string.artist_info_intro, intro));
llArtistInfoContainer.addView(tvIntro);
}
if (!TextUtils.isEmpty(url)) {
TextView tvUrl = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
tvUrl.setLinkTextColor(ContextCompat.getColor(this, R.color.blue));
tvUrl.setMovementMethod(LinkMovementMethod.getInstance());
SpannableString spannableString = new SpannableString("查看更多信息");
spannableString.setSpan(new URLSpan(url), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tvUrl.setText(spannableString);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
tvUrl.setLayoutParams(layoutParams);
llArtistInfoContainer.addView(tvUrl);
}
if (llArtistInfoContainer.getChildCount() == 0) {
ViewUtils.changeViewState(svArtistInfo, llLoading, llLoadFail, LoadStateEnum.LOAD_FAIL);
((TextView) llLoadFail.findViewById(R.id.tv_load_fail_text)).setText(R.string.artist_info_empty);
}
}
use of android.text.style.URLSpan in project AisenWeiBo by wangdan.
the class VideoService method parseCommentURL.
public static void parseCommentURL(List<StatusComment> comments) throws TaskException {
if (comments.size() == 0)
return;
List<String> shortUrlList = new ArrayList<>();
Map<String, List<StatusComment>> url2status = new HashMap<>();
// 把未解析的短连接拎出来
for (StatusComment comment : comments) {
String content = comment.getText();
if (!TextUtils.isEmpty(content)) {
SpannableString spannableString = SpannableString.valueOf(content);
Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
if (!urlSpan.getURL().startsWith("http://t.cn/"))
continue;
shortUrlList.add(urlSpan.getURL());
List<StatusComment> l = url2status.get(urlSpan.getURL());
if (l == null) {
l = new ArrayList<>();
url2status.put(urlSpan.getURL(), l);
}
if (!l.contains(comment))
l.add(comment);
}
}
}
if (shortUrlList.size() > 0) {
do {
String[] parseArr = new String[20];
for (int i = 0; i < parseArr.length; i++) {
if (shortUrlList.size() > 0) {
parseArr[i] = shortUrlList.remove(0);
}
}
Logger.w(TAG, parseArr);
UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(parseArr);
for (UrlBean urlBean : urlsBean.getUrls()) {
String id = KeyGenerator.generateMD5(urlBean.getUrl_short());
List<StatusComment> statusList = url2status.get(urlBean.getUrl_short());
for (StatusComment s : statusList) {
s.setVideoUrl(urlBean);
VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
boolean isNew = false;
if (videoBean == null) {
videoBean = new VideoBean();
isNew = true;
}
videoBean.setIdStr(id);
videoBean.setShortUrl(urlBean.getUrl_short());
videoBean.setLongUrl(urlBean.getUrl_long());
if (isSinaVideo(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_SINA);
s.setPicture(true);
} else if (isWeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_WEIPAI);
s.setPicture(true);
} else if (isPhoto(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_PHOTO);
s.setPicture(true);
} else {
videoBean.setType(VideoService.TYPE_VIDEO_NONE);
}
if (isNew) {
SinaDB.getDB().insert(null, videoBean);
} else {
SinaDB.getDB().update(null, videoBean);
}
Logger.v(TAG, "Id[%s], Type[%d], 短链[%s], 长链[%s]", videoBean.getIdStr(), videoBean.getType(), urlBean.getUrl_short(), urlBean.getUrl_long());
}
}
} while (shortUrlList.size() > 0);
}
}
Aggregations