diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1afbd9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +Utils/URLChecker/out +Utils/URLChecker/*.class +Utils/.idea +Utils/Utils.iml +Utils/out diff --git a/README.md b/README.md index 26805c5..ce5a8f9 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,111 @@ # Android-Tips -学习 Android 至今,大大小小的坑没少踩,庆幸的是,在强大的搜索引擎与无私奉献的人们的帮助下,我遇到的坑都顺利地被填平了。 +This is an awesome list of tips for android. -为了便于日后遇到同样的问题时,能免于再次搜索带来的麻烦,我养成了收藏书签的习惯,随着书签(Tips)的日积月累,我想,是时候该有这个项目了。 +If you are a beginner, this list will be the first choice for you when you have a difficult time. -**如果你是个 Android 新人,那么我希望这份列表,可以成为你踩到坑时的不完全手册。** +Welcome `Star` and `Fork`, your support is my greatest affirmation. -当然,这份列表一定会有遗漏,如果不幸,这里没有你所踩到的坑,或者对于某个问题你有更好的 Tips,欢迎分享,让我们一起来维护这个项目!你可以通过 [Commit](https://github.com/tangqi92/Android-Tips/issues) 的形式,当然也欢迎 `Star` 与 `Fork` :) +--- + +学习 Android 至今,大大小小的坑没少踩过,庆幸的是,在强大的搜索引擎与无私奉献的人们的帮助下,那些坑都顺利地被填平了。 + +为了日后在遇到同样的问题时,能免于再次搜索带来的麻烦,我养成了收藏书签的习惯,随着书签(Tips)的日积月累,我想,是时候该有这个项目了。 + +**如果你是个 Android 新人,又不善于搜索或不知道从何开始,那么我相信这份列表,将会成为你的首选。** + +当然,这份列表并不完美,如果不幸,这里没有你所踩到的坑,或者对于某个问题你有更好的 Tips,欢迎与大家分享,让我们一起来维护这个项目! + +你可以通过 [Pull request](https://github.com/tangqi92/Android-Tips/pulls) 的形式进行提交,当然也欢迎 `Star` 与 `Fork` :) + +> 由于各种问题,给出的链接可能会无法正常访问。遇到这种情况欢迎大家提交 [Issue](https://github.com/tangqi92/Android-Tips/issues),Contributers 也可以使用 [Utils](https://github.com/tangqi92/Android-Tips/tree/master/Utils) 里面的 [URLChecker](https://github.com/tangqi92/Android-Tips/blob/master/Utils/UrlCheckerREADME.md) 来检测列表里链接的有效性,你可以选择更改为新的有效连接,或者把需要**梯子**的文章以 Markdown 的形式保存在 Utils/Content 目录下,并注明原文章链接和作者。 + +--- + +## 目录 + +* [A](#a) +* [B](#b) +* [C](#c) +* [D](#d) +* [E](#e) +* [F](#f) +* [G](#g) +* [H](#h) +* [I](#i) +* [J](#j) +* [K](#k) +* [L](#l) +* [M](#m) +* [N](#n) +* [O](#o) +* [P](#p) +* [Q](#q) +* [R](#r) +* [S](#s) +* [T](#t) +* [U](#u) +* [V](#v) +* [W](#w) +* [X](#x) +* [Y](#y) +* [Z](#z) +* [Others](#others) +* [Contributors](#contributors) +* [Contact Me](#contact-me) + +--- ->由于本项目面向的群体为初学者,所以列表的知识点以初级为主,资源大多数为中文,如遇到少数无法访问的情况,请自备梯子。 +### A + +### Activity + +1. [Android Activity为什么要细化出onCreate、onStart、onResume、onPause、onStop、onDesdroy这么多方法让应用去重载?](http://blog.csdn.net/zhao_3546/article/details/12843477) -## A ### ADB -1. [Android ADB常用命令](http://segmentfault.com/a/1190000000426049) -2. [Android开发调试工具ADB的使用](http://www.cnblogs.com/meil/archive/2012/05/24/2516055.html) -3. [Installing ADB on Windows 7](https://www.youtube.com/watch?v=5U_BfrXV90I) -4. [Adb connection Error:远程主机强迫关闭了一个现有的连接](http://www.oschina.net/question/54100_33209) -5. [Android通过Wifi来调试你的应用](http://www.stormzhang.com/android/2014/08/27/adb-over-wifi/) +1. [Installing ADB on Windows 7](https://www.youtube.com/watch?v=5U_BfrXV90I) +2. [Android ADB常用命令](http://android.jobbole.com/61592/) +3. [Android开发调试工具ADB的使用](http://www.cnblogs.com/meil/archive/2012/05/24/2516055.html) +4. [Android通过Wifi来调试你的应用](http://stormzhang.com/android/2014/08/27/adb-over-wifi/) +5. [Adb connection Error:远程主机强迫关闭了一个现有的连接](http://www.oschina.net/question/54100_33209) ### Adapter 1. [Android简便通用的SimpleBaseAdapter](http://www.stormzhang.com/androidtips/2014/08/31/android-common-simplebaseadapter/) -2. [Android数据适配器(Adapter)优化:使用高效的ViewHolder](http://stackvoid.com/using-adapter-in-efficiency-way/) -3. [Android 快速开发系列 打造万能的ListView GridView 适配器](http://blog.csdn.net/lmj623565791/article/details/38902805/) +2. [Android 快速开发系列 打造万能的ListView GridView 适配器](http://blog.csdn.net/lmj623565791/article/details/38902805/) ### AIDL 1. [android进程间通信:使用AIDL](http://blog.csdn.net/saintswordsman/article/details/5130947) 2. [Android AIDL使用详解](http://blog.csdn.net/stonecao/article/details/6425019) 3. [android跨进程通信(IPC): 使用AIDL](http://blog.csdn.net/singwhatiwanna/article/details/17041691) -4. [Android中的跨进程通信的实现(一)——远程调用过程和aidl](http://foocoder.com/blog/androidzhong-de-kua-jin-cheng-tong-xin-de-shi-xian-(%5B%3F%5D-)-yuan-cheng-diao-yong-guo-cheng-he-aidl.html/) +4. [Android中的跨进程通信的实现(一)——远程调用过程和aidl](http://blog.csdn.net/notice520/article/details/8135600) 5. [Android Studio下如何配置AIDL文件](http://chenqichao.me/2014/05/13/003-Android-Studio-AIDL/) +### AlarmManager + +1. [Android AlarmManager实现不间断轮询服务](http://blog.csdn.net/ryantang03/article/details/9317499) + ### Android-Async-Http -1. [快速Android开发系列网络篇之Android-Async-Http](http://www.cnblogs.com/angeldevil/p/3729808.html) -2. [android-async-http框架库使用基础](http://yanbober.github.io/2014/11/11/csdn-opensource-analysis-5/) +1. [Asynchronous Http Client for Android](https://github.com/loopj/android-async-http) +2. [快速Android开发系列网络篇之Android-Async-Http](http://www.cnblogs.com/angeldevil/p/3729808.html) +3. [android-async-http框架库使用基础](http://yanbober.github.io/2014/11/11/csdn-opensource-analysis-5/) + +### Android Studio + +1. [Android Studio导入项目](http://ask.android-studio.org/?/article/21) +2. [Android Studio 简单设置](http://blog.gaoqixhb.com/p/54b9c293bf1ac9364284af78) +3. [Android Studio 简介及导入 jar 包和第三方开源库方法](http://drakeet.me/android-studio) +4. [Android Studio使用技巧系列教程(一)](http://blog.csdn.net/growth58/article/details/46729803) +5. [Android Studio中如何使用Git和Github来管理项目](http://blog.csdn.net/wei18359100306/article/details/45645145) +6. [Android Studio 权威教程](http://blog.csdn.net/column/details/zsl-androidstudio.html) +7. [倍数提高工作效率的Android Studio奇技](http://zlv.me/posts/2015/07/13/14_android-studio-tips/) +8. [Android Studio 快捷键(Windows)](http://blog.csdn.net/altair86/article/details/8972178) +9. [Android Studio详细教程汇总](http://www.stormzhang.com/devtools/2015/06/17/android-studio-all/) +10. [Android Studio有什么奇技淫巧](http://www.zhihu.com/question/27482725) ### AQuery @@ -49,6 +117,21 @@ 1. [Android AsyncTask完全解析,带你从源码的角度彻底理解](http://blog.csdn.net/guolin_blog/article/details/11711405) 2. [Android中AsyncTask的简单用法](http://blog.csdn.net/cjjky/article/details/6684959) 3. [Android开发者:你真的会用AsyncTask吗?](http://code.oneapm.com/android/2015/06/02/android1/) +4. [深入解析AsyncTask,多例子版](http://www.cnblogs.com/anee/archive/2012/09/24/2699829.html) + +### Annotations + +1. [AndroidAnnotations框架入门教程一之介绍](http://zhenhappy.github.io/2015/10/11/Android-Annotations-1-Introduce.html) +2. [How to stop an animation (cancel() does not work)](http://stackoverflow.com/questions/4112599/how-to-stop-an-animation-cancel-does-not-work) + +### Android 6.0 + +1. [Android6.0运行时权限简介](http://unclechen.github.io/2016/03/05/Android6.0%E8%BF%90%E8%A1%8C%E6%97%B6%E6%9D%83%E9%99%90%E7%AE%80%E4%BB%8B/) +2. [Android 6.0 - 动态权限管理的解决方案](http://www.jianshu.com/p/dbe4d37731e6) +3. [聊一聊Android 6.0的运行时权限](http://droidyue.com/blog/2016/01/17/understanding-marshmallow-runtime-permission/) +4. [Android6.0权限系统](https://github.com/CharonChui/AndroidNote/blob/master/Android%E5%8A%A0%E5%BC%BA/Android6.0%E6%9D%83%E9%99%90%E7%B3%BB%E7%BB%9F.md) + +--- ## B @@ -59,6 +142,7 @@ 3. [Android学习笔记进阶16之BitmapShader](http://blog.csdn.net/sjf0115/article/details/7267532) 4. [Android 优化Bitmap避免OutOfMemoryError](http://chjmars.iteye.com/blog/1157137) 5. [Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅](http://blog.csdn.net/xiaanming/article/details/9825113) +6. [Android 开发绕不过的坑:你的 Bitmap 究竟占多大内存?](http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=498&fromuid=6) ### Broadcast @@ -66,8 +150,14 @@ 2. [玩转Android---组件篇---Broadcast Receiver(广播接收器)](http://hualang.iteye.com/blog/1003374) 3. [【Android】动态注册广播接收器](http://blog.csdn.net/etzmico/article/details/7317528) +--- + ## C +### Canvas + +1. [Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)](http://blog.csdn.net/rhljiayou/article/details/7212620) + ### Callback 1. [How to Define Callbacks in Android?](http://stackoverflow.com/questions/3398363/how-to-define-callbacks-in-android) @@ -79,43 +169,59 @@ 1. [Android5.0新控件CardView的介绍和使用](http://www.cnblogs.com/tianzhijiexian/p/4067308.html) 2. [Android CardView Example](http://www.truiton.com/2015/03/android-cardview-example/) 3. [Android CardView Widget – Add Cards to a List using RecyclerView](http://techlovejump.com/android-cardview-widget-example-add-to-list-using-recyclerview/) - -### Check - -1. [How to check visibility of software keyboard in Android?](http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android) +4. [CardView在API 21以下的圆角效果处理](http://www.jianshu.com/p/07097b562acb) ### Configuration Change 1. [Android Configuration change引发的问题及解决方法](http://blog.csdn.net/aliaooooo/article/details/23606179?utm_source=tuicool) -2. [Handling Runtime Changes](http://developer.android.com/guide/topics/resources/runtime-changes.html) +2. [Handling Runtime Changes](https://github.com/troyliu0105/Android-Tips/blob/master/Utils/Content/Handing_Runtime_Changes.md) ### Context 1. [android学习—— context 和 getApplicationContext()](http://blog.csdn.net/janronehoo/article/details/7348566) 2. [Android中Context详解 ---- 你所不知道的Context](http://blog.csdn.net/qinjuning/article/details/7310620) +3. [Difference between getContext() , getApplicationContext() , getBaseContext() and “this”](http://stackoverflow.com/questions/10641144/difference-between-getcontext-getapplicationcontext-getbasecontext-and) ### CoordinatorLayout 1. [CoordinatorLayout与滚动的处理](http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0717/3196.html) 2. [Handling Scrolls with CoordinatorLayout](https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout) +--- + ## D ### Download -1. [Download a file with Android, and showing the progress in a ProgressDialog](http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog) +1. [Download a file with Android, and showing the progress in a ProgressDialog](http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog) [**译文**](https://github.com/troyliu0105/stackoverflow-java-top-qa/blob/master/contents/Download_a_file_with_Android_and_showing_the_progress_in_a_ProgressDialog.md) 2. [Java 服务器端支持断点续传的源代码【支持快车、迅雷】](http://blog.csdn.net/defonds/article/details/7074352) 3. [Java 多线程断点下载文件](http://www.cnblogs.com/hoojo/archive/2011/09/30/2196767.html) 4. [Android 后台Service下载 (一)](http://blog.csdn.net/qingye_love/article/details/14163511) 5. [Android网络编程 --断点续传下载文件](http://blog.csdn.net/wwj_748/article/details/20146869) 6. [android 多线程断点续传下载 一](http://blog.csdn.net/shimiso/article/details/6763664) +### DownloadManager + +1. [Android DownloadManager 的使用](http://www.jianshu.com/p/5b1ad56b9cef) + + +### Dagger + +1. [Dagger on Android-Dagger2详解](http://blog.fidroid.com/post/android/dagger-on-android-dagger2xiang-jie) +2. [使用Dagger 2进行依赖注入](http://codethink.me/2015/08/06/dependency-injection-with-dagger-2/) + + +--- + ## E ### EventBus 1. [EventBus使用详解(一)——初步使用EventBus](http://blog.csdn.net/harvic880925/article/details/40660137) 2. [快速Android开发系列通信篇之EventBus](http://www.cnblogs.com/angeldevil/p/3715934.html) +3. [Android EventBus实战 没听过你就out了](http://blog.csdn.net/lmj623565791/article/details/40794879) + +--- ## F @@ -126,9 +232,28 @@ 3. [Android系列之Fragment(二)----Fragment的生命周期和返回栈](http://www.cnblogs.com/smyhvae/p/3983234.html) 4. [处女男学Android(九)---Fragment进阶篇之Fragment生命周期和回退栈](http://blog.csdn.net/wlwlwlwl015/article/details/40584567) 5. [Fragment笔记整理](http://www.lightskystreet.com/2015/02/02/fragment-note/) -5. [Android实战技巧:Fragment的那些坑](http://toughcoder.net/blog/2015/04/30/android-fragment-the-bad-parts/) -6. [android Fragments详解四:管理fragment](http://www.cnblogs.com/mybkn/articles/2455138.html) -7. [Android Fragment 嵌套使用(Nested Fragments)](http://blog.csdn.net/top_code/article/details/37343075) +6. [Android实战技巧:Fragment的那些坑](http://toughcoder.net/blog/2015/04/30/android-fragment-the-bad-parts/) +7. [android Fragments详解四:管理fragment](http://www.cnblogs.com/mybkn/articles/2455138.html) +8. [Android Fragment 嵌套使用(Nested Fragments)](http://blog.csdn.net/top_code/article/details/37343075) +9. [Fragment MyFragment not attached to Activity](http://stackoverflow.com/questions/10919240/fragment-myfragment-not-attached-to-activity) +10. [Fragment全解析系列(一):那些年踩过的坑](http://www.jianshu.com/p/d9143a92ad94) +11. [onActivityResult is not being called in Fragment](http://stackoverflow.com/questions/6147884/onactivityresult-is-not-being-called-in-fragment) + +### Fresco + +1. [Fresco学习笔记](http://blog.happyhls.me/2015/08/03/fresco%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/) +2. [why use fresco datasource to get bitmap is empty](http://stackoverflow.com/questions/30477827/why-use-fresco-datasource-to-get-bitmap-is-empty) +3. [Always cannot show the images when loading lots of bitmaps on screen](https://github.com/facebook/fresco/issues/256) +4. [SimpleDraweeView did not recycled in RecyclerView](https://github.com/facebook/fresco/issues/414) +5. [Fresco-Facebook的图片加载框架的使用](http://www.voidcn.com/blog/chwnpp2/article/p-5761715.html) +6. [Resizing and Rotating](http://frescolib.org/docs/resizing-rotating.html#_) + + +### FlowLayout - 自定义流布局 + +1. [Android 自定义ViewGroup - 实现FlowLayout - 本文出自【张鸿洋的博客】](http://blog.csdn.net/lmj623565791/article/details/38352503) + +--- ## G @@ -146,17 +271,39 @@ 5. [灵活强大的构建系统Gradle](http://tech.meituan.com/gradle-practice.html) 6. [Gradle Android Could not find method testPackage()](http://stackoverflow.com/questions/16971740/gradle-android-could-not-find-method-testpackage) 7. [Android Studio 1.0 Gradle Error with getConfiguration()](http://stackoverflow.com/questions/27410183/android-studio-1-0-gradle-error-with-getconfiguration) +8. [Android打包的那些事](http://www.jayfeng.com/2015/11/07/Android%E6%89%93%E5%8C%85%E7%9A%84%E9%82%A3%E4%BA%9B%E4%BA%8B/) +9. [深入理解Android之Gradle](http://blog.csdn.net/innost/article/details/48228651) +10. [gradle build fails on lint task](http://stackoverflow.com/questions/20699147/gradle-build-fails-on-lint-task) +11. [“Gradle Version 2.10 is required.” Error](http://stackoverflow.com/questions/34814368/gradle-version-2-10-is-required-error) ### greenDao -1. [ORM 框架之 greenDAO 使用心得](http://itangqi.me/2015/07/26/orm-greendao-summary/) +1. [ORM 框架之 greenDAO 使用心得](http://imtangqi.com/2015/07/26/orm-greendao-summary/) 2. [SQLite数据库框架ORMLite与GreenDao的简单比较](http://blog.csdn.net/xushuaic/article/details/24434881) 3. [在AndoridStudio中引入GreenDAO](http://blog.csdn.net/h3c4lenovo/article/details/43566169) +4. [gradle脚本集成greendao-generator生成android端greendao](http://www.chenkaihua.com/2016/01/05/gradle-integration-greendao_generator-generate-greendao) ### GridView 1. [Android入门第八篇之GridView(九宫图)](http://blog.csdn.net/hellogv/article/details/4567095) 2. [用Volley让GridView加载网络图片](http://www.cnblogs.com/tianzhijiexian/p/4277873.html) +3. [Add space to top and bottom of GridView](http://stackoverflow.com/questions/23709114/add-space-to-top-and-bottom-of-gridview) + +--- + +## H + +### Hotfix + +1. [Android热更新实现原理](http://blog.csdn.net/lzyzsd/article/details/49843581#0-tsina-1-98317-397232819ff9a47a7b7e80a40613cfe1) +2. [Android App 线上热修复方案](http://lirenlong.github.io/hotfix/) +3. [Nuwa](https://github.com/jasonross/Nuwa) +4. [Android 热补丁动态修复框架小结](http://blog.csdn.net/lmj623565791/article/details/49883661) +5. [安卓App热补丁动态修复技术介绍](https://mp.weixin.qq.com/s?__biz=MzI1MTA1MzM2Nw==&mid=400118620&idx=1&sn=b4fdd5055731290eef12ad0d17f39d4a&scene=1&srcid=1106Imu9ZgwybID13e7y2nEi#wechat_redirect) + +### Handler + +1. [Handler和他的小伙伴们](http://www.jianshu.com/p/e04698eaba88) ## I @@ -166,8 +313,7 @@ ### Immersive Full-Screen Mode -1. [Using Immersive Full-Screen Mode](https://developer.android.com/training/system-ui/immersive.html) -2. [全屏沉浸式应用](http://hukai.me/android-training-course-in-chinese/ui/system-ui/immersive.html) +1. [Using Immersive Full-Screen Mode](https://developer.android.com/training/system-ui/immersive.html) [**译文**](http://hukai.me/android-training-course-in-chinese/ui/system-ui/immersive.html) ### Intent @@ -177,16 +323,50 @@ 4. [startActivityForResult用法详解](http://www.cnblogs.com/linjiqin/archive/2011/06/03/2071956.html) 5. [Android 开发笔记——通过 Intent 传递类对象](http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) +--- + ## J -### Json +### Java 8 + +1. [Modern Java - A Guide to Java 8](https://github.com/winterbe/java8-tutorial) +2. [Java8系列 - Java8简明指南](https://biezhi.me/article/java8-tutorial.html) + +### JSON 1. [Android系列---JSON数据解析](http://www.cnblogs.com/xiaoluo501395377/p/3446605.html) 2. [android json解析及简单例子](http://blog.csdn.net/lilu_leo/article/details/7000077) 3. [Android开源库--Gson谷歌官方json解析库](http://www.cnblogs.com/leestar54/p/4212318.html) +4. [DataContract4A-简化Json解析与生成](https://github.com/jywanghold/DataContract4A) + +### JNI + +1. [Hello JNI](https://github.com/googlesamples/android-ndk/tree/master/hello-jni) + +--- + +## K + +### Kotlin + +1. [Using Kotlin for Android Development](http://imtangqi.com/2017/03/28/using-kotlin-for-android-development/) +2. [Kotlin: Java 6 废土中的一线希望](https://realm.io/cn/news/droidcon-michael-pardo-kotlin/) +3. [Kotlin 语言高级安卓开发入门](https://realm.io/cn/news/oredev-jake-wharton-kotlin-advancing-android-dev/) +4. [Kotlin的黑魔法](http://blog.inico.me/2016/10/26/Kotlin-Magic-Java-Swift#.WONK-nR972R) +5. [Learn Kotlin with Keddit](https://medium.com/@juanchosaravia/learn-kotlin-while-developing-an-android-app-introduction-567e21ff9664) +6. [Coding Android Apps in Kotlin](https://code.tutsplus.com/series/coding-android-apps-in-kotlin--cms-1119) +7. [Kotlin 一门强大的语言](https://kymjs.com/column/kotlin.html) +8. [kotlin 学习](https://www.feel88.cn/2016/09/21/kotlin%E5%AD%A6%E4%B9%A0/) +9. [Kotlin从入门到『放弃』系列 视频教程](https://github.com/enbandari/Kotlin-Tutorials) + +--- ## L +### largeHeap + +1. [探究android:largeHeap](http://droidyue.com/blog/2015/08/01/dive-into-android-large-heap/index.html) + ### ListFragment 1. [Android App组件之ListFragment -- 说明和示例](http://www.cnblogs.com/skywang12345/p/3160260.html) @@ -196,6 +376,13 @@ 1. [在Activity中响应ListView内部按钮的点击事件](http://www.cnblogs.com/ivan-xu/p/4124967.html) +### Log + +1. [Logger工具类](https://github.com/orhanobut/logger) +2. [KLog](https://github.com/ZhaoKaiQiang/KLog) + +--- + ## M ### MessageDigest @@ -210,11 +397,29 @@ 3. [谢谷歌大神传我动画设计30年功力](http://www.zcool.com.cn/article/ZMTU5MzAw.html#jtss-tsina) 4. [Codelab for Android Design Support Library used in I/O Rewind Bangkok session](http://inthecheesefactory.com/blog/android-design-support-library-codelab/en) +### MVP + +1. [浅谈 MVP in Android](http://blog.csdn.net/lmj623565791/article/details/46596109) +2. [Android中的MVP](http://rocko.xyz/2015/02/06/Android%E4%B8%AD%E7%9A%84MVP/) +3. [开源项目Philm的MVP架构分析](http://www.lightskystreet.com/2015/02/10/philm_mvp/) +4. [一种在android中实现MVP模式的新思路](https://github.com/bboyfeiyu/android-tech-frontier/tree/master/androidweekly/%E4%B8%80%E7%A7%8D%E5%9C%A8android%E4%B8%AD%E5%AE%9E%E7%8E%B0MVP%E6%A8%A1%E5%BC%8F%E7%9A%84%E6%96%B0%E6%80%9D%E8%B7%AF) +5. ​[说说Android的MVP模式](http://toughcoder.net/blog/2015/11/29/understanding-android-mvp-pattern/) + +--- + ## N +### NavigationView + +1. [Easy Navigation Drawer with Design Support Library](http://blog.grafixartist.com/easy-navigation-drawer-with-design-support-library/) + +### Notification + 1. [Android——Notifications笔记](http://segmentfault.com/a/1190000000402154) 2. [Android学习之Notification的简单使用](http://blog.csdn.net/cjllife/article/details/8565370) +--- + ## O ### ORMLite @@ -222,6 +427,13 @@ 1. [Android 快速开发系列 ORMLite 框架最佳实践](http://blog.csdn.net/lmj623565791/article/details/39122981) 2. [Android ORM框架之 ORMLite](https://www.zybuluo.com/flyouting/note/6996) +### OkHttp + +1. [开源项目OkHttpPlus——支持GET、POST、UI线程回调、JSON格式解析、链式调用、文件上传下载](http://blog.csdn.net/zhaokaiqiang1992/article/details/50016815) +2. [Android OkHttp完全解析 是时候来了解OkHttp了](http://blog.csdn.net/lmj623565791/article/details/47911083) + +--- + ## P ### Parcelable @@ -238,15 +450,33 @@ ### Palette 1. [Extracting Colors to a Palette with Android Lollipop](https://www.bignerdranch.com/blog/extracting-colors-to-a-palette-with-android-lollipop/) -2. [Android Lollipop 新特性 - Palette](http://baoyz.com/android/2014/10/21/android-palette-use/) +2. [Android Lollipop 新特性 - Palette](https://github.com/troyliu0105/Android-Tips/blob/master/Utils/Content/Android_Lollipop_%E6%96%B0%E7%89%B9%E6%80%A7-Palette.md) + +### PopupWindow + +1. [http://wuxiaolong.me/2015/09/02/SharePopupWindow/](http://wuxiaolong.me/2015/09/02/SharePopupWindow/) ### Preference 1. [PreferenceActivity(首选项设置页)](http://blog.csdn.net/plussoft/article/details/9993759) 2. [Android的设置界面及Preference使用](http://blog.csdn.net/ichliebephone/article/details/5916320) +### Picasso + +1. [Picasso官方网站及javadoc](http://square.github.io/picasso/) +2. [Android图片下载缓存库picasso解析](http://blog.csdn.net/xu_fu/article/details/17043231) + +--- + ## R +### React Native + +1. [React Native for Android 入门老虎](http://www.race604.com/react-native-for-android-start/) +2. [React Native For Android初体验](http://www.jianshu.com/p/847a54e0c385) +3. [React Native for Android 实践 -- 实现知乎日报客户端](http://www.race604.com/react-native-android-practice/) +4. [React Native Android 踩坑之旅](http://www.alloyteam.com/2015/10/react-native-android-steps-on-tour/) + ### Reference 1. [Java的引用StrongReference、 SoftReference、 WeakReference 、PhantomReference](http://blog.csdn.net/mxbhxx/article/details/9111711) @@ -259,13 +489,37 @@ 3. [A Guide to Android RecyclerView and CardView](http://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156) 4. [Android-RecyclerView-Item点击事件设置](http://blog.csdn.net/guxiao1201/article/details/40423361) 5. [Why doesn't RecyclerView have onItemClickListener()? And how RecyclerView is different from Listview?](http://stackoverflow.com/questions/24885223/why-doesnt-recyclerview-have-onitemclicklistener-and-how-recyclerview-is-dif) +6. [Create RecyclerView with multiple view type](http://doublewong.com/2014/create-recyclerview-with-multiple-view-type/) +7. [Simple RecyclerView Divider](https://github.com/troyliu0105/Android-Tips/blob/master/Utils/Content/Simple_RecyclerView_Divider.md) + +### Retrofit + +1. [我对Retrofit的认识](http://blog.fangjie.info/2016/07/14/%E6%88%91%E5%AF%B9Retrofit%E7%9A%84%E8%AE%A4%E8%AF%86/) + + +### RxJava + +1. [RxJava: Reactive Extensions for the JVM](https://github.com/ReactiveX/RxJava) +2. [给 Android 开发者的 RxJava 详解](http://gank.io/post/560e15be2dca930e00da1083) +3. [NotRxJava懒人专用指南](http://www.devtf.cn/?p=323) +4. [小试RxJava](http://kescoode.com/try-rxjava/) + +### RxAndroid + +1. [IllegalStateException onError](https://github.com/ReactiveX/RxAndroid/issues/79) ### RandomAccessFile 1. [Java RandomAccessFile用法](http://blog.csdn.net/akon_vm/article/details/7429245) +--- + ## S +### SearchView + +1. [详细解读Android中的搜索框(三)—— SearchView](http://www.cnblogs.com/tianzhijiexian/p/4226675.html) + ### Serializable 1. [Android系统中Parcelable和Serializable的区别](http://greenrobot.me/devpost/android-parcelable-serializable/) @@ -276,37 +530,57 @@ 1. [Android Service完全解析,关于服务你所需知道的一切(上)](http://blog.csdn.net/guolin_blog/article/details/11952435) 2. [ExecutorService 的理解与使用](http://blog.csdn.net/bairrfhoinn/article/details/16848785) 3. [Android基本功:IntentService的使用](http://blog.csdn.net/p106786860/article/details/17885115) +4. [Android基础笔记(十一)- Service基础和注意事项以及Activity与Service的通信](http://blog.csdn.net/biezhihua/article/details/44281029) ### SharedPreference 1. [Android SharedPreferences使用以及原理详解](http://blog.csdn.net/wxyyxc1992/article/details/17222841) 2. [Google为何这样设计OnSharedPreferenceChangeListener](http://droidyue.com/blog/2014/11/29/why-onsharedpreferencechangelistener-was-not-called/) +3. [SharedPreferences在多进程中的使用及注意事项](http://zmywly8866.github.io/2015/09/09/sharedpreferences-in-multiprocess.html) +4. [What's the difference between commit() and apply() in Shared Preference](http://stackoverflow.com/questions/5960678/whats-the-difference-between-commit-and-apply-in-shared-preference) ### SparseArray 1. [Android应用性能优化之使用SparseArray替代HashMap](http://liuzhichao.com/p/832.html) 2. [Android SparseArray](http://lmbj.net/blog/android-sparsearray/) 3. [Android性能优化之使用SparseArray代替HashMap](http://stormzhang.com/android/2013/08/01/android-use-sparsearray-for-performance-optimization/) +4. [HashMap的实现与优化](http://www.jianshu.com/p/e54047b2b563) ### SQLite 1. [Android中SQLite应用详解](http://blog.csdn.net/liuhe688/article/details/6715983) 2. [ANDROID开发之SQLite详解](http://www.cnblogs.com/Excellent/archive/2011/11/19/2254888.html) 3. [使用嵌入式关系型SQLite数据库存储数据](http://justsee.iteye.com/blog/932591) +4. [Android将数据库保存到SD卡的实现](http://zmywly8866.github.io/2015/03/09/android-save-database-in-sdcard.html) ### Support Library -1. [Android Support兼容包详解](https://getpocket.com/a/read/881902653) +1. [Android Support兼容包详解](http://stormzhang.com/android/2015/03/29/android-support-library/) +2. [Android各个Support Library介绍](http://zmywly8866.github.io/2015/10/09/android-support-library.html) +3. [Android Support Library 23.1的变化](http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/1025/3622.html) ### SwipeRefreshLayout 1. [Android SwipeRefreshLayout](http://www.stormzhang.com/android/2014/03/29/android-swiperefreshlayout/) +2. [下拉刷新之 swipeRefreshLayout](http://blog.csdn.net/xinjianwuhen1991/article/details/49914343) + +--- ## T ### Textview 1. [Remove underline from links in TextView](http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android) +2. [What is the default text size on Android?](http://stackoverflow.com/questions/5611411/what-is-the-default-text-size-on-android) +3. [Which unit of measurement does the Paint.setTextSize(float) use?](http://stackoverflow.com/questions/11720093/which-unit-of-measurement-does-the-paint-settextsizefloat-use) +4. [How to set unit for Paint.setTextSize()](http://stackoverflow.com/questions/3061930/how-to-set-unit-for-paint-settextsize) +5. [Android Center text on canvas](http://stackoverflow.com/questions/11120392/android-center-text-on-canvas) + +### TouchEvent + +1. [两分钟彻底让你明白Android中onInterceptTouchEvent与onTouchEvent(图文)!](http://blog.csdn.net/android_tutor/article/details/7193090) +2. [MotionEvent事件在onInterceptTouchEvent()、onTouchEvent()中的传递顺序](http://www.cnblogs.com/rocky_yi/archive/2011/01/21/1941522.html#) +3. [Android Deeper(00) - Touch事件分发响应机制](http://hukai.me/android-deeper-touch-event-dispatch-process/) ### Thread @@ -320,12 +594,35 @@ 8. [Java(Android)中线程池的使用](http://landerlyoung.github.io/blog/2014/09/23/javazhong-xian-cheng-chi-de-shi-yong/) 9. [Java(Android)线程池](http://www.trinea.cn/android/java-android-thread-pool/) +--- + +## U + +### Unit Test + +1. [Android单元测试](http://www.cnblogs.com/tianzhijiexian/p/4296055.html) +2. [Don’t Test Blindly: The Right Methods for Unit Testing Your Java Apps](http://zeroturnaround.com/rebellabs/dont-test-blindly-the-right-methods-for-unit-testing-your-java-apps/) +3. [在Android Studio中进行单元测试和UI测试](http://www.jianshu.com/p/03118c11c199) + +### URL Routing - 路由协议 + +1. [Android路由框架设计与实现](http://www.sixwolf.net/blog/2016/03/23/Android%E8%B7%AF%E7%94%B1%E6%A1%86%E6%9E%B6%E8%AE%BE%E8%AE%A1/) +2. [UrlRouter路由框架的设计](http://zhengxiaoyong.me/2016/04/24/UrlRouter%E8%B7%AF%E7%94%B1%E6%A1%86%E6%9E%B6%E7%9A%84%E8%AE%BE%E8%AE%A1/) +3. [需要给activity跳转增加路由么?](https://github.com/android-cn/android-discuss/issues/383) +4. [通过 URL 打开 Activity](http://caodongping.me/2016/04/11/%E9%80%9A%E8%BF%87URL%E6%89%93%E5%BC%80Activity/#more) + +--- + ## V ### ViewPager -1. [ViewPager + Fragment实现滑动标签页](http://blog.csdn.net/lizhenmingdirk/article/details/13631813) -2. [【移动开发】Android中Fragment+ViewPager的配合使用](http://smallwoniu.blog.51cto.com/3911954/1322746) +1. [Android ViewPager使用详解](http://blog.csdn.net/wangjinyu501/article/details/8169924) +2. [ViewPager + Fragment实现滑动标签页](http://blog.csdn.net/lizhenmingdirk/article/details/13631813) +3. [【移动开发】Android中Fragment+ViewPager的配合使用](http://smallwoniu.blog.51cto.com/3911954/1322746) +4. [Android 手把手教您自定义ViewGroup(一)本文出自:【张鸿洋的博客】](http://blog.csdn.net/lmj623565791/article/details/38339817) +5. [Android的坑之ScrollView嵌套ViewPager](http://hellsam.com/2015/01/29/Android%E7%9A%84%E5%9D%91%E4%B9%8BScrollView%E5%B5%8C%E5%A5%97ViewPager/) +6. [IllegalStateException: The application's PagerAdapter changed the adapter's content without calling PagerAdapter#notifyDataSetChanged](http://stackoverflow.com/questions/22943658/illegalstateexception-the-applications-pageradapter-changed-the-adapters-cont) ### View @@ -333,6 +630,7 @@ 2. [Android中View绘制流程以及invalidate()等相关方法分析](http://blog.csdn.net/qinjuning/article/details/7110211) 3. [Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)](http://blog.csdn.net/qinjuning/article/details/8051811) 4. [Android开发:LayoutParams的用法](http://www.cnblogs.com/shaweng/archive/2012/07/10/2585134.html) +5. [Saving Android View state correctly](http://trickyandroid.com/saving-android-view-state-correctly/) ### ViewFlipper @@ -343,51 +641,36 @@ 1. [Android--使用VideoView播放视频](http://www.cnblogs.com/plokmju/p/android_videoview.html) 2. [Playing a video in VideoView in Android](http://stackoverflow.com/questions/3263736/playing-a-video-in-videoview-in-android) +3. [Position Video Inside a VideoView](http://stackoverflow.com/questions/4619563/position-video-inside-a-videoview/4855315#4855315) ### Volley -1. [Android Volley完全解析(一),初识Volley的基本用法](http://blog.csdn.net/guolin_blog/article/details/17482095) -2. [Android库Volley的使用介绍](https://bxbxbai.github.io/2014/09/14/android-working-with-volley/) +1. [Android Volley](https://github.com/mcxiaoke/android-volley) +2. [Android Volley完全解析(一),初识Volley的基本用法](http://blog.csdn.net/guolin_blog/article/details/17482095) +3. [Android库Volley的使用介绍](https://bxbxbai.github.io/2014/09/14/android-working-with-volley/) +4. [网络请求库Volley详解](http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0526/2934.html) +5. [Volley 源码解析](http://www.codekk.com/blogs/detail/54cfab086c4761e5001b2542) +6. [使用okHttp、Volley、Gson快速组装HttpClinet](http://oakzmm.com/2015/07/22/okHttp-Volley-Gson/) + +--- ## W ### WebView -1. [Java 与 JavaScript 如何进行交互](http://itangqi.me/2015/03/07/java-and-javascript-interaction-in-android/) -2. [android与javascript交互调用](http://blog.csdn.net/chenzheng_java/article/details/6260872) -3. [Android与js交互实例](http://blog.csdn.net/ithomer/article/details/8737999) -4. [Android中Java和JavaScript交互](http://droidyue.com/blog/2014/09/20/interaction-between-java-and-javascript-in-android/) -5. [顶部带进度条的Webview](http://droidyue.com/blog/2014/07/12/ding-bu-dai-jin-du-tiao-de-webview/) -6. [Android WebView播放视频问题](http://www.stormzhang.com/android/2014/03/23/android-webview-play-video/) -7. [理解WebKit和Chromium: Android 4.4 上的Chromium WebView](http://blog.csdn.net/milado_nju/article/details/17098399) -8. [在WebView中如何让JS与Java安全地互相调用](http://www.pedant.cn/2014/07/04/webview-js-java-interface-research/) -9. [Android WebView的Js对象注入漏洞解决方案](http://blog.csdn.net/leehong2005/article/details/11808557) - -## 其他 - -### 自定义控件 - -1. [Android 自定义View及其在布局文件中的使用示例](http://www.cnblogs.com/crashmaker/p/3521310.html) -2. [自定义控件进阶:declare-styleable重用attr](http://droidyue.com/blog/2014/07/16/better-in-android-include-attrs-in-declare-stylable/) -3. [android 自定义控件 使用declare-styleable进行配置属性(源码角度)](http://blog.csdn.net/vipzjyno1/article/details/23696537) -4. [Android使用AttributeSet自定义控件的方法](http://www.cnblogs.com/zwl12549/archive/2011/04/13/2015366.html) -5. [从源码中浅析Android中如何利用attrs和styles定义控件](http://michaelye1988.iteye.com/blog/1773997) -6. [Android SDK: Creating Custom Views](http://code.tutsplus.com/tutorials/android-sdk-creating-custom-views--mobile-14548) -7. [Creating custom and compound Views in Android - Tutorial](http://www.vogella.com/tutorials/AndroidCustomViews/article.html) -8. [Tutorial: Enhancing Android UI with Custom Views](https://newcircle.com/s/post/1663/tutorial_enhancing_android_ui_with_custom_views_dave_smith_video) -9. [Android 自定义View (一)](http://blog.csdn.net/lmj623565791/article/details/24252901) +1. [Java 与 JavaScript 如何进行交互](http://imtangqi.com/2015/03/07/java-and-javascript-interaction/) +2. [Android与js交互实例](http://blog.csdn.net/ithomer/article/details/8737999) +3. [Android中Java和JavaScript交互](http://droidyue.com/blog/2014/09/20/interaction-between-java-and-javascript-in-android/) +4. [顶部带进度条的Webview](http://droidyue.com/blog/2014/07/12/ding-bu-dai-jin-du-tiao-de-webview/) +5. [Android WebView播放视频问题](http://www.stormzhang.com/android/2014/03/23/android-webview-play-video/) +6. [理解WebKit和Chromium: Android 4.4 上的Chromium WebView](http://blog.csdn.net/milado_nju/article/details/17098399) +7. [在WebView中如何让JS与Java安全地互相调用](http://www.pedant.cn/2014/07/04/webview-js-java-interface-research/) +8. [Android WebView的Js对象注入漏洞解决方案](http://blog.csdn.net/leehong2005/article/details/11808557) +9. [Android WebView播放视频问题](http://www.jianshu.com/p/d6d379e3f41d) --- -### Android Studio - -1. [Android Studio导入项目](http://ask.android-studio.org/?/article/21) -2. [Android Studio 简单设置](http://blog.gaoqixhb.com/p/54b9c293bf1ac9364284af78) -3. [Android Studio 简介及导入 jar 包和第三方开源库方法](http://drakeet.me/android-studio) -4. [Android Studio使用技巧系列教程(一)](http://blog.csdn.net/growth58/article/details/46729803) -5. [Android Studio中如何使用Git和Github来管理项目](http://blog.csdn.net/wei18359100306/article/details/45645145) - ---- +## Others ### Code Style @@ -403,38 +686,118 @@ 2. [GitHub秘籍](http://snowdream86.gitbooks.io/github-cheat-sheet/content/zh/index.html) 3. [git - 简易指南](http://www.bootcss.com/p/git-guide/) 4. [基于Github参与开源项目指南](http://yeungeek.com/2015/07/01/%E5%9F%BA%E4%BA%8EGithub%E5%8F%82%E4%B8%8E%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%E6%8C%87%E5%8D%97/) +5. [使用git和github进行协同开发流程](http://livoras.com/post/28) +6. [如何高效利用GitHub](http://www.yangzhiping.com/tech/github.html#q1) +7. [廖雪峰的GIT入门教程](http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000) +8. [GitHub&Git入门基础](http://www.nowcoder.com/courses/2) +9. [git-flow 备忘清单](http://danielkummer.github.io/git-flow-cheatsheet/index.zh_CN.html) --- -### Hexo +### JCenter -1. [如何搭建一个独立博客——简明Github Pages与Hexo教程](http://www.jianshu.com/p/05289a4bc8b2) -2. [Mac下程序员博客之 Hexo + GitHub Pages + GitCafe Pages + DNSPod](http://godera.org/2015/03/16/Mac%E4%B8%8B%E7%A8%8B%E5%BA%8F%E5%91%98%E5%8D%9A%E5%AE%A2%E4%B9%8BHexo-GitHub-Pages-GitCafe-Pages-DNSPod/) -3. [动动手指,NexT主题与Hexo更搭哦(基础篇)](http://www.arao.me/2015/hexo-next-theme-optimize-base/) -4. [hexo博客搭建时遇到的一些问题](http://chitanda.me/2015/06/11/tips-for-setup-hexo/) +1. [Android Studio发布项目到Jcenter](http://blog.saymagic.cn/2015/02/16/release-library-to-jcenter.html) +2. [将Library上传到Jcenter](http://www.jianshu.com/p/0ba8960f80a9) +3. [使用Gradle发布aar项目到JCenter仓库](http://www.cnblogs.com/qianxudetianxia/p/4322331.html) ---- +### JitPack + +1. [优雅的发布Android开源库(论JitPack的优越性)](https://github.com/GcsSloop/AndroidNote/blob/master/Course/ReleaseLibraryByJitPack.md) -### Smali +### 反编译 -1. [Smali--Dalvik虚拟机指令语言-->【android_smali语法学习一】 -](http://blog.csdn.net/wdaming1986/article/details/8299996) +1. [android_smali语法学习](http://blog.csdn.net/wdaming1986/article/details/8299996) 2. [apk的包名修改](http://www.cnblogs.com/tianxiaozz/archive/2012/12/26/change_apk_package_name.html) 3. [为Sublime Text安装smali代码语法高亮插件](http://liuzhichao.com/p/1476.html) +4. [Android APK反编译详解(附图)](http://blog.csdn.net/ithomer/article/details/6727581) +5. [Android开发学习总结(六)—— APK反编译](http://www.cnblogs.com/xdp-gacl/p/4677145.html) +6. [我是如何使用Android反编译软件的?](http://www.jianshu.com/p/8c24136e0c1f) +7. [Android程序的反编译对抗研究](http://www.freebuf.com/tools/76884.html) + +--- + +### 设计模式 + +1. [Java开发中的23种设计模式详解](http://zz563143188.iteye.com/blog/1847029) +2. [MVC,MVP 和 MVVM 的图示](http://www.ruanyifeng.com/blog/2015/02/mvcmvp_mvvm.html) +3. [如果让我重新设计一款Android App](http://blog.csdn.net/ahence/article/details/47154419) +4. [一个人如何开发一款 App?](https://www.zhihu.com/question/29020285/answer/66095377?utm_campaign=webshare&utm_source=weibo&utm_medium=zhihu&_t=1445344015624) +5. [Android应用架构 (Android Dev Summit 2015)](http://blog.zhaiyifan.cn/2016/01/29/android-app-architecture-2015/?from=timeline&isappinstalled=0) +6. [Android源码设计模式分析项目](https://github.com/simple-android-framework-exchange/android_design_patterns_analysis) + +--- + +### 夜间模式 + +1. [Android Night Mode 夜间模式实现](http://echo.vars.me/android/android-night-mode/) +2. [Android夜间模式实现](http://blog.kymjs.com/code/2015/05/26/01/) +3. [Android 中 知乎日报和知乎设置夜间模式是怎么样做到不重启Activity的?](https://www.zhihu.com/question/31145990) --- -1. [THE DEX 64K LIMIT IS NOT A PROBLEM ANYMORE, ALMOST](http://www.mutualmobile.com/posts/dex-64k-limit-not-problem-anymore-almost) -2. [Android 4.4从图库选择图片,获取图片路径并裁剪](http://blog.csdn.net/tempersitu/article/details/20557383) -3. [浅析android应用增量升级](http://blog.csdn.net/hmg25/article/details/8100896) -4. [Android四大基本组件介绍与生命周期](http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html) -5. [Android代码优化——使用Android lint工具](http://blog.csdn.net/xyz_lmn/article/details/14222939) -6. [Android 插件化 动态升级](http://www.trinea.cn/android/android-plugin/) -7. [两分钟彻底让你明白Android中onInterceptTouchEvent与onTouchEvent(图文)!](http://blog.csdn.net/android_tutor/article/details/7193090) -8. [MotionEvent事件在onInterceptTouchEvent()、onTouchEvent()中的传递顺序](http://www.cnblogs.com/rocky_yi/archive/2011/01/21/1941522.html#) -9. [Java String StringBuilder StringBuffer](http://www.stormzhang.com/java/2014/08/08/java-string-stringbuilder-stringbuffer/) -10. [tools:context=".MainActivity的作用](http://blog.csdn.net/caiwenfeng_for_23/article/details/8373569) -11. [MVC,MVP 和 MVVM 的图示](http://www.ruanyifeng.com/blog/2015/02/mvcmvp_mvvm.html) -12. [关于APK瘦身值得分享的一些经验](http://www.jianshu.com/p/bd90dee57ad0) -13. [Java开发中的23种设计模式详解](http://zz563143188.iteye.com/blog/1847029) -14. [性能优化之数据库优化](http://www.trinea.cn/android/database-performance/) \ No newline at end of file +### 自定义控件 + +1. [Android 自定义View及其在布局文件中的使用示例](http://www.cnblogs.com/crashmaker/p/3521310.html) +2. [自定义控件进阶:declare-styleable重用attr](https://github.com/troyliu0105/Android-Tips/blob/master/Utils/Content/declare-styleable_reuse_attr.md) +3. [android 自定义控件 使用declare-styleable进行配置属性(源码角度)](http://blog.csdn.net/vipzjyno1/article/details/23696537) +4. [Android使用AttributeSet自定义控件的方法](http://www.cnblogs.com/zwl12549/archive/2011/04/13/2015366.html) +5. [从源码中浅析Android中如何利用attrs和styles定义控件](http://michaelye1988.iteye.com/blog/1773997) +6. [Android SDK: Creating Custom Views](http://code.tutsplus.com/tutorials/android-sdk-creating-custom-views--mobile-14548) +7. [Creating custom and compound Views in Android - Tutorial](http://www.vogella.com/tutorials/AndroidCustomViews/article.html) +8. [Tutorial: Enhancing Android UI with Custom Views](https://newcircle.com/s/post/1663/tutorial_enhancing_android_ui_with_custom_views_dave_smith_video) +9. [Android 自定义View (一)](http://blog.csdn.net/lmj623565791/article/details/24252901) +10. [What does postInvalidate() do?](http://stackoverflow.com/questions/5521596/what-does-postinvalidate-do) +11. [When it's necessary to execute invalidate() on a View?](http://stackoverflow.com/questions/10647558/when-its-necessary-to-execute-invalidate-on-a-view) +12. [Android笔记:invalidate()和postInvalidate() 的区别及使用](http://blog.csdn.net/mars2639/article/details/6650876) + +--- + +### No category + +1. [THE DEX 64K LIMIT IS NOT A PROBLEM ANYMORE, ALMOST](http://www.mutualmobile.com/posts/dex-64k-limit-not-problem-anymore-almost) +2. [Android 4.4从图库选择图片,获取图片路径并裁剪](http://blog.csdn.net/tempersitu/article/details/20557383) +3. [浅析android应用增量升级](http://blog.csdn.net/hmg25/article/details/8100896) +4. [Android四大基本组件介绍与生命周期](http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html) +5. [Android代码优化——使用Android lint工具](http://blog.csdn.net/xyz_lmn/article/details/14222939) +6. [Android 插件化 动态升级](http://www.trinea.cn/android/android-plugin/) +7. [Java String StringBuilder StringBuffer](http://www.stormzhang.com/java/2014/08/08/java-string-stringbuilder-stringbuffer/) +8. [tools:context=".MainActivity的作用](http://blog.csdn.net/caiwenfeng_for_23/article/details/8373569) +9. [关于APK瘦身值得分享的一些经验](http://www.jianshu.com/p/bd90dee57ad0) +10. [性能优化之数据库优化](http://www.trinea.cn/android/database-performance/) +11. [How to check visibility of software keyboard in Android?](http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android) +12. [android 4.4.4侧滑退出显示app启动界面](https://github.com/ikew0ng/SwipeBackLayout/issues/45) ​ +13. [How to get a Color from hexadecimal Color String](http://stackoverflow.com/questions/5248583/how-to-get-a-color-from-hexadecimal-color-string) +14. [【译】Android应用架构](http://www.jianshu.com/p/8ca27934c6e6) +15. [Android静默安装实现方案,仿360手机助手秒装和智能安装功能](http://blog.csdn.net/guolin_blog/article/details/47803149) +16. [How to convert a color integer to a hex String in Android?](http://stackoverflow.com/questions/6539879/how-to-convert-a-color-integer-to-a-hex-string-in-android) +17. [IllegalArgumentException: width and height must be > 0 while loading Bitmap from View](http://stackoverflow.com/questions/17605662/illegalargumentexception-width-and-height-must-be-0-while-loading-bitmap-from) +18. [Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication ?](http://stackoverflow.com/questions/33967703/unable-to-instantiate-application-com-android-tools-fd-runtime-bootstrapapplicat) +19. [Unknown URL content://downloads/my_downloads](http://blog.csdn.net/mackkill/article/details/52003858) +20. [Android开发之实现多次点击事件](http://blog.csdn.net/fengshizty/article/details/41675923) +21. [Android完美解决输入框EditText隐藏密码打勾显示密码问题](http://blog.csdn.net/a2bgeek/article/details/9705305) +22. [Android获取手机型号,系统版本,App版本号等信息](http://blog.csdn.net/lfdfhl/article/details/9070183) +23. [你需要知道的Android拍照适配方案](http://www.jianshu.com/p/f269bcda335f) +24. [Can't create handler inside thread that has not called Looper.prepare()](http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare) + +--- + +## Contributors + +- [troyliu0105](https://github.com/troyliu0105) +- [whiskeyfei](https://github.com/whiskeyfei) +- [pingfanganwei](https://github.com/pingfanganwei) +- [whilu](https://github.com/whilu) +- [yy1300326388](https://github.com/yy1300326388) +- [ichenkaihua](https://github.com/ichenkaihua) +- [wavever](https://github.com/wavever) +- [windog](https://github.com/windog) +- [Henryzhugithub](https://github.com/Henryzhugithub) +- [Dimon94](https://github.com/Dimon94) +- [nitta-honoka](https://github.com/nitta-honoka) + +--- + +## Contact Me + +If you have any questions or want to make friends with me, please feel free to contact me : [imtangqi#gmail.com](mailto:imtangqi@gmail.com "Welcome to contact me") + diff --git "a/Utils/Content/Android_Lollipop_\346\226\260\347\211\271\346\200\247-Palette.md" "b/Utils/Content/Android_Lollipop_\346\226\260\347\211\271\346\200\247-Palette.md" new file mode 100644 index 0000000..8809b6e --- /dev/null +++ "b/Utils/Content/Android_Lollipop_\346\226\260\347\211\271\346\200\247-Palette.md" @@ -0,0 +1,91 @@ +[原文链接](http://baoyz.com/android/2014/10/21/android-palette-use/) (*需要科学上网*) + +## Android Lollipop 新特性 - Palette + +> *Palette 可以从一张图片中提取颜色,我们可以把提取的颜色融入到App UI中,可以使UI风格更加美观融洽。比如,我们可以从图片中提取颜色设置给ActionBar做背景颜色,这样ActionBar的颜色就会随着显示图片的变化而变化。* + +Palette可以提取的颜色如下: ++ Vibrant (有活力的) ++ Vibrant dark(有活力的 暗色) ++ Vibrant light(有活力的 亮色) ++ Muted (柔和的) ++ Muted dark(柔和的 暗色) ++ Muted light(柔和的 亮色) + +### 使用方法 + +> *我们要想使用Palette,需要导入Palette的兼容库,`Gradle` 中添加下面依赖。* + +``` +compile 'com.android.support:palette-v7:21.0.0' +``` + +第一步,我们需要通过一个Bitmap对象来生成一个对应的Palette对象。 +Palette 提供了四个静态方法用来生成对象。 + ++ `Palette generate(Bitmap bitmap)` ++ `Palette generate(Bitmap bitmap, int numColors)` ++ `generateAsync(Bitmap bitmap, PaletteAsyncListener listener)` ++ `generateAsync(Bitmap bitmap, int numColors, final PaletteAsyncListener listener)` + +> *不难看出,生成方法分为`generate`(同步)和`generateAsync`(异步)两种,如果图片过大使用generate方法,可能会阻塞主线程,我们更倾向于使用`generateAsync`的方法,其实内部就是创建了一个`AsyncTask`。`generateAsync`方法需要一个`PaletteAsyncListener`对象用于监听生成完毕的回调。除了必须的`Bitmap`参数外,还可以传入一个`numColors`参数指定颜色数,默认是 16。* + +第二步,得到Palette对象后,就可以拿到提取到的颜色值 + ++ `Palette.getVibrantSwatch()` ++ `Palette.getDarkVibrantSwatch()` ++ `Palette.getLightVibrantSwatch()` ++ `Palette.getMutedSwatch()` ++ `Palette.getDarkMutedSwatch()` ++ `Palette.getLightMutedSwatch()` + +第三步,使用颜色,上面get方法中返回的是一个 `Swatch` 样本对象,这个样本对象是Palette的一个内部类,它提供了一些获取最终颜色的方法。 + ++ `getPopulation()`: 样本中的像素数量 ++ `getRgb()`: 颜色的RBG值 ++ `getHsl()`: 颜色的HSL值 ++ `getBodyTextColor()`: 主体文字的颜色值 ++ `getTitleTextColor()`: 标题文字的颜色值 + +> *通过 `getRgb()` 可以得到最终的颜色值并应用到UI中。`getBodyTextColor()` 和 `getTitleTextColor()` 可以得到此颜色下文字适合的颜色,这样很方便我们设置文字的颜色,使文字看起来更加舒服。* + +### 实例代码 + +```java +// 此方法可能会阻塞主线程,建议使用异步方法 +Palette palette = Palette.generate(bitmap); +// 异步提取Bitmap颜色 +Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { + @Override + public void onGenerated(Palette palette) { + // 提取完毕 + // 有活力的颜色 + Palette.Swatch vibrant = palette.getVibrantSwatch(); + // 有活力的暗色 + Palette.Swatch darkVibrant = palette.getDarkVibrantSwatch(); + // 有活力的亮色 + Palette.Swatch lightVibrant = palette.getLightVibrantSwatch(); + // 柔和的颜色 + Palette.Swatch muted = palette.getMutedSwatch(); + // 柔和的暗色 + Palette.Swatch darkMuted = palette.getDarkMutedSwatch(); + // 柔和的亮色 + Palette.Swatch lightMuted = palette.getLightMutedSwatch(); +  + // 使用颜色 + // 修改Actionbar背景颜色 + getActionBar().setBackgroundDrawable(new ColorDrawable(vibrant.getRgb())); + // 修改文字的颜色 + mTextView.setTextColor(vibrant.getTitleTextColor()); + ... + // 根据需求选择不同效果的颜色应用 + }); +``` + +### 效果 + +![pic](https://raw.githubusercontent.com/baoboy/baoboy.github.io/master/images/screenshots/palette_3.png) + +### 代码下载 + +[https://github.com/baoyongzhang/android-lollipop-samples](https://github.com/baoyongzhang/android-lollipop-samples)中的[palette-sample](https://github.com/baoyongzhang/android-lollipop-samples/tree/master/palette-sample) diff --git a/Utils/Content/Handing_Runtime_Changes.md b/Utils/Content/Handing_Runtime_Changes.md new file mode 100644 index 0000000..9677977 --- /dev/null +++ b/Utils/Content/Handing_Runtime_Changes.md @@ -0,0 +1,143 @@ +# Handling Runtime Changes + +Some device configurations can change during runtime (such as screen orientation, keyboard availability, and language). When such a change occurs, Android restarts the running `Activity` (`onDestroy()` is called, followed by `onCreate()`). The restart behavior is designed to help your application adapt to new configurations by automatically reloading your application with alternative resources that match the new device configuration. + +To properly handle a restart, it is important that your activity restores its previous state through the normal `Activity` lifecycle, in which Android calls `onSaveInstanceState()` before it destroys your activity so that you can save data about the application state. You can then restore the state during `onCreate()` or `onRestoreInstanceState()`. + +To test that your application restarts itself with the application state intact, you should invoke configuration changes (such as changing the screen orientation) while performing various tasks in your application. Your application should be able to restart at any time without loss of user data or state in order to handle events such as configuration changes or when the user receives an incoming phone call and then returns to your application much later after your application process may have been destroyed. To learn how you can restore your activity state, read about the `Activity lifecycle`. + +However, you might encounter a situation in which restarting your application and restoring significant amounts of data can be costly and create a poor user experience. In such a situation, you have two other options: + +1. Retain an object during a configuration change + + Allow your activity to restart when a configuration changes, but carry a stateful object to the new instance of your activity. +2. Handle the configuration change yourself + Prevent the system from restarting your activity during certain configuration changes, but receive a callback when the configurations do change, so that you can manually update your activity as necessary. + + +### Retaining an Object During a Configuration Change + +If restarting your activity requires that you recover large sets of data, re-establish a network connection, or perform other intensive operations, then a full restart due to a configuration change might be a slow user experience. Also, it might not be possible for you to completely restore your activity state with the `Bundle` that the system saves for you with the `onSaveInstanceState()` callback—it is not designed to carry large objects (such as bitmaps) and the data within it must be serialized then deserialized, which can consume a lot of memory and make the configuration change slow. In such a situation, you can alleviate the burden of reinitializing your activity by retaining a `Fragment` when your activity is restarted due to a configuration change. This fragment can contain references to stateful objects that you want to retain. + +When the Android system shuts down your activity due to a configuration change, the fragments of your activity that you have marked to retain are not destroyed. You can add such fragments to your activity to preserve stateful objects. + +To retain stateful objects in a fragment during a runtime configuration change: + +1. Extend the Fragment class and declare references to your stateful objects. +2. Call setRetainInstance(boolean) when the fragment is created. +3. Add the fragment to your activity. +4. Use FragmentManager to retrieve the fragment when the activity is restarted. + +For example, define your fragment as follows: + +```java +public class RetainedFragment extends Fragment { + + // data object we want to retain + private MyDataObject data; + + // this method is only called once for this fragment + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // retain this fragment + setRetainInstance(true); + } + + public void setData(MyDataObject data) { + this.data = data; + } + + public MyDataObject getData() { + return data; + } +} +``` +> **Caution**: While you can store any object, you should never pass an object that is tied to the `Activity`, such as a `Drawable`, an `Adapter`, a `View` or any other object that's associated with a `Context`. If you do, it will leak all the views and resources of the original activity instance. (Leaking resources means that your application maintains a hold on them and they cannot be garbage-collected, so lots of memory can be lost.) + +Then use `FragmentManager` to add the fragment to the activity. You can obtain the data object from the fragment when the activity starts again during runtime configuration changes. For example, define your activity as follows: + +```java +public class MyActivity extends Activity { + + private RetainedFragment dataFragment; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + // find the retained fragment on activity restarts + FragmentManager fm = getFragmentManager(); + dataFragment = (DataFragment) fm.findFragmentByTag(“data”); + + // create the fragment and data the first time + if (dataFragment == null) { + // add the fragment + dataFragment = new DataFragment(); + fm.beginTransaction().add(dataFragment, “data”).commit(); + // load the data from the web + dataFragment.setData(loadMyData()); + } + + // the data is available in dataFragment.getData() + ... + } + + @Override + public void onDestroy() { + super.onDestroy(); + // store the data in the fragment + dataFragment.setData(collectMyLoadedData()); + } +} +``` + +In this example, `onCreate()` adds a fragment or restores a reference to it. `onCreate()` also stores the stateful object inside the fragment instance. `onDestroy()` updates the stateful object inside the retained fragment instance. + +### Handling the Configuration Change Yourself +If your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity. + +> **Note**: Handling the configuration change yourself can make it much more difficult to use alternative resources, because the system does not automatically apply them for you. This technique should be considered a last resort when you must avoid restarts due to a configuration change and is not recommended for most applications. + +To declare that your activity handles a configuration change, edit the appropriate `` element in your manifest file to include the `android:configChanges` attribute with a value that represents the configuration you want to handle. Possible values are listed in the documentation for the `android:configChanges` attribute (the most commonly used values are `"orientation"` to prevent restarts when the screen orientation changes and `"keyboardHidden"` to prevent restarts when the keyboard availability changes). You can declare multiple configuration values in the attribute by separating them with a pipe `|` character. + +For example, the following manifest code declares an activity that handles both the screen orientation change and keyboard availability change: + +``` + +``` + +Now, when one of these configurations change, `MyActivity` does not restart. Instead, the MyActivity receives a call to `onConfigurationChanged()`. This method is passed a `Configuration` object that specifies the new device configuration. By reading fields in the Configuration, you can determine the new configuration and make appropriate changes by updating the resources used in your interface. At the time this method is called, your activity's `Resources` object is updated to return resources based on the new configuration, so you can easily reset elements of your UI without the system restarting your activity. + +> **Caution**: Beginning with Android 3.2 (API level 13), **the "screen size" also changes** when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the `minSdkVersion` and `targetSdkVersion` attributes), you must include the `"screenSize"` value in addition to the `"orientation"` value. That is, you must decalare `android:configChanges="orientation|screenSize"`. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device). + +For example, the following `onConfigurationChanged()` implementation checks the current device orientation: + +```java +@Override +public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + // Checks the orientation of the screen + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); + } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ + Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); + } +} +``` + +The `Configuration` object represents all of the current configurations, not just the ones that have changed. Most of the time, you won't care exactly how the configuration has changed and can simply re-assign all your resources that provide alternatives to the configuration that you're handling. For example, because the `Resources` object is now updated, you can reset any `ImageViews` with `setImageResource()` and the appropriate resource for the new configuration is used (as described in `Providing Resources`). + +Notice that the values from the `Configuration` fields are integers that are matched to specific constants from the `Configuration` class. For documentation about which constants to use with each field, refer to the appropriate field in the `Configuration` reference. + +> **Remember**: When you declare your activity to handle a configuration change, you are responsible for resetting any elements for which you provide alternatives. If you declare your activity to handle the orientation change and have images that should change between landscape and portrait, you must re-assign each resource to each element during `onConfigurationChanged()`. + +If you don't need to update your application based on these configuration changes, you can instead not implement `onConfigurationChanged()`. In which case, all of the resources used before the configuration change are still used and you've only avoided the restart of your activity. However, your application should always be able to shutdown and restart with its previous state intact, so you should not consider this technique an escape from retaining your state during normal activity lifecycle. Not only because there are other configuration changes that you cannot prevent from restarting your application, but also because you should handle events such as when the user leaves your application and it gets destroyed before the user returns to it. + +For more about which configuration changes you can handle in your activity, see the [`android:configChanges`](http://developer.android.com/guide/topics/manifest/activity-element.html#config) documentation and the [`Configuration`](http://developer.android.com/reference/android/content/res/Configuration.html) class. [注1] + +[注1]: 需要科学上网 diff --git a/Utils/Content/Simple_RecyclerView_Divider.md b/Utils/Content/Simple_RecyclerView_Divider.md new file mode 100644 index 0000000..8e459b8 --- /dev/null +++ b/Utils/Content/Simple_RecyclerView_Divider.md @@ -0,0 +1,72 @@ +[原文链接](https://gist.github.com/polbins/e37206fbc444207c0e92) by [polbins](https://gist.github.com/polbins) + +--- +### Simple RecyclerView Divider +Simple Horizontal Divider Item Decoration for RecyclerView + +```java +mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration( + getApplicationContext() + )); +``` + +**NOTE**: Add item decoration prior to setting the adapter + +--- +#### line_divider: + +```java + + + + + + + + + + + +``` + +--- + +#### SimpleDividerItemDecoration.java + +```java +public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration { + private Drawable mDivider; + + + public SimpleDividerItemDecoration(Context context) { + mDivider = context.getResources().getDrawable(R.drawable.line_divider); + } + + + @Override + public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { + int left = parent.getPaddingLeft(); + int right = parent.getWidth() - parent.getPaddingRight(); + + + int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = parent.getChildAt(i); + + + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); + + + int top = child.getBottom() + params.bottomMargin; + int bottom = top + mDivider.getIntrinsicHeight(); + + + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } +} +``` diff --git a/Utils/Content/declare-styleable_reuse_attr.md b/Utils/Content/declare-styleable_reuse_attr.md new file mode 100644 index 0000000..065adaa --- /dev/null +++ b/Utils/Content/declare-styleable_reuse_attr.md @@ -0,0 +1,84 @@ +[原文链接](http://droidyue.com/blog/2014/07/16/better-in-android-include-attrs-in-declare-stylable/)(*需要科学上网*) + +## 自定义控件进阶:declare-styleable重用attr + +最近接触了Android自定义控件,涉及到自定义xml中得属性(attribute),其实也很简单,但是写着写着,发现代码不完美了,就是在attrs.xml这个文件中,发现属性冗余,于是就想有没有类似属性继承或者include之类的方法.本文将就declare-stylable中属性重用记录一下. + +--- + +### 不完美的代码 + +```xml + + + + + + + + + + + + + +``` + +如上面代码,在ExTextView和ExEditText这个stylable中有着重复的属性申明.虽然上面可以工作,但是总感觉写的不专业,于是寻找优化方法. + +--- + +### 还可以这样么 + +尝试着为declare-stylable指定一个parent,如下代码 + +```xml + + + + + + + + + + + + +``` + +attrs.xml没有报告语法错误.但是当我使用R.styleable.ExEditText_supportDeviceType时候,R文件却没有生成,重新清理了工程还是不生效,不知道是否为adt插件的问题.其他人也遇到了这样的问题. 这个方法目前是不行的. + +--- + +### 终极答案 + +实际上我们可以在declare-stylable之前,申明要多次使用的属性,在declare-stylable节点内部,只需调用即可.具体代码如下. + +```xml + + + + + + + + + + + + + + + +``` + +每次引用attr后,建议清理一下工程,确保R文件重新生成. + +#### 延伸阅读 + ++ [http://stackoverflow.com/questions/18827875/how-to-declare-several-stylable-attributes-with-the-same-name-for-different-tags](http://stackoverflow.com/questions/18827875/how-to-declare-several-stylable-attributes-with-the-same-name-for-different-tags) + +#### 其他 + ++ [Android系统源代码情景分析](http://www.amazon.cn/gp/product/B009OLU8EE/ref=as_li_tf_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B009OLU8EE&linkCode=as2&tag=droidyue-23) diff --git a/Utils/URLChecker/BadUrlsSaver.java b/Utils/URLChecker/BadUrlsSaver.java new file mode 100644 index 0000000..382b404 --- /dev/null +++ b/Utils/URLChecker/BadUrlsSaver.java @@ -0,0 +1,38 @@ +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Map; + +/** + * Created by Troy Liu on 2015,九月,17, 23:21. + */ +public class BadUrlsSaver { + + /** + * 保存有问题的网址到repo目录下 + * + * @param map + * @param isSaveAlLMatterUrls + * @throws IOException + */ + public static void save(Map map, boolean isSaveAlLMatterUrls) throws IOException { + File file = new File("..\\badUrls.txt"); + if (file.exists()) { + System.out.println("删除先前文件: " + (file.delete() ? "成功" : "失败")); + } + FileWriter writer = new FileWriter(file); + BufferedWriter bufferedWriter = new BufferedWriter(writer); + for (Map.Entry entry : map.entrySet()) { + if (isSaveAlLMatterUrls) { + bufferedWriter.write(entry.getValue() + "\t\t" + entry.getKey() + "\r\n"); + } else { + if (entry.getValue().equals("TIMEOUT")) { + bufferedWriter.write(entry.getValue() + "\t\t" + entry.getKey() + "\r\n"); + } + } + } + bufferedWriter.close(); + } + +} diff --git a/Utils/URLChecker/Main.java b/Utils/URLChecker/Main.java new file mode 100644 index 0000000..b835494 --- /dev/null +++ b/Utils/URLChecker/Main.java @@ -0,0 +1,28 @@ +import java.io.IOException; +import java.util.Map; + +/** + * Created by Troy Liu on 2015,九月,17, 22:10. + */ +public class Main { + + // 是否保存所有有连接问题的url + public static final boolean saveAllMatterUrls = true; + + public static void main(String[] args) { + long before = System.currentTimeMillis(); + String urlBundle = "https://raw.githubusercontent.com/tangqi92/Android-Tips/master/README.md"; + Map matterUrls = NetUtils.getNotAvailableUrl(urlBundle); + for (Map.Entry entry : matterUrls.entrySet()) { + System.out.println(entry.getValue() + "--->" + entry.getKey()); + } + try { + BadUrlsSaver.save(matterUrls, saveAllMatterUrls); + } catch (IOException e) { + e.printStackTrace(); + } finally { + long after = System.currentTimeMillis(); + System.out.println("耗时:" + (after - before) / 1000 + "s"); + } + } +} diff --git a/Utils/URLChecker/NetUtils.java b/Utils/URLChecker/NetUtils.java new file mode 100644 index 0000000..06d1ec7 --- /dev/null +++ b/Utils/URLChecker/NetUtils.java @@ -0,0 +1,127 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +interface ICallback { + void finish(int code); + + void timeout(); +} + +/** + * Created by Troy Liu on 2015,九月,17, 22:16. + */ +public class NetUtils { + + public static String getBundle(String urlMain) { + StringBuilder stringBuilder = new StringBuilder(); + try { + URL url = new URL(urlMain); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("Content-Type", "text/html"); + connection.setRequestProperty("Accept-Charset", "utf-8"); + connection.setRequestProperty("Content-Type", "utf-8"); + connection.setRequestProperty("Charset", "utf-8"); + connection.setRequestMethod("GET"); + InputStream inputStream; + BufferedReader bufferedReader = null; + if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + String line = null; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + } + if (bufferedReader != null) { + bufferedReader.close(); + } + connection.disconnect(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return stringBuilder.toString(); + } + + public static Map getNotAvailableUrl(String urlMain) { + ExecutorService threadPool = Executors.newCachedThreadPool(); + final Map matterUrls = new HashMap(); + String response = getBundle(urlMain); + List urlList = UrlMatcher.getUrlStr(response); + for (final String url : urlList) { + threadPool.execute(new ItemThread(url, new ICallback() { + @Override + public void finish(int code) { + matterUrls.put(url, "BAD" + "[Code: " + code + "]"); + } + + @Override + public void timeout() { + matterUrls.put(url, "TIMEOUT"); + } + })); + } + threadPool.shutdown(); + while (true) { + if (threadPool.isTerminated()) { + return matterUrls; + } + } + } + + +} + +class ItemThread implements Runnable { + + private final String url; + private ICallback callback; + + public ItemThread(String url, ICallback callback) { + this.callback = callback; + this.url = url; + } + + @Override + public void run() { + HttpURLConnection connection = null; + try { + URL tmp = new URL(url); + connection = (HttpURLConnection) tmp.openConnection(); + connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"); + connection.setRequestMethod("GET"); + connection.setReadTimeout(10000); + connection.setConnectTimeout(10000); + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + System.out.println("checking [" + url + "]" + "----->[OK]"); + } else { + System.out.println("checking [" + url + "]" + "----->[BAD]" + "; Code--->" + responseCode); + callback.finish(responseCode); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + System.out.println("checking [" + url + "]" + e.getMessage()); + callback.timeout(); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + } +} diff --git a/Utils/URLChecker/UrlMatcher.java b/Utils/URLChecker/UrlMatcher.java new file mode 100644 index 0000000..8b88b3a --- /dev/null +++ b/Utils/URLChecker/UrlMatcher.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Created by Troy Liu on 2015,九月,17, 22:11. + */ +public class UrlMatcher { + public static List getUrlStr(String response) { + Pattern pattern = Pattern.compile("[a-zA-z]+://[^\\s]*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + Matcher matcher = pattern.matcher(response); + List urls = new ArrayList(); + while (matcher.find()) { + String tmp = matcher.group(); + int index = tmp.lastIndexOf(")"); + tmp = tmp.substring(0, index); + urls.add(tmp); + } + return urls; + } + + + public static String getUrlTitle(String urlResponse) { + Pattern pattern = Pattern.compile(".*?"); + Matcher matcher = pattern.matcher(urlResponse); + String title = null; + while (matcher.find()) { + title = matcher.group(); + } + return title; + } +} diff --git a/Utils/UrlCheckerREADME.md b/Utils/UrlCheckerREADME.md new file mode 100644 index 0000000..9bb677a --- /dev/null +++ b/Utils/UrlCheckerREADME.md @@ -0,0 +1,15 @@ +### 检查URL连接是否有效的小工具 +--- + +因为有人提起,这个repo里面有些连接失效、无法访问或者被墙等。所有就打算把那些不能正常访问的连接替换,或者重写为Markdown的形式转移到repo里面。 + +PS:我只是一个初学者,可能写得很挫,但是求别嫌弃 == + +`Main.java`是入口程序,默认会在Utils目录下的badUrls.txt里面更新不能正常访问的连接。 + +> 以200返回值为连接成功的标准。 + +> 并且默认设定HttpUrlConnection实例的ReadTimeout和ConnectTimeout为10s。 +> 默认任何超时或者返回值不为200的链接都为`BadUrl`。 + +**注意**:这个小程序还不够完善,可能会在输出网址的时候出现错误,又或者输出的有问题的网址依然可以访问的情况。不过**不在**badUrls.txt文件里面的网址一般都是可以正常访问(不排除因不同地区的网络状况造成的访问不正常)。 diff --git a/Utils/badUrls.txt b/Utils/badUrls.txt new file mode 100644 index 0000000..89d02ac --- /dev/null +++ b/Utils/badUrls.txt @@ -0,0 +1 @@ +TIMEOUT http://source.android.com/source/code-style.html