Skip to content

Commit

Permalink
适配M
Browse files Browse the repository at this point in the history
  • Loading branch information
ifan-ge committed Feb 8, 2022
1 parent 9c59a25 commit 8697c4f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 57 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.util.function.Consumer
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.32'
ext.kotlin_version = '1.6.10'
ext.immersionbar_version = '3.0.0'
repositories {
google()
Expand All @@ -12,7 +12,7 @@ buildscript {
}
dependencies {

classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
6 changes: 3 additions & 3 deletions immersionbar-components/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 31
}

buildTypes {
Expand All @@ -18,6 +18,6 @@ android {
}

dependencies {
compileOnly 'androidx.appcompat:appcompat:1.2.0'
compileOnly 'androidx.appcompat:appcompat:1.4.1'
compileOnly project(':immersionbar')
}
6 changes: 3 additions & 3 deletions immersionbar-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 31
}

buildTypes {
Expand All @@ -19,7 +19,7 @@ android {

dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compileOnly 'androidx.appcompat:appcompat:1.2.0'
compileOnly 'androidx.appcompat:appcompat:1.4.1'
compileOnly project(':immersionbar')
}

Expand Down
21 changes: 11 additions & 10 deletions immersionbar-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
applicationId "com.gyf.immersionbar.sample"
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "$immersionbar_version"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -29,18 +29,18 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding = true
viewBinding true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
implementation project(':immersionbar')
Expand All @@ -58,27 +58,28 @@ dependencies {
//RecyclerView框架
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.47'
//图片加载框架
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
//下拉刷新上拉加载
implementation 'com.lcodecorex:tkrefreshlayout:1.0.7'
//圆形imageView
implementation 'de.hdodenhof:circleimageview:3.0.0'
// 内存泄漏检测
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
// Fragment框架
implementation 'me.yokeyword:fragmentationx:1.0.1'
//腾讯bugly
implementation 'com.tencent.bugly:crashreport:3.3.3'
// Rx
implementation "io.reactivex.rxjava2:rxjava:2.2.8"
implementation "io.reactivex.rxjava2:rxjava:2.2.19"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// EventBus
implementation 'org.greenrobot:eventbus:3.1.1'

implementation 'jp.wasabeef:blurry:3.0.0'
implementation "androidx.multidex:multidex:2.0.1"
}
repositories {
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions immersionbar-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<activity
android:name="com.gyf.immersionbar.sample.activity.MainActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden"
android:exported="true"
android:theme="@style/SplashAppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.gyf.immersionbar.sample.service.NetworkService;
Expand Down
7 changes: 4 additions & 3 deletions immersionbar/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 31
}
lintOptions {
checkReleaseBuilds false
Expand All @@ -16,5 +16,6 @@ android {
}

dependencies {
compileOnly 'androidx.appcompat:appcompat:1.2.0'
compileOnly 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.core:core:1.7.0'
}
95 changes: 60 additions & 35 deletions immersionbar/src/main/java/com/gyf/immersionbar/ImmersionBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -354,6 +357,7 @@ void setBar() {
uiFlags = hideBar(uiFlags);
mDecorView.setSystemUiVisibility(uiFlags);
setSpecialBarDarkMode();
adapterM();
//导航栏显示隐藏监听,目前只支持带有导航栏的华为和小米手机
if (mBarParams.onNavigationBarListener != null) {
NavigationBarObserver.getInstance().register(mActivity.getApplication());
Expand Down Expand Up @@ -548,26 +552,6 @@ private void adjustDarkModeParams() {
*/
private int hideBar(int uiFlags) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController controller = mContentView.getWindowInsetsController();
switch (mBarParams.barHide) {
case FLAG_HIDE_BAR:
controller.hide(WindowInsets.Type.statusBars());
controller.hide(WindowInsets.Type.navigationBars());
break;
case FLAG_HIDE_STATUS_BAR:
controller.hide(WindowInsets.Type.statusBars());
break;
case FLAG_HIDE_NAVIGATION_BAR:
controller.hide(WindowInsets.Type.navigationBars());
break;
case FLAG_SHOW_BAR:
controller.show(WindowInsets.Type.statusBars());
controller.show(WindowInsets.Type.navigationBars());
break;
default:
break;
}
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
return uiFlags;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
switch (mBarParams.barHide) {
Expand Down Expand Up @@ -693,7 +677,6 @@ private void fitsWindowsKITKAT() {
right = mBarConfig.getNavigationBarWidth();
}
}

}
setPadding(0, top, right, bottom);
}
Expand Down Expand Up @@ -776,21 +759,13 @@ public void onNavigationBarChange(boolean show, NavigationBarType type) {
*/
private int setStatusBarDarkFont(int uiFlags) {
if (mBarParams.statusBarDarkFont) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController controller = mContentView.getWindowInsetsController();
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
return uiFlags;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return uiFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
return uiFlags;
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController controller = mContentView.getWindowInsetsController();
controller.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
return uiFlags;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return uiFlags & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
return uiFlags;
Expand All @@ -805,8 +780,6 @@ private int setStatusBarDarkFont(int uiFlags) {
private int setNavigationIconDark(int uiFlags) {
if (mBarParams.navigationBarDarkIcon) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController controller = mContentView.getWindowInsetsController();
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);
return uiFlags;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return uiFlags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
Expand All @@ -815,8 +788,6 @@ private int setNavigationIconDark(int uiFlags) {
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController controller = mContentView.getWindowInsetsController();
controller.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);
return uiFlags;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return uiFlags & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
Expand All @@ -826,6 +797,60 @@ private int setNavigationIconDark(int uiFlags) {
}
}

/**
* 适配M以上机型
*/
private void adapterM() {
setStatusBarDarkFontAboutM();
setNavigationIconDarkAboutM();
hideBarAboutM();
}

private void setStatusBarDarkFontAboutM() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsControllerCompat controller = ViewCompat.getWindowInsetsController(mContentView);
if (controller != null) {
controller.setAppearanceLightStatusBars(mBarParams.statusBarDarkFont);
}
}
}

private void setNavigationIconDarkAboutM() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsControllerCompat controller = ViewCompat.getWindowInsetsController(mContentView);
if (controller != null) {
controller.setAppearanceLightNavigationBars(mBarParams.navigationBarDarkIcon);
}
}
}

private void hideBarAboutM() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsControllerCompat controller = ViewCompat.getWindowInsetsController(mContentView);
if (controller != null) {
switch (mBarParams.barHide) {
case FLAG_HIDE_BAR:
controller.hide(WindowInsetsCompat.Type.statusBars());
controller.hide(WindowInsetsCompat.Type.navigationBars());
break;
case FLAG_HIDE_STATUS_BAR:
controller.hide(WindowInsetsCompat.Type.statusBars());
break;
case FLAG_HIDE_NAVIGATION_BAR:
controller.hide(WindowInsetsCompat.Type.navigationBars());
break;
case FLAG_SHOW_BAR:
controller.show(WindowInsetsCompat.Type.statusBars());
controller.show(WindowInsetsCompat.Type.navigationBars());
break;
default:
break;
}
controller.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
}
}

/**
* 适配状态栏与布局重叠问题
* Fits layout overlap.
Expand Down

0 comments on commit 8697c4f

Please sign in to comment.