Skip to content
Closed
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
9 changes: 9 additions & 0 deletions java/res/values/strings-uix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@
<!-- When translating, rename it to gesture typing if it makes more sense for that language -->
<string name="typing_settings_swipe">Swipe Typing (alpha)</string>
<string name="typing_settings_swipe_subtitle">Allow swiping from key to key to write words.</string>
<string name="swipe_gesture_left_delete">Swipe left to delete word</string>
<string name="swipe_gesture_right_space">Swipe right for space</string>
<string name="swipe_gesture_down_prediction">Swipe down to accept middle prediction</string>
<string name="swipe_gesture_down_lr_prediction">Swipe diagonal down to accept side predictions</string>
<string name="swipe_gesture_down_lr_prediction_subtitle">Swipe diagonal down right to accept right-side prediction, diagonal down left to accept left-side prediction</string>
<string name="swipe_gesture_up_undo">Swipe up to undo</string>
<string name="swipe_gestures_title">Swipe Gestures</string>
<string name="typing_settings_suggest_emojis">Emoji Suggestions</string>
<string name="typing_settings_suggest_emojis_subtitle">Suggest emojis while you\'re typing</string>
<string name="typing_settings_vibration_strength">Vibration</string>
Expand Down Expand Up @@ -470,6 +477,8 @@
<string name="keyboard_settings_extra_layouts_subtitle">Configure additional layouts in the languages screen</string>
<string name="keyboard_settings_show_suggestion_row">Show action/suggestions bar</string>
<string name="keyboard_settings_show_suggestion_row_subtitle">Show the bar containing suggestions. Recommended to keep enabled</string>
<string name="keyboard_settings_compact_suggestion_bar">Compact suggestion bar</string>
<string name="keyboard_settings_compact_suggestion_bar_subtitle">Reduce the height of the suggestion bar and remove buttons from it</string>
<string name="keyboard_settings_inline_autofill">Inline autofill</string>
<string name="keyboard_settings_inline_autofill_subtitle">Display password manager autofill and auto-reply suggestions (provided by app) in suggestion bar</string>
<string name="keyboard_settings_period_key">Quick period key</string>
Expand Down
10 changes: 10 additions & 0 deletions java/src/org/futo/inputmethod/keyboard/KeyboardActionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ public interface KeyboardActionListener {
public void onUpWithDeletePointerActive();
public void onUpWithPointerActive();
public void onSwipeLanguage(int direction);
public void onSwipeAction(int direction);
public void onMovingCursorLockEvent(boolean canMoveCursor);

public static final int SWIPE_ACTION_LEFT = -1;
public static final int SWIPE_ACTION_RIGHT = 1;
public static final int SWIPE_ACTION_UP = 2;
public static final int SWIPE_ACTION_DOWN = 3;
public static final int SWIPE_ACTION_DOWN_LEFT = 4;
public static final int SWIPE_ACTION_DOWN_RIGHT = 5;

public static final KeyboardActionListener EMPTY_LISTENER = new Adapter();

public static class Adapter implements KeyboardActionListener {
Expand Down Expand Up @@ -144,6 +152,8 @@ public void onUpWithPointerActive() {}
@Override
public void onSwipeLanguage(int direction) {}
@Override
public void onSwipeAction(int direction) {}
@Override
public void onMovingCursorLockEvent(boolean canMoveCursor) {}
}
}
80 changes: 79 additions & 1 deletion java/src/org/futo/inputmethod/keyboard/PointerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
private boolean mStartedOnFastLongPress;
private boolean mCursorMoved = false;
private boolean mSpacebarLongPressed = false;
private boolean mSwipeActionTriggered = false;

private static final int sSwipeActionStep =
(int)(18.0 * Resources.getSystem().getDisplayMetrics().density);

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

mIsSlidingCursor = key.getCode() == Constants.CODE_DELETE || key.getCode() == Constants.CODE_SPACE;
final boolean swipeActionsMode = !Settings.getInstance().getCurrent().mGestureInputEnabled;
mIsSlidingCursor = key.getCode() == Constants.CODE_DELETE
|| key.getCode() == Constants.CODE_SPACE
|| swipeActionsMode;
mIsFlickingKey = !mIsSlidingCursor && key.getHasFlick();
mFlickDirection = key.flickDirection(0, 0);
mCurrentKey = key;
Expand Down Expand Up @@ -954,6 +962,72 @@ private void onMoveEventInternal(final int x, final int y, final long eventTime)

final SettingsValues settingsValues = Settings.getInstance().getCurrent();

// Swipe actions (when gesture typing is off)
// Skip spacebar — it has its own swipe gestures (cursor movement, language switch)
if (mIsSlidingCursor && oldKey != null && !mSwipeActionTriggered
&& !settingsValues.mGestureInputEnabled
&& oldKey.getCode() != Constants.CODE_SPACE
&& oldKey.getCode() != Constants.CODE_DELETE) {
final int dx = x - mStartX;
final int dy = y - mStartY;
final long swipeDistSq = (long)dx * dx + (long)dy * dy;
final long thresholdSq = (long)sSwipeActionStep * sSwipeActionStep;
final int swipeIgnoreTime = settingsValues.mKeyLongpressTimeout
/ MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;

if (swipeDistSq >= thresholdSq
&& mStartTime + swipeIgnoreTime < System.currentTimeMillis()) {
final int absDx = Math.abs(dx);
final int absDy = Math.abs(dy);
int direction = 0;
boolean enabled = false;

if (absDx > 2 * absDy) {
// Horizontal swipe
if (dx < 0) {
direction = KeyboardActionListener.SWIPE_ACTION_LEFT;
enabled = settingsValues.mSwipeLeftDelete;
} else {
direction = KeyboardActionListener.SWIPE_ACTION_RIGHT;
enabled = settingsValues.mSwipeRightSpace;
}
} else if (absDy > 2 * absDx) {
// Vertical swipe
if (dy < 0) {
direction = KeyboardActionListener.SWIPE_ACTION_UP;
enabled = settingsValues.mSwipeUpUndo;
} else {
direction = KeyboardActionListener.SWIPE_ACTION_DOWN;
enabled = settingsValues.mSwipeDownPrediction;
}
} else if (dy > 0) {
// Diagonal down
if (dx < 0) {
direction = KeyboardActionListener.SWIPE_ACTION_DOWN_LEFT;
enabled = settingsValues.mSwipeDownLRPrediction;
} else {
direction = KeyboardActionListener.SWIPE_ACTION_DOWN_RIGHT;
enabled = settingsValues.mSwipeDownLRPrediction;
}
}

if (enabled && direction != 0) {
mSwipeActionTriggered = true;
sTimerProxy.cancelKeyTimersOf(this);
sListener.onSwipeAction(direction);
mLastX = x;
mLastY = y;
return;
}
}
}

if (mSwipeActionTriggered) {
mLastX = x;
mLastY = y;
return;
}

if (mIsSlidingCursor && oldKey != null && oldKey.getCode() == Constants.CODE_SPACE) {
int pointerStep = sPointerStep;
if(settingsValues.mSpacebarMode == Settings.SPACEBAR_MODE_SWIPE_LANGUAGE && !mSpacebarLongPressed) {
Expand Down Expand Up @@ -1100,6 +1174,10 @@ private void onUpEventInternal(final int x, final int y, final long eventTime) {
sListener.onUpWithPointerActive();
}

if (mSwipeActionTriggered) {
return;
}

if(mIsFlickingKey && currentKey != null) {
final Key flickedKey = currentKey.flick(x - mStartX, y - mStartY);
detectAndSendKey(flickedKey, mKeyX, mKeyY, eventTime);
Expand Down
36 changes: 36 additions & 0 deletions java/src/org/futo/inputmethod/latin/LatinIMELegacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodSubtype;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -648,6 +649,41 @@ public void onSwipeLanguage(int direction) {
Subtypes.INSTANCE.switchToNextLanguage(mInputMethodService, direction);
}

@Override
public void onSwipeAction(int direction) {
if (direction == KeyboardActionListener.SWIPE_ACTION_LEFT) {
// Delete word before cursor
sendCtrlKeyEvent(KeyEvent.KEYCODE_DEL);
} else if (direction == KeyboardActionListener.SWIPE_ACTION_RIGHT) {
// Insert space
onCodeInput(Constants.CODE_SPACE,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false);
} else if (direction == KeyboardActionListener.SWIPE_ACTION_UP) {
// Undo
sendCtrlKeyEvent(KeyEvent.KEYCODE_Z);
} else if (direction == KeyboardActionListener.SWIPE_ACTION_DOWN) {
// Accept center prediction
getLatinIME().getUixManager().pickSuggestionAtVisualPosition(1);
} else if (direction == KeyboardActionListener.SWIPE_ACTION_DOWN_LEFT) {
// Accept left prediction
getLatinIME().getUixManager().pickSuggestionAtVisualPosition(0);
} else if (direction == KeyboardActionListener.SWIPE_ACTION_DOWN_RIGHT) {
// Accept right prediction
getLatinIME().getUixManager().pickSuggestionAtVisualPosition(2);
}
}

private void sendCtrlKeyEvent(int keyCode) {
final InputConnection ic = mInputMethodService.getCurrentInputConnection();
if (ic != null) {
final long now = android.os.SystemClock.uptimeMillis();
ic.sendKeyEvent(new KeyEvent(
now, now, KeyEvent.ACTION_DOWN, keyCode, 0, KeyEvent.META_CTRL_ON));
ic.sendKeyEvent(new KeyEvent(
now, now, KeyEvent.ACTION_UP, keyCode, 0, KeyEvent.META_CTRL_ON));
}
}

@Override
public void onMovingCursorLockEvent(boolean canMoveCursor) {
if(canMoveCursor) {
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 @@ -143,6 +143,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang

public static final String PREF_USE_WESTERN_NUMERALS = "pref_use_western_numerals";

public static final String PREF_SWIPE_LEFT_DELETE = "swipe_left_delete";
public static final String PREF_SWIPE_RIGHT_SPACE = "swipe_right_space";
public static final String PREF_SWIPE_DOWN_PREDICTION = "swipe_down_prediction";
public static final String PREF_SWIPE_DOWN_LR_PREDICTION = "swipe_down_lr_prediction";
public static final String PREF_SWIPE_UP_UNDO = "swipe_up_undo";

public static final int DEFAULT_ALT_SPACES_MODE = SPACES_MODE_ALL;

// Emoji
Expand Down
12 changes: 12 additions & 0 deletions java/src/org/futo/inputmethod/latin/settings/SettingsValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public class SettingsValues {
public final int mNumberRowMode;
public final int mAltSpacesMode;

public final boolean mSwipeLeftDelete;
public final boolean mSwipeRightSpace;
public final boolean mSwipeDownPrediction;
public final boolean mSwipeDownLRPrediction;
public final boolean mSwipeUpUndo;

// From the input box
@Nonnull
public final InputAttributes mInputAttributes;
Expand Down Expand Up @@ -202,6 +208,12 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
: Settings.NUMBER_ROW_MODE_DEFAULT;
mAltSpacesMode = prefs.getInt(Settings.PREF_ALT_SPACES_MODE, Settings.DEFAULT_ALT_SPACES_MODE);

mSwipeLeftDelete = prefs.getBoolean(Settings.PREF_SWIPE_LEFT_DELETE, false);
mSwipeRightSpace = prefs.getBoolean(Settings.PREF_SWIPE_RIGHT_SPACE, false);
mSwipeDownPrediction = prefs.getBoolean(Settings.PREF_SWIPE_DOWN_PREDICTION, false);
mSwipeDownLRPrediction = prefs.getBoolean(Settings.PREF_SWIPE_DOWN_LR_PREDICTION, false);
mSwipeUpUndo = prefs.getBoolean(Settings.PREF_SWIPE_UP_UNDO, false);

mShouldShowLxxSuggestionUi = Settings.SHOULD_SHOW_LXX_SUGGESTION_UI
&& prefs.getBoolean(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI, true);
// Compute other readable settings
Expand Down
Loading