Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 88f6d49e authored by Georg Veichtlbauer's avatar Georg Veichtlbauer Committed by Michael Bestas
Browse files

LatinIME: Implement space bar cursor trackpad

Change-Id: Iffb3b230e4e1160a29520be657bbef257db0ecda
parent 1037a1b1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -35,4 +35,8 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM
    <!-- Preference item for enabling the number row -->
    <string name="number_row">Number row</string>
    <string name="number_row_summary">Always show a number row for all layouts that feature 4 rows of keys</string>

    <!-- Preference item for the space bar track pad -->
    <string name="space_trackpad">Space bar trackpad</string>
    <string name="space_trackpad_summary">Swipe on the spacebar to move the cursor</string>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@
        android:title="@string/show_setup_wizard_icon"
        android:summary="@string/show_setup_wizard_icon_summary"
        android:persistent="true" />
    <CheckBoxPreference
        android:key="pref_space_trackpad"
        android:title="@string/space_trackpad"
        android:summary="@string/space_trackpad_summary"
        android:defaultValue="true" />
    <com.android.inputmethod.latin.settings.SeekBarDialogPreference
        android:key="pref_keyboard_height_scale"
        android:title="@string/prefs_keyboard_height_scale"
+7 −0
Original line number Diff line number Diff line
@@ -101,6 +101,11 @@ public interface KeyboardActionListener {
     */
    public boolean onCustomRequest(int requestCode);

    /**
     * Called when user finished sliding space bar.
     */
    public void onMovePointer(int steps);

    public static final KeyboardActionListener EMPTY_LISTENER = new Adapter();

    public static class Adapter implements KeyboardActionListener {
@@ -128,5 +133,7 @@ public interface KeyboardActionListener {
        public boolean onCustomRequest(int requestCode) {
            return false;
        }
        @Override
        public void onMovePointer(int steps) {}
    }
}
+39 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,

    // Parameters for pointer handling.
    private static PointerTrackerParams sParams;
    private static int sPointerStep;
    private static GestureStrokeRecognitionParams sGestureStrokeRecognitionParams;
    private static GestureStrokeDrawingParams sGestureStrokeDrawingParams;
    private static boolean sNeedsPhantomSuddenMoveEventHack;
@@ -128,6 +129,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
    private int mLastX;
    private int mLastY;

    // For spacebar slide tracking.
    private int mStartX;
    private int mStartY;
    private long mStartTime;
    private boolean mSlidOnSpaceBar = false;

    // true if keyboard layout has been changed.
    private boolean mKeyboardLayoutHasBeenChanged;

@@ -156,6 +163,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
    public static void init(final TypedArray mainKeyboardViewAttr, final TimerProxy timerProxy,
            final DrawingProxy drawingProxy) {
        sParams = new PointerTrackerParams(mainKeyboardViewAttr);
        sPointerStep = (int)(10.0 * Resources.getSystem().getDisplayMetrics().density);
        sGestureStrokeRecognitionParams = new GestureStrokeRecognitionParams(mainKeyboardViewAttr);
        sGestureStrokeDrawingParams = new GestureStrokeDrawingParams(mainKeyboardViewAttr);
        sTypingTimeRecorder = new TypingTimeRecorder(
@@ -696,6 +704,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
            startRepeatKey(key);
            startLongPressTimer(key);
            setPressedKeyGraphics(key, eventTime);

            mStartX = x;
            mStartY = y;
            mStartTime = System.currentTimeMillis();
        }
    }

@@ -899,6 +911,20 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
        final Key oldKey = mCurrentKey;
        final Key newKey = onMoveKey(x, y);

        // Cursor space bar slider
        if (oldKey != null && oldKey.getCode() == Constants.CODE_SPACE
                && Settings.getInstance().getCurrent().mSpaceTrackpadEnabled) {
            int steps = (x - mStartX) / sPointerStep;
            if (steps != 0
                    && mStartTime + Settings.getInstance().getCurrent().mKeyLongpressTimeout
                        < System.currentTimeMillis()) {
                mSlidOnSpaceBar = true;
                mStartX += steps * sPointerStep;
                sListener.onMovePointer(steps);
            }
            return;
        }

        if (sGestureEnabler.shouldHandleGesture()) {
            // Register move event on gesture tracker.
            onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
@@ -981,6 +1007,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
            return;
        }

        if (mSlidOnSpaceBar) {
            mSlidOnSpaceBar = false;
            return;
        }

        if (sInGesture) {
            if (currentKey != null) {
                callListenerOnRelease(currentKey, currentKey.getCode(), true /* withSliding */);
@@ -1023,6 +1054,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
        if (isShowingMoreKeysPanel()) {
            return;
        }
        if (mSlidOnSpaceBar) {
            return;
        }
        final Key key = getKey();
        if (key == null) {
            return;
@@ -1148,6 +1182,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
            // We use longer timeout for sliding finger input started from the modifier key.
            return longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
        }
        if (code == Constants.CODE_SPACE
                && Settings.getInstance().getCurrent().mSpaceTrackpadEnabled) {
            // Increase timeout when space bar trackpad is on, to not interfere with language switch
            return longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
        }
        return longpressTimeout;
    }

+20 −0
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
    static final long DELAY_WAIT_FOR_DICTIONARY_LOAD_MILLIS = TimeUnit.SECONDS.toMillis(2);
    static final long DELAY_DEALLOCATE_MEMORY_MILLIS = TimeUnit.SECONDS.toMillis(10);

    private static final int MAX_SPACESLIDE_CHARS = 32;

    /**
     * A broadcast intent action to hide the software keyboard.
     */
@@ -1419,6 +1421,24 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        return false;
    }

    @Override
    public void onMovePointer(int steps) {
        if (steps < 0) {
            int availableCharacters =
                getCurrentInputConnection().getTextBeforeCursor(MAX_SPACESLIDE_CHARS, 0).length();
            steps = availableCharacters < -steps ? -availableCharacters : steps;
        } else if (steps > 0) {
            int availableCharacters =
                getCurrentInputConnection().getTextAfterCursor(MAX_SPACESLIDE_CHARS, 0).length();
            steps = availableCharacters < steps ? availableCharacters : steps;
        } else {
            return;
        }

        int newPosition = mInputLogic.mConnection.getExpectedSelectionStart() + steps;
        getCurrentInputConnection().setSelection(newPosition, newPosition);
    }

    private boolean isShowingOptionDialog() {
        return mOptionsDialog != null && mOptionsDialog.isShowing();
    }
Loading