From 207427babcbf511dbe6dc8e4f28d345646113302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E7=91=9E=E9=93=B6?= Date: Thu, 4 Apr 2019 00:11:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3support=20design=2028?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=8D=E9=80=82=E9=85=8D=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 50 ++++++++++++++---- .idea/caches/build_file_checksums.ser | Bin 603 -> 0 bytes .idea/codeStyles/Project.xml | 29 ---------- .idea/gradle.xml | 19 ------- .idea/misc.xml | 33 ------------ .idea/runConfigurations.xml | 12 ----- .idea/vcs.xml | 6 --- appbarlayoutbehavior/build.gradle | 7 +-- .../AppBarLayoutBehavior.java | 42 +++++++++++++-- build.gradle | 20 +++++++ sample/build.gradle | 21 ++++---- sample/src/main/res/layout/activity_main.xml | 24 ++++----- 12 files changed, 124 insertions(+), 139 deletions(-) delete mode 100644 .idea/caches/build_file_checksums.ser delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 5edb4ee..081b0e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,42 @@ +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Idea tool config +.idea *.iml -.gradle -/local.properties -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -.DS_Store -/build -/captures -.externalNativeBuild + +traces.txt + +reports/ + +*.DS_Store diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser deleted file mode 100644 index ae5cdb327bdacefd2d8d8434a50f20ef8008015e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 603 zcmZ4UmVvdnh`~NNKUXg?FQq6yGexf?KR>5fFEb@IQ7^qHF(oHeub?PDD>b=9F91S2 zm1gFoxMk*~I%lLNXBU^|7Q2L-Ts|(GuF1r}XAUQpdoSsKwaRyMH zmHpPi!(s^+nHiYe7`Srs6I0w0lS}f8JQ+AkGKx}*GxBp%Dhli!7(jrhoC8P-05Lnz zqTnf0c10Sz&hqb+mRXCzt;;G%0br9#Fy{kdvRBm;(x}g4Cjt%+%sixZ<5N zzeOBhu6i@-hGkSMkb3yv(>Fwzqpb3sQ%?kzFeoM#6eJ}U z_Ndl~AFLn34+f%|Ih=@rHw+ZYn3poE)^M}PM zhl2&5lJrX$H1$J^Q;UlAD@%(?Gb=Om^r4>D$74#>>QcG17kAlKzE(Iq diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index a6dad1e..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 821cf50..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/appbarlayoutbehavior/build.gradle b/appbarlayoutbehavior/build.gradle index d16a0ad..1d0a34c 100644 --- a/appbarlayoutbehavior/build.gradle +++ b/appbarlayoutbehavior/build.gradle @@ -6,11 +6,10 @@ group='com.github.yuruiyin' android { compileSdkVersion 27 - - defaultConfig { minSdkVersion 15 targetSdkVersion 27 + buildToolsVersion '27.0.3' versionCode 1 versionName "1.0" @@ -31,10 +30,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' } diff --git a/appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/AppBarLayoutBehavior.java b/appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/AppBarLayoutBehavior.java index dc93f38..9debb5e 100644 --- a/appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/AppBarLayoutBehavior.java +++ b/appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/AppBarLayoutBehavior.java @@ -49,6 +49,42 @@ public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout chil return super.onInterceptTouchEvent(parent, child, ev); } + /** + * 反射获取私有的flingRunnable 属性,考虑support 28以后变量名修改的问题 + * @return Field + * @throws NoSuchFieldException + */ + private Field getFlingRunnableField() throws NoSuchFieldException { + try { + // support design 27及一下版本 + Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass(); + return headerBehaviorType.getDeclaredField("mFlingRunnable"); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + // 可能是28及以上版本 + Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass().getSuperclass(); + return headerBehaviorType.getDeclaredField("flingRunnable"); + } + } + + /** + * 反射获取私有的scroller 属性,考虑support 28以后变量名修改的问题 + * @return Field + * @throws NoSuchFieldException + */ + private Field getScrollerField() throws NoSuchFieldException { + try { + // support design 27及一下版本 + Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass(); + return headerBehaviorType.getDeclaredField("mScroller"); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + // 可能是28及以上版本 + Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass().getSuperclass(); + return headerBehaviorType.getDeclaredField("scroller"); + } + } + /** * 停止appbarLayout的fling事件 * @param appBarLayout @@ -56,9 +92,9 @@ public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout chil private void stopAppbarLayoutFling(AppBarLayout appBarLayout) { //通过反射拿到HeaderBehavior中的flingRunnable变量 try { - Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass(); - Field flingRunnableField = headerBehaviorType.getDeclaredField("mFlingRunnable"); - Field scrollerField = headerBehaviorType.getDeclaredField("mScroller"); + Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass().getSuperclass(); + Field flingRunnableField = getFlingRunnableField(); + Field scrollerField = getScrollerField(); flingRunnableField.setAccessible(true); scrollerField.setAccessible(true); diff --git a/build.gradle b/build.gradle index 24e67e9..960a85d 100644 --- a/build.gradle +++ b/build.gradle @@ -29,3 +29,23 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } + +ext { + compileSdkVersion = 28 + buildToolsVersion = '28.0.3' + minSdkVersion = 15 + targetSdkVersion = 28 + androidSupportVersion = "28.0.0" +} + +subprojects { + project.configurations.all { + resolutionStrategy.eachDependency { details -> + if (details.requested.group == 'com.android.support' + && !details.requested.name.contains('multidex') ) { + details.useVersion androidSupportVersion + } + } + } +} + diff --git a/sample/build.gradle b/sample/build.gradle index d115179..aca86e8 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 + compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { applicationId "com.yuruiyin.sample" - minSdkVersion 15 - targetSdkVersion 27 - versionCode 2 - versionName "1.0.1" + minSdkVersion rootProject.ext.minSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 3 + versionName "1.0.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -25,9 +26,9 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' - implementation 'com.android.support.constraint:constraint-layout:1.1.2' + implementation "com.android.support:appcompat-v7:$androidSupportVersion" + implementation "com.android.support:design:$androidSupportVersion" + implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' @@ -39,6 +40,8 @@ dependencies { implementation project(':appbarlayoutbehavior') -// implementation 'com.github.yuruiyin:AppbarLayoutBehavior:v1.0.0' +// implementation 'com.github.yuruiyin:AppbarLayoutBehavior:v1.0.1' } + + diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 398a221..60c38b3 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -19,16 +19,17 @@ + app:layout_scrollFlags="scroll|exitUntilCollapsed" + > @@ -40,7 +41,8 @@ android:layout_height="@dimen/common_tab_height" android:layout_gravity="left" android:background="@color/white" - android:visibility="visible"/> + android:visibility="visible" + /> - - - - - + app:layout_behavior="@string/appbar_scrolling_view_behavior" + /> \ No newline at end of file