最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

有關(guān)微博content的封裝實(shí)現(xiàn)詳解

 更新時(shí)間:2012年11月20日 16:39:47   作者:  
本文將詳細(xì)介紹關(guān)于微博content的封裝實(shí)現(xiàn),需要的朋友可以參考下
可以不用經(jīng)過(guò) Html.fromHtml 因?yàn)槲业臄?shù)據(jù)里面含有一點(diǎn) html的標(biāo)簽。所以經(jīng)過(guò)html轉(zhuǎn)換了。
實(shí)現(xiàn)方法:
復(fù)制代碼 代碼如下:

TextView content = (TextView) convertView.findViewById(R.id.content);
content.setText(Html.fromHtml("<html><head>"+temp.get(position).getContent()+"</html></head>"));
CharSequence str = content.getText();
SpannableString spann = WeiboUtils.formatContentNoClick(str);
content.setText(spann);

具體的封裝如下:
復(fù)制代碼 代碼如下:

package com.lizheng.little.yiqu.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.lizheng.little.yiqu.ui.ActWeiBoInfo;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
public class WeiboUtils {
/**
* 將text中@某人、#某主題、http://網(wǎng)址的字體加亮,匹配的表情文字以表情顯示
* @param text
* @param context
* @return*/
public static SpannableString formatContent(CharSequence text,Context context) {
SpannableString spannableString = new SpannableString(text);
/*
* @[^\\s::]+[::\\s] 匹配@某人
* #([^\\#|.]+)# 匹配#某主題 http://t\\.cn/\\w+ 匹配網(wǎng)址
*/
Pattern pattern = Pattern.compile("@[^\\s::]+[::\\s]|#([^\\#|.]+)#|http://t\\.cn/\\w");
Matcher matcher = pattern.matcher(spannableString);
final Context mcontext = context;
while (matcher.find()) {
final String match=matcher.group();
if(match.startsWith("@")){ //@某人,加亮字體
spannableString.setSpan(new ClickableSpan()
{
// 在onClick方法中可以編寫單擊鏈接時(shí)要執(zhí)行的動(dòng)作
@Override
public void onClick(View widget)
{
String username = match;
username = username.replace("@", "");
username = username.replace(":", "");
username = username.trim();
Intent intent = new Intent(mcontext,XXX.class);
ConstantsUtil.clickName = username;
mcontext.startActivity(intent);//跳轉(zhuǎn)到用戶信息界面
}
}, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new ForegroundColorSpan(0xff0077ff),
matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else if(match.startsWith("#")){ //#某主題
spannableString.setSpan(new ClickableSpan()
{
// 在onClick方法中可以編寫單擊鏈接時(shí)要執(zhí)行的動(dòng)作
@Override
public void onClick(View widget)
{
String theme = match;
theme = theme.replace("#", "");
theme = theme.trim();
ConstantsUtil.clickName = theme;
Intent intent = new Intent(mcontext,XXX.class);
mcontext.startActivity(intent);//跳轉(zhuǎn)到話題信息界面
}
}, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new ForegroundColorSpan(0xff0077ff),
matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else if(match.startsWith("http://")){ //匹配網(wǎng)址
spannableString.setSpan(new ClickableSpan()
{
// 在onClick方法中可以編寫單擊鏈接時(shí)要執(zhí)行的動(dòng)作
@Override
public void onClick(View widget)
{
Uri uri = Uri.parse(match);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
mcontext.startActivity(intent);
}
}, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new ForegroundColorSpan(0xff0077ff),
matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return spannableString;
}
public static SpannableString formatContentNoClick(CharSequence text) {
SpannableString spannableString = new SpannableString(text);
/*
* @[^\\s::]+[::\\s] 匹配@某人
* #([^\\#|.]+)# 匹配#某主題 http://t\\.cn/\\w+ 匹配網(wǎng)址
*/
Pattern pattern = Pattern.compile("@[^\\s::]+[::\\s]|#([^\\#|.]+)#|http://t\\.cn/\\w");
Matcher matcher = pattern.matcher(spannableString);
while (matcher.find()) {
final String match=matcher.group();
if(match.startsWith("@")){ //@某人,加亮字體
spannableString.setSpan(new ForegroundColorSpan(0xff0077ff),
matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else if(match.startsWith("#")){ //#某主題
spannableString.setSpan(new ForegroundColorSpan(0xff0077ff),
matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else if(match.startsWith("http://")){ //匹配網(wǎng)址
spannableString.setSpan(new ForegroundColorSpan(0xff0077ff),
matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return spannableString;
}
public static long calculateWeiboLength(CharSequence c) {
double len = 0;
for (int i = 0; i < c.length(); i++) {
int temp = (int)c.charAt(i);
if (temp > 0 && temp < 127) {
len += 0.5;
}else{
len ++;
}
}
return Math.round(len);
}
}

自己封裝的dialog控件:http://www.fzitv.net/article/32030.htm

相關(guān)文章

最新評(píng)論

于田县| 夏津县| 陆丰市| 沙雅县| 东丽区| 奎屯市| 灵武市| 乌鲁木齐市| 潍坊市| 峡江县| 荥阳市| 信阳市| 张家港市| 蚌埠市| 许昌县| 福鼎市| 大石桥市| 绥中县| 台江县| 托克托县| 平陆县| 通州市| 镇原县| 揭西县| 建平县| 城口县| 休宁县| 富顺县| 辽宁省| 扎兰屯市| 建湖县| 噶尔县| 竹溪县| 武威市| 资源县| 华阴市| 井冈山市| 商南县| 宣城市| 满城县| 永丰县|