Skip to content

Commit b45a2cc

Browse files
committed
FIX: StatusBarAppearanceManager 수정
1 parent b924953 commit b45a2cc

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

presentation/src/main/java/com/threegap/bitnagil/presentation/util/statusbar/NavStatusBarEffect.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun NavStatusBarEffect(navController: NavController) {
1717
LaunchedEffect(navBackStackEntry) {
1818
navBackStackEntry?.repeatOnLifecycle(Lifecycle.State.RESUMED) {
1919
activity?.window?.let { window ->
20-
StatusBarAppearanceManager().applyStatusBarColorByLuminance(window)
20+
StatusBarAppearanceManager.applyStatusBarColorByLuminance(window)
2121
}
2222
}
2323
}

presentation/src/main/java/com/threegap/bitnagil/presentation/util/statusbar/StatusBarAppearanceManager.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import androidx.core.view.WindowInsetsCompat
1313
import androidx.core.graphics.get
1414
import androidx.core.view.WindowInsetsControllerCompat
1515

16-
class StatusBarAppearanceManager {
16+
object StatusBarAppearanceManager {
17+
private const val LUMINANCE_THRESHOLD = 150
18+
1719
fun applyStatusBarColorByLuminance(window: Window) {
1820
val height = getStatusBarHeight(window = window)
1921
if (height <= 0) return
@@ -24,7 +26,8 @@ class StatusBarAppearanceManager {
2426
) { bmp ->
2527
bmp?.let {
2628
val lum = calculateLuminance(it)
27-
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars = (lum > 150)
29+
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars = (lum > LUMINANCE_THRESHOLD)
30+
it.recycle()
2831
}
2932
}
3033
}
@@ -40,9 +43,28 @@ class StatusBarAppearanceManager {
4043
height: Int,
4144
onResult: (Bitmap?) -> Unit
4245
) {
46+
val width = window.decorView.width
47+
if (width <= 0) {
48+
onResult(null)
49+
return
50+
}
51+
4352
val rect = Rect(0, 0, window.decorView.width, height)
4453
val bmp = createBitmap(rect.width(), rect.height())
45-
PixelCopy.request(window, rect, bmp, {_ -> onResult(bmp)}, Handler(Looper.getMainLooper()))
54+
55+
try {
56+
PixelCopy.request(window, rect, bmp, { result ->
57+
if (result == PixelCopy.SUCCESS) {
58+
onResult(bmp)
59+
} else {
60+
bmp.recycle()
61+
onResult(null)
62+
}
63+
}, Handler(Looper.getMainLooper()))
64+
} catch (_: Exception) {
65+
bmp.recycle()
66+
onResult(null)
67+
}
4668
}
4769

4870
private fun calculateLuminance(bitmap: Bitmap): Int {

0 commit comments

Comments
 (0)