mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 16:17:44 +00:00
Improve behavior for language swipe cycling (#1319)
--------- Co-authored-by: Helium314 <helium314@mailbox.org>
This commit is contained in:
parent
82ec37f339
commit
274c6b0212
9 changed files with 82 additions and 2 deletions
|
@ -97,6 +97,7 @@ public interface KeyboardActionListener {
|
|||
*/
|
||||
boolean onHorizontalSpaceSwipe(int steps);
|
||||
boolean onVerticalSpaceSwipe(int steps);
|
||||
void onEndSpaceSwipe();
|
||||
boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha);
|
||||
|
||||
void onMoveDeletePointer(int steps);
|
||||
|
@ -148,6 +149,8 @@ public interface KeyboardActionListener {
|
|||
return false;
|
||||
}
|
||||
@Override
|
||||
public void onEndSpaceSwipe() {}
|
||||
@Override
|
||||
public void onMoveDeletePointer(int steps) {}
|
||||
@Override
|
||||
public void onUpWithDeletePointerActive() {}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package helium314.keyboard.keyboard
|
||||
|
||||
import android.view.KeyEvent
|
||||
import android.view.inputmethod.InputMethodSubtype
|
||||
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
|
||||
import helium314.keyboard.latin.LatinIME
|
||||
import helium314.keyboard.latin.RichInputMethodManager
|
||||
|
@ -19,6 +20,10 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
|||
private val settings = Settings.getInstance()
|
||||
private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers?
|
||||
|
||||
// language slide state
|
||||
private var initialSubtype: InputMethodSubtype? = null
|
||||
private var subtypeSwitchCount = 0
|
||||
|
||||
// todo: maybe keep meta state presses to KeyboardActionListenerImpl, and avoid calls to press/release key
|
||||
private fun adjustMetaState(code: Int, remove: Boolean) {
|
||||
val metaCode = when (code) {
|
||||
|
@ -84,6 +89,11 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
|||
else -> false
|
||||
}
|
||||
|
||||
override fun onEndSpaceSwipe(){
|
||||
initialSubtype = null
|
||||
subtypeSwitchCount = 0
|
||||
}
|
||||
|
||||
override fun toggleNumpad(withSliding: Boolean, forceReturnToAlpha: Boolean): Boolean {
|
||||
KeyboardSwitcher.getInstance().toggleNumpad(withSliding, latinIME.currentAutoCapsState, latinIME.currentRecapitalizeState, forceReturnToAlpha)
|
||||
return true
|
||||
|
@ -124,7 +134,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
|||
}
|
||||
|
||||
private fun onLanguageSlide(steps: Int): Boolean {
|
||||
if (abs(steps) < 4) return false
|
||||
if (abs(steps) < settings.current.mLanguageSwipeDistance) return false
|
||||
val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(false)
|
||||
if (subtypes.size <= 1) { // only allow if we have more than one subtype
|
||||
return false
|
||||
|
@ -135,7 +145,18 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
|||
wantedIndex %= subtypes.size
|
||||
if (wantedIndex < 0)
|
||||
wantedIndex += subtypes.size
|
||||
KeyboardSwitcher.getInstance().switchToSubtype(subtypes[wantedIndex])
|
||||
val newSubtype = subtypes[wantedIndex]
|
||||
|
||||
// do not switch if we would switch to the initial subtype after cycling all other subtypes
|
||||
if (initialSubtype == null)
|
||||
initialSubtype = current
|
||||
if (initialSubtype == newSubtype) {
|
||||
if ((subtypeSwitchCount > 0 && steps > 0) || ((subtypeSwitchCount < 0 && steps < 0)))
|
||||
return true
|
||||
}
|
||||
if (steps > 0) subtypeSwitchCount++ else subtypeSwitchCount--
|
||||
|
||||
KeyboardSwitcher.getInstance().switchToSubtype(newSubtype)
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -1076,6 +1076,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
|||
if (mInHorizontalSwipe || mInVerticalSwipe) {
|
||||
mInHorizontalSwipe = false;
|
||||
mInVerticalSwipe = false;
|
||||
sListener.onEndSpaceSwipe();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import androidx.preference.PreferenceManager
|
|||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import helium314.keyboard.dictionarypack.DictionaryPackConstants
|
||||
import helium314.keyboard.keyboard.KeyboardActionListener
|
||||
import helium314.keyboard.latin.utils.ChecksumCalculator
|
||||
import helium314.keyboard.keyboard.KeyboardLayoutSet
|
||||
import helium314.keyboard.keyboard.KeyboardSwitcher
|
||||
|
@ -125,6 +126,8 @@ class AdvancedSettingsFragment : SubScreenFragment() {
|
|||
}
|
||||
setupKeyLongpressTimeoutSettings()
|
||||
setupEmojiSdkSetting()
|
||||
setupLanguageSwipeDistanceSettings()
|
||||
updateLangSwipeDistanceVisibility(sharedPreferences)
|
||||
findPreference<Preference>("load_gesture_library")?.setOnPreferenceClickListener { onClickLoadLibrary() }
|
||||
findPreference<Preference>("backup_restore")?.setOnPreferenceClickListener { showBackupRestoreDialog() }
|
||||
|
||||
|
@ -560,10 +563,37 @@ class AdvancedSettingsFragment : SubScreenFragment() {
|
|||
})
|
||||
}
|
||||
|
||||
private fun setupLanguageSwipeDistanceSettings() {
|
||||
val prefs = sharedPreferences
|
||||
findPreference<SeekBarDialogPreference>(Settings.PREF_LANGUAGE_SWIPE_DISTANCE)?.setInterface(object : ValueProxy {
|
||||
override fun writeValue(value: Int, key: String) = prefs.edit().putInt(key, value).apply()
|
||||
|
||||
override fun writeDefaultValue(key: String) = prefs.edit().remove(key).apply()
|
||||
|
||||
override fun readValue(key: String) = Settings.readLanguageSwipeDistance(prefs, resources)
|
||||
|
||||
override fun readDefaultValue(key: String) = Settings.readDefaultLanguageSwipeDistance(resources)
|
||||
|
||||
override fun getValueText(value: Int) = value.toString()
|
||||
|
||||
override fun feedbackValue(value: Int) {}
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateLangSwipeDistanceVisibility(prefs: SharedPreferences) {
|
||||
val horizontalSpaceSwipe = Settings.readHorizontalSpaceSwipe(prefs)
|
||||
val verticalSpaceSwipe = Settings.readVerticalSpaceSwipe(prefs)
|
||||
val visibility = horizontalSpaceSwipe == KeyboardActionListener.SWIPE_SWITCH_LANGUAGE
|
||||
|| verticalSpaceSwipe == KeyboardActionListener.SWIPE_SWITCH_LANGUAGE
|
||||
setPreferenceVisible(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, visibility)
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String?) {
|
||||
when (key) {
|
||||
Settings.PREF_SHOW_SETUP_WIZARD_ICON -> SystemBroadcastReceiver.toggleAppIcon(requireContext())
|
||||
Settings.PREF_MORE_POPUP_KEYS -> KeyboardLayoutSet.onSystemLocaleChanged()
|
||||
Settings.PREF_SPACE_HORIZONTAL_SWIPE -> updateLangSwipeDistanceVisibility(prefs)
|
||||
Settings.PREF_SPACE_VERTICAL_SWIPE -> updateLangSwipeDistanceVisibility(prefs)
|
||||
Settings.PREF_EMOJI_MAX_SDK -> KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,6 +157,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
public static final String PREF_MORE_POPUP_KEYS = "more_popup_keys";
|
||||
|
||||
public static final String PREF_SPACE_TO_CHANGE_LANG = "prefs_long_press_keyboard_to_change_lang";
|
||||
public static final String PREF_LANGUAGE_SWIPE_DISTANCE = "language_swipe_distance";
|
||||
|
||||
public static final String PREF_ENABLE_CLIPBOARD_HISTORY = "enable_clipboard_history";
|
||||
public static final String PREF_CLIPBOARD_HISTORY_RETENTION_TIME = "clipboard_history_retention_time";
|
||||
|
@ -453,6 +454,18 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
};
|
||||
}
|
||||
|
||||
public static int readLanguageSwipeDistance(final SharedPreferences prefs,
|
||||
final Resources res) {
|
||||
final int sensitivity = prefs.getInt(
|
||||
PREF_LANGUAGE_SWIPE_DISTANCE, UNDEFINED_PREFERENCE_VALUE_INT);
|
||||
return (sensitivity != UNDEFINED_PREFERENCE_VALUE_INT) ? sensitivity
|
||||
: readDefaultLanguageSwipeDistance(res);
|
||||
}
|
||||
|
||||
public static int readDefaultLanguageSwipeDistance(final Resources res) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
public static boolean readDeleteSwipeEnabled(final SharedPreferences prefs) {
|
||||
return prefs.getBoolean(PREF_DELETE_SWIPE, true);
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ public class SettingsValues {
|
|||
public final boolean mBlockPotentiallyOffensive;
|
||||
public final int mSpaceSwipeHorizontal;
|
||||
public final int mSpaceSwipeVertical;
|
||||
public final int mLanguageSwipeDistance;
|
||||
public final boolean mDeleteSwipeEnabled;
|
||||
public final boolean mAutospaceAfterPunctuationEnabled;
|
||||
public final boolean mClipboardHistoryEnabled;
|
||||
|
@ -232,6 +233,7 @@ public class SettingsValues {
|
|||
mDisplayOrientation = res.getConfiguration().orientation;
|
||||
mSpaceSwipeHorizontal = Settings.readHorizontalSpaceSwipe(prefs);
|
||||
mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs);
|
||||
mLanguageSwipeDistance = Settings.readLanguageSwipeDistance(prefs, res);
|
||||
mDeleteSwipeEnabled = Settings.readDeleteSwipeEnabled(prefs);
|
||||
mAutospaceAfterPunctuationEnabled = Settings.readAutospaceAfterPunctuationEnabled(prefs);
|
||||
mClipboardHistoryEnabled = Settings.readClipboardHistoryEnabled(prefs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue