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
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
if (requestCode == Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER) {
return latinIME.showInputPickerDialog()
}
if (requestCode == Constants.CUSTOM_CODE_SWITCH_LANGUAGE) {
latinIME.switchToNextSubtype()
return true
}
if (requestCode == KeyboardActionListener.CODE_TOUCHPAD_ON) {
isSpaceSwipeActive = true
latinIME.isCursorGestureActive = true
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/java/helium314/keyboard/keyboard/PointerTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1201,12 +1201,16 @@ class PointerTracker private constructor(
}
val code = key.code
val sv = Settings.getValues()
if (code == KeyCode.LANGUAGE_SWITCH || (code == Constants.CODE_SPACE && key.popupKeys.isNullOrEmpty() && sv.mSpaceForLangChange)) {
if (sListener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
cancelKeyTracking()
sListener.onReleaseKey(code, false)
return
}
val spaceLongPress = if (code == Constants.CODE_SPACE && key.popupKeys.isNullOrEmpty()) sv.mSpaceLongPress else null
val request = when {
code == KeyCode.LANGUAGE_SWITCH || spaceLongPress == "input_method_picker" -> Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER
spaceLongPress == "switch_language" -> Constants.CUSTOM_CODE_SWITCH_LANGUAGE
else -> null
}
if (request != null && sListener.onCustomRequest(request)) {
cancelKeyTracking()
sListener.onReleaseKey(code, false)
return
}
if (code == Constants.CODE_SPACE && key.popupKeys.isNullOrEmpty()) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ object Constants {
}

const val CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER = 1
/** like the language switch key, following "Language switch key behavior" */
const val CUSTOM_CODE_SWITCH_LANGUAGE = 2

const val CODE_ENTER = '\n'.code
const val CODE_TAB = '\t'.code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ object Defaults {
const val PREF_ANIMATION_SPEED_SCALE = 1.0f
const val PREF_MORE_POPUP_KEYS = "main"
const val PREF_SPACE_TO_CHANGE_LANG = true
const val PREF_SPACE_LONG_PRESS = "input_method_picker"
const val PREF_LANGUAGE_SWIPE_DISTANCE = 5
const val PREF_FULL_KEYBOARD_SWIPE = "none"
const val PREF_FULL_SWIPE_SWITCH_LANGUAGE = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
const val PREF_POPUP_KEYS_VERTICAL_OFFSET_PERCENT = "popup_keys_vertical_offset_percent"
const val PREF_ANIMATION_SPEED_SCALE = "pref_animation_speed_scale"

/** legacy switch, replaced by [PREF_SPACE_LONG_PRESS] and only read when that is not set, see [readSpaceLongPress] */
const val PREF_SPACE_TO_CHANGE_LANG = "prefs_long_press_keyboard_to_change_lang"
const val PREF_SPACE_LONG_PRESS = "space_long_press"
const val PREF_LANGUAGE_SWIPE_DISTANCE = "language_swipe_distance"
const val PREF_TOUCHPAD_SENSITIVITY = "touchpad_sensitivity"
const val PREF_TOUCHPAD_FULLSCREEN = "touchpad_fullscreen"
Expand Down Expand Up @@ -682,6 +684,12 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
}
}

/** what a long press on the space bar does: "input_method_picker", "switch_language" or "none" */
fun readSpaceLongPress(prefs: SharedPreferences): String =
prefs.getString(PREF_SPACE_LONG_PRESS, null)
?: if (prefs.getBoolean(PREF_SPACE_TO_CHANGE_LANG, Defaults.PREF_SPACE_TO_CHANGE_LANG)) Defaults.PREF_SPACE_LONG_PRESS
else "none"

fun readVerticalDownSpaceSwipe(prefs: SharedPreferences): Int {
return when (prefs.getString(PREF_SPACE_VERTICAL_DOWN_SWIPE, Defaults.PREF_SPACE_VERTICAL_DOWN_SWIPE)) {
"move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ open class SettingsValues(
@Deprecated("Use mPopupKeysVerticalOffsetPercent or mPopupKeysVerticalOffsetFraction")
val mPopupKeysVerticalOffset: Float get() = mPopupKeysVerticalOffsetPercent
val mAnimationSpeedScale: Float
val mSpaceForLangChange: Boolean
/** see [Settings.readSpaceLongPress] */
val mSpaceLongPress: String
val mShowsEmojiKey: Boolean
val mVarToolbarDirection: Boolean
val mUsePersonalizedDicts: Boolean
Expand Down Expand Up @@ -332,7 +333,7 @@ open class SettingsValues(
}
mPopupKeysVerticalOffsetFraction = mPopupKeysVerticalOffsetPercent / 100f
mAnimationSpeedScale = prefs.getFloat(Settings.PREF_ANIMATION_SPEED_SCALE, Defaults.PREF_ANIMATION_SPEED_SCALE)
mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, Defaults.PREF_SPACE_TO_CHANGE_LANG)
mSpaceLongPress = Settings.readSpaceLongPress(prefs)
mShowsEmojiKey = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_KEY, Defaults.PREF_SHOW_EMOJI_KEY)
mVarToolbarDirection = mToolbarMode != ToolbarMode.HIDDEN && prefs.getBoolean(Settings.PREF_VARIABLE_TOOLBAR_DIRECTION, Defaults.PREF_VARIABLE_TOOLBAR_DIRECTION)
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, Defaults.PREF_KEY_USE_PERSONALIZED_DICTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fun PreferencesScreen(
R.string.settings_category_additional_keys,
Settings.PREF_SHOW_NUMBER_ROW,
Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY,
Settings.PREF_SPACE_TO_CHANGE_LANG,
Settings.PREF_SPACE_LONG_PRESS,
Settings.PREF_EXPAND_FINE_TUNE_ADDITIONAL_KEYS,
if (fineTuneAdditionalKeysExpanded && SubtypeSettings.getEnabledSubtypes(true).any { it.locale().language in localesWithLocalizedNumberRow })
Settings.PREF_LOCALIZED_NUMBER_ROW else null,
Expand Down Expand Up @@ -255,11 +255,17 @@ fun createPreferencesSettings(context: Context) = listOf(
Defaults.PREF_LANGUAGE_SWITCH_KEY
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_SPACE_TO_CHANGE_LANG,
R.string.prefs_long_press_keyboard_to_change_lang,
R.string.prefs_long_press_keyboard_to_change_lang_summary)
{
SwitchPreference(it, Defaults.PREF_SPACE_TO_CHANGE_LANG)
Setting(context, Settings.PREF_SPACE_LONG_PRESS, R.string.prefs_long_press_keyboard_to_change_lang) {
ListPreference(
it,
listOf(
stringResource(R.string.select_input_method) to "input_method_picker",
stringResource(R.string.switch_language) to "switch_language",
stringResource(R.string.action_none) to "none"
),
// until changed here, the value comes from the old on/off switch
Settings.readSpaceLongPress(LocalContext.current.prefs())
)
},
Setting(context, Settings.PREF_DIRECT_IME_SWITCH_TARGET, R.string.direct_ime_switch_title, R.string.direct_ime_switch_summary) {
ListPreference(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,7 @@ New dictionary:
<item>theme_style|design look shape rounded</item>
<item>theme_key_borders|outline frame look</item>
<item>cursor_swipe_step|sensitivity speed fast</item>
<item>space_long_press|language switch long press</item>
<item>keyboard_height_scale|size big small tall</item>
<item>font_scale|text size letters big small</item>
<item>vibrate_on|haptic feedback vibration buzz</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.latin.settings

import androidx.core.content.edit
import helium314.keyboard.latin.utils.prefs
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

@RunWith(RobolectricTestRunner::class)
class SpaceLongPressTest {
private val prefs get() = RuntimeEnvironment.getApplication().prefs()

@Before fun clear() = prefs.edit { clear() }

@Test fun `default shows the input method picker`() {
assertEquals("input_method_picker", Settings.readSpaceLongPress(prefs))
}

@Test fun `the old switch turned off means nothing`() {
prefs.edit { putBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, false) }
assertEquals("none", Settings.readSpaceLongPress(prefs))
}

@Test fun `the old switch turned on keeps the input method picker`() {
prefs.edit { putBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, true) }
assertEquals("input_method_picker", Settings.readSpaceLongPress(prefs))
}

@Test fun `the new setting wins over the old switch`() {
prefs.edit {
putBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, false)
putString(Settings.PREF_SPACE_LONG_PRESS, "switch_language")
}
assertEquals("switch_language", Settings.readSpaceLongPress(prefs))
}
}
Loading