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

Commit ca7ec209 authored by satok's avatar satok
Browse files

Integrate the logic to calculate the proximities

Bug: 4343280

Change-Id: I0f6a7e6912ed4abea07c10d266da4c7ccb0dae76
parent e31060dc
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -41,11 +41,6 @@ public interface KeyboardActionListener {
     * Send a key code to the listener.
     *
     * @param primaryCode this is the code of the key that was pressed
     * @param keyCodes the codes for all the possible alternative keys with the primary code being
     *            the first. If the primary key code is a single character such as an alphabet or
     *            number or symbol, the alternatives will include other characters that may be on
     *            the same key or adjacent keys. These codes are useful to correct for accidental
     *            presses of a key adjacent to the intended key.
     * @param x x-coordinate pixel of touched event. If {@link #onCodeInput} is not called by
     *            {@link PointerTracker#onTouchEvent} or so, the value should be
     *            {@link #NOT_A_TOUCH_COORDINATE}. If it's called on insertion from the suggestion
@@ -55,10 +50,11 @@ public interface KeyboardActionListener {
     *            {@link #NOT_A_TOUCH_COORDINATE}. If it's called on insertion from the suggestion
     *            strip, it should be {@link #SUGGESTION_STRIP_COORDINATE}.
     */
    public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y);
    public void onCodeInput(int primaryCode, int x, int y);

    public static final int NOT_A_TOUCH_COORDINATE = -1;
    public static final int SUGGESTION_STRIP_COORDINATE = -2;
    public static final int SPELL_CHECKER_COORDINATE = -3;

    /**
     * Sends a sequence of characters to the listener.
@@ -84,7 +80,7 @@ public interface KeyboardActionListener {
        @Override
        public void onReleaseKey(int primaryCode, boolean withSliding) {}
        @Override
        public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {}
        public void onCodeInput(int primaryCode, int x, int y) {}
        @Override
        public void onTextInput(CharSequence text) {}
        @Override
+2 −1
Original line number Diff line number Diff line
@@ -505,7 +505,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
    }

    private void invokeCodeInput(int primaryCode) {
        mKeyboardActionListener.onCodeInput(primaryCode, null,
        mKeyboardActionListener.onCodeInput(primaryCode,
                KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
                KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
    }
@@ -740,6 +740,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
     * @return {@code true} if the event was handled by the view, {@code false}
     *         otherwise
     */
    //Should not annotate @override
    public boolean dispatchHoverEvent(MotionEvent event) {
        if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
            final PointerTracker tracker = PointerTracker.getPointerTracker(0, this);
+2 −2
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
    private final KeyboardActionListener mMoreKeysKeyboardListener =
            new KeyboardActionListener.Adapter() {
        @Override
        public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
            mListener.onCodeInput(primaryCode, keyCodes, x, y);
        public void onCodeInput(int primaryCode, int x, int y) {
            mListener.onCodeInput(primaryCode, x, y);
        }

        @Override
+4 −9
Original line number Diff line number Diff line
@@ -105,7 +105,6 @@ public class PointerTracker {
        }
    }

    private static KeyboardSwitcher sKeyboardSwitcher;
    // Parameters for pointer handling.
    private static LatinKeyboardView.PointerTrackerParams sParams;
    private static int sTouchNoiseThresholdDistanceSquared;
@@ -172,7 +171,6 @@ public class PointerTracker {
        }

        setParameters(LatinKeyboardView.PointerTrackerParams.DEFAULT);
        sKeyboardSwitcher = KeyboardSwitcher.getInstance();
    }

    public static void setParameters(LatinKeyboardView.PointerTrackerParams params) {
@@ -254,13 +252,13 @@ public class PointerTracker {

    // Note that we need primaryCode argument because the keyboard may in shifted state and the
    // primaryCode is different from {@link Key#mCode}.
    private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) {
    private void callListenerOnCodeInput(Key key, int primaryCode, int x, int y) {
        final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
        final boolean alterCode = key.altCodeWhileTyping() && mTimerProxy.isTyping();
        final int code = alterCode ? key.mAltCode : primaryCode;
        if (DEBUG_LISTENER) {
            Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code) + " text=" + key.mOutputText
                    + " codes="+ KeyDetector.printableCodes(keyCodes) + " x=" + x + " y=" + y
                    + " x=" + x + " y=" + y
                    + " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode
                    + " enabled=" + key.isEnabled());
        }
@@ -271,7 +269,7 @@ public class PointerTracker {
            if (code == Keyboard.CODE_OUTPUT_TEXT) {
                mListener.onTextInput(key.mOutputText);
            } else if (code != Keyboard.CODE_UNSPECIFIED) {
                mListener.onCodeInput(code, keyCodes, x, y);
                mListener.onCodeInput(code, x, y);
            }
            if (!key.altCodeWhileTyping() && !key.isModifier()) {
                mTimerProxy.startKeyTypedTimer();
@@ -719,10 +717,7 @@ public class PointerTracker {
        }

        int code = key.mCode;
        final int[] codes = mKeyDetector.newCodeArray();
        mKeyDetector.getKeyAndNearbyCodes(x, y, codes);

        callListenerOnCodeInput(key, code, codes, x, y);
        callListenerOnCodeInput(key, code, x, y);
        callListenerOnRelease(key, code, false);
    }

+20 −18
Original line number Diff line number Diff line
@@ -728,10 +728,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        final KeyboardSwitcher switcher = mKeyboardSwitcher;
        LatinKeyboardView inputView = switcher.getKeyboardView();

        if (editorInfo == null) {
            Log.e(TAG, "Null EditorInfo in onStartInputView()");
            if (LatinImeLogger.sDBG) {
                throw new NullPointerException("Null EditorInfo in onStartInputView()");
            }
            return;
        }
        if (DEBUG) {
            Log.d(TAG, "onStartInputView: editorInfo:" + ((editorInfo == null) ? "none"
                    : String.format("inputType=0x%08x imeOptions=0x%08x",
                            editorInfo.inputType, editorInfo.imeOptions)));
            Log.d(TAG, "onStartInputView: editorInfo:"
                    + String.format("inputType=0x%08x imeOptions=0x%08x",
                            editorInfo.inputType, editorInfo.imeOptions));
        }
        if (Utils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) {
            Log.w(TAG, "Deprecated private IME option specified: "
@@ -761,7 +768,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        // Most such things we decide below in initializeInputAttributesAndGetMode, but we need to
        // know now whether this is a password text field, because we need to know now whether we
        // want to enable the voice button.
        final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
        final int inputType = editorInfo.inputType;
        mVoiceProxy.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(inputType)
                || InputTypeCompatUtils.isVisiblePasswordInputType(inputType));

@@ -1245,12 +1252,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        return mOptionsDialog != null && mOptionsDialog.isShowing();
    }

    private void insertPunctuationFromSuggestionStrip(final int code) {
        onCodeInput(code, new int[] { code },
                KeyboardActionListener.SUGGESTION_STRIP_COORDINATE,
                KeyboardActionListener.SUGGESTION_STRIP_COORDINATE);
    }

    private static int getActionId(Keyboard keyboard) {
        return keyboard != null ? keyboard.mId.imeActionId() : EditorInfo.IME_ACTION_NONE;
    }
@@ -1279,7 +1280,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar

    // Implementation of {@link KeyboardActionListener}.
    @Override
    public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
    public void onCodeInput(int primaryCode, int x, int y) {
        final long when = SystemClock.uptimeMillis();
        if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
            mDeleteCount = 0;
@@ -1331,7 +1332,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            if (mSettingsValues.isWordSeparator(primaryCode)) {
                didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
            } else {
                handleCharacter(primaryCode, keyCodes, x, y, spaceState);
                handleCharacter(primaryCode, x, y, spaceState);
            }
            mExpectingUpdateSelection = true;
            break;
@@ -1498,18 +1499,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        }
    }

    private void handleCharacter(final int primaryCode, final int[] keyCodes, final int x,
    private void handleCharacter(final int primaryCode, final int x,
            final int y, final int spaceState) {
        mVoiceProxy.handleCharacter();
        final InputConnection ic = getCurrentInputConnection();
        if (null != ic) ic.beginBatchEdit();
        // TODO: if ic is null, does it make any sense to call this?
        handleCharacterWhileInBatchEdit(primaryCode, keyCodes, x, y, spaceState, ic);
        handleCharacterWhileInBatchEdit(primaryCode, x, y, spaceState, ic);
        if (null != ic) ic.endBatchEdit();
    }

    // "ic" may be null without this crashing, but the behavior will be really strange
    private void handleCharacterWhileInBatchEdit(final int primaryCode, final int[] keyCodes,
    private void handleCharacterWhileInBatchEdit(final int primaryCode,
            final int x, final int y, final int spaceState, final InputConnection ic) {
        boolean isComposingWord = mWordComposer.isComposingWord();

@@ -1541,7 +1542,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            }
        }
        if (isComposingWord) {
            mWordComposer.add(primaryCode, keyCodes, x, y);
            mWordComposer.add(
                    primaryCode, x, y, mKeyboardSwitcher.getKeyboardView().getKeyDetector());
            if (ic != null) {
                // If it's the first letter, make note of auto-caps state
                if (mWordComposer.size() == 1) {
@@ -1912,7 +1914,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords);
            // Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
            final int primaryCode = suggestion.charAt(0);
            onCodeInput(primaryCode, new int[] { primaryCode },
            onCodeInput(primaryCode,
                    KeyboardActionListener.SUGGESTION_STRIP_COORDINATE,
                    KeyboardActionListener.SUGGESTION_STRIP_COORDINATE);
            return;
@@ -2158,7 +2160,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        final String originallyTypedWord = mLastComposedWord.mTypedWord;
        final CharSequence committedWord = mLastComposedWord.mCommittedWord;
        final int cancelLength = committedWord.length();
        final int separatorLength = mLastComposedWord.getSeparatorLength(
        final int separatorLength = LastComposedWord.getSeparatorLength(
                mLastComposedWord.mSeparatorCode);
        // TODO: should we check our saved separator against the actual contents of the text view?
        if (DEBUG) {
Loading