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

Commit 3a2896c8 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Fix issue space key preview remains on screen and would not dismiss

The space key preview should be displayed one of the following case.
- Popup preview is enabled
- Language switcher is in action, whether popup preview is enabled or
  not.

For phone number keyboard, popup preview is never displayed even if
popup preview is enabled.

Bug: 3006612
Bug: 3021091
Change-Id: I5385c776d0e8e3981fc8d8851db9140d92599ce5
parent 75c23ced
Loading
Loading
Loading
Loading
+17 −27
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.inputmethod.latin;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -87,7 +86,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
    private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;

    LatinKeyboardView mInputView;
    private LatinKeyboardView mInputView;
    private static final int[] ALPHABET_MODES = {
        KEYBOARDMODE_NORMAL,
        KEYBOARDMODE_URL,
@@ -100,7 +99,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        KEYBOARDMODE_IM_WITH_SETTINGS_KEY,
        KEYBOARDMODE_WEB_WITH_SETTINGS_KEY };

    final LatinIME mInputMethodService;
    private final LatinIME mInputMethodService;

    private KeyboardId mSymbolsId;
    private KeyboardId mSymbolsShiftedId;
@@ -120,7 +119,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;

    // Indicates whether or not we have the settings key
    boolean mHasSettingsKey;
    private boolean mHasSettingsKey;
    private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto;
    private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW = R.string.settings_key_mode_always_show;
    // NOTE: No need to have SETTINGS_KEY_MODE_ALWAYS_HIDE here because it's not being referred to
@@ -134,7 +133,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha

    private int mLayoutId;

    KeyboardSwitcher(LatinIME ims) {
    public KeyboardSwitcher(LatinIME ims) {
        mInputMethodService = ims;

        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims);
@@ -153,15 +152,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     * @param locale the current input locale, or null for default locale with no locale 
     * button.
     */
    void setLanguageSwitcher(LanguageSwitcher languageSwitcher) {
    public void setLanguageSwitcher(LanguageSwitcher languageSwitcher) {
        mLanguageSwitcher = languageSwitcher;
        mInputLocale = mLanguageSwitcher.getInputLocale();
    }

    void setInputView(LatinKeyboardView inputView) {
        mInputView = inputView;
    }

    private KeyboardId makeSymbolsId(boolean hasVoice) {
        return new KeyboardId(KBD_SYMBOLS[getCharColorId()], mHasSettingsKey ?
                KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS,
@@ -174,7 +169,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
                false, hasVoice);
    }

    void makeKeyboards(boolean forceCreate) {
    public void makeKeyboards(boolean forceCreate) {
        mSymbolsId = makeSymbolsId(mHasVoice && !mVoiceOnPrimary);
        mSymbolsShiftedId = makeSymbolsShiftedId(mHasVoice && !mVoiceOnPrimary);

@@ -229,7 +224,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        }
    }

    void setVoiceMode(boolean enableVoice, boolean voiceOnPrimary) {
    public void setVoiceMode(boolean enableVoice, boolean voiceOnPrimary) {
        if (enableVoice != mHasVoice || voiceOnPrimary != mVoiceOnPrimary) {
            mKeyboards.clear();
        }
@@ -238,11 +233,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        setKeyboardMode(mMode, mImeOptions, mHasVoice, mIsSymbols);
    }

    boolean hasVoiceButton(boolean isSymbols) {
    private boolean hasVoiceButton(boolean isSymbols) {
        return mHasVoice && (isSymbols != mVoiceOnPrimary);
    }

    void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) {
    public void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) {
        mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
        mPreferSymbols = mode == MODE_SYMBOLS;
        if (mode == MODE_SYMBOLS) {
@@ -255,7 +250,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        }
    }

    void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) {
    private void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) {
        if (mInputView == null) return;
        mMode = mode;
        mImeOptions = imeOptions;
@@ -271,7 +266,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha

        if (mode == MODE_PHONE) {
            mInputView.setPhoneKeyboard(keyboard);
            mInputView.setPreviewEnabled(false);
        }

        mCurrentId = id;
@@ -354,15 +348,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        return null;
    }

    int getKeyboardMode() {
    public int getKeyboardMode() {
        return mMode;
    }
    
    boolean isTextMode() {
        return mMode == MODE_TEXT;
    }

    boolean isAlphabetMode() {
    public boolean isAlphabetMode() {
        if (mCurrentId == null) {
            return false;
        }
@@ -375,19 +365,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        return false;
    }

    void setShifted(boolean shifted) {
    public void setShifted(boolean shifted) {
        if (mInputView != null) {
            mInputView.setShifted(shifted);
        }
    }

    void setShiftLocked(boolean shiftLocked) {
    public void setShiftLocked(boolean shiftLocked) {
        if (mInputView != null) {
            mInputView.setShiftLocked(shiftLocked);
        }
    }

    void toggleShift() {
    public void toggleShift() {
        if (mCurrentId.equals(mSymbolsId)) {
            LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId);
            mCurrentId = mSymbolsShiftedId;
@@ -412,7 +402,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        }
    }

    void toggleSymbols() {
    public void toggleSymbols() {
        setKeyboardMode(mMode, mImeOptions, mHasVoice, !mIsSymbols);
        if (mIsSymbols && !mPreferSymbols) {
            mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN;
@@ -429,7 +419,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     * Updates state machine to figure out when to automatically switch back to alpha mode.
     * Returns true if the keyboard needs to switch back 
     */
    boolean onKey(int key) {
    public boolean onKey(int key) {
        // Switch back to alpha mode if user types one or more non-space/enter characters
        // followed by a space/enter
        switch (mSymbolsModeState) {
+5 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class LatinKeyboard extends Keyboard {
                R.dimen.spacebar_vertical_correction);
        mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty
                || xmlLayoutResId == R.xml.kbd_qwerty_black;
        mSpaceKeyIndex = indexOf(' ');
        mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE);
        initializeNumberHintResources(context);
    }

@@ -384,6 +384,10 @@ public class LatinKeyboard extends Keyboard {
        }
    }

    public boolean isLanguageSwitchEnabled() {
        return mLocale != null;
    }

    private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) {
        // If application locales are explicitly selected.
        if (mLocale != null) {
+11 −2
Original line number Diff line number Diff line
@@ -881,8 +881,17 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
    public void showPreview(int keyIndex, PointerTracker tracker) {
        int oldKeyIndex = mOldPreviewKeyIndex;
        mOldPreviewKeyIndex = keyIndex;
        // If key changed and preview is on ...
        if (oldKeyIndex != keyIndex && mShowPreview) {
        final boolean isLanguageSwitchEnabled = (mKeyboard instanceof LatinKeyboard)
                && ((LatinKeyboard)mKeyboard).isLanguageSwitchEnabled();
        // We should re-draw popup preview when 1) we need to hide the preview, 2) we will show
        // the space key preview and 3) pointer moves off the space key to other letter key, we
        // should hide the preview of the previous key.
        final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null)
                || tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex);
        // If key changed and preview is on or the key is space (language switch is enabled)
        if (oldKeyIndex != keyIndex
                && (mShowPreview
                        || (hidePreviewOrShowSpaceKeyPreview && isLanguageSwitchEnabled))) {
            if (keyIndex == NOT_A_KEY) {
                mHandler.cancelPopupPreview();
                mHandler.dismissPreview(DELAY_AFTER_PREVIEW);
+10 −0
Original line number Diff line number Diff line
@@ -65,6 +65,16 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
        mPhoneKeyboard = phoneKeyboard;
    }

    @Override
    public void setPreviewEnabled(boolean previewEnabled) {
        if (getKeyboard() == mPhoneKeyboard) {
            // Phone keyboard never shows popup preview (except language switch).
            super.setPreviewEnabled(false);
        } else {
            super.setPreviewEnabled(previewEnabled);
        }
    }

    @Override
    public void setKeyboard(Keyboard k) {
        super.setKeyboard(k);
+5 −0
Original line number Diff line number Diff line
@@ -140,6 +140,11 @@ public class PointerTracker {
        return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null));
    }

    public boolean isSpaceKey(int keyIndex) {
        Key key = getKey(keyIndex);
        return key != null && key.codes[0] == LatinIME.KEYCODE_SPACE;
    }

    public void updateKey(int keyIndex) {
        if (mKeyAlreadyProcessed)
            return;