diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d02c4df7e..a48778ab3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1,17 +1,17 @@ /* * Copyright (C) 2008 The Android Open Source Project * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.android.inputmethod.latin; @@ -82,6 +82,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Locale; +import java.util.TreeSet; /** * Input method implementation for Qwerty'ish keyboard. @@ -167,6 +168,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private int mDeleteCount; private long mLastKeyTime; private int mActionId; + private TreeSet<Long> mCurrentlyPressedHardwareKeys = CollectionUtils.newTreeSet(); // Member variables for remembering the current device orientation. private int mDisplayOrientation; @@ -721,6 +723,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction resetComposingState(true /* alsoResetLastComposedWord */); mDeleteCount = 0; mSpaceState = SPACE_STATE_NONE; + mCurrentlyPressedHardwareKeys.clear(); if (mSuggestionStripView != null) { // This will set the punctuation suggestions if next word suggestion is off; @@ -773,7 +776,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // to the user dictionary. if (null != mPositionalInfoForUserDictPendingAddition && mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord( - mConnection, editorInfo, mLastSelectionEnd)) { + mConnection, editorInfo, mLastSelectionEnd, + mSubtypeSwitcher.getCurrentSubtypeLocale())) { mPositionalInfoForUserDictPendingAddition = null; } // If tryReplaceWithActualWord returns false, we don't know what word was @@ -1223,11 +1227,17 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mPositionalInfoForUserDictPendingAddition = null; return; } + final String wordToEdit; + if (StringUtils.isAutoCapsMode(mLastComposedWord.mCapitalizedMode)) { + wordToEdit = word.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale()); + } else { + wordToEdit = word; + } mPositionalInfoForUserDictPendingAddition = new PositionalInfoForUserDictPendingAddition( - word, mLastSelectionEnd, getCurrentInputEditorInfo(), + wordToEdit, mLastSelectionEnd, getCurrentInputEditorInfo(), mLastComposedWord.mCapitalizedMode); - mUserDictionary.addWordToUserDictionary(word, 128); + mUserDictionary.addWordToUserDictionary(wordToEdit); } public void onWordAddedToUserDictionary(final String newSpelling) { @@ -1240,7 +1250,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mPositionalInfoForUserDictPendingAddition.setActualWordBeingAdded(newSpelling); if (mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord( - mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd)) { + mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd, + mSubtypeSwitcher.getCurrentSubtypeLocale())) { mPositionalInfoForUserDictPendingAddition = null; } } @@ -1476,7 +1487,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction Stats.onAutoCorrection("", mWordComposer.getTypedWord(), " ", mWordComposer); } } - if (mWordComposer.size() <= 1) { + final int wordComposerSize = mWordComposer.size(); + // Since isComposingWord() is true, the size is at least 1. + final int lastChar = mWordComposer.getCodeAt(wordComposerSize - 1); + if (wordComposerSize <= 1) { // We auto-correct the previous (typed, not gestured) string iff it's one character // long. The reason for this is, even in the middle of gesture typing, you'll still // tap one-letter words and you want them auto-corrected (typically, "i" in English @@ -1490,8 +1504,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mExpectingUpdateSelection = true; // The following is necessary for the case where the user typed something but didn't - // manual pick it and didn't input any separator. - mSpaceState = SPACE_STATE_PHANTOM; + // manual pick it and didn't input any separator: we want to put a space between what + // has been entered and the coming gesture input result, so we go into phantom space + // state, which will be promoted to a space when the gesture result is committed. But if + // the current input ends in a word connector on the other hand, then we want to have + // the next input stick to the current input so we don't switch to phantom space state. + if (!mSettings.getCurrent().isWordConnector(lastChar)) { + mSpaceState = SPACE_STATE_PHANTOM; + } } else { final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor(); if (mSettings.getCurrent().isUsuallyFollowedBySpace(codePointBeforeCursor)) { @@ -1597,7 +1617,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords, final boolean dismissGestureFloatingPreviewText) { showSuggestionStrip(suggestedWords, null); - final KeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); + final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); mainKeyboardView.showGestureFloatingPreviewText(suggestedWords); if (dismissGestureFloatingPreviewText) { mainKeyboardView.dismissGestureFloatingPreviewText(); @@ -1861,6 +1881,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final int spaceState) { if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.recordTimeForLogUnitSplit(); + ResearchLogger.latinIME_handleSeparator(primaryCode, mWordComposer.isComposingWord()); } boolean didAutoCorrect = false; // Handle separator @@ -2409,15 +2430,24 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Hooks for hardware keyboard @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { + if (!ProductionFlag.IS_HARDWARE_KEYBOARD_SUPPORTED) return super.onKeyDown(keyCode, event); // onHardwareKeyEvent, like onKeyDown returns true if it handled the event, false if // it doesn't know what to do with it and leave it to the application. For example, // hardware key events for adjusting the screen's brightness are passed as is. - if (mEventInterpreter.onHardwareKeyEvent(event)) return true; + if (mEventInterpreter.onHardwareKeyEvent(event)) { + final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode(); + mCurrentlyPressedHardwareKeys.add(keyIdentifier); + return true; + } return super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(final int keyCode, final KeyEvent event) { + final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode(); + if (mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) { + return true; + } return super.onKeyUp(keyCode, event); } |