(转)本应用集成的各开源库或控件的说明(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.jianshu.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阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 170,569评论 25 707
  • 人生的成功不在于你有多好的基因,亦或是多高的天分,他需要的是你不屈不挠的精神。我知道这很困难,但你也知道这代表你离...
    一只蠢洋洋丶阅读 124评论 0 0
  • 踩着小黄车奔向麦当劳,落到了营销的圈套里。 发现小黄车真的是“小”黄车骑着才顺畅,“那么大”小黄车坑了我快两个月。...
    1658d734897e阅读 59评论 0 0
  • Now playing 魏如萱的《织花》。很喜欢这种调调,但现在也只找到了类似的椎名林檎的《ハツコイ娼女》。 中午...
    深河阅读 115评论 0 1
  • 分手那天 我把自己反锁在了小屋里 坐在书桌前 我删掉了他的电话号码 网络好友 剪了他送我的皮革手链 撕毁了所有我俩...
    麋鹿笔记阅读 190评论 1 0