From b5138e9d910b9a4b5e7f36d050c02c28fddd2599 Mon Sep 17 00:00:00 2001 From: Batmancpu Date: Mon, 9 Nov 2026 08:27:55 +0530 Subject: [PATCH 1/3] Add Reduce Transparency policy for dictionary popup --- .../currentlens/DictionarySurfacePolicy.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/src/main/java/com/mangoloads/currentlens/DictionarySurfacePolicy.kt diff --git a/app/src/main/java/com/mangoloads/currentlens/DictionarySurfacePolicy.kt b/app/src/main/java/com/mangoloads/currentlens/DictionarySurfacePolicy.kt new file mode 100644 index 00000000..7cc8906d --- /dev/null +++ b/app/src/main/java/com/mangoloads/currentlens/DictionarySurfacePolicy.kt @@ -0,0 +1,36 @@ +package com.mangoloads.currentlens + +/** + * Resolves the dictionary popup's surface treatment from the app's saved + * Reduce Transparency preference and the platform's blur-behind capability. + * + * The reduced mode is deliberately opaque and never requests window blur. + */ +internal data class DictionarySurfaceAppearance( + val blurBehindEnabled: Boolean, + val surfaceAlpha: Float +) + +internal object DictionarySurfacePolicy { + const val REDUCED_TRANSPARENCY_ALPHA = 0.985f + const val MODERN_GLASS_ALPHA = 0.86f + const val LEGACY_SURFACE_ALPHA = 0.94f + + fun resolve( + reduceTransparency: Boolean, + supportsBlurBehind: Boolean + ): DictionarySurfaceAppearance = when { + reduceTransparency -> DictionarySurfaceAppearance( + blurBehindEnabled = false, + surfaceAlpha = REDUCED_TRANSPARENCY_ALPHA + ) + supportsBlurBehind -> DictionarySurfaceAppearance( + blurBehindEnabled = true, + surfaceAlpha = MODERN_GLASS_ALPHA + ) + else -> DictionarySurfaceAppearance( + blurBehindEnabled = false, + surfaceAlpha = LEGACY_SURFACE_ALPHA + ) + } +} From a16a0120f83fce74830aa64f0312fc48804360e1 Mon Sep 17 00:00:00 2001 From: Batmancpu Date: Mon, 9 Nov 2026 08:27:58 +0530 Subject: [PATCH 2/3] Test dictionary popup Reduce Transparency behaviour --- .../DictionarySurfacePolicyTest.kt | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/src/test/java/com/mangoloads/currentlens/DictionarySurfacePolicyTest.kt diff --git a/app/src/test/java/com/mangoloads/currentlens/DictionarySurfacePolicyTest.kt b/app/src/test/java/com/mangoloads/currentlens/DictionarySurfacePolicyTest.kt new file mode 100644 index 00000000..a3f957a7 --- /dev/null +++ b/app/src/test/java/com/mangoloads/currentlens/DictionarySurfacePolicyTest.kt @@ -0,0 +1,52 @@ +package com.mangoloads.currentlens + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class DictionarySurfacePolicyTest { + @Test + fun reducedTransparencyDisablesBlurAndUsesOpaqueSurfaceOnModernAndroid() { + val appearance = DictionarySurfacePolicy.resolve( + reduceTransparency = true, + supportsBlurBehind = true + ) + + assertFalse(appearance.blurBehindEnabled) + assertEquals(0.985f, appearance.surfaceAlpha, 0f) + } + + @Test + fun normalAppearanceKeepsBlurBehindOnSupportedAndroid() { + val appearance = DictionarySurfacePolicy.resolve( + reduceTransparency = false, + supportsBlurBehind = true + ) + + assertTrue(appearance.blurBehindEnabled) + assertEquals(0.86f, appearance.surfaceAlpha, 0f) + } + + @Test + fun normalAppearanceKeepsExistingOpaqueFallbackOnOlderAndroid() { + val appearance = DictionarySurfacePolicy.resolve( + reduceTransparency = false, + supportsBlurBehind = false + ) + + assertFalse(appearance.blurBehindEnabled) + assertEquals(0.94f, appearance.surfaceAlpha, 0f) + } + + @Test + fun reducedTransparencyNeverEnablesBlurOnOlderAndroid() { + val appearance = DictionarySurfacePolicy.resolve( + reduceTransparency = true, + supportsBlurBehind = false + ) + + assertFalse(appearance.blurBehindEnabled) + assertEquals(0.985f, appearance.surfaceAlpha, 0f) + } +} From 55afb9ab662d2926675f0a57737d3f817b1fc2cb Mon Sep 17 00:00:00 2001 From: Batmancpu Date: Mon, 9 Nov 2026 08:28:11 +0530 Subject: [PATCH 3/3] Honor Reduce Transparency in dictionary popup --- .../currentlens/DictionaryActivity.kt | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/mangoloads/currentlens/DictionaryActivity.kt b/app/src/main/java/com/mangoloads/currentlens/DictionaryActivity.kt index d30b0a4d..fe878fec 100644 --- a/app/src/main/java/com/mangoloads/currentlens/DictionaryActivity.kt +++ b/app/src/main/java/com/mangoloads/currentlens/DictionaryActivity.kt @@ -221,17 +221,41 @@ class DictionaryActivity : ComponentActivity() { window?.setBackgroundDrawableResource(android.R.color.transparent) window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) window?.attributes = window?.attributes?.apply { dimAmount = 0.08f } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - // Blur-behind samples the whole app window, unlike a blur confined to this popup. - window?.addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND) - window?.attributes = window?.attributes?.apply { - blurBehindRadius = (resources.displayMetrics.density * 24f).toInt() - } - } window?.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT) window?.decorView?.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK) window?.setGravity(Gravity.BOTTOM) setContent { + // Fail closed to an opaque, unblurred surface until the saved preference is + // restored. SharedPreferences is read on IO because it shares a file with + // the app's article and study data. + var reduceTransparency by remember { mutableStateOf(true) } + LaunchedEffect(Unit) { + val restored = withContext(Dispatchers.IO) { + LocalStore.reduceTransparency(applicationContext) + } + reduceTransparency = restored + val appearance = DictionarySurfacePolicy.resolve( + reduceTransparency = restored, + supportsBlurBehind = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (appearance.blurBehindEnabled) { + // Blur-behind samples the whole app window, unlike a blur confined to this popup. + window?.addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND) + window?.attributes = window?.attributes?.apply { + blurBehindRadius = (resources.displayMetrics.density * 24f).toInt() + } + } else { + window?.clearFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND) + } + } + } + val surfaceAppearance = remember(reduceTransparency) { + DictionarySurfacePolicy.resolve( + reduceTransparency = reduceTransparency, + supportsBlurBehind = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + ) + } val dark = androidx.compose.foundation.isSystemInDarkTheme() MaterialTheme( colorScheme = if (dark) { @@ -258,14 +282,17 @@ class DictionaryActivity : ComponentActivity() { ) } ) { - DictionaryPopup(word.ifBlank { "Select one word" }) { finish() } + DictionaryPopup( + word = word.ifBlank { "Select one word" }, + surfaceAlpha = surfaceAppearance.surfaceAlpha + ) { finish() } } } } } @Composable -private fun DictionaryPopup(word: String, onClose: () -> Unit) { +private fun DictionaryPopup(word: String, surfaceAlpha: Float, onClose: () -> Unit) { val context = LocalContext.current var result by remember(word) { mutableStateOf(null) } var loading by remember(word) { mutableStateOf(true) } @@ -309,7 +336,7 @@ private fun DictionaryPopup(word: String, onClose: () -> Unit) { .then(contentSizeMotion), shape = RoundedCornerShape(26.dp), color = MaterialTheme.colorScheme.surface.copy( - alpha = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) 0.86f else 0.94f + alpha = surfaceAlpha ), contentColor = MaterialTheme.colorScheme.onSurface, tonalElevation = 0.dp,