Skip to content
Open
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
5 changes: 5 additions & 0 deletions java/res/values/strings-uix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@
<string name="morekey_settings_spacebar_hold_shortcut">Hold</string>
<string name="morekey_settings_spacebar_hold_shortcut_cursor">Move cursor</string>
<string name="morekey_settings_spacebar_hold_shortcut_language">Switch language</string>
<string name="morekey_settings_spacebar_language_swipe_distance">Language swipe distance</string>
<string name="morekey_settings_spacebar_language_swipe_distance_subtitle">Shorter distance makes the language swipe more sensitive</string>

<!-- Units abbreviation for a distance in density-independent pixels [CHAR LIMIT=10] -->
<string name="abbreviation_unit_dp"><xliff:g id="DPI">%s</xliff:g>dp</string>

<!-- Types of morekeys that can be configured, and examples of them -->
<string name="morekey_settings_kind_numbers">Numbers</string>
Expand Down
25 changes: 19 additions & 6 deletions java/src/org/futo/inputmethod/keyboard/PointerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;

Expand Down Expand Up @@ -97,10 +98,6 @@ public static void setStateHint(StateHint stateHint) {
private static PointerTrackerParams sParams;
private static final int sPointerStep = (int)(16.0 * Resources.getSystem().getDisplayMetrics().density);
private static final int sPointerBigStep = (int)(32.0 * Resources.getSystem().getDisplayMetrics().density);
private static final int sPointerHugeStep = Integer.min(
(int)(128.0 * Resources.getSystem().getDisplayMetrics().density),
Resources.getSystem().getDisplayMetrics().widthPixels * 3 / 2
);

private static GestureStrokeRecognitionParams sGestureStrokeRecognitionParams;
private static GestureStrokeDrawingParams sGestureStrokeDrawingParams;
Expand Down Expand Up @@ -157,6 +154,9 @@ public static void setStateHint(StateHint stateHint) {
private boolean mStartedOnFastLongPress;
private boolean mCursorMoved = false;
private boolean mSpacebarLongPressed = false;
// A spacebar language swipe may only switch the language once per gesture, regardless of how
// far the finger travels. Changing two languages requires lifting and swiping again.
private boolean mLanguageSwiped = false;

// true if keyboard layout has been changed.
private boolean mKeyboardLayoutHasBeenChanged;
Expand Down Expand Up @@ -760,6 +760,7 @@ private void onDownEventInternal(final int x, final int y, final long eventTime)
mStartTime = System.currentTimeMillis();
mStartedOnFastLongPress = key.isFastLongPress();
mSpacebarLongPressed = false;
mLanguageSwiped = false;

mIsSlidingCursor = key.getCode() == Constants.CODE_DELETE || key.getCode() == Constants.CODE_SPACE;
mIsFlickingKey = !mIsSlidingCursor && key.getHasFlick();
Expand Down Expand Up @@ -976,7 +977,14 @@ private void onMoveEventInternal(final int x, final int y, final long eventTime)
if(allowedBySettings) {
int pointerStep = sPointerStep;
if (settingsValues.mSpacebarSwipeMode == Settings.SPACEBAR_MODE_LANGUAGE && !mSpacebarLongPressed) {
pointerStep = sPointerHugeStep;
// The language-switch step distance is user-configurable in dp. The
// widthPixels*3/2 clamp is a safety bound for narrow screens.
final DisplayMetrics displayMetrics =
Resources.getSystem().getDisplayMetrics();
pointerStep = Integer.min(
(int)(settingsValues.mSpacebarLanguageSwipeStepDp * displayMetrics.density),
displayMetrics.widthPixels * 3 / 2
);
}

int steps = (x - mStartX) / pointerStep;
Expand All @@ -986,7 +994,12 @@ private void onMoveEventInternal(final int x, final int y, final long eventTime)
mStartX += steps * pointerStep;

if (settingsValues.mSpacebarSwipeMode == Settings.SPACEBAR_MODE_LANGUAGE && !mSpacebarLongPressed) {
sListener.onSwipeLanguage(steps);
// Cap the switch at one language per gesture, in the swipe's direction,
// independent of swipe distance/sensitivity.
if (!mLanguageSwiped) {
mLanguageSwiped = true;
sListener.onSwipeLanguage(Integer.signum(steps));
}
} else {
sListener.onMovePointer(steps);
}
Expand Down
6 changes: 6 additions & 0 deletions java/src/org/futo/inputmethod/latin/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final int SPACEBAR_MODE_CURSOR = 1;
public static final int SPACEBAR_MODE_LANGUAGE = 2;

// Per-step horizontal swipe distance (in dp) required to advance one language when the
// spacebar swipe mode is LANGUAGE. Default keeps the original hardcoded 128dp behaviour.
public static final String PREF_SPACEBAR_LANGUAGE_SWIPE_SENSITIVITY =
"pref_spacebar_language_swipe_sensitivity";
public static final int DEFAULT_SPACEBAR_LANGUAGE_SWIPE_SENSITIVITY = 128;

public static final String PREF_BACKSPACE_MODE_HOLD = "pref_backspace_mode_hold";
public static final String PREF_BACKSPACE_MODE = "pref_backspace_mode";
public static final int BACKSPACE_MODE_CHARACTERS = 0; // Long-press backspace and swipe backspace removes just characters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class SettingsValues {
public final boolean mBackspaceUndoesAutocorrect;
public final int mSpacebarSwipeMode;
public final int mSpacebarHoldMode;
public final int mSpacebarLanguageSwipeStepDp;
public final int mBackspaceMode;
public final int mBackspaceModeHold;
public final int mNumberRowMode;
Expand Down Expand Up @@ -209,6 +210,8 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
legacySpacebarMode == Settings.SPACEBAR_MODE_SWIPE_LANGUAGE_LEGACY ? Settings.SPACEBAR_MODE_LANGUAGE : Settings.SPACEBAR_MODE_CURSOR);
mSpacebarHoldMode = prefs.getInt(Settings.PREF_SPACEBAR_HOLD_MODE,
legacySpacebarMode == Settings.SPACEBAR_MODE_SWIPE_CURSOR_LEGACY ? Settings.SPACEBAR_MODE_LANGUAGE : Settings.SPACEBAR_MODE_CURSOR);
mSpacebarLanguageSwipeStepDp = prefs.getInt(Settings.PREF_SPACEBAR_LANGUAGE_SWIPE_SENSITIVITY,
Settings.DEFAULT_SPACEBAR_LANGUAGE_SWIPE_SENSITIVITY);

mBackspaceMode = prefs.getInt(Settings.PREF_BACKSPACE_MODE, Settings.BACKSPACE_MODE_CHARACTERS);
mBackspaceModeHold = prefs.getInt(Settings.PREF_BACKSPACE_MODE_HOLD, mBackspaceMode);
Expand Down Expand Up @@ -580,6 +583,8 @@ public String dump() {
sb.append("" + mBackspaceUndoesAutocorrect);
sb.append("\n mBackspaceMode = ");
sb.append("" + mBackspaceMode);
sb.append("\n mSpacebarLanguageSwipeStepDp = ");
sb.append("" + mSpacebarLanguageSwipeStepDp);
sb.append("\n mNumberRowMode = ");
sb.append("" + mNumberRowMode);
sb.append("\n mAltSpacesMode = ");
Expand Down
18 changes: 18 additions & 0 deletions java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,24 @@ val LongPressMenu = UserSettingsMenu(
)
},

UserSetting(
name = R.string.morekey_settings_spacebar_language_swipe_distance,
subtitle = R.string.morekey_settings_spacebar_language_swipe_distance_subtitle,
) {
val resources = LocalResources.current
SettingSliderSharedPrefsInt(
title = stringResource(R.string.morekey_settings_spacebar_language_swipe_distance),
subtitle = stringResource(R.string.morekey_settings_spacebar_language_swipe_distance_subtitle),
key = Settings.PREF_SPACEBAR_LANGUAGE_SWIPE_SENSITIVITY,
default = Settings.DEFAULT_SPACEBAR_LANGUAGE_SWIPE_SENSITIVITY,
range = 24.0f..160.0f,
hardRange = 24.0f..160.0f,
transform = { it.roundToInt() },
indicator = { resources.getString(R.string.abbreviation_unit_dp, "$it") },
steps = 16
)
},

// TODO: Might not work well for showing up in search
UserSetting(name = R.string.morekey_settings_layout) {
val context = LocalContext.current
Expand Down