From c93ada03c74fba60027919fa87e1cb6ab7bf43c4 Mon Sep 17 00:00:00 2001 From: RikkaW Date: Thu, 22 Oct 2020 16:11:07 +0800 Subject: [PATCH] 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. --- .../topjohnwu/magisk/arch/BaseUIActivity.kt | 28 ++++++++++++++ app/src/main/res/values-night/styles_md2.xml | 8 ++++ app/src/main/res/values-v19/styles_md2.xml | 7 ---- app/src/main/res/values-v19/themes.xml | 18 +++++++++ app/src/main/res/values-v21/styles_md2.xml | 7 ---- app/src/main/res/values-v21/themes.xml | 38 +++++++++++++++++++ app/src/main/res/values-v23/themes.xml | 17 +++++++++ app/src/main/res/values-v27/themes.xml | 24 ++++++++++++ app/src/main/res/values/styles_md2.xml | 17 ++------- app/src/main/res/values/themes.xml | 32 ++++++++++++++++ 10 files changed, 168 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/values-night/styles_md2.xml delete mode 100644 app/src/main/res/values-v19/styles_md2.xml create mode 100644 app/src/main/res/values-v19/themes.xml delete mode 100644 app/src/main/res/values-v21/styles_md2.xml create mode 100644 app/src/main/res/values-v21/themes.xml create mode 100644 app/src/main/res/values-v23/themes.xml create mode 100644 app/src/main/res/values-v27/themes.xml create mode 100644 app/src/main/res/values/themes.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIActivity.kt b/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIActivity.kt index e327820e5..2f3c0da00 100644 --- a/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIActivity.kt @@ -1,5 +1,8 @@ package com.topjohnwu.magisk.arch +import android.content.res.Resources +import android.graphics.Color +import android.os.Build import android.os.Bundle import android.view.KeyEvent import android.view.View @@ -59,6 +62,31 @@ abstract class BaseUIActivity : 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() { diff --git a/app/src/main/res/values-night/styles_md2.xml b/app/src/main/res/values-night/styles_md2.xml new file mode 100644 index 000000000..2c8a3c5c3 --- /dev/null +++ b/app/src/main/res/values-night/styles_md2.xml @@ -0,0 +1,8 @@ + + + + - diff --git a/app/src/main/res/values-v19/themes.xml b/app/src/main/res/values-v19/themes.xml new file mode 100644 index 000000000..6b4e43bf4 --- /dev/null +++ b/app/src/main/res/values-v19/themes.xml @@ -0,0 +1,18 @@ + + + + + + + + - diff --git a/app/src/main/res/values-v21/themes.xml b/app/src/main/res/values-v21/themes.xml new file mode 100644 index 000000000..54ccddd36 --- /dev/null +++ b/app/src/main/res/values-v21/themes.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + +