mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 06:09:09 +00:00
add gesture typing settings
This commit is contained in:
parent
e2bb405291
commit
f825f6a422
4 changed files with 141 additions and 2 deletions
|
@ -10,6 +10,7 @@ import androidx.compose.runtime.Composable
|
|||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.settings.screens.createAboutPrefs
|
||||
import helium314.keyboard.settings.screens.createCorrectionPrefs
|
||||
import helium314.keyboard.settings.screens.createGestureTypingPrefs
|
||||
import helium314.keyboard.settings.screens.createPreferencesPrefs
|
||||
import helium314.keyboard.settings.screens.createToolbarPrefs
|
||||
|
||||
|
@ -54,7 +55,8 @@ class PrefDef(
|
|||
}
|
||||
|
||||
private fun createPrefDefs(context: Context) = createAboutPrefs(context) +
|
||||
createCorrectionPrefs(context) + createPreferencesPrefs(context) + createToolbarPrefs(context)
|
||||
createCorrectionPrefs(context) + createPreferencesPrefs(context) + createToolbarPrefs(context) +
|
||||
createGestureTypingPrefs(context)
|
||||
|
||||
// todo: move somewhere else
|
||||
fun Context.getActivity(): ComponentActivity? {
|
||||
|
|
|
@ -11,6 +11,7 @@ import androidx.navigation.compose.NavHost
|
|||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import helium314.keyboard.settings.screens.AboutScreen
|
||||
import helium314.keyboard.settings.screens.GestureTypingScreen
|
||||
import helium314.keyboard.settings.screens.MainSettingsScreen
|
||||
import helium314.keyboard.settings.screens.PreferencesScreen
|
||||
import helium314.keyboard.settings.screens.TextCorrectionScreen
|
||||
|
@ -50,6 +51,7 @@ fun SettingsNavHost(
|
|||
onClickTextCorrection = { navController.navigate(SettingsDestination.TextCorrection) },
|
||||
onClickPreferences = { navController.navigate(SettingsDestination.Preferences) },
|
||||
onClickToolbar = { navController.navigate(SettingsDestination.Toolbar) },
|
||||
onClickGestureTyping = { navController.navigate(SettingsDestination.GestureTyping) },
|
||||
onClickBack = ::goBack,
|
||||
)
|
||||
}
|
||||
|
@ -73,6 +75,11 @@ fun SettingsNavHost(
|
|||
onClickBack = ::goBack
|
||||
)
|
||||
}
|
||||
composable(SettingsDestination.GestureTyping) {
|
||||
GestureTypingScreen (
|
||||
onClickBack = ::goBack
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +89,7 @@ object SettingsDestination {
|
|||
const val TextCorrection = "text_correction"
|
||||
const val Preferences = "preferences"
|
||||
const val Toolbar = "toolbar"
|
||||
const val GestureTyping = "gesture_typing"
|
||||
val navTarget = MutableStateFlow(Settings)
|
||||
|
||||
private val navScope = CoroutineScope(Dispatchers.Default)
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
package helium314.keyboard.settings.screens
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.settings.AllPrefs
|
||||
import helium314.keyboard.settings.PrefDef
|
||||
import helium314.keyboard.settings.SearchPrefScreen
|
||||
import helium314.keyboard.settings.SettingsActivity2
|
||||
import helium314.keyboard.settings.SliderPreference
|
||||
import helium314.keyboard.settings.SwitchPreference
|
||||
import helium314.keyboard.settings.Theme
|
||||
import helium314.keyboard.settings.getActivity
|
||||
import helium314.keyboard.settings.prefs
|
||||
import helium314.keyboard.settings.themeChanged
|
||||
|
||||
@Composable
|
||||
fun GestureTypingScreen(
|
||||
onClickBack: () -> Unit,
|
||||
) {
|
||||
val prefs = LocalContext.current.prefs()
|
||||
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
||||
if (b?.value ?: 0 < 0)
|
||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||
val gestureEnabled = prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true)
|
||||
val gestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true)
|
||||
val gestureFloatingPreviewEnabled = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true)
|
||||
SearchPrefScreen(
|
||||
onClickBack = onClickBack,
|
||||
title = stringResource(R.string.settings_screen_gesture),
|
||||
) {
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_INPUT]!!.Preference()
|
||||
if (gestureEnabled) {
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_PREVIEW_TRAIL]!!.Preference()
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT]!!.Preference()
|
||||
if (gestureFloatingPreviewEnabled)
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC]!!.Preference()
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_SPACE_AWARE]!!.Preference()
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN]!!.Preference()
|
||||
if (gestureTrailEnabled || gestureFloatingPreviewEnabled)
|
||||
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION]!!.Preference()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createGestureTypingPrefs(context: Context) = listOf(
|
||||
PrefDef(context, Settings.PREF_GESTURE_INPUT, R.string.gesture_input, R.string.gesture_input_summary) {
|
||||
SwitchPreference(
|
||||
def = it,
|
||||
default = true
|
||||
)
|
||||
},
|
||||
PrefDef(context, Settings.PREF_GESTURE_PREVIEW_TRAIL, R.string.gesture_preview_trail) {
|
||||
SwitchPreference(
|
||||
def = it,
|
||||
default = true
|
||||
)
|
||||
},
|
||||
PrefDef(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, R.string.gesture_floating_preview_static, R.string.gesture_floating_preview_static_summary) {
|
||||
SwitchPreference(
|
||||
def = it,
|
||||
default = true
|
||||
)
|
||||
},
|
||||
PrefDef(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary) {
|
||||
SwitchPreference(
|
||||
def = it,
|
||||
default = true
|
||||
) { themeChanged = true }
|
||||
},
|
||||
PrefDef(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) {
|
||||
SwitchPreference(
|
||||
def = it,
|
||||
default = false
|
||||
)
|
||||
},
|
||||
PrefDef(context, Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, R.string.gesture_fast_typing_cooldown) {
|
||||
SliderPreference(
|
||||
name = it.title,
|
||||
pref = it.key,
|
||||
default = 500,
|
||||
range = 0f..500f,
|
||||
description = {
|
||||
if (it <= 0) stringResource(R.string.gesture_fast_typing_cooldown_instant)
|
||||
else stringResource(R.string.abbreviation_unit_milliseconds, it.toString())
|
||||
}
|
||||
)
|
||||
},
|
||||
PrefDef(context, Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, R.string.gesture_trail_fadeout_duration) {
|
||||
// todo: there is some weird stuff going on
|
||||
// for some uses there is an additional 100 ms delay
|
||||
// see config_gesture_trail_fadeout_start_delay
|
||||
// -> check whether this should be changes, or at least made less complicated
|
||||
SliderPreference(
|
||||
name = it.title,
|
||||
pref = it.key,
|
||||
default = 800,
|
||||
range = 100f..1900f,
|
||||
description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) },
|
||||
// todo: 50 ms steps?
|
||||
) { themeChanged = true }
|
||||
},
|
||||
)
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun Preview() {
|
||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
||||
Theme(true) {
|
||||
Surface {
|
||||
GestureTypingScreen { }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ fun MainSettingsScreen(
|
|||
onClickTextCorrection: () -> Unit,
|
||||
onClickPreferences: () -> Unit,
|
||||
onClickToolbar: () -> Unit,
|
||||
onClickGestureTyping: () -> Unit,
|
||||
onClickBack: () -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
|
@ -66,6 +67,12 @@ fun MainSettingsScreen(
|
|||
contentDescription = null
|
||||
)
|
||||
}
|
||||
if (JniUtils.sHaveGestureLib)
|
||||
Preference(
|
||||
name = stringResource(R.string.settings_screen_gesture),
|
||||
onClick = onClickGestureTyping,
|
||||
icon = R.drawable.ic_settings_gesture_foreground
|
||||
)
|
||||
Preference(
|
||||
name = stringResource(R.string.settings_screen_correction),
|
||||
onClick = onClickTextCorrection,
|
||||
|
@ -141,7 +148,7 @@ fun Activity.switchTo(fragment: androidx.fragment.app.Fragment) {
|
|||
private fun PreviewScreen() {
|
||||
Theme(true) {
|
||||
Surface {
|
||||
MainSettingsScreen({}, {}, {}, {}, {})
|
||||
MainSettingsScreen({}, {}, {}, {}, {}, {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue