还是一样先上图

主要新增:
1.文章详情界面图片点击放大,移动,缩放
2.新增个人资料界面【未完成】
主要涉及知识点:
1.TextView中解析html中img标签,设置点击事件
2.自定义ImageView,实现缩放,移动
3.借鉴FadingActionBar实现FadingToolBar【参考我的资料的截图,采用ToolBar实现】
4.针对网络图片采用Base64编码处理解码成Bitmap
具体讲解TextView中html标签中img设置点击事件监听,代码如下:
public class TextImageHandle implements Html.TagHandler {
private Context context;
private String imgPath;
public TextImageHandle(Context context, String imgPath) {
this.context = context;
this.imgPath = imgPath;
}
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
if (tag.toLowerCase().equals("img")) {
int len = output.length();
ImageSpan[] images = output.getSpans(len - 1, len, ImageSpan.class);
String imgUrl = images[0].getSource();
// 注册点击事件
output.setSpan(new ImageClick(context, imgUrl), len - 1, len,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
private class ImageClick extends ClickableSpan {
private String imgUrl;
private Context context;
public ImageClick(Context context, String imgUrl) {
this.imgUrl = imgUrl;
this.context = context;
}
@Override
public void onClick(View widget) {
if (StringUtil.isBlank(imgUrl)) {
return;
}
//do something
}
}
}
其中:
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE(前 后都不包括)
Spanned.SPAN_INCLUSIVE_EXCLUSIVE(前面包括,后面不包括)
Spanned.SPAN_EXCLUSIVE_INCLUSIVE(前面不包括,后面包括)
Spanned.SPAN_INCLUSIVE_INCLUSIVE(前后都包括)
图片Base64转码,网上有很多,这里提供其中一种处理:
/**
* Base64转码
* @param string
* @return
*/
public static Bitmap stringtoBitmap(String string) {
Bitmap bitmap = null;
try {
byte[] bitmapArray;
bitmapArray = Base64.decode(string, Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
慢慢地完善着功能,其中也遇到了各种奇奇怪怪的问题,如:
1.抓取CSDN的博客数据时,返回的html数据竟然和浏览器请求返回的不一样,后台通过设置URLConnection的各种RequestProperty属性才解决,起初还以为是CSDN对请求IP拦截,尝试采用代理服务器请求,结果真被拦截了,直接404。。。
2.网络图片,有的采用直接提供url,有的采用Base64编码处理,结果本地图片缓存时,Base64的只有通过强制转换命名来实现了。
3.FadingActionBar的处理和FadingToolBar的处理,异曲同工,但是也耽搁了好半天才弄好。
待完成:
1.用户资料模块【用户基本信息,用户文章信息】
2.文章评论 【啊!!!今天忘了做了。】