(轉)本應用集成的各開源庫或控件的說明(2)

Logger 日志打印

Github地址:https://github.com/orhanobut/logger

粗略用法:

引入:

compile 'com.orhanobut:logger:1.15'

初始化:

Logger.init();//在application中

用法方式:

Logger.d("hello");?

Logger.e("hello");?

Logger.w("hello");?

Logger.v("hello");?

Logger.wtf("hello");?

Logger.json(JSON_CONTENT);?

Logger.xml(XML_CONTENT);?

Logger.log(DEBUG, "tag", "message", throwable);

參數設置:

Logger

.init(YOUR_TAG)? ? ? ? ? ? ? ? // default PRETTYLOGGER or use just init()?

.methodCount(3)? ? ? ? ? ? ? ? // default 2?

.hideThreadInfo()? ? ? ? ? ? ? // default shown?

.logLevel(LogLevel.NONE)? ? ? ? // default LogLevel.FULL?

.methodOffset(2)? ? ? ? ? ? ? ? // default 0?

.logAdapter(new AndroidLogAdapter()); //default AndroidLogAdapter?

GsonFormat & Gson json 數據解析

GsonFormat Github地址:https://github.com/zzz40500/GsonFormat

Gson Github地址:https://github.com/google/gson

引入:

compile 'com.google.code.gson:gson:2.7'

Gson 用法教程:

地址:http://ocnyang.com/tags/Gson/

butterknife 依賴注入框架

Github地址:https://github.com/JakeWharton/butterknife

引入:

compile 'com.jakewharton:butterknife:8.4.0'

annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

leakcanary 內存泄漏檢測工具

Github地址:https://github.com/square/leakcanary

引入:

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'?

releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'?

testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'?

Glide 圖片請求庫

Github地址:https://github.com/bumptech/glide

引入:

compile 'com.github.bumptech.glide:glide:3.7.0'

compile 'com.android.support:support-v4:19.1.0' //v4包

Glide 用法教程:

地址:http://ocnyang.com/tags/Glide/

circleimageview 圓形圖片庫

Github地址:https://github.com/hdodenhof/CircleImageView

引入:

compile 'de.hdodenhof:circleimageview:2.1.0'

Rxjava + Retrofit + okhttp 網絡請求框架

三個庫的地址請自行查找,這里提供一個介紹用法的 Demo 地址

Github地址:https://github.com/rengwuxian/RxJavaSamples

(基本的使用,不做三者的封裝(因為目前還找不到好的封裝框架))

引入:

compile 'com.squareup.okhttp3:okhttp:3.4.1'

compile 'com.squareup.retrofit2:retrofit:2.1.0'

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'

compile 'io.reactivex:rxjava:1.2.1'

compile 'io.reactivex:rxandroid:1.2.1'

compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'

Okhttp 教程:

地址:http://ocnyang.com/tags/OkHttp/

Retrofit2 教程:

地址:http://ocnyang.com/tags/Retrofit2/

SlidingTutorial-Android 引導頁庫

Github地址:https://github.com/Cleveroad/slidingtutorial-android

引入:

compile 'com.cleveroad:slidingtutorial:1.0.5'

nineoldandrolid 開源動畫庫

Github地址:https://github.com/JakeWharton/NineOldAndroids

引入:

compile 'com.nineoldandroids:library:2.4.0'

percent 百分比布局

說明:非本項目使用,貌似引入的某個開源庫依賴此庫

Github地址:https://github.com/JulienGenoud/android-percent-support-lib-sample

引入:

compile 'com.android.support:percent:25.3.0'

ReactiveNetwork 手機網絡連接狀態動態監控

Github地址:https://github.com/pwittchen/ReactiveNetwork

引入:

compile 'com.github.pwittchen:reactivenetwork-rx2:0.9.0'

設想:

網絡的檢測邏輯的代碼放在了BaseActivity中,

網絡變化時,需要自動顯示網絡錯誤的布局主要繼承這個Base類就行了,

同時這個類開放的有網絡變化時的回調接口。

自動顯示網絡錯誤的布局的幾種設想:

第一種:當網絡無連接時可以顯示一個大的網絡錯誤布局, 或者跳轉到一個網絡錯誤布局,當網絡連接上的時候再自動跳轉回來

(用戶也可以通過點擊返回,在無網絡的情況下的頁面)。

第二種:當網絡無連接、網絡請求數據錯誤時都顯示一個小警示布局提醒網絡錯誤。

第三種:上面兩種結合在一起,同時在網絡請求數據錯誤的時候,就加載一定數量的網絡錯誤數據集合。

picasso 圖片請求庫

Github地址:https://github.com/square/picasso

引入:

compile 'com.squareup.picasso:picasso:2.3.2'

AndroidImageSlider 輪播圖片控件

貌似只引入了庫,并沒有真正使用

Github地址:https://github.com/daimajia/AndroidImageSlider

引入:

compile "com.android.support:support-v4:+"

compile 'com.squareup.picasso:picasso:2.3.2'

compile 'com.nineoldandroids:library:2.4.0'

compile 'com.daimajia.slider:library:1.1.5@aar'

才發現,好幾個庫都是它在依賴呀,由于沒有用到,下個版本可能會刪除這個引入

BaseRecyclerViewAdapterHelper RecycleView 拓展庫

Github 地址:https://github.com/CymChad/BaseRecyclerViewAdapterHelper

引入:

compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:VERSION_CODE'

中文 Wiki:

地址:https://github.com/CymChad/BaseRecyclerViewAdapterHelper/wiki/%E9%A6%96%E9%A1%B5

greenDAO 數據庫

Github 地址:https://github.com/greenrobot/greenDAO

引入:

較為繁瑣,詳細查看 Github 地址

eventbus 事件發布/訂閱框架

Github 地址:https://github.com/greenrobot/EventBus

引入:

compile 'org.greenrobot:eventbus:3.0.0'

用法簡述::

1.Define events:

? public static class MessageEvent { /* Additional fields if needed */ }?

2.Prepare subscribers: Declare and annotate your subscribing method, optionally specify a thread mode:

? @Subscribe(threadMode = ThreadMode.MAIN)?

? public void onMessageEvent(MessageEvent event) {/* Do something */};

Register and unregister your subscriber. For example on Android, activities and fragments should usually register according to their life cycle:

@Override

public void onStart() {

? ? super.onStart();

? ? EventBus.getDefault().register(this);

}

@Override

public void onStop() {

? ? super.onStop();

? ? EventBus.getDefault().unregister(this);

}

3.Post events:

? EventBus.getDefault().post(new MessageEvent());

RippleEffect 控件點擊的漣漪效果

Github 地址:https://github.com/traex/RippleEffect

引入:

compile 'com.github.traex.rippleeffect:library:1.3'

takephoto 拍照上傳庫

Github 地址:https://github.com/crazycodeboy/TakePhoto

引入:

compile 'com.jph.takephoto:takephoto_library:4.0.3'

colorpicker 顏色畫板選擇庫

Github 地址:https://github.com/QuadFlask/colorpicker

引入:

compile 'com.github.QuadFlask:colorpicker:0.0.13'

android-autofittextview 自適應大小文本控件

Github 地址:https://github.com/grantland/android-autofittextview

引入:

compile 'me.grantland:autofittextview:0.2.+'

HTextView 動態文本控件

Github 地址:https://github.com/hanks-zyh/HTextView

引入:

compile 'hanks.xyz:htextview-library:0.1.5'

BGAQRCode-Android 二維碼掃描項目

對比了一些通過Zxing封裝的二維碼識別的項目,獨獨比較喜歡這個。

Github 地址:https://github.com/bingoogolapple/BGAQRCode-Android

引入:

compile 'com.google.zxing:core:3.2.1'

compile 'cn.bingoogolapple:bga-qrcodecore:latestVersion@aar'

compile 'cn.bingoogolapple:bga-zxing:latestVersion@aar'

MPAndroidChart 圖表庫

Github 地址:https://github.com/PhilJay/MPAndroidChart

引入:

//在 Android 開發中使用過圖表的,應該都會知道這個庫吧。

compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'

material-calendarview 材料設計日歷控件

Github 地址:https://github.com/prolificinteractive/material-calendarview

引入:

compile 'com.prolificinteractive:material-calendarview:1.4.3'

flexbox-layout 官方的盒子布局控件

Github 地址:https://github.com/google/flexbox-layout

引入:

compile 'com.google.android:flexbox:0.3.0-alpha3'

KenBurnsView 視差圖片控件

Github 地址:https://github.com/flavioarfaria/KenBurnsView

引入:

compile 'com.flaviofaria:kenburnsview:1.0.7'

materialsearchview 材料設計搜索框

Github 地址:https://github.com/MiguelCatalan/MaterialSearchView

引入:

compile 'com.miguelcatalan:materialsearchview:1.4.0'

材料設計需要的官方包

引入:

compile 'com.android.support:cardview-v7:25.1.1'//卡片

MagicIndicator 指示器庫

Github 地址:https://github.com/hackware1993/MagicIndicator

引入:

compile 'com.github.hackware1993:MagicIndicator:1.5.0'

記得鴻洋大神也開源一個差不多的庫,也挺不錯的。

第三方平臺引入集中說明

小米推送(本來沒想用小米的,抵不住前幾年小米手機買的好名氣大,我就用用試試。這里說一下和其他平臺的不足點,目前發現小米推送不支持富文本的)

ShareSDK Mob 平臺的社會化分享和登錄

SMSSDK Mob 平臺的手機短信驗證(感覺 Mob 平臺名氣穩健,一方面是名字取得好呀,一方面永久免費)

友盟統計 (這個小應用大部分都會用吧)

沉浸式狀態欄

項目地址:http://blog.csdn.net/lmj623565791/article/details/48649563

注意三點:

ToolBar高度設置為wrap_content?

ToolBar添加屬性android:fitsSystemWindows="true"?

header_just_username.xml的根布局RelativeLayout,添加屬性? android:fitsSystemWindows="true"?

android:fitsSystemWindows這個屬性,主要是通過調整當前設置這個屬性的view的padding去為我們的status_bar留下空間。?

為了Android4.4適配:

那么只需要在Activity里面去寫上(設置Toolbar之后):StatusBarCompat.compat(this);就可以了。

如果你希望自己設置狀態看顏色,那么就用這個方法:

StatusBarCompat.compat(this, getResources().getColor(R.color.status_bar_color));

關于沉浸式的說明,6.0及以上不能達到半透明的效果。 同時沉浸式和夜間模式結合要考慮兩方面。

具體差別請看V21/style

Android應用自動更新庫(android-auto-update)

項目地址:https://github.com/feicien/android-auto-update

用法:

導入library項目(本項目是直接把library直接復制放在了 /update 目錄下)

提供2種版本檢查方式,在你的項目中添加以下代碼即可

? 使用Dialog? `UpdateChecker.checkForDialog(this);`?

? 使用Notification? UpdateChecker.checkForNotification(this);?

添加權限

? 添加訪問網絡的權限?

? 添加寫SDCard權限(可選,非必須)?

? 如果添加這個權限 apk下載在sdcard中的Android/data/包名/cache目錄下 否則下載到 內存中的 /data/data/包名/cache中?

? ?

SlidingTutorial-Android引導頁

根據Demo直接使用,可定制的東西很少,當然引導頁本身也沒什么可定制的,

就看自己喜歡不喜歡這個引導頁的設計了

項目地址:https://github.com/Cleveroad/slidingtutorial-android

這個引導頁在布局上用到的全是百分比布局

需要自己定制的可能是最后一頁添加一個按鈕的點擊事件

Slidinglayout 果凍彈跳效果

依賴nineoldandorid開源動畫庫

Slidinglayout其實就是一個自定義的布局

XML樣式參數:

background_view?背景?view

sliding_mode?滑動模式,both為上下可彈跳,top?為頂部彈跳,bottom?為底部彈跳,默認為 both?sliding_pointer_mode?手指模式,one為只識別一個手指,more為支持多指滑動,默認為more?top_max?當滑動模式為top時才有效,用于可滑動的最大距離,如"top_max:200dp",默認為-1(不限制)

常用API:

public void setSlidingOffset(float slidingOffset)設置控件的滑動阻力,有效值為0.1F~1.0F,值越小阻力越大,默認為0.5F

public void setTargetView(View view)設置控件的前景View

public void setBackgroundView(View view)?設置控件的背景View

public void setSlidingListener(SlidingListener slidingListener)?給控件設置監聽,可以監聽滑動情況

public void setSlidingMode(int mode)?設置滑動模式

public void setSlidingDistance(int max)?設置最大滑動距離,僅在top模式下有效

夜間主題(仿知乎/改變主題的方式)

(本應用中還未使用)

博客參考地址:http://www.lxweimin.com/p/3b55e84742e5

項目地址:https://github.com/D-clock/AndroidStudyCode

DayNightActivity的例子的方式是在設置頁的的代碼方式。

在其他有夜間模式的頁面,只要在setcontentView之前判斷目前設置的模式然后設置 此種模式就行了。即實現initData();initTheme();方法就行了,同時可以在BaseActivity中實現。

主導航頁面(設計思路)

(目前應用的問題,個人感覺就是這個設計的有問題)

下面具有導航欄的主體app的設計思路。

由于這種導航是一級導航,目前不建議在app的一級頁面就采用?viewpager+Fragment?或導航欄+?Fragment?的形式設計。

建議采用獨立?activity+include?布局 +?android:launchMode="singleTask"?+?theme:@style/noAnimation?(取消activity跳轉自帶的原生動畫)的形式

這樣的好處:能將每個一級功能分類頁相互分離開來不相互影響。經過觀察和猜想知乎采用的應該是這種方式。這樣的方式也能達到和上面一樣的效果,同時又解決了Fragment帶來的不便。

關于主導航頁返回鍵的監聽處理方式:

一種是在每個主導航頁中設置監聽,點擊一次沒反應,連點擊兩次退出程序。

另外一種:點擊一次返回到main主導航頁面,在main頁面點擊一次直接退出程序(這也是知乎實現的方式,同時因為在main頁面點擊一次就直接退出了,所以在其他主導航頁面如果連續點擊兩次也能達到直接退出程序的效果。)

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,117評論 6 537
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,860評論 3 423
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 177,128評論 0 381
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,291評論 1 315
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,025評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,421評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,477評論 3 444
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,642評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,177評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,970評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,157評論 1 371
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,717評論 5 362
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,410評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,821評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,053評論 1 289
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,896評論 3 395
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,157評論 2 375

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,681評論 25 708
  • 人生的成功不在于你有多好的基因,亦或是多高的天分,他需要的是你不屈不撓的精神。我知道這很困難,但你也知道這代表你離...
    一只蠢洋洋丶閱讀 138評論 0 0
  • 踩著小黃車奔向麥當勞,落到了營銷的圈套里。 發現小黃車真的是“小”黃車騎著才順暢,“那么大”小黃車坑了我快兩個月。...
    1658d734897e閱讀 65評論 0 0
  • Now playing 魏如萱的《織花》。很喜歡這種調調,但現在也只找到了類似的椎名林檎的《ハツコイ娼女》。 中午...
    深河閱讀 146評論 0 1
  • 分手那天 我把自己反鎖在了小屋里 坐在書桌前 我刪掉了他的電話號碼 網絡好友 剪了他送我的皮革手鏈 撕毀了所有我倆...
    麋鹿筆記閱讀 213評論 1 0