You deserve to be able to cooperate openly and freely with other people who use software.You deserve to be able to learn how the software works, and to teach your students with it.You deserve to be able to hire your favorite programmer to fix it when it breaks. You deserve free software.
你可以公開、自由地與其他軟件使用者合作,你有權瞭解軟件的工作原理,並將其傳授給你的學生,當軟件發生問題時你完全可以僱用你所喜愛的程序員對它進行完善。 你理應得到自由的軟件。 ——Richard Matthew Stallman(理查·馬修·斯托曼,自由軟件運動的精神領袖)
選擇開源框架的原則
本部分引用自:編寫高質量代碼之Java 秦小波 著 建議139:大膽採用開源工具
1. 普適性原則:選擇一個工具或框架就必須考慮項目成員的整體技術水平,不能有太大的跨度或跳躍性,要確保大部分項目成員對工具都比較熟悉,若一個項目中的成員大部分是新員工,那麼在持久層框架的選擇上
2. 唯一性原則:相同的工具只選擇一個或一種,不要讓多種相同或相似職能的工具共存
3. “大樹納涼”原則:選擇大的開源項目
4. 精而專原則
5. 高熱度原則
一個開源項目的熱度越高,更新得就越頻繁,使用的人羣就越廣,Bug的曝光率就越快,修復效率也就越高,這對我們項目的穩定性來說是非常重要的。有很多開源項目可能已經很長時間沒有更新了,或者是已經非常成熟了,或者是瀕於關閉了,這我們不能要求太高,畢竟開源項目已經共享出了他人的精力和智力,我們在享受他人提供的成果的同時,也應該珍惜他人的勞動,最低的標準是不要詆譭開源項目。
1.網絡
- volley
volley https://github.com/google/volley
缺點:上傳文件 、session 處理、大數據量處理不適合使用
- async-http
async-http
https://github.com/loopj/android-async-http
處理cookie
public static void post(String url,RequestParams params,JsonHttpResponseHandler responseHandler){
AsyncHttpClient client = new AsyncHttpClient();
//保存cookie,自動保存到了shareprefercece
PersistentCookieStore myCookieStore = new PersistentCookieStore(Application.mInstance);
client.setCookieStore(myCookieStore);
if(params == null){
params = new RequestParams();
}
List<Cookie> cookies = myCookieStore.getCookies();
int size =cookies.size();
if(size>0){
BasicCookieStore bcs = new BasicCookieStore();
bcs.addCookies(cookies.toArray(
new Cookie[cookies.size()]));
client.setCookieStore(bcs);
}
try {
client.post(url, params, responseHandler);
} catch (Exception e) {
e.printStackTrace();
responseHandler.onFailure(-1, new Header[]{}, new Throwable(e.getMessage()), new JSONObject());
}
}
上傳圖片:
List<File> images
if (images != null) {
for (int i = 0; i < images.size(); i++) {
File file = images.get(i);
try {
params.put("img_file[" + i + "]", file, "image/png");
} catch (FileNotFoundException e) {
failuredListener.onRespone("file not found", -1);
return;
}
}
}
- okhttp
https://github.com/square/okhttp
2.導航指示器
viewpagerindicator
https://github.com/hackware1993/MagicIndicatorViewPagerIndicator
https://github.com/JakeWharton/ViewPagerIndicator
3.跑馬燈
俗名:可垂直跑、可水平跑的跑馬燈;學名:可垂直翻、可水平翻的翻頁公告
https://github.com/sfsheng0322/MarqueeView
4.側滑菜單
slidingMenu_library
https://github.com/jfeinstein10/SlidingMenu
5.黃油刀
butterknife
https://github.com/JakeWharton/butterknife
6.dialog
- material-dialogs
https://github.com/afollestad/material-dialogs
- sweet-alert-dialog
https://github.com/pedant/sweet-alert-dialog
7.EventBu
EventBu
https://github.com/greenrobot/EventBus
8.圖片
- glide
https://github.com/bumptech/glide
- Android-Universal-Image-Loader
https://github.com/nostra13/Android-Universal-Image-Loader
9.掃碼
BGAQRCode-Android
https://github.com/bingoogolapple/BGAQRCode-Android
10.輪播圖
android-auto-scroll-view-pager
https://github.com/Trinea/android-auto-scroll-view-pager/
11.Json解析
- fastjson
https://github.com/alibaba/fastjson
- gson
https://github.com/google/gson
12.下拉刷新
com.navercorp.pulltorefresh
compile ‘com.navercorp.pulltorefresh:library:3.2.0@aar’
CommonPullToRefresh
https://github.com/Chanven/CommonPullToRefresh
13.數據庫
LitePal
https://github.com/LitePalFramework/LitePal
14.logger
logger
https://github.com/orhanobut/logger
15.內存泄漏檢測
leakcanary