diff options
author | 2012-03-06 14:56:46 +0900 | |
---|---|---|
committer | 2012-03-06 15:34:27 +0900 | |
commit | ca7ec2097ca6af1505c1e6aa8b81b6068ba46dae (patch) | |
tree | 4789eb1bc2b9094f61696a642585b790d38d8d78 /java/src/com/android/inputmethod/latin | |
parent | e31060dc776246b64a9081fedf162babbe87064c (diff) | |
download | latinime-ca7ec2097ca6af1505c1e6aa8b81b6068ba46dae.tar.gz latinime-ca7ec2097ca6af1505c1e6aa8b81b6068ba46dae.tar.xz latinime-ca7ec2097ca6af1505c1e6aa8b81b6068ba46dae.zip |
Integrate the logic to calculate the proximities
Bug: 4343280
Change-Id: I0f6a7e6912ed4abea07c10d266da4c7ccb0dae76
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
5 files changed, 69 insertions, 40 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 64b9f3364..044f05014 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -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) { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index f6e177aaf..298ead665 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -323,7 +323,6 @@ public class Suggest implements Dictionary.WordCallback { } } else { // Word entered: return only bigrams that match the first char of the typed word - @SuppressWarnings("null") final char currentChar = consideredWord.charAt(0); // TODO: Must pay attention to locale when changing case. final char currentCharUpper = Character.toUpperCase(currentChar); diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 8121ada7f..2a597b86d 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -19,6 +19,9 @@ package com.android.inputmethod.latin; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.KeyboardActionListener; +import com.android.inputmethod.latin.spellcheck.AndroidSpellCheckerService; +import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo; import java.util.ArrayList; import java.util.Arrays; @@ -119,19 +122,60 @@ public class WordComposer { return previous && !Character.isUpperCase(codePoint); } + // TODO: remove input keyDetector + public void add(int primaryCode, int keyX, int keyY, KeyDetector keyDetector) { + final int[] codes; + if (keyX == KeyboardActionListener.SPELL_CHECKER_COORDINATE + || keyY == KeyboardActionListener.SPELL_CHECKER_COORDINATE) { + // only used for tests in InputLogicTests + addKeyForSpellChecker(primaryCode, AndroidSpellCheckerService.SCRIPT_LATIN); + return; + } else if (keyX == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE + || keyY == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE + || keyX == KeyboardActionListener.NOT_A_TOUCH_COORDINATE + || keyY == KeyboardActionListener.NOT_A_TOUCH_COORDINATE) { + codes = new int[] { primaryCode }; + } else { + codes = keyDetector.newCodeArray(); + keyDetector.getKeyAndNearbyCodes(keyX, keyY, codes); + } + add(primaryCode, codes, keyX, keyY); + } + + // TODO: remove this function + public void addKeyForSpellChecker(int primaryCode, int script) { + final int[] proximities; + final int proximityIndex = + SpellCheckerProximityInfo.getIndexOfCodeForScript(primaryCode, script); + if (-1 == proximityIndex) { + proximities = new int[] { primaryCode }; + } else { + // TODO: an initial examination seems to reveal this is actually used + // read-only. It should be possible to compute the arrays statically once + // and skip doing a copy each time here. + proximities = Arrays.copyOfRange( + SpellCheckerProximityInfo.getProximityForScript(script), + proximityIndex, + proximityIndex + SpellCheckerProximityInfo.ROW_SIZE); + } + add(primaryCode, proximities, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + } + /** * Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of * the array containing unicode for adjacent keys, sorted by reducing probability/proximity. * @param codes the array of unicode values */ - public void add(int primaryCode, int[] codes, int x, int y) { + private void add(int primaryCode, int[] codes, int keyX, int keyY) { final int newIndex = mCodes.size(); mTypedWord.appendCodePoint(primaryCode); correctPrimaryJuxtapos(primaryCode, codes); mCodes.add(codes); if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) { - mXCoordinates[newIndex] = x; - mYCoordinates[newIndex] = y; + mXCoordinates[newIndex] = keyX; + mYCoordinates[newIndex] = keyY; } mIsFirstCharCapitalized = isFirstCharCapitalized( newIndex, primaryCode, mIsFirstCharCapitalized); diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 8ac82ee5b..755c75b2e 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -570,23 +570,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService final WordComposer composer = new WordComposer(); final int length = text.length(); for (int i = 0; i < length; i = text.offsetByCodePoints(i, 1)) { - final int character = text.codePointAt(i); - final int proximityIndex = - SpellCheckerProximityInfo.getIndexOfCodeForScript(character, mScript); - final int[] proximities; - if (-1 == proximityIndex) { - proximities = new int[] { character }; - } else { - // TODO: an initial examination seems to reveal this is actually used - // read-only. It should be possible to compute the arrays statically once - // and skip doing a copy each time here. - proximities = Arrays.copyOfRange( - SpellCheckerProximityInfo.getProximityForScript(mScript), - proximityIndex, - proximityIndex + SpellCheckerProximityInfo.ROW_SIZE); - } - composer.add(character, proximities, - WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); + composer.addKeyForSpellChecker(text.codePointAt(i), mScript); } final int capitalizeType = getCapitalizationType(text); diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index cd83c3e21..1f7214777 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -66,7 +66,7 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { } @Override - public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) { + public void onCodeInput(int primaryCode, int x, int y) { final int index = primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE; if (index >= 0 && index < SuggestionsView.MAX_SUGGESTIONS) { mListener.onCustomRequest(index); |