Categories
Android

新浪微博Android客户端实战 – 使用ActionBarSherlock与MenuDrawer

很久没有为 Android for WordPress 项目贡献代码了,最近他们把代码放在 github 上,pull requests 方便了许多。之前我都是在trac上给他们提交patch, 新建一个ticket 贴上 svn diff 的结果,苦不堪言,最后只好放弃。在google play 上更新了客户端,界面比以前有很大的进步,可圈可点。因此,我决定参考wordpress, 使用上 ActionBarSherlock 与 MenuDrawer, 替换 android-action 组件。为什么一开始使用 android-action?因为 actionbar 的颜色我喜欢,而且组件使用简单。学习 ActionBarSherlock 是有些成本的,编译 sample 示例,边看效果边看代码。

主要修改点:

1. 将 android.app.Activity 替换为 SherlockActivity

// file: BaseActivity.java
import com.actionbarsherlock.app.SherlockActivity;

public class BaseActivity extends SherlockActivity {
// activity implementation
}

2. getMenuInflater 修改为 getSupportMenuInflater,注意,要把android 自带导入的Menu包删掉,导入ActionBarSherlock的包,不然会提示无法 Override onCreateOptionsMenu。

3. 把项目中 libs/android-support-v4.jar 干掉,这个会与abs的冲突。eclipse 报错:

Found 2 versions of android-support-v4.jar in the dependency list, but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Jar mismatch! Fix your dependencies

4. abs 进度条尺寸很大,需要改小一点的,参考: Android: Changing the Default Indeterminate Progress Size in ActionBarSherlock

ActionBarSherlock 修改记录: https://github.com/lytsing/weibo/commit/3d6f203a390460b4cdd1c8f8543c523ad55f0ccb

使用 MenuDrawer

MenuDrawer 跟 abs 可以很好的结合使用,照着 android-menudrawer-abs-sample 写。修改记录:https://github.com/lytsing/weibo/commit/15e61dc2fbb556b68db21d2fe8a4d0e2aadc4938 图标,背景颜色,后期再需要调整。

Categories
Android

Google I/O 2013 – Volley: Easy, Fast Networking for Android

我把这视频高清版本从youtube下载优放在优酷上,地址: http://v.youku.com/v_show/id_XNTU4ODgzNjg4.html ppt下载: Volley

以前反编译过android market,发现里面有用到volley,起这么个名字不知道啥用的,现在才知道主讲者Ficus Kirkpatrick 就是负责开发Google play 的。

看完视频,发现 Jeff Sharkey 就利用它写了简单的Flickr 客户端 , 这速度快得没的说。在前面写的新浪微博客户,Timeline 图片异步下载,使用的是AQuery.image, 但效果还是差一点,于是也考虑试试 volley,代码提交记录见 https://github.com/lytsing/weibo/commit/7c84aea7ae27e6fa7da7aa4e477e41e07c1d79ac 。图片加载性能改善很多,谁用谁知道 🙂

有人问:

Network loaded images in a list view? Solved by several different Android libraries, 3 years ago 😉

https://github.com/koush/UrlImageViewHelper/
https://github.com/nostra13/Android-Universal-Image-Loader
https://code.google.com/p/android-query/wiki/ImageLoading

Ficus 回答说:

Volley does a lot more than that, and does better at the images problem than any of them.

volley 没有提供jar包,需要自己手动编译,使用方法:

git clone https://android.googlesource.com/platform/frameworks/volley
cd volley
android update project -p .
ant jar

拷贝 bin/volley 到 libs 文件夹下面。注意,这个库要求最低SDK版本为Froyo,即至少要设置android:minSdkVersion为8以上。