Implement Edge-to-edge with newer APIs

The implementation adds a "Base" family styles, making creating themes across multiple API versions more clearer and easier.
This commit is contained in:
RikkaW 2020-10-22 16:11:07 +08:00 committed by John Wu
parent 0064b01ae0
commit c93ada03c7
10 changed files with 168 additions and 28 deletions

View File

@ -1,5 +1,8 @@
package com.topjohnwu.magisk.arch package com.topjohnwu.magisk.arch
import android.content.res.Resources
import android.graphics.Color
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
@ -59,6 +62,31 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
directionsDispatcher.value = null directionsDispatcher.value = null
} }
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window?.decorView?.let {
it.systemUiVisibility = (it.systemUiVisibility
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
window?.decorView?.post {
// If navigation bar is short enough (gesture navigation enabled), make it transparent
if (window.decorView.rootWindowInsets?.systemWindowInsetBottom ?: 0 < Resources.getSystem().displayMetrics.density * 40) {
window.navigationBarColor = Color.TRANSPARENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.navigationBarDividerColor = Color.TRANSPARENT
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
window.isStatusBarContrastEnforced = false
}
}
}
}
}
} }
fun setContentView() { fun setContentView() {

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SplashTheme" parent="Theme.Splash" />
<style name="Foundation" parent="Theme.Foundation" />
</resources>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SplashTheme" parent="SplashThemeBase">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V19.Theme.Splash.Light" parent="Base.V17.Theme.Splash.Light">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="Base.V19.Theme.Splash" parent="Base.V17.Theme.Splash">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="Theme.Splash.Light" parent="Base.V19.Theme.Splash.Light" />
<style name="Theme.Splash" parent="Base.V19.Theme.Splash" />
</resources>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Foundation.Compat">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V21.Theme.Foundation.Light" parent="Base.V17.Theme.Foundation.Light">
<item name="android:statusBarColor">#38000000</item>
<item name="android:navigationBarColor">#38000000</item>
</style>
<style name="Base.V21.Theme.Foundation" parent="Base.V17.Theme.Foundation">
<item name="android:statusBarColor">#60000000</item>
<item name="android:navigationBarColor">#60000000</item>
</style>
<style name="Theme.Foundation.Light" parent="Base.V21.Theme.Foundation.Light" />
<style name="Theme.Foundation" parent="Base.V21.Theme.Foundation" />
<style name="Base.V21.Theme.Splash.Light" parent="Base.V19.Theme.Splash.Light">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="Base.V21.Theme.Splash" parent="Base.V19.Theme.Splash">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="Theme.Splash.Light" parent="Base.V21.Theme.Splash.Light" />
<style name="Theme.Splash" parent="Base.V21.Theme.Splash" />
</resources>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V23.Theme.Foundation.Light" parent="Base.V21.Theme.Foundation.Light">
<item name="android:statusBarColor">#40bdbdbd</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="Theme.Foundation.Light" parent="Base.V23.Theme.Foundation.Light" />
<style name="Base.V23.Theme.Splash.Light" parent="Base.V21.Theme.Splash.Light">
<item name="android:windowLightStatusBar">false</item>
</style>
<style name="Theme.Splash.Light" parent="Base.V23.Theme.Splash.Light" />
</resources>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V27.Theme.Foundation.Light" parent="Base.V23.Theme.Foundation.Light">
<item name="android:navigationBarColor">#e0fafafa</item>
<item name="android:navigationBarDividerColor">#1f000000</item>
<item name="android:windowLightNavigationBar">true</item>
</style>
<style name="Base.V27.Theme.Foundation" parent="Base.V21.Theme.Foundation">
<item name="android:navigationBarDividerColor">@android:color/transparent</item>
</style>
<style name="Theme.Foundation.Light" parent="Base.V27.Theme.Foundation.Light" />
<style name="Theme.Foundation" parent="Base.V27.Theme.Foundation" />
<style name="Base.V27.Theme.Splash.Light" parent="Base.V23.Theme.Splash.Light">
<item name="android:windowLightNavigationBar">false</item>
</style>
<style name="Theme.Splash.Light" parent="Base.V27.Theme.Splash.Light" />
</resources>

View File

@ -1,20 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="SplashThemeBase" parent="android:Theme.DeviceDefault.NoActionBar"> <style name="SplashTheme" parent="Theme.Splash.Light" />
<item name="android:windowBackground">@drawable/ic_splash_activity</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="SplashTheme" parent="SplashThemeBase" /> <style name="Foundation" parent="Theme.Foundation.Light" />
<style name="Foundation" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowBackground">?colorSurface</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<!--This should be overridden in v21 for transparency, etc-->
<style name="Foundation.Compat" />
<!--region Do not remove--> <!--region Do not remove-->
<style name="Empty" /> <style name="Empty" />
@ -28,7 +17,7 @@
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
</style> </style>
<style name="Foundation.Default" parent="Foundation.Compat"> <style name="Foundation.Default">
<item name="android:includeFontPadding">false</item> <item name="android:includeFontPadding">false</item>
<item name="actionBarSize">@dimen/internal_action_bar_size</item> <item name="actionBarSize">@dimen/internal_action_bar_size</item>
<item name="popupMenuStyle">@style/Foundation.PopupMenu</item> <item name="popupMenuStyle">@style/Foundation.PopupMenu</item>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V17.Theme.Foundation.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowBackground">?colorSurface</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="Base.V17.Theme.Foundation" parent="Theme.MaterialComponents.NoActionBar">
<item name="android:windowBackground">?colorSurface</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="Theme.Foundation.Light" parent="Base.V17.Theme.Foundation.Light" />
<style name="Theme.Foundation" parent="Base.V17.Theme.Foundation" />
<style name="Base.V17.Theme.Splash.Light" parent="android:Theme.DeviceDefault.Light.NoActionBar">
<item name="android:windowBackground">@drawable/ic_splash_activity</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="Base.V17.Theme.Splash" parent="android:Theme.DeviceDefault.NoActionBar">
<item name="android:windowBackground">@drawable/ic_splash_activity</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="Theme.Splash.Light" parent="Base.V17.Theme.Splash.Light" />
<style name="Theme.Splash" parent="Base.V17.Theme.Splash" />
</resources>