From 4d5e182ce5090c4cfad9261d3802a0f51dc6f3ac Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Jun 2025 16:21:24 +0200 Subject: [PATCH 1/3] add documentation Signed-off-by: alperozturk --- .../extensions/AppCompatActivityExtensions.kt | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt b/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt index 122a96d3..458a55ae 100644 --- a/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt +++ b/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt @@ -31,15 +31,46 @@ fun AppCompatActivity.adjustUIForAPILevel35( window.addSystemBarPaddings() } + +/** + * Initializes the status bar color with Android 15+ compatibility handling. + * + * This function provides a unified approach to setting status bar colors across different + * Android versions, with special handling for Android 15 (VANILLA_ICE_CREAM) and above + * where direct status bar color modification is no longer supported. + * + * ## Android Version Compatibility: + * + * ### Android 14 and below (API < 35): + * - Uses the traditional `Window.setStatusBarColor()` method + * + * ### Android 15+ (API 35+): + * - **⚠️ IMPORTANT**: Direct status bar color modification is NOT possible + * - Uses a workaround by applying top padding equal to status bar height + * - Sets the view's background color to simulate the desired appearance + * - This is a visual approximation, not actual status bar color change + * + * @param color The desired color as a ColorInt. On Android 15+, this will be applied + * to the view background rather than the actual status bar. + * + * @see [Android Documentation](https://developer.android.com/reference/kotlin/android/view/Window#setstatusbarcolor) + * @see Window.setStatusBarColor (deprecated in API 35) + * + * + * @warning On Android 15+, this is a visual workaround only. The actual status bar + * color cannot be modified and will remain transparent with system-managed contrast. + */ fun AppCompatActivity.initStatusBar( @ColorInt color: Int ) { window.decorView.setOnApplyWindowInsetsListener { view, insets -> - view.setBackgroundColor(color) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { val statusBarHeight = insets.getInsets(WindowInsets.Type.statusBars()).top view.setPadding(0, statusBarHeight, 0, 0) + view.setBackgroundColor(color) + } else { + @Suppress("DEPRECATION") + window.statusBarColor = color } insets From 411419606194d61451b1d2ae62878a63cf3645a2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Jun 2025 16:30:40 +0200 Subject: [PATCH 2/3] add documentation Signed-off-by: alperozturk --- .../ui/util/extensions/AppCompatActivityExtensions.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt b/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt index 458a55ae..34fd0093 100644 --- a/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt +++ b/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt @@ -33,7 +33,6 @@ fun AppCompatActivity.adjustUIForAPILevel35( /** - * Initializes the status bar color with Android 15+ compatibility handling. * * This function provides a unified approach to setting status bar colors across different * Android versions, with special handling for Android 15 (VANILLA_ICE_CREAM) and above @@ -45,17 +44,15 @@ fun AppCompatActivity.adjustUIForAPILevel35( * - Uses the traditional `Window.setStatusBarColor()` method * * ### Android 15+ (API 35+): - * - **⚠️ IMPORTANT**: Direct status bar color modification is NOT possible + * - **⚠ IMPORTANT**: Direct status bar color modification is NOT possible * - Uses a workaround by applying top padding equal to status bar height * - Sets the view's background color to simulate the desired appearance * - This is a visual approximation, not actual status bar color change * - * @param color The desired color as a ColorInt. On Android 15+, this will be applied - * to the view background rather than the actual status bar. - * - * @see [Android Documentation](https://developer.android.com/reference/kotlin/android/view/Window#setstatusbarcolor) - * @see Window.setStatusBarColor (deprecated in API 35) + * * @see [Android Documentation](https://developer.android.com/reference/kotlin/android/view/Window#setstatusbarcolor) + * * @see Window.setStatusBarColor (deprecated in API 35) * + * @param color The desired color as a ColorInt. * * @warning On Android 15+, this is a visual workaround only. The actual status bar * color cannot be modified and will remain transparent with system-managed contrast. From 071bc3a7ddb55189b637df68b62aed1065e2d7fc Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Jun 2025 16:35:36 +0200 Subject: [PATCH 3/3] fix kt spotless Signed-off-by: alperozturk --- .../common/ui/util/extensions/AppCompatActivityExtensions.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt b/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt index 34fd0093..c1b02738 100644 --- a/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt +++ b/ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/AppCompatActivityExtensions.kt @@ -31,7 +31,6 @@ fun AppCompatActivity.adjustUIForAPILevel35( window.addSystemBarPaddings() } - /** * * This function provides a unified approach to setting status bar colors across different