diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt index 7b8e7a7c2..61aaed33e 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt @@ -1,6 +1,5 @@ package helium314.keyboard.latin -import helium314.keyboard.latin.utils.CenterCropDrawable import helium314.keyboard.latin.utils.applyKeyboardStyle import android.Manifest import android.annotation.SuppressLint @@ -2289,10 +2288,7 @@ class LatinIME : InputMethodService(), window.isNavigationBarContrastEnforced = true } val settingsValues = settings.current - // from Android 15 the keyboard extends behind the navigation bar, so leave a wallpaper visible there - val showsWallpaper = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM - && inputView?.findViewById(R.id.main_keyboard_frame)?.background is CenterCropDrawable - if (!settingsValues.mCustomNavBarColor || showsWallpaper) { + if (!settingsValues.mCustomNavBarColor) { setNavigationBarFrameBackground(null) clearNavigationBarColor() return diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.kt b/app/src/main/java/helium314/keyboard/latin/settings/Settings.kt index c2bc57e09..82fa16858 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.kt +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.kt @@ -20,6 +20,7 @@ import android.graphics.BitmapFactory import android.graphics.Typeface import android.graphics.drawable.Drawable import android.os.Build +import androidx.core.content.edit import android.view.ContextThemeWrapper import android.view.inputmethod.EditorInfo import androidx.annotation.StringRes @@ -542,6 +543,8 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang const val PREF_ADD_TO_PERSONAL_DICT_THRESHOLD = "add_to_personal_dict_threshold" const val PREF_USER_DICT_SORT_ORDER = "user_dict_sort_order" const val PREF_NAVBAR_COLOR = "navbar_color" + /** set while the navigation bar color is off only because a wallpaper was set */ + const val PREF_NAVBAR_COLOR_OFF_FOR_WALLPAPER = "navbar_color_off_for_wallpaper" const val PREF_NARROW_KEY_GAPS = "narrow_key_gaps" const val PREF_NARROW_KEY_GAPS_LEVEL = "narrow_key_gaps_level" const val PREF_ENABLED_SUBTYPES = "enabled_subtypes" @@ -980,6 +983,29 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang File(dir, "custom_background_image_landscape_night").isFile } + /** + * From Android 15 the keyboard extends behind the navigation bar, and coloring the bar covers the wallpaper. + * So setting a wallpaper switches the color off, the user can switch it on again. Removing the last + * wallpaper restores it, unless the user changed the setting in the meantime. + */ + fun adjustNavBarColorForWallpaper(context: Context, wallpaperWasSet: Boolean) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) return + val prefs = context.prefs() + if (wallpaperWasSet) { + if (prefs.getBoolean(PREF_NAVBAR_COLOR, Defaults.PREF_NAVBAR_COLOR)) + prefs.edit { + putBoolean(PREF_NAVBAR_COLOR, false) + putBoolean(PREF_NAVBAR_COLOR_OFF_FOR_WALLPAPER, true) + } + } else if (prefs.getBoolean(PREF_NAVBAR_COLOR_OFF_FOR_WALLPAPER, false) && !hasCustomBackgroundImage(context) + && !prefs.getBoolean(PREF_USE_SYSTEM_WALLPAPER, Defaults.PREF_USE_SYSTEM_WALLPAPER)) { + prefs.edit { + putBoolean(PREF_NAVBAR_COLOR, true) + remove(PREF_NAVBAR_COLOR_OFF_FOR_WALLPAPER) + } + } + } + fun clearCachedBackgroundImages(context: Context? = null) { sCachedBackgroundImages.fill(null) val ctx = context ?: sInstance.mContext diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/ColorThemePickerDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/ColorThemePickerDialog.kt index c9bbf61b7..f0d7a63da 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/ColorThemePickerDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/ColorThemePickerDialog.kt @@ -236,6 +236,7 @@ private fun ColorItemRow(onDismissRequest: () -> Unit, item: String, isSelected: } if (showDialog) ConfirmationDialog( + title = { Text(stringResource(R.string.storage_delete_confirm_title)) }, onDismissRequest = { showDialog = false }, content = { Text(stringResource(R.string.delete_confirmation, item)) }, onConfirmed = { diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/CustomizeIconsDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/CustomizeIconsDialog.kt index 40f710ba0..805a08f5e 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/CustomizeIconsDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/CustomizeIconsDialog.kt @@ -193,6 +193,7 @@ fun CustomizeIconsDialog( } if (showDeletePrefConfirmDialog) { ConfirmationDialog( + title = { Text(stringResource(R.string.app_quirks_reset_default)) }, onDismissRequest = { showDeletePrefConfirmDialog = false }, onConfirmed = { showDeletePrefConfirmDialog = false diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/InfoDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/InfoDialog.kt index 869b0dc3a..409b3cb52 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/InfoDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/InfoDialog.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only package helium314.keyboard.settings.dialogs +import helium314.keyboard.latin.R import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource @@ -12,18 +13,21 @@ import helium314.keyboard.settings.previewDark @Composable fun InfoDialog( message: String, + title: String = stringResource(R.string.voice_badge_error), onDismissRequest: () -> Unit ) { - InfoDialog(AnnotatedString(message), onDismissRequest) + InfoDialog(AnnotatedString(message), title, onDismissRequest) } @Composable fun InfoDialog( message: AnnotatedString, + title: String = stringResource(R.string.voice_badge_error), onDismissRequest: () -> Unit ) { ThreeButtonAlertDialog( onDismissRequest = onDismissRequest, + title = { Text(title) }, content = { Text(message) }, scrollContent = true, cancelButtonText = stringResource(android.R.string.ok), diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/NewDictionaryDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/NewDictionaryDialog.kt index 4b7c4cbc6..e84385a38 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/NewDictionaryDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/NewDictionaryDialog.kt @@ -46,7 +46,7 @@ fun NewDictionaryDialog( ) { val (error, header) = checkDict(cachedFile) if (error != null) { - InfoDialog(stringResource(error), onDismissRequest) + InfoDialog(stringResource(error), onDismissRequest = onDismissRequest) cachedFile.delete() } else if (header != null) { val ctx = LocalContext.current diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/ToolbarKeysCustomizer.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/ToolbarKeysCustomizer.kt index e5dc1ef2c..10697bd9a 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/ToolbarKeysCustomizer.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/ToolbarKeysCustomizer.kt @@ -89,6 +89,7 @@ fun ToolbarKeysCustomizer( } if (showDeletePrefConfirmDialog) ConfirmationDialog( + title = { Text(stringResource(R.string.app_quirks_reset_default)) }, onDismissRequest = { showDeletePrefConfirmDialog = false }, onConfirmed = { showDeletePrefConfirmDialog = false diff --git a/app/src/main/java/helium314/keyboard/settings/preferences/BackgroundImagePreference.kt b/app/src/main/java/helium314/keyboard/settings/preferences/BackgroundImagePreference.kt index 89c408379..874b2426d 100644 --- a/app/src/main/java/helium314/keyboard/settings/preferences/BackgroundImagePreference.kt +++ b/app/src/main/java/helium314/keyboard/settings/preferences/BackgroundImagePreference.kt @@ -59,6 +59,7 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) { scope.launch(Dispatchers.IO) { val success = setBackgroundImage(ctx, uri, isNight, isLandscape) withContext(Dispatchers.Main) { + Settings.adjustNavBarColorForWallpaper(ctx, success) // rebuilds the keyboard views, so main thread only KeyboardSwitcher.getInstance().setThemeNeedsReload() if (!success) showErrorDialog = true @@ -111,6 +112,7 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) { onNeutral = { getFile().delete() Settings.clearCachedBackgroundImages(ctx) + Settings.adjustNavBarColorForWallpaper(ctx, false) KeyboardSwitcher.getInstance().setThemeNeedsReload() showSelectionDialog = false } diff --git a/app/src/main/java/helium314/keyboard/settings/preferences/LoadGestureLibPreference.kt b/app/src/main/java/helium314/keyboard/settings/preferences/LoadGestureLibPreference.kt index 0ffcce2db..eefbb1a2e 100644 --- a/app/src/main/java/helium314/keyboard/settings/preferences/LoadGestureLibPreference.kt +++ b/app/src/main/java/helium314/keyboard/settings/preferences/LoadGestureLibPreference.kt @@ -296,6 +296,7 @@ fun LoadGestureLibPreference( val currentTempPath = tempFilePath if (currentTempPath != null) ConfirmationDialog( + title = { Text(stringResource(R.string.backup_api_keys_warning_title)) }, onDismissRequest = { File(currentTempPath).delete() tempFilePath = null diff --git a/app/src/main/java/helium314/keyboard/settings/preferences/SwitchPreference.kt b/app/src/main/java/helium314/keyboard/settings/preferences/SwitchPreference.kt index 423a9373b..c3e788f14 100644 --- a/app/src/main/java/helium314/keyboard/settings/preferences/SwitchPreference.kt +++ b/app/src/main/java/helium314/keyboard/settings/preferences/SwitchPreference.kt @@ -103,6 +103,7 @@ fun SwitchPreferenceWithEmojiDictWarning(setting: Setting, default: Boolean) { val link = stringResource(R.string.dictionary_link_text).withHtmlLink(Links.DICTIONARY_URL + Links.DICTIONARY_DOWNLOAD_SUFFIX.replace("raw", "src") + Links.DICTIONARY_EMOJI_CLDR_SUFFIX) val message = stringResource(R.string.emoji_dictionary_required, link) - InfoDialog(message.htmlToAnnotated(), onDismissRequest = { showWarningDialog = false }) + InfoDialog(message.htmlToAnnotated(), stringResource(android.R.string.dialog_alert_title), + onDismissRequest = { showWarningDialog = false }) } } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt index 8fadbb548..e698cea08 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt @@ -359,7 +359,10 @@ fun createAppearanceSettings(context: Context) = listOf( SwitchPreference(it, Defaults.PREF_THEME_DAY_NIGHT) { KeyboardSwitcher.getInstance().setThemeNeedsReload() } }, Setting(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) { - SwitchPreference(it, Defaults.PREF_NAVBAR_COLOR) + SwitchPreference(it, Defaults.PREF_NAVBAR_COLOR) { + // the user decided, so removing the wallpaper must not change it + context.prefs().edit { remove(Settings.PREF_NAVBAR_COLOR_OFF_FOR_WALLPAPER) } + } }, Setting(context, SettingsWithoutKey.BACKGROUND_IMAGE, R.string.customize_background_image) { BackgroundImagePref(it, false) @@ -403,13 +406,15 @@ fun createAppearanceSettings(context: Context) = listOf( true } } - ) { + ) { enabled -> Settings.clearCachedBackgroundImages(context) + Settings.adjustNavBarColorForWallpaper(context, enabled) KeyboardSwitcher.getInstance().setThemeNeedsReload() } if (showRestrictedDialog) { InfoDialog( message = stringResource(R.string.system_wallpaper_restricted), + title = stringResource(android.R.string.dialog_alert_title), onDismissRequest = { showRestrictedDialog = false } ) } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/BlockedWordsScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/BlockedWordsScreen.kt index 4c4956da5..bee0e7c9b 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/BlockedWordsScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/BlockedWordsScreen.kt @@ -387,6 +387,7 @@ fun BlockedWordsScreen( if (showClearAllDialog) { ConfirmationDialog( + title = { Text(stringResource(R.string.storage_delete_confirm_title)) }, onDismissRequest = { showClearAllDialog = false }, onConfirmed = { showClearAllDialog = false diff --git a/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt index e100de631..7a1b484a0 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt @@ -211,6 +211,7 @@ fun PersonalDictionaryScreen( } if (showClearAllDialog) { ConfirmationDialog( + title = { Text(stringResource(R.string.storage_delete_confirm_title)) }, onDismissRequest = { showClearAllDialog = false }, onConfirmed = { showClearAllDialog = false diff --git a/app/src/main/java/helium314/keyboard/settings/screens/SuggestionsScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/SuggestionsScreen.kt index ed3cf14bd..b4c410f44 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/SuggestionsScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/SuggestionsScreen.kt @@ -163,6 +163,7 @@ fun createSuggestionsSettings(context: Context) = listOf( if (showConfirmDialog) { val prefs = LocalContext.current.prefs() ConfirmationDialog( + title = { Text(stringResource(R.string.clear_learned_words_title)) }, onDismissRequest = { showConfirmDialog = false }, onConfirmed = { prefs.edit { putBoolean(setting.key, false) } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/TextExpanderTextEditor.kt b/app/src/main/java/helium314/keyboard/settings/screens/TextExpanderTextEditor.kt index be976824f..88471fb4b 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/TextExpanderTextEditor.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/TextExpanderTextEditor.kt @@ -371,6 +371,7 @@ fun TextExpanderTextEditor(onClose: (Boolean) -> Unit) { if (askRestore) { ThreeButtonAlertDialog( + title = { Text(stringResource(R.string.button_restore)) }, onDismissRequest = { askRestore = false }, onConfirmed = { val now = prefs.getString(TextExpanderUtils.PREF_DATA, null) ?: "{}" @@ -396,7 +397,7 @@ fun TextExpanderTextEditor(onClose: (Boolean) -> Unit) { confirmButtonText = stringResource(R.string.text_expander_discard), confirmButtonColor = MaterialTheme.colorScheme.error, cancelButtonText = stringResource(android.R.string.cancel), - content = { Text(stringResource(R.string.text_expander_discard_title)) }, + title = { Text(stringResource(R.string.text_expander_discard_title)) }, ) } } diff --git a/app/src/test/java/helium314/keyboard/latin/WallpaperNavBarTest.kt b/app/src/test/java/helium314/keyboard/latin/WallpaperNavBarTest.kt new file mode 100644 index 000000000..106778bab --- /dev/null +++ b/app/src/test/java/helium314/keyboard/latin/WallpaperNavBarTest.kt @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-only +package helium314.keyboard.latin + +import android.content.Context +import androidx.core.content.edit +import androidx.test.core.app.ApplicationProvider +import helium314.keyboard.latin.settings.Settings +import helium314.keyboard.latin.utils.prefs +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import kotlin.test.Test +import kotlin.test.assertEquals + +@RunWith(RobolectricTestRunner::class) +class WallpaperNavBarTest { + private val context = ApplicationProvider.getApplicationContext() + private val prefs get() = context.prefs() + private fun colored() = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, true) + private fun reset(colored: Boolean) = prefs.edit { clear(); putBoolean(Settings.PREF_NAVBAR_COLOR, colored) } + + @Test @Config(sdk = [35]) fun `setting a wallpaper switches the color off until it is removed`() { + reset(true) + Settings.adjustNavBarColorForWallpaper(context, true) + assertEquals(false, colored()) + Settings.adjustNavBarColorForWallpaper(context, true) // a second wallpaper keeps the restore + Settings.adjustNavBarColorForWallpaper(context, false) + assertEquals(true, colored()) + } + + @Test @Config(sdk = [35]) fun `a color that was already off stays off`() { + reset(false) + Settings.adjustNavBarColorForWallpaper(context, true) + Settings.adjustNavBarColorForWallpaper(context, false) + assertEquals(false, colored()) + } + + @Test @Config(sdk = [35]) fun `color is not restored while the system wallpaper is still used`() { + reset(true) + Settings.adjustNavBarColorForWallpaper(context, true) + prefs.edit { putBoolean(Settings.PREF_USE_SYSTEM_WALLPAPER, true) } + Settings.adjustNavBarColorForWallpaper(context, false) + assertEquals(false, colored()) + } + + @Test @Config(sdk = [34]) fun `nothing changes before Android 15`() { + reset(true) + Settings.adjustNavBarColorForWallpaper(context, true) + assertEquals(true, colored()) + } +}