From 75cc9a8f87318b0a2b20e24b11b844772d253d2a Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 12 Aug 2019 09:46:03 +0800 Subject: [PATCH] Support day/night theme in custom tabs --- mobile/build.gradle | 2 +- mobile/src/main/java/be/mygod/vpnhotspot/App.kt | 13 ++++++++++--- mobile/src/main/res/values-night/colors.xml | 2 +- mobile/src/main/res/values/colors.xml | 5 ++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mobile/build.gradle b/mobile/build.gradle index 96e6d07e..81d28c06 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -75,7 +75,7 @@ androidExtensions { dependencies { kapt "androidx.room:room-compiler:$roomVersion" implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.browser:browser:1.0.0' + implementation 'androidx.browser:browser:1.2.0-alpha07' implementation 'androidx.core:core-ktx:1.1.0-rc03' implementation 'androidx.emoji:emoji:1.0.0' implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index 257f3ffb..e81ce3e7 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -8,6 +8,7 @@ import android.content.res.Configuration import android.net.ConnectivityManager import android.net.wifi.WifiManager import android.os.Build +import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent import androidx.core.content.ContextCompat import androidx.core.content.getSystemService @@ -78,8 +79,14 @@ class App : Application() { val hasTouch by lazy { packageManager.hasSystemFeature("android.hardware.faketouch") } val customTabsIntent by lazy { - CustomTabsIntent.Builder() - .setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)) - .build() + CustomTabsIntent.Builder().apply { + setColorScheme(CustomTabsIntent.COLOR_SCHEME_SYSTEM) + setColorSchemeParams(CustomTabsIntent.COLOR_SCHEME_LIGHT, CustomTabColorSchemeParams.Builder().apply { + setToolbarColor(ContextCompat.getColor(app, R.color.light_colorPrimary)) + }.build()) + setColorSchemeParams(CustomTabsIntent.COLOR_SCHEME_DARK, CustomTabColorSchemeParams.Builder().apply { + setToolbarColor(ContextCompat.getColor(app, R.color.dark_colorPrimary)) + }.build()) + }.build() } } diff --git a/mobile/src/main/res/values-night/colors.xml b/mobile/src/main/res/values-night/colors.xml index 4f30ef87..3803eff6 100644 --- a/mobile/src/main/res/values-night/colors.xml +++ b/mobile/src/main/res/values-night/colors.xml @@ -1,6 +1,6 @@ - #2e7d32 + @color/dark_colorPrimary #005005 #AEEA00 diff --git a/mobile/src/main/res/values/colors.xml b/mobile/src/main/res/values/colors.xml index c3e6806d..329530c6 100644 --- a/mobile/src/main/res/values/colors.xml +++ b/mobile/src/main/res/values/colors.xml @@ -1,6 +1,9 @@ - #4CAF50 + #4CAF50 + #2e7d32 + + @color/light_colorPrimary #087f23 #AEEA00 @android:color/black