use of android.text.style.URLSpan in project AisenWeiBo by wangdan.
the class VideoService method parseStatusURL.
public static void parseStatusURL(List<StatusContent> statusContents) throws TaskException {
if (statusContents.size() == 0)
return;
List<String> shortUrlList = new ArrayList<>();
Map<String, List<StatusContent>> url2status = new HashMap<>();
// 把未解析的短连接拎出来
for (StatusContent statusContent : statusContents) {
String content = statusContent.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<StatusContent> l = url2status.get(urlSpan.getURL());
if (l == null) {
l = new ArrayList<>();
url2status.put(urlSpan.getURL(), l);
}
if (!l.contains(statusContent))
l.add(statusContent);
}
}
if (statusContent.getRetweeted_status() != null) {
statusContent = statusContent.getRetweeted_status();
content = statusContent.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<StatusContent> l = url2status.get(urlSpan.getURL());
if (l == null) {
l = new ArrayList<>();
url2status.put(urlSpan.getURL(), l);
}
if (!l.contains(statusContent))
l.add(statusContent);
}
}
}
}
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<StatusContent> statusList = url2status.get(urlBean.getUrl_short());
for (StatusContent s : statusList) {
s.setVideoUrl(urlBean);
boolean isNew = false;
VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
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.setVideo(true);
} else if (isWeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_WEIPAI);
s.setVideo(true);
} else if (isMeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_MEIPAI);
s.setVideo(true);
} else if (isPhoto(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_PHOTO);
} 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);
}
}
use of android.text.style.URLSpan in project EhViewer by seven332.
the class HtmlToSpannedConverter method endA.
private static void endA(SpannableStringBuilder text) {
int len = text.length();
Object obj = getLast(text, Href.class);
int where = text.getSpanStart(obj);
text.removeSpan(obj);
if (where != len) {
Href h = (Href) obj;
if (h.mHref != null) {
text.setSpan(new URLSpan(h.mHref), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
use of android.text.style.URLSpan in project EhViewer by seven332.
the class TextUrl method handleTextUrl.
public static CharSequence handleTextUrl(CharSequence content) {
Matcher m = URL_PATTERN.matcher(content);
Spannable spannable = null;
while (m.find()) {
// Ensure spannable
if (spannable == null) {
if (content instanceof Spannable) {
spannable = (Spannable) content;
} else {
spannable = new SpannableString(content);
}
}
int start = m.start();
int end = m.end();
URLSpan[] links = spannable.getSpans(start, end, URLSpan.class);
if (links.length > 0) {
// There has been URLSpan already, leave it alone
continue;
}
URLSpan urlSpan = new URLSpan(m.group(0));
spannable.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spannable == null ? content : spannable;
}
use of android.text.style.URLSpan in project android_packages_apps_Dialer by LineageOS.
the class Vvm3Subscriber method findSubscribeLink.
@VisibleForTesting
static String findSubscribeLink(@NonNull List<Pattern> patterns, String response) throws ProvisioningException {
if (patterns.isEmpty()) {
throw new IllegalArgumentException("empty patterns");
}
Spanned doc = Html.fromHtml(response, Html.FROM_HTML_MODE_LEGACY);
URLSpan[] spans = doc.getSpans(0, doc.length(), URLSpan.class);
StringBuilder fulltext = new StringBuilder();
for (URLSpan span : spans) {
String text = doc.subSequence(doc.getSpanStart(span), doc.getSpanEnd(span)).toString();
for (Pattern pattern : patterns) {
if (pattern.matcher(text).matches()) {
return span.getURL();
}
}
fulltext.append(text);
}
throw new ProvisioningException("Subscribe link not found: " + fulltext);
}
use of android.text.style.URLSpan in project android_packages_apps_Settings by omnirom.
the class SupportDisclaimerDialogFragment method stripUnderlines.
/**
* Removes the underlines of {@link android.text.style.URLSpan}s.
*/
private static void stripUnderlines(Spannable input) {
final URLSpan[] urls = input.getSpans(0, input.length(), URLSpan.class);
for (URLSpan span : urls) {
final int start = input.getSpanStart(span);
final int end = input.getSpanEnd(span);
if (!TextUtils.isEmpty(span.getURL())) {
input.removeSpan(span);
input.setSpan(new NoUnderlineUrlSpan(span.getURL()), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
Aggregations