Fix some icons being untinted, add haptic vibration setting

This commit is contained in:
Aleksandras Kostarevas 2024-03-19 12:35:51 -05:00
parent 25229530f0
commit 03a028a9fa
2 changed files with 51 additions and 36 deletions

View File

@ -130,44 +130,30 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
colors[R.styleable.Keyboard_Key_keyPreviewTextColor] = onSecondary colors[R.styleable.Keyboard_Key_keyPreviewTextColor] = onSecondary
colors[R.styleable.MainKeyboardView_languageOnSpacebarTextColor] = onBackgroundHalf colors[R.styleable.MainKeyboardView_languageOnSpacebarTextColor] = onBackgroundHalf
drawables[R.styleable.Keyboard_iconDeleteKey] = AppCompatResources.getDrawable( val overrideDrawable: (Int, Int, Int) -> Unit = { a, b, color ->
context, drawables[a] = AppCompatResources.getDrawable(
R.drawable.delete context,
)!!.apply { b
setTint(onBackground) )!!.apply {
} setTint(color)
drawables[R.styleable.Keyboard_iconSettingsKey] = AppCompatResources.getDrawable( }
context,
R.drawable.settings
)!!.apply {
setTint(onPrimary)
}
drawables[R.styleable.Keyboard_iconEnterKey] = AppCompatResources.getDrawable(
context,
R.drawable.sym_keyboard_return_lxx_light
)!!.apply {
setTint(onPrimary)
}
drawables[R.styleable.Keyboard_iconLanguageSwitchKey] = AppCompatResources.getDrawable(
context,
R.drawable.globe
)!!.apply {
setTint(onBackground)
} }
drawables[R.styleable.Keyboard_iconShiftKey] = AppCompatResources.getDrawable( // No good replacements for these cons yet, but we set them anyway for setTint
context, overrideDrawable(R.styleable.Keyboard_iconEnterKey, R.drawable.sym_keyboard_return_lxx_light, onPrimary)
R.drawable.shift overrideDrawable(R.styleable.Keyboard_iconGoKey, R.drawable.sym_keyboard_go_lxx_light, onPrimary)
)!!.apply { overrideDrawable(R.styleable.Keyboard_iconNextKey, R.drawable.sym_keyboard_next_lxx_light, onPrimary)
setTint(onBackground) overrideDrawable(R.styleable.Keyboard_iconDoneKey, R.drawable.sym_keyboard_done_lxx_light, onPrimary)
} overrideDrawable(R.styleable.Keyboard_iconPreviousKey, R.drawable.sym_keyboard_previous_lxx_light, onPrimary)
overrideDrawable(R.styleable.Keyboard_iconSearchKey, R.drawable.sym_keyboard_search_lxx_light, onPrimary)
drawables[R.styleable.Keyboard_iconShiftKeyShifted] = AppCompatResources.getDrawable( overrideDrawable(R.styleable.Keyboard_iconDeleteKey, R.drawable.delete, onBackground)
context, overrideDrawable(R.styleable.Keyboard_iconSettingsKey, R.drawable.settings, onBackground)
R.drawable.shiftshifted overrideDrawable(R.styleable.Keyboard_iconEmojiActionKey, R.drawable.smile, onPrimary)
)!!.apply { overrideDrawable(R.styleable.Keyboard_iconEmojiNormalKey, R.drawable.smile, onBackground)
setTint(onBackground) overrideDrawable(R.styleable.Keyboard_iconLanguageSwitchKey, R.drawable.globe, onBackground)
} overrideDrawable(R.styleable.Keyboard_iconShiftKey, R.drawable.shift, onBackground)
overrideDrawable(R.styleable.Keyboard_iconShiftKeyShifted, R.drawable.shiftshifted, onBackground)
primaryKeyboardColor = background primaryKeyboardColor = background

View File

@ -1,24 +1,53 @@
package org.futo.inputmethod.latin.uix.settings.pages package org.futo.inputmethod.latin.uix.settings.pages
import android.preference.PreferenceManager
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.booleanResource import androidx.compose.ui.res.booleanResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.core.content.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.settings.Settings import org.futo.inputmethod.latin.settings.Settings
import org.futo.inputmethod.latin.settings.Settings.PREF_VIBRATION_DURATION_SETTINGS
import org.futo.inputmethod.latin.uix.SHOW_EMOJI_SUGGESTIONS import org.futo.inputmethod.latin.uix.SHOW_EMOJI_SUGGESTIONS
import org.futo.inputmethod.latin.uix.SettingsKey
import org.futo.inputmethod.latin.uix.settings.ScreenTitle import org.futo.inputmethod.latin.uix.settings.ScreenTitle
import org.futo.inputmethod.latin.uix.settings.ScrollableList import org.futo.inputmethod.latin.uix.settings.ScrollableList
import org.futo.inputmethod.latin.uix.settings.SettingRadio
import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore
import org.futo.inputmethod.latin.uix.settings.SettingToggleSharedPrefs import org.futo.inputmethod.latin.uix.settings.SettingToggleSharedPrefs
import org.futo.inputmethod.latin.uix.settings.useDataStore
import org.futo.inputmethod.latin.uix.settings.useSharedPrefsBool
val vibrationDurationSetting = SettingsKey(
intPreferencesKey("vibration_duration"),
-1
)
@Preview @Preview
@Composable @Composable
fun TypingScreen(navController: NavHostController = rememberNavController()) { fun TypingScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current val context = LocalContext.current
val (vibration, _) = useDataStore(key = vibrationDurationSetting.key, default = vibrationDurationSetting.default)
LaunchedEffect(vibration) {
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
withContext(Dispatchers.Main) {
sharedPrefs.edit {
putInt(PREF_VIBRATION_DURATION_SETTINGS, vibration)
}
}
}
ScrollableList { ScrollableList {
ScreenTitle("Typing Preferences", showBack = true, navController) ScreenTitle("Typing Preferences", showBack = true, navController)
@ -62,6 +91,6 @@ fun TypingScreen(navController: NavHostController = rememberNavController()) {
default = false default = false
) )
// TODO: SeekBarDialogPreference pref_vibration_duration_settings etc SettingRadio(title = "Vibration Duration", options = listOf(-1, 5, 10, 20, 40), optionNames = listOf("Default", "Low", "Medium", "High", "Higher"), setting = vibrationDurationSetting)
} }
} }