├── .gitignore ├── .idea ├── .gitignore ├── AndroidEngineerAdvanced.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── AndroidLessons ├── PlayVideo │ └── Play_Video.html ├── lesson_eight │ ├── HtmlLessons │ │ └── 第08讲:既生 Synchronized,何生 ReentrantLock.html │ ├── JsonLessons │ │ └── 第08讲:既生 Synchronized,何生 ReentrantLock.json │ └── SourceCode │ │ ├── LagouFairLockTest.java │ │ ├── LagouReentrantLockTest.java │ │ ├── LagouSynchronizedMehtods.java │ │ ├── README.md │ │ └── ReadWriteTest.java ├── lesson_eighteen │ ├── HtmlLessons │ │ └── 第18讲:Android Bitmap 全面详解.html │ └── JsonLessons │ │ └── 第18讲:Android Bitmap 全面详解.json ├── lesson_eleven │ ├── HtmlLessons │ │ └── 第11讲:线程池之刨根问底.html │ ├── JsonLessons │ │ └── 第11讲:线程池之刨根问底.json │ └── SourceCode │ │ ├── CachedThreadPoolOOM.java │ │ ├── CreateCacheThreadPool.java │ │ ├── CreateFixThreadPool.java │ │ ├── CreateScheduledThreadPool.java │ │ ├── CreateSingleThreadPool.java │ │ ├── FixedThreadPoolOOM.java │ │ ├── LessThanCoreCount.java │ │ ├── MoreThanCoreCount.java │ │ ├── NonCoreThread.java │ │ ├── README.md │ │ └── ThreadPoolRejectHandle.java ├── lesson_fifteen │ ├── HtmlLessons │ │ └── 第15讲:Android 如何自定义 View?.html │ ├── JsonLessons │ │ └── 第15讲:Android 如何自定义 View?.json │ └── SourceCode │ │ └── LagouCustomizedView │ │ ├── .gitignore │ │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── material │ │ │ │ └── danny_jiang │ │ │ │ └── com │ │ │ │ └── lagoucustomizedview │ │ │ │ └── ExampleInstrumentedTest.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── material │ │ │ │ │ └── danny_jiang │ │ │ │ │ └── com │ │ │ │ │ └── lagoucustomizedview │ │ │ │ │ ├── FlowLayoutActivity.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ ├── PieImageActivity.java │ │ │ │ │ └── views │ │ │ │ │ ├── CustomToolBar.java │ │ │ │ │ ├── FlowLayout.java │ │ │ │ │ └── PieImageView.java │ │ │ └── res │ │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ │ ├── layout │ │ │ │ ├── activity_flow_layout.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_pie_image.xml │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── attrs.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── test │ │ │ └── java │ │ │ └── material │ │ │ └── danny_jiang │ │ │ └── com │ │ │ └── lagoucustomizedview │ │ │ └── ExampleUnitTest.java │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle ├── lesson_five │ ├── HtmlLessons │ │ └── 第05讲:深入理解 ClassLoader 的加载机制.html │ ├── JsonLessons │ │ └── 第05讲:深入理解 ClassLoader 的加载机制.json │ └── SourceCode │ │ ├── DexClassLoaderHotFix │ │ ├── .gitignore │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── androidTest │ │ │ │ └── java │ │ │ │ │ └── material │ │ │ │ │ └── danny_jiang │ │ │ │ │ └── com │ │ │ │ │ └── dexclassloaderhotfix │ │ │ │ │ └── ExampleInstrumentedTest.java │ │ │ │ ├── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ │ └── material │ │ │ │ │ │ └── danny_jiang │ │ │ │ │ │ └── com │ │ │ │ │ │ └── dexclassloaderhotfix │ │ │ │ │ │ ├── ISay.java │ │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ │ └── SayException.java │ │ │ │ └── res │ │ │ │ │ ├── drawable-v24 │ │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ │ ├── drawable │ │ │ │ │ └── ic_launcher_background.xml │ │ │ │ │ ├── layout │ │ │ │ │ └── activity_main.xml │ │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── values │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── material │ │ │ │ └── danny_jiang │ │ │ │ └── com │ │ │ │ └── dexclassloaderhotfix │ │ │ │ └── ExampleUnitTest.java │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ │ ├── ISay.java │ │ ├── README.md │ │ └── SayHotFix.java ├── lesson_four │ ├── HtmlLessons │ │ └── 第04讲:编译插桩操纵字节码,实现不可能完成的任务.html │ ├── JsonLessons │ │ └── 第04讲:编译插桩操纵字节码,实现不可能完成的任务.json │ └── SourceCode │ │ ├── ASMLifeCycleDemo │ │ ├── .gitignore │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ └── material │ │ │ │ │ └── danny_jiang │ │ │ │ │ └── com │ │ │ │ │ └── asmlifecycledemo │ │ │ │ │ ├── BActivity.java │ │ │ │ │ └── MainActivity.java │ │ │ │ └── res │ │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ │ ├── layout │ │ │ │ ├── activity_b.xml │ │ │ │ └── activity_main.xml │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── asm_lifecycle_plugin │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── groovy │ │ │ │ └── danny.jiang.plugin │ │ │ │ │ ├── LifeCyclePlugin.groovy │ │ │ │ │ └── LifeCycleTransform.groovy │ │ │ │ ├── java │ │ │ │ └── danny │ │ │ │ │ └── jiang │ │ │ │ │ └── asm │ │ │ │ │ ├── LifecycleClassVisitor.java │ │ │ │ │ └── LifecycleMethodVisitor.java │ │ │ │ └── resources │ │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── danny.asm.lifecycle.properties │ │ ├── asm_lifecycle_repo │ │ │ └── danny │ │ │ │ └── lifecycle │ │ │ │ └── plugin │ │ │ │ └── asm_lifecycle_plugin │ │ │ │ ├── 1.0.0 │ │ │ │ ├── asm_lifecycle_plugin-1.0.0.jar.md5 │ │ │ │ ├── asm_lifecycle_plugin-1.0.0.jar.sha1 │ │ │ │ ├── asm_lifecycle_plugin-1.0.0.pom │ │ │ │ ├── asm_lifecycle_plugin-1.0.0.pom.md5 │ │ │ │ └── asm_lifecycle_plugin-1.0.0.pom.sha1 │ │ │ │ ├── maven-metadata.xml │ │ │ │ ├── maven-metadata.xml.md5 │ │ │ │ └── maven-metadata.xml.sha1 │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ │ └── README.md ├── lesson_fourteen │ ├── HtmlLessons │ │ └── 第14讲:彻底掌握 Android touch 事件分发时序.html │ ├── JsonLessons │ │ └── 第14讲:彻底掌握 Android touch 事件分发时序.json │ └── SourceCode │ │ └── LagouTouchExplanation │ │ ├── .gitignore │ │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── material │ │ │ │ └── danny_jiang │ │ │ │ └── com │ │ │ │ └── lagoutouchexplanation │ │ │ │ └── ExampleInstrumentedTest.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── material │ │ │ │ │ └── danny_jiang │ │ │ │ │ └── com │ │ │ │ │ └── lagoutouchexplanation │ │ │ │ │ ├── CancelEventActivity.java │ │ │ │ │ ├── InterceptActivity.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ ├── PrintUtils.java │ │ │ │ │ └── views │ │ │ │ │ ├── CaptureTouchView.java │ │ │ │ │ ├── DownInterceptGroup.java │ │ │ │ │ └── MyScrollView.java │ │ │ └── res │ │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ │ ├── layout │ │ │ │ ├── activity_cancel.xml │ │ │ │ ├── activity_intercept.xml │ │ │ │ └── activity_main.xml │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── test │ │ │ └── java │ │ │ └── material │ │ │ └── danny_jiang │ │ │ └── com │ │ │ └── lagoutouchexplanation │ │ │ └── ExampleUnitTest.java │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle ├── lesson_nine │ ├── HtmlLessons │ │ └── 第09讲:Java 线程优化 偏向锁,轻量级锁、重量级锁.html │ └── JsonLessons │ │ └── 第09讲:Java 线程优化 偏向锁,轻量级锁、重量级锁.json ├── lesson_nineteen │ ├── HtmlLessons │ │ └── 第19讲:startActivity 启动过程分析.html │ └── JsonLessons │ │ └── 第19讲:startActivity 启动过程分析.json ├── lesson_one │ ├── HtmlLessons │ │ └── 第01讲:程序运行时,内存到底是如何进行分配的?.html │ └── JsonLessons │ │ └── 第01讲:程序运行时,内存到底是如何进行分配的?.json ├── lesson_seven │ ├── HtmlLessons │ │ └── 第07讲:Java 内存模型与线程.html │ └── JsonLessons │ │ └── 第07讲:Java 内存模型与线程.json ├── lesson_seventeen │ ├── HtmlLessons │ │ └── 第17讲:Android OkHttp 全面详解.html │ ├── JsonLessons │ │ └── 第17讲:Android OkHttp 全面详解.json │ └── SourceCode │ │ └── SquareUtils.java ├── lesson_six │ ├── HtmlLessons │ │ └── 第06讲:Class 对象在执行引擎中的初始化过程.html │ ├── JsonLessons │ │ └── 第06讲:Class 对象在执行引擎中的初始化过程.json │ └── SourceCode │ │ ├── ClassInit.java │ │ ├── ClassInitTest.java │ │ ├── InitOrder.java │ │ └── README.md ├── lesson_sixteen │ ├── HtmlLessons │ │ └── 第16讲:为什么 RecyclerView 可以完美替代 Listview?.html │ └── JsonLessons │ │ └── 第16讲:为什么 RecyclerView 可以完美替代 Listview?.json ├── lesson_ten │ ├── HtmlLessons │ │ └── 第10讲:深入理解 AQS 和 CAS 原理.html │ └── JsonLessons │ │ └── 第10讲:深入理解 AQS 和 CAS 原理.json ├── lesson_thirteen │ ├── HtmlLessons │ │ └── 第13讲:Android 是如何通过 Activity 进行交互的?.html │ └── JsonLessons │ │ └── 第13讲:Android 是如何通过 Activity 进行交互的?.json ├── lesson_thirty │ ├── HtmlLessons │ │ └── 第30讲:如何设计一个比较合理的 LogUtil 类?.html │ └── JsonLessons │ │ └── 第30讲:如何设计一个比较合理的 LogUtil 类?.json ├── lesson_thirty_four │ ├── HtmlLessons │ │ └── 第34讲:混合开发真的适合你吗?.html │ └── JsonLessons │ │ └── 第34讲:混合开发真的适合你吗?.json ├── lesson_thirty_one │ ├── HtmlLessons │ │ └── 第31讲:Android 屏幕适配的处理技巧都有哪些?.html │ └── JsonLessons │ │ └── 第31讲:Android 屏幕适配的处理技巧都有哪些?.json ├── lesson_thirty_three │ ├── HtmlLessons │ │ └── 第33讲:对于网络编程,你做过哪些优化?.html │ └── JsonLessons │ │ └── 第33讲:对于网络编程,你做过哪些优化?.json ├── lesson_thirty_two │ ├── HtmlLessons │ │ └── 第32讲:解析动态权限适配遇到的问题.html │ └── JsonLessons │ │ └── 第32讲:解析动态权限适配遇到的问题.json ├── lesson_three │ ├── HtmlLessons │ │ └── 第03讲:字节码层面分析 class 类文件结构.html │ └── JsonLessons │ │ └── 第03讲:字节码层面分析 class 类文件结构.json ├── lesson_twelve │ ├── HtmlLessons │ │ └── 第12讲:DVM 以及 ART 是如何对 JVM 进行优化的?.html │ └── JsonLessons │ │ └── 第12讲:DVM 以及 ART 是如何对 JVM 进行优化的?.json ├── lesson_twenty │ ├── HtmlLessons │ │ └── 第20讲:底层剖析 Window 、Activity、 View 三者关系.html │ └── JsonLessons │ │ └── 第20讲:底层剖析 Window 、Activity、 View 三者关系.json ├── lesson_twenty_eight │ ├── HtmlLessons │ │ └── 第28讲:Android Gradle 构建问题解析.html │ └── JsonLessons │ │ └── 第28讲:Android Gradle 构建问题解析.json ├── lesson_twenty_five │ ├── HtmlLessons │ │ └── 第25讲:Android 崩溃的那些事儿.html │ └── JsonLessons │ │ └── 第25讲:Android 崩溃的那些事儿.json ├── lesson_twenty_four │ ├── HtmlLessons │ │ └── 第24讲:APK 如何做到包体积优化?.html │ └── JsonLessons │ │ └── 第24讲:APK 如何做到包体积优化?.json ├── lesson_twenty_nine │ ├── HtmlLessons │ │ └── 第29讲:MVP 中 presenter 生命周期的管理.html │ └── JsonLessons │ │ └── 第29讲:MVP 中 presenter 生命周期的管理.json ├── lesson_twenty_one │ ├── HtmlLessons │ │ └── 第21讲:Android 如何通过 View 进行渲染?.html │ └── JsonLessons │ │ └── 第21讲:Android 如何通过 View 进行渲染?.json ├── lesson_twenty_seven │ ├── HtmlLessons │ │ └── 第27讲:面对 UI 卡顿,如何入手分析解决问题?.html │ └── JsonLessons │ │ └── 第27讲:面对 UI 卡顿,如何入手分析解决问题?.json ├── lesson_twenty_six │ ├── HtmlLessons │ │ └── 第26讲:面对内存泄漏,如何进行优化?.html │ └── JsonLessons │ │ └── 第26讲:面对内存泄漏,如何进行优化?.json ├── lesson_twenty_three │ ├── HtmlLessons │ │ └── 第23讲:15 分钟彻底掌握 Handler.html │ └── JsonLessons │ │ └── 第23讲:15 分钟彻底掌握 Handler.json ├── lesson_twenty_two │ ├── HtmlLessons │ │ └── 第22讲:Android App 的安装过程.html │ └── JsonLessons │ │ └── 第22讲:Android App 的安装过程.json ├── lesson_two │ ├── HtmlLessons │ │ └── 第02讲:GC 回收机制与分代回收策略.html │ ├── JsonLessons │ │ └── 第02讲:GC 回收机制与分代回收策略.json │ └── SourceCode │ │ ├── GCRootClassVariable.java │ │ ├── GCRootLocalVariable.java │ │ ├── GCRootStaticVariable.java │ │ ├── GCRootThread.java │ │ └── MinorGCTest.java └── lesson_zero │ ├── HtmlLessons │ └── 开篇词:跳出舒适区,走在行业前端.html │ └── JsonLessons │ └── 开篇词:跳出舒适区,走在行业前端.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/AndroidEngineerAdvanced.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AndroidLessons/PlayVideo/Play_Video.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 前端播放m3u8格式视频 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 |
17 | 20 |
21 |
切换视频
22 | 23 | 51 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eight/SourceCode/LagouFairLockTest.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.locks.ReentrantLock; 2 | 3 | public class LagouFairLockTest implements Runnable{ 4 | private int sharedNumber = 0; 5 | //创建公平锁 6 | private static ReentrantLock lock=new ReentrantLock(true); 7 | public void run() { 8 | while(sharedNumber < 20){ 9 | try{ 10 | lock.lock(); 11 | sharedNumber++; 12 | System.out.println(Thread.currentThread().getName() 13 | + " 获得锁, sharedNumber is " + sharedNumber); 14 | }finally{ 15 | lock.unlock(); 16 | } 17 | } 18 | } 19 | public static void main(String[] args) { 20 | LagouFairLockTest lft = new LagouFairLockTest(); 21 | Thread th1 = new Thread(lft); 22 | Thread th2 = new Thread(lft); 23 | Thread th3 = new Thread(lft); 24 | th1.start(); 25 | th2.start(); 26 | th3.start(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eight/SourceCode/LagouReentrantLockTest.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.locks.*; 2 | 3 | public class LagouReentrantLockTest { 4 | 5 | ReentrantLock lock = new ReentrantLock(); 6 | 7 | public static void main(String[] args){ 8 | LagouReentrantLockTest l1 = new LagouReentrantLockTest(); 9 | 10 | Thread t1 = new Thread(new Runnable(){ 11 | @Override 12 | public void run(){ 13 | l1.printLog(); 14 | } 15 | }); 16 | Thread t2 = new Thread(new Runnable(){ 17 | @Override 18 | public void run(){ 19 | l1.printLog(); 20 | } 21 | }); 22 | 23 | t1.start(); 24 | t2.start(); 25 | } 26 | 27 | public void printLog(){ 28 | try{ 29 | lock.lock(); 30 | for(int i = 0; i < 5; i++) { 31 | System.out.println(Thread.currentThread().getName() + " is printing " + i); 32 | } 33 | }catch(Exception e){ 34 | } finally{ 35 | lock.unlock(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eight/SourceCode/LagouSynchronizedMehtods.java: -------------------------------------------------------------------------------- 1 | public class LagouSynchronizedMehtods{ 2 | private Object lock = new Object(); 3 | 4 | public static void main(String[] args){ 5 | LagouSynchronizedMehtods l1 = new LagouSynchronizedMehtods(); 6 | 7 | Thread t1 = new Thread(new Runnable(){ 8 | @Override 9 | public void run(){ 10 | l1.printLog(); 11 | } 12 | }); 13 | 14 | Thread t2 = new Thread(new Runnable(){ 15 | @Override 16 | public void run(){ 17 | l1.printLog(); 18 | } 19 | }); 20 | 21 | t1.start(); 22 | t2.start(); 23 | } 24 | 25 | public void printLog(){ 26 | synchronized(lock) { 27 | for(int i = 0; i < 5; i ++) { 28 | System.out.println(Thread.currentThread().getName() + " is printing " + i); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eight/SourceCode/README.md: -------------------------------------------------------------------------------- 1 | ### synchronized & ReentrantLock 2 | 3 | ##### LagouSynchronizedMehtods.java 4 | synchronized可以作用于3个层面 5 | 1. 修饰实例方法; 6 | 2. 修饰静态类方法; 7 | 3. 修饰代码块。 8 | 9 | > 需要注意如果synchronized锁对象时当前实例对象this,如果调用不同对象的同步方法,不会产生互斥效果 10 | 11 | ##### LagouReentrantLockTest.java 12 | ReentrantLock需要手动加锁和释放锁,因此一般在finally语句块中调用unlock操作,释放锁对象。 13 | 14 | ##### LagouFairLockTest.java 15 | ReentrantLock可以实现公平锁 16 | 17 | ##### ReadWriteTest.java 18 | ReentrantReadWriteLock读写锁可以实现读写操作分离,当读操作时不产生互斥,只有写操作时才会阻塞其它线程的读写操作 19 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eight/SourceCode/ReadWriteTest.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest; 2 | 3 | import java.util.concurrent.Executors; 4 | import java.util.concurrent.locks.ReentrantReadWriteLock; 5 | /** 6 | * Created by Danny 姜 on 2020-03-27. 7 | */ 8 | public class ReadWriteTest { 9 | 10 | private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); 11 | private static String number = "0"; 12 | 13 | public static void main(String[] args) throws InterruptedException{ 14 | Thread t1 = new Thread(new Reader(),"读线程 1"); 15 | Thread t2 = new Thread(new Reader(),"读线程 2"); 16 | Thread t3 = new Thread(new Writer(),"写线程"); 17 | t1.start(); 18 | t2.start(); 19 | t3.start(); 20 | t1.join(); 21 | t2.join(); 22 | t3.join(); 23 | } 24 | 25 | static class Reader implements Runnable { 26 | public void run() { 27 | for(int i = 0; i<= 10; i ++) { 28 | lock.readLock().lock(); 29 | System.out.println(Thread.currentThread().getName() + " ---> Number is " + number); 30 | lock.readLock().unlock(); 31 | } 32 | } 33 | } 34 | static class Writer implements Runnable { 35 | public void run() { 36 | for(int i = 1; i<= 7; i+=2) { 37 | try { 38 | lock.writeLock().lock(); 39 | System.out.println(Thread.currentThread().getName() + " 正在写入 " + i); 40 | number = number.concat("" + i); 41 | } finally { 42 | lock.writeLock().unlock(); 43 | } 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/CachedThreadPoolOOM.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.Executors; 4 | import java.util.concurrent.ThreadPoolExecutor; 5 | 6 | /** 7 | * Created by Danny 姜. 8 | */ 9 | public class CachedThreadPoolOOM { 10 | 11 | public static void main(String[] args) throws InterruptedException{ 12 | ThreadPoolExecutor fixedThreadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); 13 | 14 | for (int i = 1; i <= 1000000; i++) { 15 | final int taskId = i; 16 | System.out.println("execute tast:" + taskId); 17 | 18 | fixedThreadPool.execute(new Runnable() { 19 | @Override 20 | public void run() { 21 | try { 22 | System.out.println("线程:" + Thread.currentThread().getName() 23 | + " 正在执行 task: " + taskId); 24 | // 任务耗时10秒 25 | Thread.sleep(10000); 26 | } catch (InterruptedException ignored) { 27 | } 28 | } 29 | }); 30 | } 31 | fixedThreadPool.shutdownNow(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/CreateCacheThreadPool.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * Created by Danny 姜. 8 | */ 9 | public class CreateCacheThreadPool { 10 | public static void main(String[] args) throws InterruptedException{ 11 | ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); 12 | for (int i = 1; i <= 5; i++) { 13 | final int taskId = i; 14 | 15 | cachedThreadPool.execute(new Runnable() { 16 | @Override 17 | public void run() { 18 | try { 19 | System.out.println("线程:" + Thread.currentThread().getName() 20 | + " 正在执行 task: " + taskId); 21 | Thread.sleep(500); 22 | } catch (InterruptedException ignored) { 23 | } 24 | } 25 | }); 26 | } 27 | cachedThreadPool.shutdown(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/CreateFixThreadPool.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * Created by Danny 姜. 8 | */ 9 | public class CreateFixThreadPool { 10 | 11 | public static void main(String[] args) { 12 | // 创建线程数量为3的线程池 13 | ExecutorService singleThreadExecutor = Executors.newFixedThreadPool(3); 14 | // 提交10个任务交给线程池执行 15 | for (int i = 1; i <= 10; i++) { 16 | final int taskId = i; 17 | 18 | singleThreadExecutor.submit(new Runnable() { 19 | @Override 20 | public void run() { 21 | System.out.println("线程:" + Thread.currentThread().getName() 22 | + " 正在执行 task: " + taskId); 23 | } 24 | 25 | }); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/CreateScheduledThreadPool.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.Executors; 4 | import java.util.concurrent.ScheduledExecutorService; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * Created by Danny 姜. 9 | */ 10 | public class CreateScheduledThreadPool { 11 | private static int count = 0; 12 | 13 | public static void main(String[] args) throws Exception { 14 | 15 | 16 | // 指定线程数量为4的定时任务线程池 17 | ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(2); 18 | // 延迟1s秒执行,每隔1s执行一次 19 | scheduledThreadPool.scheduleAtFixedRate(new Runnable() { 20 | @Override 21 | public void run() { 22 | System.out.println("线程 " + Thread.currentThread().getName() + "修改 count:" + count++); 23 | } 24 | 25 | }, 500, 500, TimeUnit.MILLISECONDS); 26 | 27 | Thread.sleep(5000); 28 | // 使用shutdown关闭定时任务 29 | scheduledThreadPool.shutdown(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/CreateSingleThreadPool.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * Created by Danny 姜. 8 | */ 9 | public class CreateSingleThreadPool { 10 | 11 | public static void main(String[] args) throws InterruptedException{ 12 | ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); 13 | 14 | for (int i = 1; i <= 5; i++) { 15 | final int taskId = i; 16 | 17 | singleThreadExecutor.submit(new Runnable() { 18 | @Override 19 | public void run() { 20 | System.out.println("线程:" + Thread.currentThread().getName() 21 | + " 正在执行 task: " + taskId); 22 | } 23 | 24 | }); 25 | Thread.sleep(1000); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/FixedThreadPoolOOM.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.Executors; 4 | import java.util.concurrent.ThreadPoolExecutor; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * Created by Danny 姜. 9 | */ 10 | public class FixedThreadPoolOOM { 11 | 12 | public static void main(String[] args) throws InterruptedException{ 13 | ThreadPoolExecutor fixedThreadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(2); 14 | 15 | for (int i = 1; i <= 1000000; i++) { 16 | final int taskId = i; 17 | System.out.println("execute tast:" + taskId); 18 | 19 | fixedThreadPool.execute(new Runnable() { 20 | @Override 21 | public void run() { 22 | try { 23 | System.out.println("线程:" + Thread.currentThread().getName() 24 | + " 正在执行 task: " + taskId); 25 | // 任务耗时10秒 26 | Thread.sleep(10000); 27 | } catch (InterruptedException ignored) { 28 | } 29 | } 30 | }); 31 | } 32 | fixedThreadPool.shutdownNow(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/LessThanCoreCount.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * Created by Danny 姜 8 | * 9 | * 当前线程池中运行的线程数量还没有达到 corePoolSize 大小时, 10 | * 线程池会创建一个新线程执行提交的任务, 11 | * 无论之前创建的线程是否处于空闲状态。 12 | */ 13 | public class LessThanCoreCount { 14 | 15 | public static void main(String[] args) throws InterruptedException{ 16 | ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3); 17 | 18 | for (int i = 1; i <= 5; i++) { 19 | final int taskId = i; 20 | 21 | fixedThreadPool.execute(new Runnable() { 22 | @Override 23 | public void run() { 24 | try { 25 | System.out.println("线程:" + Thread.currentThread().getName() 26 | + " 正在执行 task: " + taskId); 27 | // 任务耗时100毫秒 28 | Thread.sleep(100); 29 | } catch (InterruptedException ignored) { 30 | } 31 | } 32 | }); 33 | // 延迟2s向线程池中提交任务 34 | Thread.sleep(2000); 35 | } 36 | fixedThreadPool.shutdown(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/MoreThanCoreCount.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.ThreadPoolExecutor; 6 | 7 | /** 8 | * Created by Danny 姜 9 | * 当前线程池中运行的线程数量已经达到 corePoolSize 大小时, 10 | * 线程池会把任务加入到等待队列中,直到某一个线程空闲了, 11 | * 线程池会根据我们设置的等待队列规则,从队列中取出一个新的任务执行。 12 | */ 13 | public class MoreThanCoreCount { 14 | 15 | public static void main(String[] args) throws InterruptedException{ 16 | ThreadPoolExecutor fixedThreadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(2); 17 | 18 | for (int i = 1; i <= 5; i++) { 19 | final int taskId = i; 20 | 21 | fixedThreadPool.execute(new Runnable() { 22 | @Override 23 | public void run() { 24 | try { 25 | System.out.println("线程:" + Thread.currentThread().getName() 26 | + " 正在执行 task: " + taskId); 27 | // 任务耗时4秒 28 | Thread.sleep(4000); 29 | } catch (InterruptedException ignored) { 30 | } 31 | } 32 | }); 33 | System.out.println("此时等待队列中有 " + fixedThreadPool.getQueue().size() + " 个元素"); 34 | // 每500毫秒向线程池中提交任务 35 | Thread.sleep(500); 36 | } 37 | fixedThreadPool.shutdown(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/NonCoreThread.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.LinkedBlockingQueue; 4 | import java.util.concurrent.ThreadPoolExecutor; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * Created by Danny 姜. 9 | */ 10 | public class NonCoreThread { 11 | 12 | public static void main(String[] args) throws InterruptedException{ 13 | // 核心线程为2、最大线程数为10、等待队列长度为2 14 | ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2, 10, 15 | 0L, TimeUnit.MILLISECONDS, 16 | new LinkedBlockingQueue(2)); 17 | 18 | for (int i = 1; i <= 5; i++) { 19 | final int taskId = i; 20 | 21 | threadPool.execute(new Runnable() { 22 | @Override 23 | public void run() { 24 | try { 25 | System.out.println("线程:" + Thread.currentThread().getName() 26 | + " 正在执行 task: " + taskId); 27 | // 任务耗时6秒 28 | Thread.sleep(5000); 29 | } catch (InterruptedException ignored) { 30 | } 31 | } 32 | }); 33 | System.out.println("此时等待队列中有 " + threadPool.getQueue().size() + " 个元素"); 34 | } 35 | threadPool.shutdown(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/README.md: -------------------------------------------------------------------------------- 1 | ### 线程池的创建 2 | ##### CreateSingleThreadPool.java 3 | 创建一个单线程化的线程池,它只会用唯一的工作线程来执行任务,保证所有任务按先进先出的顺序执行。 4 | 5 | ##### CreateCachedThreadPool.java 6 | 创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程。 7 | 8 | ##### CreateFixThreadPool.java 9 | 创建一个固定数目的、可重用的线程池。 10 | 11 | ##### CreateScheduledThreadPool,java 12 | 创建一个定时线程池,支持定时及周期性任务执行。 13 | 14 | ### 线程池流程分析 15 | ##### LessThanCoreCount.java 16 | 当前线程池中运行的线程数量还没有达到 corePoolSize 大小时,线程池会创建一个新线程执行提交的任务,无论之前创建的线程是否处于空闲状态。 17 | 18 | ##### MoreThanCoreCount.java 19 | 当前线程池中运行的线程数量已经达到 corePoolSize 大小时,线程池会把任务加入到等待队列中,直到某一个线程空闲了,线程池会根据我们设置的等待队列规则,从队列中取出一个新的任务执行。 20 | 21 | ##### NoCoreThread.java 22 | 如果线程数大于 corePoolSize 数量但是还没有达到最大线程数 maximumPoolSize,并且等待队列已满,则线程池会创建新的线程来执行任务。 23 | 24 | ##### ThreadPoolRejectHandle.java 25 | 如果提交的任务,无法被核心线程直接执行,又无法加入等待队列,又无法创建“非核心线程”直接执行,线程池将根据拒绝处理器定义的策略处理这个任务。 26 | 27 | ### 线程池造成OOM 28 | ##### FixedThreadPoolOOM.java 29 | 使用无界阻塞队列,当核心线程执行时间很长,则新提交的任务还在不断地插入到阻塞队列中,最终造成OOM。 30 | 31 | ##### CachedThreadPoolOOM.java 32 | 缓存线程池的最大线程数为 Integer 最大值。当核心线程耗时很久,线程池会尝试创建新的线程来执行提交的任务,当内存不足时就会报无法创建线程的错误。 33 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_eleven/SourceCode/ThreadPoolRejectHandle.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.bmwtest.course11; 2 | 3 | import java.util.concurrent.LinkedBlockingQueue; 4 | import java.util.concurrent.ThreadPoolExecutor; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * Created by Danny 姜. 9 | * 如果提交的任务,无法被核心线程直接执行, 10 | * 又无法加入等待队列,又无法创建“非核心线程”直接执行, 11 | * 线程池将根据拒绝处理器定义的策略处理这个任务 12 | */ 13 | public class ThreadPoolRejectHandle { 14 | 15 | public static void main(String[] args) { 16 | // 核心线程为2、最大线程数为10、等待队列长度为2 17 | ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2, 3, 18 | 0L, TimeUnit.MILLISECONDS, 19 | new LinkedBlockingQueue(2)); 20 | 21 | for (int i = 1; i <= 6; i++) { // 提交6次任务 22 | final int taskId = i; 23 | 24 | threadPool.execute(new Runnable() { 25 | @Override 26 | public void run() { 27 | try { 28 | System.out.println("线程:" + Thread.currentThread().getName() 29 | + " 正在执行 task: " + taskId); 30 | // 任务耗时5秒 31 | Thread.sleep(5000); 32 | } catch (InterruptedException ignored) { 33 | } 34 | } 35 | }); 36 | System.out.println("此时等待队列中有 " + threadPool.getQueue().size() + " 个元素"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "material.danny_jiang.com.lagoucustomizedview" 7 | minSdkVersion 22 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | } 29 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/androidTest/java/material/danny_jiang/com/lagoucustomizedview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("material.danny_jiang.com.lagoucustomizedview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/java/material/danny_jiang/com/lagoucustomizedview/FlowLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | /** 7 | * Created by Danny 姜. 8 | */ 9 | public class FlowLayoutActivity extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_flow_layout); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/java/material/danny_jiang/com/lagoucustomizedview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import material.danny_jiang.com.lagoucustomizedview.views.PieImageView; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/java/material/danny_jiang/com/lagoucustomizedview/PieImageActivity.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import material.danny_jiang.com.lagoucustomizedview.views.PieImageView; 8 | 9 | /** 10 | * Created by Danny 姜. 11 | */ 12 | public class PieImageActivity extends AppCompatActivity { 13 | 14 | PieImageView pieImageView; 15 | 16 | @Override 17 | protected void onCreate(@Nullable Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_pie_image); 20 | 21 | // pieImageView = findViewById(R.id.pieImageView); 22 | // pieImageView.setProgress(45); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/java/material/danny_jiang/com/lagoucustomizedview/views/CustomToolBar.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview.views; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.graphics.drawable.Drawable; 7 | import android.util.AttributeSet; 8 | import android.util.TypedValue; 9 | import android.view.View; 10 | import android.widget.ImageView; 11 | import android.widget.RelativeLayout; 12 | import android.widget.TextView; 13 | 14 | import material.danny_jiang.com.lagoucustomizedview.R; 15 | 16 | /** 17 | * Created by Danny 姜. 18 | */ 19 | public class CustomToolBar extends RelativeLayout { 20 | 21 | private ImageView leftImg, rightImg; 22 | private TextView titleTextView; 23 | 24 | //1.声明一个接口 25 | public interface ImgClickListener{ 26 | public void leftImgClick(); 27 | public void rightImgClick(); 28 | } 29 | //2.创建一个接口变量 30 | private ImgClickListener imgClickListener; 31 | 32 | //3.为接口变量声明一个set方法, 33 | public void setImgClickListener(ImgClickListener imgClickListener) { 34 | this.imgClickListener = imgClickListener; 35 | } 36 | 37 | public CustomToolBar(Context context) { 38 | this(context, null); 39 | } 40 | 41 | public CustomToolBar(Context context, AttributeSet attrs) { 42 | this(context, attrs, 0); 43 | } 44 | 45 | public CustomToolBar(final Context context, AttributeSet attrs, int defStyleAttr) { 46 | super(context, attrs, defStyleAttr); 47 | titleTextView = new TextView(context); 48 | leftImg = new ImageView(context); 49 | leftImg.setPadding(12, 12, 12, 12); 50 | rightImg = new ImageView(context); 51 | rightImg.setPadding(12, 12, 12, 12); 52 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CustomToolBar); 53 | String titleText = ta.getString(R.styleable.CustomToolBar_titleText); 54 | //第二个参数表示默认颜色 55 | int titleTextColor = ta.getColor(R.styleable.CustomToolBar_myTitleTextColor, Color.BLACK); 56 | //已经由sp转为px 57 | float titleTextSize = ta.getDimension(R.styleable.CustomToolBar_titleTextSize, 12); 58 | 59 | //读取图片 60 | Drawable leftDrawable = ta.getDrawable(R.styleable.CustomToolBar_leftImageSrc); 61 | Drawable rightDrawable = ta.getDrawable(R.styleable.CustomToolBar_rightImageSrc); 62 | 63 | //回收TypedArray 64 | ta.recycle(); 65 | 66 | leftImg.setImageDrawable(leftDrawable); 67 | rightImg.setImageDrawable(rightDrawable); 68 | titleTextView.setText(titleText); 69 | titleTextView.setTextSize(titleTextSize); 70 | titleTextView.setTextColor(titleTextColor); 71 | 72 | //给控件设置LayoutParams时,该控件的父容器是那个,就选那个的LayoutParams 73 | LayoutParams leftParams = new LayoutParams((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()), 74 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics())); 75 | //表示该控件和父容器的左边对齐 76 | leftParams.addRule(ALIGN_PARENT_LEFT, TRUE); 77 | this.addView(leftImg, leftParams); 78 | 79 | LayoutParams titleParams = new LayoutParams(LayoutParams.WRAP_CONTENT, 80 | LayoutParams.WRAP_CONTENT); 81 | titleParams.addRule(CENTER_IN_PARENT, TRUE); 82 | addView(titleTextView, titleParams); 83 | 84 | LayoutParams rightParams = new LayoutParams((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()), 85 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics())); 86 | rightParams.addRule(ALIGN_PARENT_RIGHT, TRUE); 87 | addView(rightImg, rightParams); 88 | 89 | //4.点击ImageView时调用接口中的方法 90 | leftImg.setOnClickListener(new OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | if (imgClickListener!=null) { 94 | imgClickListener.leftImgClick(); 95 | } 96 | } 97 | }); 98 | rightImg.setOnClickListener(new OnClickListener() { 99 | @Override 100 | public void onClick(View v) { 101 | if (imgClickListener!=null) { 102 | imgClickListener.rightImgClick(); 103 | } 104 | } 105 | }); 106 | 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/java/material/danny_jiang/com/lagoucustomizedview/views/PieImageView.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview.views; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.RectF; 8 | import android.support.annotation.IntRange; 9 | import android.support.v4.view.ViewCompat; 10 | import android.support.v7.widget.AppCompatImageView; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | /** 16 | * Created by Danny 姜 17 | */ 18 | public class PieImageView extends View { 19 | 20 | private static final int MAX_PROGRESS = 100; 21 | private Paint mArcPaint; 22 | private RectF mBound; 23 | private Paint mCirclePaint; 24 | private int mProgress = 0; 25 | 26 | public PieImageView(Context context) { 27 | this(context, null, 0); 28 | } 29 | 30 | public PieImageView(Context context, AttributeSet attrs) { 31 | this(context, attrs, 0); 32 | } 33 | 34 | public PieImageView(Context context, AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | init(); 37 | } 38 | 39 | public void setProgress(@IntRange(from = 0, to = MAX_PROGRESS) int mProgress) { 40 | this.mProgress = mProgress; 41 | ViewCompat.postInvalidateOnAnimation(this); 42 | } 43 | 44 | private void init() { 45 | mArcPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 46 | mArcPaint.setStyle(Paint.Style.FILL_AND_STROKE); 47 | mArcPaint.setStrokeWidth(dpToPixel(0.1f, getContext())); 48 | mArcPaint.setColor(Color.RED); 49 | 50 | mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 51 | mCirclePaint.setStyle(Paint.Style.STROKE); 52 | mCirclePaint.setStrokeWidth(dpToPixel(2, getContext())); 53 | mCirclePaint.setColor(Color.argb(120, 0xff, 0xff, 0xff)); 54 | mBound = new RectF(); 55 | } 56 | 57 | @Override 58 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 59 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 60 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 61 | // 判断是wrap_content的测量模式 62 | if (MeasureSpec.AT_MOST == widthMode || MeasureSpec.AT_MOST == heightMode) { 63 | int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); 64 | int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); 65 | // 将宽高设置为传入宽高的最小值 66 | int size = measuredWidth > measuredHeight ? measuredHeight : measuredWidth; 67 | // 调用setMeasuredDimension设置View实际大小 68 | setMeasuredDimension(size, size); 69 | } 70 | } 71 | 72 | @Override 73 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 74 | super.onSizeChanged(w, h, oldw, oldh); 75 | int min = Math.min(w, h); 76 | int max = w + h - min; 77 | int r = Math.min(w, h) / 3; 78 | mBound.set((max >> 1) - r, (min >> 1) - r, (max >> 1) + r, (min >> 1) + r); 79 | } 80 | 81 | @Override 82 | protected void onDraw(Canvas canvas) { 83 | super.onDraw(canvas); 84 | if (mProgress != MAX_PROGRESS && mProgress != 0) { 85 | float mAngle = mProgress * 360f / MAX_PROGRESS; 86 | canvas.drawArc(mBound, 270, mAngle, true, mArcPaint); 87 | canvas.drawCircle(mBound.centerX(), mBound.centerY(), mBound.height() / 2, mCirclePaint); 88 | } 89 | } 90 | 91 | private float scale = 0; 92 | 93 | private int dpToPixel(float dp, Context context) { 94 | if (scale == 0) { 95 | scale = context.getResources().getDisplayMetrics().density; 96 | } 97 | return (int) (dp * scale); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/layout/activity_flow_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | 23 | 24 | 30 | 31 | 37 | 38 | 44 | 45 | 51 | 52 | 58 | 59 | 65 | 66 | 72 | 73 | 79 | 80 | 86 | 87 | 93 | 94 | 100 | 101 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/layout/activity_pie_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingking888/AndroidEngineerAdvanced/2ffe994b165851cc004b857913d5c40a93684d97/AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LagouCustomizedView 3 | 4 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/app/src/test/java/material/danny_jiang/com/lagoucustomizedview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.lagoucustomizedview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.4.1' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 02 12:22:37 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_fifteen/SourceCode/LagouCustomizedView/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "material.danny_jiang.com.dexclassloaderhotfix" 7 | minSdkVersion 22 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | } 29 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/androidTest/java/material/danny_jiang/com/dexclassloaderhotfix/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.dexclassloaderhotfix; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("material.danny_jiang.com.dexclassloaderhotfix", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/java/material/danny_jiang/com/dexclassloaderhotfix/ISay.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.dexclassloaderhotfix; 2 | 3 | /** 4 | * @author Danny 姜 5 | */ 6 | public interface ISay { 7 | String saySomething(); 8 | } 9 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/java/material/danny_jiang/com/dexclassloaderhotfix/MainActivity.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.dexclassloaderhotfix; 2 | 3 | import android.os.Environment; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.Toast; 9 | 10 | import java.io.File; 11 | 12 | import dalvik.system.DexClassLoader; 13 | 14 | /** 15 | * @author Danny 姜 16 | */ 17 | public class MainActivity extends AppCompatActivity { 18 | 19 | private static final String TAG = MainActivity.class.getSimpleName(); 20 | 21 | ISay say; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | 28 | Button btnSay = findViewById(R.id.btn_say); 29 | btnSay.setOnClickListener(new View.OnClickListener() { 30 | @Override 31 | public void onClick(View v) { 32 | // 获取hotfix的jar包文件 33 | final File jarFile = new File(Environment.getExternalStorageDirectory().getPath() 34 | + File.separator + "say_something_hotfix.jar"); 35 | 36 | if (!jarFile.exists()) { 37 | say = new SayException(); 38 | Toast.makeText(MainActivity.this, say.saySomething(), Toast.LENGTH_SHORT).show(); 39 | } else { 40 | // 只要有读写权限的路径均可 41 | DexClassLoader dexClassLoader = new DexClassLoader(jarFile.getAbsolutePath(), 42 | getExternalCacheDir().getAbsolutePath(), null, getClassLoader()); 43 | try { 44 | // 加载 SayHotFix 类 45 | Class clazz = dexClassLoader.loadClass("material.danny_jiang.com.dexclassloaderhotfix.SayHotFix"); 46 | // 强转成 ISay, 注意 ISay 的包名需要和hotfix jar包中的一致 47 | ISay iSay = (ISay) clazz.newInstance(); 48 | Toast.makeText(MainActivity.this, iSay.saySomething(), Toast.LENGTH_SHORT).show(); 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | } 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/java/material/danny_jiang/com/dexclassloaderhotfix/SayException.java: -------------------------------------------------------------------------------- 1 | package material.danny_jiang.com.dexclassloaderhotfix; 2 | 3 | /** 4 | * @author Danny 姜 5 | */ 6 | public class SayException implements ISay { 7 | @Override 8 | public String saySomething() { 9 | return "something wrong here!"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /AndroidLessons/lesson_five/SourceCode/DexClassLoaderHotFix/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 |