Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<View>(R.id.main_keyboard_frame)?.background is CenterCropDrawable
if (!settingsValues.mCustomNavBarColor || showsWallpaper) {
if (!settingsValues.mCustomNavBarColor) {
setNavigationBarFrameBackground(null)
clearNavigationBarColor()
return
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ fun CustomizeIconsDialog(
}
if (showDeletePrefConfirmDialog) {
ConfirmationDialog(
title = { Text(stringResource(R.string.app_quirks_reset_default)) },
onDismissRequest = { showDeletePrefConfirmDialog = false },
onConfirmed = {
showDeletePrefConfirmDialog = false
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fun ToolbarKeysCustomizer(
}
if (showDeletePrefConfirmDialog)
ConfirmationDialog(
title = { Text(stringResource(R.string.app_quirks_reset_default)) },
onDismissRequest = { showDeletePrefConfirmDialog = false },
onConfirmed = {
showDeletePrefConfirmDialog = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ fun BlockedWordsScreen(

if (showClearAllDialog) {
ConfirmationDialog(
title = { Text(stringResource(R.string.storage_delete_confirm_title)) },
onDismissRequest = { showClearAllDialog = false },
onConfirmed = {
showClearAllDialog = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fun PersonalDictionaryScreen(
}
if (showClearAllDialog) {
ConfirmationDialog(
title = { Text(stringResource(R.string.storage_delete_confirm_title)) },
onDismissRequest = { showClearAllDialog = false },
onConfirmed = {
showClearAllDialog = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?: "{}"
Expand All @@ -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)) },
)
}
}
Expand Down
51 changes: 51 additions & 0 deletions app/src/test/java/helium314/keyboard/latin/WallpaperNavBarTest.kt
Original file line number Diff line number Diff line change
@@ -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<Context>()
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())
}
}
Loading