Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 開源工具庫精選(第二篇)

編輯:關於 Android 程式設計

善用這些優秀的開源專案,能大幅減少重複而繁瑣的開發工作,讓你把精力集中在更重要的地方。

一、依賴注入(DI)

透過依賴注入簡化 View、服務與資源的初始化以及事件綁定。

AndroidAnnotations:功能完整的快速開發框架,具備依賴注入、簡潔的執行緒模型、事件綁定與 REST 客戶端等特點。它在編譯時生成子類,僅約 50kb,對執行期效能幾乎沒有影響。專案地址:https://github.com/excilys/androidannotations

roboguice:利用 annotation 以更少程式碼完成專案,但它在執行期透過反射讀取註解,可能影響效能。專案地址:https://github.com/roboguice/roboguice

ButterKnife:以 annotation 快速完成 View 初始化,大幅減少樣板程式碼。專案地址:https://github.com/JakeWharton/butterknife

Dagger:適用於 Android 與 Java 的依賴注入框架。專案地址:https://github.com/square/dagger

二、圖片緩存

Android-Universal-Image-Loader:目前使用最廣泛的圖片緩存庫,支援絕大多數主流特性。專案地址:https://github.com/nostra13/Android-Universal-Image-Loader

Picasso:Square 開源的圖片庫,能自動偵測 adapter 的重用並取消先前下載,支援圖片變換、載入本地資源、設置佔位圖與 debug 模式。專案地址:https://github.com/square/picasso

ImageCache:包含記憶體與 SD 卡二級緩存,支援預取、多達 13 種緩存算法、可自定義保存規則與不同網路類型處理。專案地址:https://github.com/Trinea/AndroidCommon

三、網路相關

Android Asynchronous Http Client:支援匿名回呼、UI 執行緒外請求、斷點上傳、智能重試、gzip 壓縮、JSON 解析與 Cookies 持久化。專案地址:https://github.com/loopj/android-async-http

android-query:以更少程式碼完成異步加載。專案地址:https://github.com/androidquery/androidquery

Ion:支援圖片、JSON、http post 等異步請求。專案地址:https://github.com/koush/ion

HttpCache:根據 cache-control、expires 緩存請求,支援同步與異步請求。專案地址:https://github.com/Trinea/AndroidCommon

okhttp:Square 開源的 HTTP 工具,支援 SPDY 協議、連接池、gzip 壓縮與 Response 緩存。專案地址:https://github.com/square/okhttp

Retrofit:用於 RESTful API 設計。專案地址:https://github.com/square/retrofit

四、資料庫 ORM 工具

greenDAO:效能佳、API 簡單易用、記憶體與庫大小都小的 SQLite ORM。專案地址:https://github.com/greenrobot/greenDAO

ActiveAndroid:另一套 SQLite ORM 工具。專案地址:https://github.com/pardom/ActiveAndroid

Sprinkles:可搭配 Retrofit 保存從伺服器取得的數據。專案地址:https://github.com/emilsjolander/sprinkles

五、Android 公共庫

Guava:Google 基於 Java 1.6 的類庫擴展,涵蓋 collections、caching、concurrency、string processing、I/O 等,讓 Java 程式碼更優雅簡潔。專案地址:https://code.google.com/p/guava-libraries/

AndroidCommon:包含緩存、公共 View 與大量常用工具類。專案地址:https://github.com/Trinea/AndroidCommon

六、高版本向低版本相容

ActionBarSherlock:為所有 Android 版本提供統一的 ActionBar,解決 4.0 以下的相容問題。專案地址:https://github.com/JakeWharton/ActionBarSherlock

NineOldAndroids:將 Android 3.0 的動畫 API 相容到 1.0。專案地址:https://github.com/JakeWharton/NineOldAndroids

HoloEverywhere:將 Android 3.0 的 Holo 主題相容到 2.1 以上。專案地址:https://github.com/Prototik/HoloEverywhere

七、多媒體相關

cocos2d-x:跨平台的 2D 遊戲框架,支援 Android、iOS、Linux、Windows 等平台。專案地址:https://github.com/cocos2d/cocos2d-x

Vitamio:Android 與 iOS 上的全能多媒體開發框架,全面支援硬體解碼與 GPU 渲染,能流暢播放 720P 甚至 1080P 高清影片,並支援多種串流協議。專案地址:https://github.com/yixia/VitamioBundle

PhotoProcessing:利用 NDK 處理圖片,支援多種濾鏡效果。專案地址:https://github.com/lightbox/PhotoProcessing

Android StackBlur:圖片模糊效果工具類。專案地址:https://github.com/kikoso/android-stackblur

八、其他實用庫

Salvage:帶有 View 緩存的 ViewPager PagerAdapter,使用方便。專案地址:https://github.com/JakeWharton/salvage

Android-PasscodeLock:應用鎖,每次啟動需輸入四位數字密碼。專案地址:https://github.com/wordpress-mobile/Android-PasscodeLock

android-lockpattern:圖案密碼解鎖。專案地址:https://code.google.com/p/android-lockpattern/

Android Priority Job Queue:Android 背景任務佇列。專案地址:https://github.com/path/android-priority-jobqueue

jsoup:解析 HTML 的 Java 庫,可從 URL、檔案或字串擷取並操作數據,並能防止 XSS 攻擊。專案地址:https://github.com/jhy/jsoup

zt-zip:Java 壓縮與解壓庫,支援遞迴操作、包含與排除元素、重命名與遍歷 zip 內容。專案地址:https://github.com/zeroturnaround/zt-zip

Cobub Razor:開源的行動行為分析系統,含 Web 端與 Android 端。專案地址:https://github.com/cobub/razor

aFileChooser:可內嵌到程式中的檔案選擇器。專案地址:https://github.com/iPaulPro/aFileChooser

androidpn:基於 XMPP 協議的訊息推送解決方案,含伺服器端與 Android 端。專案地址:https://github.com/dannytiehui/androidpn

以上這些工具庫涵蓋了依賴注入、圖片緩存、網路請求、資料庫、多媒體與相容性等各個層面,依需求挑選合適的庫,往往能讓開發事半功倍。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved