From 06b5c69cae1b0c1dc8e05efaaba8343050728cee Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 3 Jul 2022 13:38:10 +0200 Subject: [PATCH] Fix android navigation panel color --- .../android/platformhelperandroid.cpp | 66 ++++++++++++++----- .../android/platformhelperandroid.h | 1 + 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/nymea-app/platformintegration/android/platformhelperandroid.cpp b/nymea-app/platformintegration/android/platformhelperandroid.cpp index 318fa18e..01655bee 100644 --- a/nymea-app/platformintegration/android/platformhelperandroid.cpp +++ b/nymea-app/platformintegration/android/platformhelperandroid.cpp @@ -38,9 +38,11 @@ // WindowManager.LayoutParams #define FLAG_TRANSLUCENT_STATUS 0x04000000 +#define FLAG_TRANSLUCENT_NAVIGATION 0x08000000 #define FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 0x80000000 // View #define SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 0x00002000 +#define SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR 0x00000010 static PlatformHelperAndroid *m_instance = nullptr; @@ -197,6 +199,53 @@ void PlatformHelperAndroid::setBottomPanelColor(const QColor &color) if (QtAndroid::androidSdkVersion() < 21) return; + + QtAndroid::runOnAndroidThread([=]() { + QAndroidJniObject window = getAndroidWindow(); + window.callMethod("clearFlags", "(I)V", FLAG_TRANSLUCENT_NAVIGATION); + window.callMethod("setNavigationBarColor", "(I)V", color.rgba()); + + if (((color.red() * 299 + color.green() * 587 + color.blue() * 114) / 1000) > 123) { + setBottomPanelTheme(Light); + } else { + setBottomPanelTheme(Dark); + } + }); +} + +void PlatformHelperAndroid::setTopPanelTheme(PlatformHelperAndroid::Theme theme) +{ + if (QtAndroid::androidSdkVersion() < 23) + return; + + QtAndroid::runOnAndroidThread([=]() { + QAndroidJniObject window = getAndroidWindow(); + QAndroidJniObject view = window.callObjectMethod("getDecorView", "()Landroid/view/View;"); + int visibility = view.callMethod("getSystemUiVisibility", "()I"); + if (theme == Theme::Light) + visibility |= SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + else + visibility &= ~SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + view.callMethod("setSystemUiVisibility", "(I)V", visibility); + }); +} + +void PlatformHelperAndroid::setBottomPanelTheme(Theme theme) +{ + if (QtAndroid::androidSdkVersion() < 23) + return; + + QtAndroid::runOnAndroidThread([=]() { + QAndroidJniObject window = getAndroidWindow(); + QAndroidJniObject view = window.callObjectMethod("getDecorView", "()Landroid/view/View;"); + int visibility = view.callMethod("getSystemUiVisibility", "()I"); + if (theme == Theme::Light) + visibility |= SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + else + visibility &= ~SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + view.callMethod("setSystemUiVisibility", "(I)V", visibility); + }); + } bool PlatformHelperAndroid::darkModeEnabled() const @@ -225,20 +274,3 @@ void PlatformHelperAndroid::darkModeEnabledChangedJNI() emit m_instance->darkModeEnabledChanged(); } } - -void PlatformHelperAndroid::setTopPanelTheme(PlatformHelperAndroid::Theme theme) -{ - if (QtAndroid::androidSdkVersion() < 23) - return; - - QtAndroid::runOnAndroidThread([=]() { - QAndroidJniObject window = getAndroidWindow(); - QAndroidJniObject view = window.callObjectMethod("getDecorView", "()Landroid/view/View;"); - int visibility = view.callMethod("getSystemUiVisibility", "()I"); - if (theme == Theme::Light) - visibility |= SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - else - visibility &= ~SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - view.callMethod("setSystemUiVisibility", "(I)V", visibility); - }); -} diff --git a/nymea-app/platformintegration/android/platformhelperandroid.h b/nymea-app/platformintegration/android/platformhelperandroid.h index bfbe5c7e..50a5554f 100644 --- a/nymea-app/platformintegration/android/platformhelperandroid.h +++ b/nymea-app/platformintegration/android/platformhelperandroid.h @@ -61,6 +61,7 @@ public: void setTopPanelColor(const QColor &color) override; void setTopPanelTheme(Theme theme); void setBottomPanelColor(const QColor &color) override; + void setBottomPanelTheme(Theme theme); bool darkModeEnabled() const override;