From eda4049a0142029c192e1690bafffbb98ee4ff99 Mon Sep 17 00:00:00 2001 From: Bartlomiej Moskal Date: Wed, 14 Dec 2022 11:17:46 +0100 Subject: [PATCH] Android: Fix for low contrast status bar After we start to use THEME: Theme_DeviceDefault_DayNight, status bar icons have low contrasts on some devices. That is why we need to set APPEARANCE_LIGHT_STATUS_BARS[0] in case when Status bar color is too bright. [0]https://developer.android.com/reference/android/view/WindowInsetsController#APPEARANCE_LIGHT_STATUS_BARS Fixes: QTBUG-108365 Pick-to: 6.5 6.4 6.2 Change-Id: I38a31cfb0a3a1b912b86ed1b302c567e14a7ffcc Reviewed-by: Assam Boudjelthia --- .../qtproject/qt/android/QtActivityDelegate.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java index 05c1cef7c6..bf17f9fcad 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java @@ -14,6 +14,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; import android.content.res.Configuration; +import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.Rect; @@ -43,6 +44,8 @@ import android.view.Surface; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowInsetsController; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.view.ViewTreeObserver; @@ -978,6 +981,19 @@ public class QtActivityDelegate private void handleUiModeChange(int uiMode) { + // QTBUG-108365 + if (Build.VERSION.SDK_INT >= 29) { + // Since 29 version we are using Theme_DeviceDefault_DayNight + Window window = m_activity.getWindow(); + WindowInsetsController controller = window.getInsetsController(); + if (controller != null) { + // set APPEARANCE_LIGHT_STATUS_BARS if needed + int appearanceLight = Color.luminance(window.getStatusBarColor()) > 0.5 ? + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS : 0; + controller.setSystemBarsAppearance(appearanceLight, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS); + } + } switch (uiMode) { case Configuration.UI_MODE_NIGHT_NO: ExtractStyle.runIfNeeded(m_activity, false);