diff options
Diffstat (limited to 'src')
4 files changed, 148 insertions, 142 deletions
diff --git a/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/src/com/android/inputmethod/latin/KeyboardSwitcher.java index b3fcbda6f..92b7cd4a1 100644 --- a/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -16,9 +16,8 @@ package com.android.inputmethod.latin; -import android.inputmethodservice.Keyboard; - -import java.util.List; +import java.util.HashMap; +import java.util.Map; public class KeyboardSwitcher { @@ -37,31 +36,28 @@ public class KeyboardSwitcher { public static final int KEYBOARDMODE_URL = R.id.mode_url; public static final int KEYBOARDMODE_EMAIL = R.id.mode_email; public static final int KEYBOARDMODE_IM = R.id.mode_im; - LatinKeyboardView mInputView; LatinIME mContext; - private LatinKeyboard mPhoneKeyboard; - private LatinKeyboard mPhoneSymbolsKeyboard; - private LatinKeyboard mSymbolsKeyboard; - private LatinKeyboard mSymbolsShiftedKeyboard; - private LatinKeyboard mQwertyKeyboard; - private LatinKeyboard mAlphaKeyboard; - private LatinKeyboard mUrlKeyboard; - private LatinKeyboard mEmailKeyboard; - private LatinKeyboard mIMKeyboard; - - List<Keyboard> mKeyboards; + private KeyboardId mSymbolsId; + private KeyboardId mSymbolsShiftedId; + + private KeyboardId mCurrentId; + private Map<KeyboardId, LatinKeyboard> mKeyboards; private int mMode; private int mImeOptions; private int mTextMode = MODE_TEXT_QWERTY; + private boolean mIsSymbols; private int mLastDisplayWidth; KeyboardSwitcher(LatinIME context) { mContext = context; + mKeyboards = new HashMap<KeyboardId, LatinKeyboard>(); + mSymbolsId = new KeyboardId(R.xml.kbd_symbols); + mSymbolsShiftedId = new KeyboardId(R.xml.kbd_symbols_shift); } void setInputView(LatinKeyboardView inputView) { @@ -72,92 +68,109 @@ public class KeyboardSwitcher { // Configuration change is coming after the keyboard gets recreated. So don't rely on that. // If keyboards have already been made, check if we have a screen width change and // create the keyboard layouts again at the correct orientation - if (mKeyboards != null) { - int displayWidth = mContext.getMaxWidth(); - if (displayWidth == mLastDisplayWidth) return; - mLastDisplayWidth = displayWidth; + int displayWidth = mContext.getMaxWidth(); + if (displayWidth == mLastDisplayWidth) return; + mLastDisplayWidth = displayWidth; + mKeyboards.clear(); + mSymbolsId = new KeyboardId(R.xml.kbd_symbols); + mSymbolsShiftedId = new KeyboardId(R.xml.kbd_symbols_shift); + } + + /** + * Represents the parameters necessary to construct a new LatinKeyboard, + * which also serve as a unique identifier for each keyboard type. + */ + private static class KeyboardId { + public int mXml; + public int mMode; + public boolean mEnableShiftLock; + + public KeyboardId(int xml, int mode, boolean enableShiftLock) { + this.mXml = xml; + this.mMode = mode; + this.mEnableShiftLock = enableShiftLock; + } + + public KeyboardId(int xml) { + this(xml, 0, false); + } + + public boolean equals(Object other) { + return other instanceof KeyboardId && equals((KeyboardId) other); + } + + public boolean equals(KeyboardId other) { + return other.mXml == this.mXml && other.mMode == this.mMode; + } + + public int hashCode() { + return (mXml + 1) * (mMode + 1) * (mEnableShiftLock ? 2 : 1); } - // Delayed creation when keyboard mode is set. - mQwertyKeyboard = null; - mAlphaKeyboard = null; - mUrlKeyboard = null; - mEmailKeyboard = null; - mIMKeyboard = null; - mPhoneKeyboard = null; - mPhoneSymbolsKeyboard = null; - mSymbolsKeyboard = null; - mSymbolsShiftedKeyboard = null; } void setKeyboardMode(int mode, int imeOptions) { + setKeyboardMode(mode, imeOptions, false); + } + + void setKeyboardMode(int mode, int imeOptions, boolean isSymbols) { mMode = mode; mImeOptions = imeOptions; - LatinKeyboard keyboard = (LatinKeyboard) mInputView.getKeyboard(); + mIsSymbols = isSymbols; mInputView.setPreviewEnabled(true); + KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); + LatinKeyboard keyboard = getKeyboard(id); + + if (mode == MODE_PHONE) { + mInputView.setPhoneKeyboard(keyboard); + mInputView.setPreviewEnabled(false); + } + + mCurrentId = id; + mInputView.setKeyboard(keyboard); + keyboard.setShifted(false); + keyboard.setShiftLocked(keyboard.isShiftLocked()); + keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions); + + } + + private LatinKeyboard getKeyboard(KeyboardId id) { + if (!mKeyboards.containsKey(id)) { + LatinKeyboard keyboard = new LatinKeyboard( + mContext, id.mXml, id.mMode); + if (id.mEnableShiftLock) { + keyboard.enableShiftLock(); + } + mKeyboards.put(id, keyboard); + } + return mKeyboards.get(id); + } + + private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) { + if (isSymbols) { + return (mode == MODE_PHONE) + ? new KeyboardId(R.xml.kbd_phone_symbols) : new KeyboardId(R.xml.kbd_symbols); + } + switch (mode) { case MODE_TEXT: if (mTextMode == MODE_TEXT_QWERTY) { - if (mQwertyKeyboard == null) { - mQwertyKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, - KEYBOARDMODE_NORMAL); - mQwertyKeyboard.enableShiftLock(); - } - keyboard = mQwertyKeyboard; + return new KeyboardId(R.xml.kbd_qwerty, KEYBOARDMODE_NORMAL, true); } else if (mTextMode == MODE_TEXT_ALPHA) { - if (mAlphaKeyboard == null) { - mAlphaKeyboard = new LatinKeyboard(mContext, R.xml.kbd_alpha, - KEYBOARDMODE_NORMAL); - mAlphaKeyboard.enableShiftLock(); - } - keyboard = mAlphaKeyboard; + return new KeyboardId(R.xml.kbd_alpha, KEYBOARDMODE_NORMAL, true); } break; case MODE_SYMBOLS: - if (mSymbolsKeyboard == null) { - mSymbolsKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols); - } - if (mSymbolsShiftedKeyboard == null) { - mSymbolsShiftedKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols_shift); - } - keyboard = mSymbolsKeyboard; - break; + return new KeyboardId(R.xml.kbd_symbols); case MODE_PHONE: - if (mPhoneKeyboard == null) { - mPhoneKeyboard = new LatinKeyboard(mContext, R.xml.kbd_phone); - } - mInputView.setPhoneKeyboard(mPhoneKeyboard); - if (mPhoneSymbolsKeyboard == null) { - mPhoneSymbolsKeyboard = new LatinKeyboard(mContext, R.xml.kbd_phone_symbols); - } - keyboard = mPhoneKeyboard; - mInputView.setPreviewEnabled(false); - break; + return new KeyboardId(R.xml.kbd_phone); case MODE_URL: - if (mUrlKeyboard == null) { - mUrlKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, KEYBOARDMODE_URL); - mUrlKeyboard.enableShiftLock(); - } - keyboard = mUrlKeyboard; - break; + return new KeyboardId(R.xml.kbd_qwerty, KEYBOARDMODE_URL, true); case MODE_EMAIL: - if (mEmailKeyboard == null) { - mEmailKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, KEYBOARDMODE_EMAIL); - mEmailKeyboard.enableShiftLock(); - } - keyboard = mEmailKeyboard; - break; + return new KeyboardId(R.xml.kbd_qwerty, KEYBOARDMODE_EMAIL, true); case MODE_IM: - if (mIMKeyboard == null) { - mIMKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, KEYBOARDMODE_IM); - mIMKeyboard.enableShiftLock(); - } - keyboard = mIMKeyboard; - break; + return new KeyboardId(R.xml.kbd_qwerty, KEYBOARDMODE_IM, true); } - mInputView.setKeyboard(keyboard); - keyboard.setShifted(false); - keyboard.setShiftLocked(keyboard.isShiftLocked()); - keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions); + return null; } int getKeyboardMode() { @@ -186,56 +199,34 @@ public class KeyboardSwitcher { } boolean isAlphabetMode() { - Keyboard current = mInputView.getKeyboard(); - if (current == mQwertyKeyboard - || current == mAlphaKeyboard - || current == mUrlKeyboard - || current == mIMKeyboard - || current == mEmailKeyboard) { - return true; - } - return false; + KeyboardId current = mCurrentId; + return current.mMode == KEYBOARDMODE_NORMAL + || current.mMode == KEYBOARDMODE_URL + || current.mMode == KEYBOARDMODE_EMAIL + || current.mMode == KEYBOARDMODE_IM; } void toggleShift() { - Keyboard currentKeyboard = mInputView.getKeyboard(); - if (currentKeyboard == mSymbolsKeyboard) { - mSymbolsKeyboard.setShifted(true); - mInputView.setKeyboard(mSymbolsShiftedKeyboard); - mSymbolsShiftedKeyboard.setShifted(true); - mSymbolsShiftedKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); - } else if (currentKeyboard == mSymbolsShiftedKeyboard) { - mSymbolsShiftedKeyboard.setShifted(false); - mInputView.setKeyboard(mSymbolsKeyboard); - mSymbolsKeyboard.setShifted(false); - mSymbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); + if (mCurrentId.equals(mSymbolsId)) { + LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId); + LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId); + symbolsKeyboard.setShifted(true); + mCurrentId = mSymbolsShiftedId; + mInputView.setKeyboard(symbolsShiftedKeyboard); + symbolsShiftedKeyboard.setShifted(true); + symbolsShiftedKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); + } else if (mCurrentId.equals(mSymbolsShiftedId)) { + LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId); + LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId); + symbolsShiftedKeyboard.setShifted(false); + mCurrentId = mSymbolsId; + mInputView.setKeyboard(getKeyboard(mSymbolsId)); + symbolsKeyboard.setShifted(false); + symbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); } } void toggleSymbols() { - Keyboard current = mInputView.getKeyboard(); - if (mSymbolsKeyboard == null) { - mSymbolsKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols); - } - if (mSymbolsShiftedKeyboard == null) { - mSymbolsShiftedKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols_shift); - } - if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) { - setKeyboardMode(mMode, mImeOptions); // Could be qwerty, alpha, url, email or im - return; - } else if (current == mPhoneKeyboard) { - current = mPhoneSymbolsKeyboard; - mPhoneSymbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); - } else if (current == mPhoneSymbolsKeyboard) { - current = mPhoneKeyboard; - mPhoneKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); - } else { - current = mSymbolsKeyboard; - mSymbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); - } - mInputView.setKeyboard(current); - if (current == mSymbolsKeyboard) { - current.setShifted(false); - } + setKeyboardMode(mMode, mImeOptions, !mIsSymbols); } } diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java index f81637580..240668ebb 100644 --- a/src/com/android/inputmethod/latin/LatinIME.java +++ b/src/com/android/inputmethod/latin/LatinIME.java @@ -113,7 +113,6 @@ public class LatinIME extends InputMethodService private boolean mAutoCap; private boolean mQuickFixes; private boolean mShowSuggestions; - private boolean mAutoComplete; private int mCorrectionMode; // Indicates whether the suggestion strip is to be on in landscape private boolean mJustAccepted; @@ -223,9 +222,10 @@ public class LatinIME extends InputMethodService } mKeyboardSwitcher.makeKeyboards(); - + TextEntryState.newSession(this); - + + boolean disableAutoCorrect = false; mPredictionOn = false; mCompletionOn = false; mCompletions = null; @@ -271,6 +271,12 @@ public class LatinIME extends InputMethodService attribute.imeOptions); } else if (variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) { mPredictionOn = false; + } else if (variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) { + // If it's a browser edit field and auto correct is not ON explicitly, then + // disable auto correction, but keep suggestions on. + if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) { + disableAutoCorrect = true; + } } if ((attribute.inputType&EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) { mPredictionOn = false; @@ -290,6 +296,13 @@ public class LatinIME extends InputMethodService setCandidatesViewShown(false); if (mCandidateView != null) mCandidateView.setSuggestions(null, false, false, false); loadSettings(); + // Override auto correct + if (disableAutoCorrect) { + mAutoCorrectOn = false; + if (mCorrectionMode == Suggest.CORRECTION_FULL) { + mCorrectionMode = Suggest.CORRECTION_BASIC; + } + } mInputView.setProximityCorrectionEnabled(true); if (mSuggest != null) { mSuggest.setCorrectionMode(mCorrectionMode); @@ -1005,10 +1018,12 @@ public class LatinIME extends InputMethodService // will continue to work if (AutoText.getSize(mInputView) < 1) mQuickFixes = true; mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true) & mQuickFixes; - mAutoComplete = sp.getBoolean(PREF_AUTO_COMPLETE, + boolean autoComplete = sp.getBoolean(PREF_AUTO_COMPLETE, getResources().getBoolean(R.bool.enable_autocorrect)) & mShowSuggestions; - mAutoCorrectOn = mSuggest != null && (mAutoComplete || mQuickFixes); - mCorrectionMode = mAutoComplete ? 2 : (mQuickFixes ? 1 : 0); + mAutoCorrectOn = mSuggest != null && (autoComplete || mQuickFixes); + mCorrectionMode = autoComplete + ? Suggest.CORRECTION_FULL + : (mQuickFixes ? Suggest.CORRECTION_BASIC : Suggest.CORRECTION_NONE); } private void showOptionsMenu() { diff --git a/src/com/android/inputmethod/latin/LatinKeyboard.java b/src/com/android/inputmethod/latin/LatinKeyboard.java index 7720dfbe5..8527d9cd5 100644 --- a/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -213,19 +213,19 @@ public class LatinKeyboard extends Keyboard { pressed = !pressed; } } - + /** * Overriding this method so that we can reduce the target area for certain keys. */ @Override public boolean isInside(int x, int y) { - if ((edgeFlags & Keyboard.EDGE_BOTTOM) != 0 || - codes[0] == KEYCODE_SHIFT || - codes[0] == KEYCODE_DELETE) { + final int code = codes[0]; + if (code == KEYCODE_SHIFT || + code == KEYCODE_DELETE) { y -= height / 10; + if (code == KEYCODE_SHIFT) x += width / 6; + if (code == KEYCODE_DELETE) x -= width / 6; } - if (codes[0] == KEYCODE_SHIFT) x += width / 6; - if (codes[0] == KEYCODE_DELETE) x -= width / 6; return super.isInside(x, y); } } diff --git a/src/com/android/inputmethod/latin/LatinKeyboardView.java b/src/com/android/inputmethod/latin/LatinKeyboardView.java index 363dcd0b0..d9ff0aa8c 100644 --- a/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -33,7 +33,7 @@ public class LatinKeyboardView extends KeyboardView { static final int KEYCODE_OPTIONS = -100; static final int KEYCODE_SHIFT_LONGPRESS = -101; - + private Keyboard mPhoneKeyboard; public LatinKeyboardView(Context context, AttributeSet attrs) { @@ -43,11 +43,11 @@ public class LatinKeyboardView extends KeyboardView { public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } - + public void setPhoneKeyboard(Keyboard phoneKeyboard) { mPhoneKeyboard = phoneKeyboard; } - + @Override protected boolean onLongPress(Key key) { if (key.codes[0] == Keyboard.KEYCODE_MODE_CHANGE) { @@ -55,7 +55,7 @@ public class LatinKeyboardView extends KeyboardView { return true; } else if (key.codes[0] == Keyboard.KEYCODE_SHIFT) { getOnKeyboardActionListener().onKey(KEYCODE_SHIFT_LONGPRESS, null); - invalidate(); + invalidateAllKeys(); return true; } else if (key.codes[0] == '0' && getKeyboard() == mPhoneKeyboard) { // Long pressing on 0 in phone number keypad gives you a '+'. |