Android開源項目第二篇:工具庫篇
本文為那些不錯的Android開源項目第二篇——開發(fā)工具庫篇,**主要介紹常用的開發(fā)庫,包括依賴注入框架、圖片緩存、網(wǎng)絡(luò)相關(guān)、數(shù)據(jù)庫ORM建模、Android公共庫、Android 高版本向低版本兼容、多媒體相關(guān)及其他**。
Android開源項目系列匯總已完成,包括:
通過這些項目你可以大幅度減少不必要的開發(fā)而將精力放在更重要的地方。
一、依賴注入DI
通過依賴注入減少View、服務(wù)、資源簡化初始化,事件綁定等重復(fù)繁瑣工作
1. AndroidAnnotations(Code Diet) android快速開發(fā)框架
項目地址:https://github.com/excilys/androidannotations
文檔介紹:https://github.com/excilys/androidannotations/wiki
官方網(wǎng)站:http://androidannotations.org/
特點:(1)依賴注入:包括view,extras,系統(tǒng)服務(wù),資源等等
(2)簡單的線程模型,通過annotation表示方法運行在ui線程還是后臺線程
(3)事件綁定:通過annotation表示view的響應(yīng)事件,不用在寫內(nèi)部類
(4)REST客戶端:定義客戶端接口,自動生成REST請求的實現(xiàn)
(5)沒有你想象的復(fù)雜:AndroidAnnotations只是在在編譯時生成相應(yīng)子類
(6)不影響應(yīng)用性能:僅50kb,在編譯時完成,不會對運行時有性能影響。
PS:與roboguice的比較:roboguice通過運行時讀取annotations進行反射,所以可能影響應(yīng)用性能,而AndroidAnnotations在編譯時生成子類,所以對性能沒有影響
2. roboguice 幫你處理了很多代碼異常,利用annotation使得更少的代碼完成項目
項目地址:https://github.com/roboguice/roboguice
文檔介紹:https://github.com/roboguice/roboguice/wiki
3. butterknife 利用annotation幫你快速完成View的初始化,減少代碼
項目地址:https://github.com/JakeWharton/butterknife
文檔介紹:http://jakewharton.github.io/butterknife/
4. Dagger 依賴注入,適用于Android和Java
項目地址:https://github.com/square/dagger
文檔介紹:http://square.github.io/dagger/
二、圖片緩存
1. Android-Universal-Image-Loader 圖片緩存
目前使用最廣泛的圖片緩存,支持主流圖片緩存的絕大多數(shù)特性。
項目地址:https://github.com/nostra13/Android-Universal-Image-Loader
Demo地址:https://github.com/Trinea/TrineaDownload/blob/master/universal-imageloader-demo.apk?raw=true
文檔介紹:http://www.intexsoft.com/blog/item/74-universal-image-loader-part-3.html
2. picasso square開源的圖片緩存
項目地址:https://github.com/square/picasso
文檔介紹:http://square.github.io/picasso/
特點:(1)可以自動檢測adapter的重用并取消之前的下載
(2)圖片變換
(3)可以加載本地資源
(4)可以設(shè)置占位資源
(5)支持debug模式
3. ImageCache 圖片緩存,包含內(nèi)存和Sdcard緩存
項目地址:https://github.com/Trinea/AndroidCommon
Demo地址:https://play.google.com/store/apps/details?id=cn.trinea.android.demo
文檔介紹:http://www.trinea.cn/?p=704
特點:(1)支持預(yù)取新圖片,支持等待隊列
(2)包含二級緩存,可自定義文件名保存規(guī)則
(3)可選擇多種緩存算法(FIFO、LIFO、LRU、MRU、LFU、MFU等13種)或自定義緩存算法
(4)可方便的保存及初始化恢復(fù)數(shù)據(jù)
(5)支持不同類型網(wǎng)絡(luò)處理
(6)可根據(jù)系統(tǒng)配置初始化緩存等
三、網(wǎng)絡(luò)相關(guān)
1. Asynchronous Http Client for Android Android異步Http請求
項目地址:https://github.com/loopj/android-async-http
文檔介紹:http://loopj.com/android-async-http/
特點:(1) 在匿名回調(diào)中處理請求結(jié)果
(2) 在UI線程外進行http請求
(3) 文件斷點上傳
(4) 智能重試
(5) 默認gzip壓縮
(6) 支持解析成Json格式
(7) 可將Cookies持久化到SharedPreferences
2. android-query 異步加載,更少代碼完成Android加載
項目地址:https://github.com/androidquery/androidquery或https://code.google.com/p/android-query/
文檔介紹:https://code.google.com/p/android-query/#Why_AQuery?
Demo地址:https://play.google.com/store/apps/details?id=com.androidquery
特點:https://code.google.com/p/android-query/#Why_AQuery?
3. Async Http Client Java異步Http請求
項目地址:https://github.com/AsyncHttpClient/async-http-client
文檔介紹:http://sonatype.github.io/async-http-client/
4. Ion 支持圖片、json、http post等異步請求
項目地址:https://github.com/koush/ion
文檔介紹:https://github.com/koush/ion#more-examples
5. HttpCache Http緩存
項目地址:https://github.com/Trinea/AndroidCommon
Demo地址:https://play.google.com/store/apps/details?id=cn.trinea.android.demo
Demo代碼:https://github.com/Trinea/AndroidDemo/blob/master/src/cn/trinea/android/demo/HttpCacheDemo.java
特點是:(1) 根據(jù)cache-control、expires緩存http請求
(2) 支持同步、異步Http請求
(3) 在匿名回調(diào)中處理請求結(jié)果
(4) 在UI線程外進行http請求
(5) 默認gzip壓縮
6. Http Request
項目地址:https://github.com/kevinsawicki/http-request
文檔介紹:https://github.com/kevinsawicki/http-request#examples
7. okhttp square開源的http工具類
項目地址:https://github.com/square/okhttp
文檔介紹:http://square.github.io/okhttp/
特點:(1) 支持SPDY(http://zh.wikipedia.org/wiki/SPDY)協(xié)議。SPDY協(xié)議是Google開發(fā)的基于傳輸控制協(xié)議的應(yīng)用層協(xié)議,通過壓縮,多路復(fù)用(一個TCP鏈接傳送網(wǎng)頁和圖片等資源%E5 %8D%8F%E8%AE%AE%E3%80%82SPDY%E5%8D%8F%E8%AE%AE%E6%98%AFGoogle%E5%BC%80 %E5%8F%91%E7%9A%84%E5%9F%BA%E4%BA%8E%E4%BC%A0%E8%BE%93%E6%8E%A7%E5%88%B6 %E5%8D%8F%E8%AE%AE%E7%9A%84%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE %EF%BC%8C%E9%80%9A%E8%BF%87%E5%8E%8B%E7%BC%A9%EF%BC%8C%E5%A4%9A%E8%B7%AF %E5%A4%8D%E7%94%A8(%E4%B8%80%E4%B8%AATCP%E9%93%BE%E6%8E%A5%E4%BC%A0%E9 %80%81%E7%BD%91%E9%A1%B5%E5%92%8C%E5%9B%BE%E7%89%87%E7%AD%89%E8%B5%84%E6 %BA%90))和優(yōu)先級來縮短加載時間。
(2) 如果SPDY不可用,利用連接池減少請求延遲
(3) Gzip壓縮
(4) Response緩存減少不必要的請求
8. Retrofit RESTFUL API設(shè)計
項目地址:https://github.com/square/retrofit
文檔介紹:http://square.github.io/retrofit/
四、數(shù)據(jù)庫 orm工具包
orm的db工具類,簡化建表、查詢、更新、插入、事務(wù)、索引的操作
1. greenDAO Android Sqlite orm的db工具類
項目地址:https://github.com/greenrobot/greenDAO
文檔介紹:http://greendao-orm.com/documentation/
官方網(wǎng)站:http://greendao-orm.com/
特點:(1)性能佳
(2) 簡單易用的API
(3) 內(nèi)存小好小
(4) 庫大小小
2. ActiveAndroid Android Sqlite orm的db工具類
項目地址:https://github.com/pardom/ActiveAndroid
文檔介紹:https://github.com/pardom/ActiveAndroid/wiki/_pages
3. Sprinkles Android Sqlite orm的db工具類
項目地址:https://github.com/emilsjolander/sprinkles
文檔介紹:http://emilsjolander.github.io/blog/2013/12/18/android-with-sprinkles/
特點:比較顯著的特點就是配合https://github.com/square/retrofit能保存從服務(wù)器獲取的數(shù)據(jù)
五、Android公共庫
1. Guava Google的基于java1.6的類庫集合的擴展項目
包括collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O等等. 這些高質(zhì)量的API可以使你的JAVa代碼更加優(yōu)雅,更加簡潔
項目地址:https://code.google.com/p/guava-libraries/
文檔介紹:https://code.google.com/p/guava-libraries/wiki/GuavaExplained
2. AndroidCommon Android公共庫
項目地址:https://github.com/Trinea/AndroidCommon
Demo地址:https://play.google.com/store/apps/details?id=cn.trinea.android.demo
文檔介紹:http://www.trinea.cn/?p=778
包括:(1)緩存(圖片緩存、預(yù)取緩存、網(wǎng)絡(luò)緩存)
(2) 公共View(下拉及底部加載更多ListView、底部加載更多ScrollView、滑動一頁Gallery)
(3) Android常用工具類(網(wǎng)絡(luò)、下載、Android資源操作、shell、文件、Json、隨機數(shù)、Collection等等)
六、Android 高版本向低版本兼容
1. ActionBarSherlock 為Android所有版本提供統(tǒng)一的ActionBar,解決4.0以下ActionBar的適配問題
項目地址:https://github.com/JakeWharton/ActionBarSherlock
Demo地址:https://play.google.com/store/apps/details?id=com.actionbarsherlock.sample.demos
APP示例:太多了。。現(xiàn)在連google都在用
2. Nine Old Androids 將Android 3.0(Honeycomb)所有動畫API(ObjectAnimator ValueAnimator等)兼容到Android1.0
項目地址:https://github.com/JakeWharton/NineOldAndroids
Demo地址:https://play.google.com/store/apps/details?id=com.jakewharton.nineoldandroids.sample
文檔介紹:http://nineoldandroids.com/
3. HoloEverywhere 將Android 3.0的Holo主題兼容到Android2.1++
項目地址:https://github.com/Prototik/HoloEverywhere
Demo地址:https://raw.github.com/Prototik/HoloEverywhere/repo/org/holoeverywhere/demo/2.1.0/demo-2.1.0.apk
文檔介紹:http://android-developers.blogspot.com/2012/01/holo-everywhere.html
七、多媒體相關(guān)
1. cocos2d-x 跨平臺的2d游戲框架,支持Android、IOS、Linux、Windows等眾多平臺
項目地址:https://github.com/cocos2d/cocos2d-x
文檔介紹:http://www.cocos2d-x.org/wiki
官方網(wǎng)站:http://www.cocos2d-x.org/
2. Vitamio 是一款A(yù)ndroid與iOS平臺上的全能多媒體開發(fā)框架
項目地址:https://github.com/yixia/VitamioBundle
網(wǎng)站介紹:http://www.vitamio.org/docs/
特點:(1) 全面支持硬件解碼與GPU渲染
(2) 能夠流暢播放720P甚至1080P高清MKV,F(xiàn)LV,MP4,MOV,TS,RMVB等常見格式的視頻
(3) 在Android與iOS上跨平臺支持 MMS, RTSP, RTMP, HLS(m3u8)等常見的多種視頻流媒體協(xié)議,包括點播與直播。
3. PhotoProcessing 利用ndk處理圖片庫,支持Instafix、Ansel、Testino、XPro、Retro、BW、Sepia、Cyano、Georgia、Sahara、HDR、Rotate、Flip
項目地址:https://github.com/lightbox/PhotoProcessing
Demo地址:https://github.com/Trinea/TrineaDownload/blob/master/photo-processing.apk?raw=true
4. Android StackBlur 圖片模糊效果工具類
項目地址:https://github.com/kikoso/android-stackblur
Demo地址:https://github.com/kikoso/android-stackblur/blob/master/StackBlurDemo/bin/StackBlurDemo.apk?raw=true
文檔介紹:https://github.com/kikoso/android-stackblur#usage
八、其他
1. Salvage view 帶View緩存的Viewpager PagerAdapter,很方便使用
項目地址:https://github.com/JakeWharton/salvage
2. Android-PasscodeLock 應(yīng)用鎖,每次啟動或從任何Activity啟動應(yīng)用都需要輸入四位數(shù)字的密碼方可進入
項目地址:https://github.com/wordpress-mobile/Android-PasscodeLock
Demo地址:https://play.google.com/store/apps/details?id=com.sothree.umano
APP示例:Wordpress Android,支付寶,挖財
3. android-lockpattern Android的圖案密碼解鎖
項目地址:https://code.google.com/p/android-lockpattern/
Demo地址:https://play.google.com/store/apps/details?id=group.pals.android.lib.ui.lockpattern.demo
使用介紹:https://code.google.com/p/android-lockpattern/wiki/QuickUse
示例APP:Android開機的圖案密碼解鎖,支付寶的密碼解鎖
4. GlowPadBackport將Android4.2的鎖屏界面解鎖擴展到Android1.6及1.6+
項目地址:https://github.com/rock3r/GlowPadBackport
Demo地址:https://play.google.com/store/apps/details?id=net.sebastianopoggi.samples.ui.GlowPadSample
效果圖:https://lh6.ggpht.com/U070b6Lh6cVsVwx4jN-5nq0xqiB1PBzrYABPeJIEe2hZQ5UWOxc-FDUG77wADelToHA=h310-rw
5. GlowPadView Android4鎖屏界面解鎖
項目地址:https://github.com/nadavfima/GlowPadView
效果圖:https://raw.github.com/nadavfima/GlowPadView/master/example.png
6. Android Priority Job Queue Android后臺任務(wù)隊列
項目地址:https://github.com/path/android-priority-jobqueue
文檔介紹:https://github.com/path/android-priority-jobqueue#getting-started
7. jsoup 一個解析html的java庫,可方便的提取和操作數(shù)據(jù)
項目地址:https://github.com/jhy/jsoup
官方網(wǎng)站:http://jsoup.org/
作用:(1) 從一個url、文件或string獲得html并解析
(2) 利用dom遍歷或css選擇器查找、提取數(shù)據(jù)
(3) 操作html元素
(4) 根據(jù)白名單去除用于提交的非法數(shù)據(jù)防止xss攻擊
(5) 輸出整齊的html
8.ZIP java壓縮和解壓庫
項目地址:https://github.com/zeroturnaround/zt-zip
文檔介紹:https://github.com/zeroturnaround/zt-zip#examples
作用:(1) 解壓和壓縮,并支持文件夾內(nèi)遞歸操作
(2) 支持包含和排除某些元素
(3) 支持重命名元素
(4) 支持遍歷zip包內(nèi)容
(5) 比較兩個zip包等功能
9. Cobub Razor 開源的mobile行為分析系統(tǒng),包括web端、android端,支持ios和window phone
項目地址:https://github.com/cobub/razor
Demo地址:http://demo.cobub.com/razor
網(wǎng)站介紹:http://dev.cobub.com/
10. aFileChooser 文件選擇器,可內(nèi)嵌到程序中,而無需使用系統(tǒng)或三方文件選擇器。
項目地址:https://github.com/iPaulPro/aFileChooser
11. androidpn 基于xmpp協(xié)議的消息推送解決方案,包括服務(wù)器端和android端。
項目地址:https://github.com/dannytiehui/androidpn
12. Android插件式開發(fā)