diff options
Diffstat (limited to 'java/src/com/android/inputmethod')
11 files changed, 155 insertions, 594 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java b/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java deleted file mode 100644 index 94615a71f..000000000 --- a/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (C) 2011 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 - * - * 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. - */ - -package com.android.inputmethod.deprecated.recorrection; - -import android.content.SharedPreferences; -import android.content.res.Resources; -import android.text.TextUtils; -import android.view.inputmethod.ExtractedText; -import android.view.inputmethod.ExtractedTextRequest; -import android.view.inputmethod.InputConnection; - -import com.android.inputmethod.compat.InputConnectionCompatUtils; -import com.android.inputmethod.compat.SuggestionSpanUtils; -import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.latin.AutoCorrection; -import com.android.inputmethod.latin.EditingUtils; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.Suggest; -import com.android.inputmethod.latin.SuggestedWords; -import com.android.inputmethod.latin.SuggestionsView; -import com.android.inputmethod.latin.TextEntryState; -import com.android.inputmethod.latin.WordComposer; - -import java.util.ArrayList; - -/** - * Manager of re-correction functionalities - */ -public class Recorrection implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final Recorrection sInstance = new Recorrection(); - - private LatinIME mService; - private boolean mRecorrectionEnabled = false; - private final ArrayList<RecorrectionSuggestionEntries> mRecorrectionSuggestionsList = - new ArrayList<RecorrectionSuggestionEntries>(); - - public static Recorrection getInstance() { - return sInstance; - } - - public static void init(LatinIME context, SharedPreferences prefs) { - if (context == null || prefs == null) { - return; - } - sInstance.initInternal(context, prefs); - } - - private Recorrection() { - } - - public boolean isRecorrectionEnabled() { - return mRecorrectionEnabled; - } - - private void initInternal(LatinIME context, SharedPreferences prefs) { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED) { - mRecorrectionEnabled = false; - return; - } - updateRecorrectionEnabled(context.getResources(), prefs); - mService = context; - prefs.registerOnSharedPreferenceChangeListener(this); - } - - public void checkRecorrectionOnStart() { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED || !mRecorrectionEnabled) return; - - final InputConnection ic = mService.getCurrentInputConnection(); - if (ic == null) return; - // There could be a pending composing span. Clean it up first. - ic.finishComposingText(); - - if (mService.isShowingSuggestionsStrip() && mService.isSuggestionsRequested()) { - // First get the cursor position. This is required by setOldSuggestions(), so that - // it can pass the correct range to setComposingRegion(). At this point, we don't - // have valid values for mLastSelectionStart/End because onUpdateSelection() has - // not been called yet. - ExtractedTextRequest etr = new ExtractedTextRequest(); - etr.token = 0; // anything is fine here - ExtractedText et = ic.getExtractedText(etr, 0); - if (et == null) return; - mService.setLastSelection( - et.startOffset + et.selectionStart, et.startOffset + et.selectionEnd); - - // Then look for possible corrections in a delayed fashion - if (!TextUtils.isEmpty(et.text) && mService.isCursorTouchingWord()) { - mService.mHandler.postUpdateOldSuggestions(); - } - } - } - - public void updateRecorrectionSelection(KeyboardSwitcher keyboardSwitcher, - SuggestionsView suggestionsView, int candidatesStart, int candidatesEnd, - int newSelStart, int newSelEnd, int oldSelStart, int lastSelectionStart, - int lastSelectionEnd, boolean hasUncommittedTypedChars) { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED || !mRecorrectionEnabled) return; - if (!mService.isShowingSuggestionsStrip()) return; - if (!keyboardSwitcher.isInputViewShown()) return; - if (!mService.isSuggestionsRequested()) return; - // Don't look for corrections if the keyboard is not visible - // Check if we should go in or out of correction mode. - if ((candidatesStart == candidatesEnd || newSelStart != oldSelStart || TextEntryState - .isRecorrecting()) - && (newSelStart < newSelEnd - 1 || !hasUncommittedTypedChars)) { - if (mService.isCursorTouchingWord() || lastSelectionStart < lastSelectionEnd) { - mService.mHandler.cancelUpdateBigramPredictions(); - mService.mHandler.postUpdateOldSuggestions(); - } else { - abortRecorrection(false); - // If showing the "touch again to save" hint, do not replace it. Else, - // show the bigrams if we are at the end of the text, punctuation - // otherwise. - if (suggestionsView != null && !suggestionsView.isShowingAddToDictionaryHint()) { - InputConnection ic = mService.getCurrentInputConnection(); - if (null == ic || !TextUtils.isEmpty(ic.getTextAfterCursor(1, 0))) { - if (!mService.isShowingPunctuationList()) { - mService.setPunctuationSuggestions(); - } - } else { - mService.mHandler.postUpdateBigramPredictions(); - } - } - } - } - } - - public void saveRecorrectionSuggestion(WordComposer word, CharSequence result) { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED || !mRecorrectionEnabled) return; - if (word.size() <= 1) { - return; - } - // Skip if result is null. It happens in some edge case. - if (TextUtils.isEmpty(result)) { - return; - } - - // Make a copy of the CharSequence, since it is/could be a mutable CharSequence - final String resultCopy = result.toString(); - RecorrectionSuggestionEntries entry = new RecorrectionSuggestionEntries( - resultCopy, new WordComposer(word)); - mRecorrectionSuggestionsList.add(entry); - } - - public void clearWordsInHistory() { - mRecorrectionSuggestionsList.clear(); - } - - /** - * Tries to apply any typed alternatives for the word if we have any cached alternatives, - * otherwise tries to find new corrections and completions for the word. - * @param touching The word that the cursor is touching, with position information - * @return true if an alternative was found, false otherwise. - */ - public boolean applyTypedAlternatives(WordComposer word, Suggest suggest, - KeyboardSwitcher keyboardSwitcher, EditingUtils.SelectedWord touching) { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED || !mRecorrectionEnabled) return false; - // If we didn't find a match, search for result in typed word history - WordComposer foundWord = null; - RecorrectionSuggestionEntries alternatives = null; - // Search old suggestions to suggest re-corrected suggestions. - for (RecorrectionSuggestionEntries entry : mRecorrectionSuggestionsList) { - if (TextUtils.equals(entry.getChosenWord(), touching.mWord)) { - foundWord = entry.mWordComposer; - alternatives = entry; - break; - } - } - // If we didn't find a match, at least suggest corrections as re-corrected suggestions. - if (foundWord == null - && (AutoCorrection.isValidWord(suggest.getUnigramDictionaries(), - touching.mWord, true))) { - foundWord = new WordComposer(); - for (int i = 0; i < touching.mWord.length(); i++) { - foundWord.add(touching.mWord.charAt(i), - new int[] { touching.mWord.charAt(i) }, WordComposer.NOT_A_COORDINATE, - WordComposer.NOT_A_COORDINATE); - } - } - // Found a match, show suggestions - if (foundWord != null || alternatives != null) { - if (alternatives == null) { - alternatives = new RecorrectionSuggestionEntries(touching.mWord, foundWord); - } - showRecorrections(suggest, keyboardSwitcher, alternatives); - if (foundWord != null) { - word.init(foundWord); - } else { - word.reset(); - } - return true; - } - return false; - } - - - private void showRecorrections(Suggest suggest, KeyboardSwitcher keyboardSwitcher, - RecorrectionSuggestionEntries entries) { - SuggestedWords.Builder builder = entries.getAlternatives(suggest, keyboardSwitcher); - builder.setTypedWordValid(false).setHasMinimalSuggestion(false); - mService.showSuggestions(builder.build(), entries.getOriginalWord()); - } - - public void fetchAndDisplayRecorrectionSuggestions(VoiceProxy voiceProxy, - SuggestionsView suggestionsView, Suggest suggest, KeyboardSwitcher keyboardSwitcher, - WordComposer word, boolean hasUncommittedTypedChars, int lastSelectionStart, - int lastSelectionEnd, String wordSeparators) { - if (!InputConnectionCompatUtils.RECORRECTION_SUPPORTED) return; - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED || !mRecorrectionEnabled) return; - voiceProxy.setShowingVoiceSuggestions(false); - if (suggestionsView != null && suggestionsView.isShowingAddToDictionaryHint()) { - return; - } - InputConnection ic = mService.getCurrentInputConnection(); - if (ic == null) return; - if (!hasUncommittedTypedChars) { - // Extract the selected or touching text - EditingUtils.SelectedWord touching = EditingUtils.getWordAtCursorOrSelection(ic, - lastSelectionStart, lastSelectionEnd, wordSeparators); - - if (touching != null && touching.mWord.length() > 1) { - ic.beginBatchEdit(); - - if (applyTypedAlternatives(word, suggest, keyboardSwitcher, touching) - || voiceProxy.applyVoiceAlternatives(touching)) { - TextEntryState.selectedForRecorrection(); - InputConnectionCompatUtils.underlineWord(ic, touching); - } else { - abortRecorrection(true); - } - - ic.endBatchEdit(); - } else { - abortRecorrection(true); - mService.updateBigramPredictions(); - } - } else { - abortRecorrection(true); - } - } - - public void abortRecorrection(boolean force) { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED) return; - if (force || TextEntryState.isRecorrecting()) { - TextEntryState.onAbortRecorrection(); - mService.setCandidatesViewShown(mService.isSuggestionsStripVisible()); - mService.getCurrentInputConnection().finishComposingText(); - mService.clearSuggestions(); - } - } - - public void updateRecorrectionEnabled(Resources res, SharedPreferences prefs) { - // If the option should not be shown, do not read the re-correction preference - // but always use the default setting defined in the resources. - if (res.getBoolean(R.bool.config_enable_show_recorrection_option)) { - mRecorrectionEnabled = prefs.getBoolean(Settings.PREF_RECORRECTION_ENABLED, - res.getBoolean(R.bool.config_default_compat_recorrection_enabled)); - } else { - mRecorrectionEnabled = - res.getBoolean(R.bool.config_default_compat_recorrection_enabled); - } - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if (SuggestionSpanUtils.SUGGESTION_SPAN_IS_SUPPORTED) return; - if (key.equals(Settings.PREF_RECORRECTION_ENABLED)) { - updateRecorrectionEnabled(mService.getResources(), prefs); - } - } -} diff --git a/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java b/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java deleted file mode 100644 index f33a46277..000000000 --- a/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2011 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 - * - * 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. - */ - -package com.android.inputmethod.deprecated.recorrection; - -import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.latin.Suggest; -import com.android.inputmethod.latin.SuggestedWords; -import com.android.inputmethod.latin.WordComposer; - -import android.text.TextUtils; - -public class RecorrectionSuggestionEntries { - public final CharSequence mChosenWord; - public final WordComposer mWordComposer; - - public RecorrectionSuggestionEntries(CharSequence chosenWord, WordComposer wordComposer) { - mChosenWord = chosenWord; - mWordComposer = wordComposer; - } - - public CharSequence getChosenWord() { - return mChosenWord; - } - - public CharSequence getOriginalWord() { - return mWordComposer.getTypedWord(); - } - - public SuggestedWords.Builder getAlternatives( - Suggest suggest, KeyboardSwitcher keyboardSwitcher) { - return getTypedSuggestions(suggest, keyboardSwitcher, mWordComposer); - } - - @Override - public int hashCode() { - return mChosenWord.hashCode(); - } - - @Override - public boolean equals(Object o) { - return o instanceof CharSequence && TextUtils.equals(mChosenWord, (CharSequence)o); - } - - private static SuggestedWords.Builder getTypedSuggestions( - Suggest suggest, KeyboardSwitcher keyboardSwitcher, WordComposer word) { - return suggest.getSuggestedWordBuilder(keyboardSwitcher.getKeyboardView(), word, null, - keyboardSwitcher.getLatinKeyboard().getProximityInfo()); - } -} diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 9e4c1ea79..8d40e7aa5 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -138,8 +138,7 @@ public class Keyboard { mProximityInfo = new ProximityInfo( params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight, - mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrectionXs, - params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii); + mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrection); } public ProximityInfo getProximityInfo() { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 837a53391..e9a7fd077 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -264,7 +264,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (keyboard == null) { final Locale savedLocale = LocaleUtils.setSystemLocale(mResources, id.mLocale); try { - keyboard = new LatinKeyboard.Builder(mThemeContext).load(id).build(); + final LatinKeyboard.Builder builder = new LatinKeyboard.Builder(mThemeContext); + builder.load(id); + builder.setTouchPositionCorrectionEnabled( + mSubtypeSwitcher.currentSubtypeContainsExtraValueKey( + LatinIME.SUBTYPE_EXTRA_VALUE_SUPPORT_TOUCH_POSITION_CORRECTION)); + keyboard = builder.build(); } finally { LocaleUtils.setSystemLocale(mResources, savedLocale); } diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index cc6feeb4a..34a77e1ca 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard; import android.graphics.Rect; import com.android.inputmethod.keyboard.Key; +import com.android.inputmethod.keyboard.internal.KeyboardParams.TouchPositionCorrection; import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo; @@ -32,8 +33,6 @@ public class ProximityInfo { /** Number of key widths from current touch point to search for nearest keys. */ private static float SEARCH_DISTANCE = 1.2f; private static final int[] EMPTY_INT_ARRAY = new int[0]; - private static final String SUPPORT_TOUCH_POSITION_CORRECTION = - "SupportTouchPositionCorrection"; private final int mKeyHeight; private final int mGridWidth; @@ -46,13 +45,8 @@ public class ProximityInfo { private final int mKeyboardHeight; private final int[][] mGridNeighbors; - private final float[] mTouchPositionCorrectionXs; - private final float[] mTouchPositionCorrectionYs; - private final float[] mTouchPositionCorrectionRadii; - ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, - int keyHeight, List<Key> keys, float[] touchPositionCorrectionXs, - float[] touchPositionCorrectionYs, float[] touchPositionCorrectionRadii) { + int keyHeight, List<Key> keys, TouchPositionCorrection touchPositionCorrection) { mGridWidth = gridWidth; mGridHeight = gridHeight; mGridSize = mGridWidth * mGridHeight; @@ -61,19 +55,16 @@ public class ProximityInfo { mKeyboardMinWidth = minWidth; mKeyboardHeight = height; mKeyHeight = keyHeight; - mTouchPositionCorrectionXs = touchPositionCorrectionXs; - mTouchPositionCorrectionYs = touchPositionCorrectionYs; - mTouchPositionCorrectionRadii = touchPositionCorrectionRadii; mGridNeighbors = new int[mGridSize][]; if (minWidth == 0 || height == 0) { // No proximity required. Keyboard might be mini keyboard. return; } - computeNearestNeighbors(keyWidth, keys); + computeNearestNeighbors(keyWidth, keys, touchPositionCorrection); } public static ProximityInfo createDummyProximityInfo() { - return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key>emptyList(), null, null, null); + return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key>emptyList(), null); } public static ProximityInfo createSpellCheckerProximityInfo() { @@ -98,7 +89,8 @@ public class ProximityInfo { private native void releaseProximityInfoNative(int nativeProximityInfo); private final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth, - int keyboardHeight, List<Key> keys) { + int keyboardHeight, List<Key> keys, + TouchPositionCorrection touchPositionCorrection) { int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE]; Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE); for (int i = 0; i < mGridSize; ++i) { @@ -123,23 +115,16 @@ public class ProximityInfo { keyCharCodes[i] = key.mCode; } - final SubtypeSwitcher switcher = SubtypeSwitcher.getInstance(); - final boolean hasTouchPositionCorrectionData = - switcher.currentSubtypeContainsExtraValueKey(SUPPORT_TOUCH_POSITION_CORRECTION) - && mTouchPositionCorrectionXs != null - && mTouchPositionCorrectionYs != null - && mTouchPositionCorrectionRadii != null - && mTouchPositionCorrectionXs.length > 0 - && mTouchPositionCorrectionYs.length > 0 - && mTouchPositionCorrectionRadii.length > 0; - final float[] sweetSpotCenterXs = - hasTouchPositionCorrectionData ? new float[keyCount] : null; - final float[] sweetSpotCenterYs = - hasTouchPositionCorrectionData ? new float[keyCount] : null; - final float[] sweetSpotRadii = - hasTouchPositionCorrectionData ? new float[keyCount] : null; - if (hasTouchPositionCorrectionData) { - calculateSweetSpot(keys, sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii); + float[] sweetSpotCenterXs = null; + float[] sweetSpotCenterYs = null; + float[] sweetSpotRadii = null; + + if (touchPositionCorrection != null && touchPositionCorrection.isValid()) { + sweetSpotCenterXs = new float[keyCount]; + sweetSpotCenterYs = new float[keyCount]; + sweetSpotRadii = new float[keyCount]; + calculateSweetSpot(keys, touchPositionCorrection, + sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii); } mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE, @@ -148,21 +133,24 @@ public class ProximityInfo { sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii); } - private void calculateSweetSpot(List<Key> keys, float[] sweetSpotCenterXs, - float[] sweetSpotCenterYs, float[] sweetSpotRadii) { + private void calculateSweetSpot(List<Key> keys, TouchPositionCorrection touchPositionCorrection, + float[] sweetSpotCenterXs, float[] sweetSpotCenterYs, float[] sweetSpotRadii) { final int keyCount = keys.size(); + final float[] xs = touchPositionCorrection.mXs; + final float[] ys = touchPositionCorrection.mYs; + final float[] radii = touchPositionCorrection.mRadii; for (int i = 0; i < keyCount; ++i) { final Key key = keys.get(i); final Rect hitBox = key.mHitBox; final int row = hitBox.top / mKeyHeight; - if (row < mTouchPositionCorrectionRadii.length) { + if (row < radii.length) { final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f; final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f; final float hitBoxWidth = hitBox.right - hitBox.left; final float hitBoxHeight = hitBox.bottom - hitBox.top; - final float x = mTouchPositionCorrectionXs[row]; - final float y = mTouchPositionCorrectionYs[row]; - final float radius = mTouchPositionCorrectionRadii[row]; + final float x = xs[row]; + final float y = ys[row]; + final float radius = radii[row]; sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth; sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight; sweetSpotRadii[i] = radius @@ -187,7 +175,8 @@ public class ProximityInfo { } } - private void computeNearestNeighbors(int defaultWidth, List<Key> keys) { + private void computeNearestNeighbors(int defaultWidth, List<Key> keys, + TouchPositionCorrection touchPositionCorrection) { final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE); final int threshold = thresholdBase * thresholdBase; // Round-up so we don't have any pixels outside the grid @@ -210,7 +199,8 @@ public class ProximityInfo { mGridNeighbors[(y / mCellHeight) * mGridWidth + (x / mCellWidth)] = cell; } } - setProximityInfo(mGridNeighbors, mKeyboardMinWidth, mKeyboardHeight, keys); + setProximityInfo(mGridNeighbors, mKeyboardMinWidth, mKeyboardHeight, keys, + touchPositionCorrection); } public int[] getNearestKeys(int x, int y) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index 46836da67..d16c71c7e 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -127,8 +127,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> { private static final int DEFAULT_KEYBOARD_COLUMNS = 10; private static final int DEFAULT_KEYBOARD_ROWS = 4; - private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; - protected final KP mParams; protected final Context mContext; protected final Resources mResources; @@ -247,64 +245,26 @@ public class KeyboardBuilder<KP extends KeyboardParams> { mParams = params; - final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme); - mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0); - a.recycle(); + setTouchPositionCorrectionData(context, params); - if (!setTouchPositionCorrectionData(context)) { - // In the regression test, setTouchPositionCorrectionData() fails - mParams.mTouchPositionCorrectionXs = null; - mParams.mTouchPositionCorrectionYs = null; - mParams.mTouchPositionCorrectionRadii = null; - } - - mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width); - mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height); + params.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width); + params.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height); } - private boolean setTouchPositionCorrectionData(Context context) { - final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme); - final int resourceId = a.getResourceId( - R.styleable.KeyboardTheme_touchPositionCorrectionData, 0); + private static void setTouchPositionCorrectionData(Context context, KeyboardParams params) { + final TypedArray a = context.obtainStyledAttributes( + null, R.styleable.Keyboard, R.attr.keyboardStyle, 0); + params.mThemeId = a.getInt(R.styleable.Keyboard_themeId, 0); + final int resourceId = a.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0); + a.recycle(); if (resourceId == 0) { - // In the regression test, we cannot use theme resources - // TODO: Fix this - return false; + if (LatinImeLogger.sDBG) + throw new RuntimeException("touchPositionCorrectionData is not defined"); + return; } + final String[] data = context.getResources().getStringArray(resourceId); - a.recycle(); - final int dataLength = data.length; - if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) { - if (LatinImeLogger.sDBG) { - throw new RuntimeException("the size of touch position correction data is invalid"); - } - return false; - } - final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE; - mParams.mTouchPositionCorrectionXs = new float[length]; - mParams.mTouchPositionCorrectionYs = new float[length]; - mParams.mTouchPositionCorrectionRadii = new float[length]; - try { - for (int i = 0; i < dataLength; ++i) { - final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE; - final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE; - final float value = Float.parseFloat(data[i]); - if (type == 0) { - mParams.mTouchPositionCorrectionXs[index] = value; - } else if (type == 1) { - mParams.mTouchPositionCorrectionYs[index] = value; - } else { - mParams.mTouchPositionCorrectionRadii[index] = value; - } - } - } catch (NumberFormatException e) { - if (LatinImeLogger.sDBG) { - throw new RuntimeException( - "the number format for touch position correction data is invalid"); - } - return false; - } - return true; + params.mTouchPositionCorrection.load(data); } public KeyboardBuilder<KP> load(KeyboardId id) { @@ -321,6 +281,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> { return this; } + public void setTouchPositionCorrectionEnabled(boolean enabled) { + mParams.mTouchPositionCorrection.setEnabled(enabled); + } + public Keyboard build() { return new Keyboard(mParams); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java index d1aea72a5..64cd37c4b 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java @@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardId; +import com.android.inputmethod.latin.LatinImeLogger; import java.util.ArrayList; import java.util.HashMap; @@ -68,9 +69,62 @@ public class KeyboardParams { public int mMostCommonKeyHeight = 0; public int mMostCommonKeyWidth = 0; - public float[] mTouchPositionCorrectionXs; - public float[] mTouchPositionCorrectionYs; - public float[] mTouchPositionCorrectionRadii; + public final TouchPositionCorrection mTouchPositionCorrection = new TouchPositionCorrection(); + + public static class TouchPositionCorrection { + private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; + + public boolean mEnabled; + public float[] mXs; + public float[] mYs; + public float[] mRadii; + + public void load(String[] data) { + final int dataLength = data.length; + if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) { + if (LatinImeLogger.sDBG) + throw new RuntimeException( + "the size of touch position correction data is invalid"); + return; + } + + final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE; + mXs = new float[length]; + mYs = new float[length]; + mRadii = new float[length]; + try { + for (int i = 0; i < dataLength; ++i) { + final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE; + final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE; + final float value = Float.parseFloat(data[i]); + if (type == 0) { + mXs[index] = value; + } else if (type == 1) { + mYs[index] = value; + } else { + mRadii[index] = value; + } + } + } catch (NumberFormatException e) { + if (LatinImeLogger.sDBG) { + throw new RuntimeException( + "the number format for touch position correction data is invalid"); + } + mXs = null; + mYs = null; + mRadii = null; + } + } + + public void setEnabled(boolean enabled) { + mEnabled = enabled; + } + + public boolean isValid() { + return mEnabled && mXs != null && mYs != null && mRadii != null + && mXs.length > 0 && mYs.length > 0 && mRadii.length > 0; + } + } protected void clearKeys() { mKeys.clear(); diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index e6ae2c5c7..fc9771065 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -50,7 +50,7 @@ public class AutoCorrection { public void updateAutoCorrectionStatus(Map<String, Dictionary> dictionaries, WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores, CharSequence typedWord, double autoCorrectionThreshold, int correctionMode, - CharSequence quickFixedWord, CharSequence whitelistedWord) { + CharSequence whitelistedWord) { if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) { mHasAutoCorrection = true; mAutoCorrectionWord = whitelistedWord; @@ -58,9 +58,6 @@ public class AutoCorrection { dictionaries, wordComposer, suggestions, typedWord, correctionMode)) { mHasAutoCorrection = true; mAutoCorrectionWord = typedWord; - } else if (hasAutoCorrectionForQuickFix(quickFixedWord)) { - mHasAutoCorrection = true; - mAutoCorrectionWord = quickFixedWord; } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, correctionMode, sortedScores, typedWord, autoCorrectionThreshold)) { mHasAutoCorrection = true; @@ -109,10 +106,6 @@ public class AutoCorrection { || correctionMode == Suggest.CORRECTION_FULL_BIGRAM); } - private static boolean hasAutoCorrectionForQuickFix(CharSequence quickFixedWord) { - return quickFixedWord != null; - } - private boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer, ArrayList<CharSequence> suggestions, int correctionMode, int[] sortedScores, CharSequence typedWord, double autoCorrectionThreshold) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dfb4d0622..36e97af11 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -60,7 +60,6 @@ import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.deprecated.recorrection.Recorrection; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; @@ -119,6 +118,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable"; /** + * The subtype extra value used to indicate that the subtype keyboard layout supports touch + * position correction. + */ + public static final String SUBTYPE_EXTRA_VALUE_SUPPORT_TOUCH_POSITION_CORRECTION = + "SupportTouchPositionCorrection"; + /** * The subtype extra value used to indicate that the subtype keyboard layout should be loaded * from the specified locale. */ @@ -168,7 +173,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private KeyboardSwitcher mKeyboardSwitcher; private SubtypeSwitcher mSubtypeSwitcher; private VoiceProxy mVoiceProxy; - private Recorrection mRecorrection; private UserDictionary mUserDictionary; private UserBigramDictionary mUserBigramDictionary; @@ -229,14 +233,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> { private static final int MSG_UPDATE_SUGGESTIONS = 0; - private static final int MSG_UPDATE_OLD_SUGGESTIONS = 1; - private static final int MSG_UPDATE_SHIFT_STATE = 2; - private static final int MSG_VOICE_RESULTS = 3; - private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 4; - private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5; - private static final int MSG_SPACE_TYPED = 6; - private static final int MSG_SET_BIGRAM_PREDICTIONS = 7; - private static final int MSG_PENDING_IMS_CALLBACK = 8; + private static final int MSG_UPDATE_SHIFT_STATE = 1; + private static final int MSG_VOICE_RESULTS = 2; + private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 3; + private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 4; + private static final int MSG_SPACE_TYPED = 5; + private static final int MSG_SET_BIGRAM_PREDICTIONS = 6; + private static final int MSG_PENDING_IMS_CALLBACK = 7; public UIHandler(LatinIME outerInstance) { super(outerInstance); @@ -251,13 +254,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case MSG_UPDATE_SUGGESTIONS: latinIme.updateSuggestions(); break; - case MSG_UPDATE_OLD_SUGGESTIONS: - latinIme.mRecorrection.fetchAndDisplayRecorrectionSuggestions( - latinIme.mVoiceProxy, latinIme.mSuggestionsView, - latinIme.mSuggest, latinIme.mKeyboardSwitcher, latinIme.mWordComposer, - latinIme.mHasUncommittedTypedChars, latinIme.mLastSelectionStart, - latinIme.mLastSelectionEnd, latinIme.mSettingsValues.mWordSeparators); - break; case MSG_UPDATE_SHIFT_STATE: switcher.updateShiftState(); break; @@ -302,16 +298,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return hasMessages(MSG_UPDATE_SUGGESTIONS); } - public void postUpdateOldSuggestions() { - removeMessages(MSG_UPDATE_OLD_SUGGESTIONS); - sendMessageDelayed(obtainMessage(MSG_UPDATE_OLD_SUGGESTIONS), - getOuterInstance().mSettingsValues.mDelayUpdateOldSuggestions); - } - - public void cancelUpdateOldSuggestions() { - removeMessages(MSG_UPDATE_OLD_SUGGESTIONS); - } - public void postUpdateShiftKeyState() { removeMessages(MSG_UPDATE_SHIFT_STATE); sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), @@ -470,7 +456,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar InputMethodManagerCompatWrapper.init(this); SubtypeSwitcher.init(this); KeyboardSwitcher.init(this, prefs); - Recorrection.init(this, prefs); AccessibilityUtils.init(this, prefs); super.onCreate(); @@ -479,7 +464,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mInputMethodId = Utils.getInputMethodId(mImm, getPackageName()); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); - mRecorrection = Recorrection.getInstance(); mVibrator = VibratorCompatWrapper.getInstance(this); DEBUG = LatinImeLogger.sDBG; @@ -550,7 +534,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } - updateAutoTextEnabled(); mUserDictionary = new UserDictionary(this, localeStr); mSuggest.setUserDictionary(mUserDictionary); @@ -734,7 +717,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar loadSettings(); updateCorrectionMode(); - updateAutoTextEnabled(); updateSuggestionVisibility(mPrefs, mResources); if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { @@ -760,8 +742,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar inputView.setKeyPreviewPopupEnabled(mSettingsValues.mKeyPreviewPopupOn, mSettingsValues.mKeyPreviewPopupDismissDelay); inputView.setProximityCorrectionEnabled(true); - // If we just entered a text field, maybe it has some old text that requires correction - mRecorrection.checkRecorrectionOnStart(); voiceIme.onStartInputView(inputView.getWindowToken()); @@ -850,7 +830,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (inputView != null) inputView.cancelAllMessages(); // Remove pending messages related to update suggestions mHandler.cancelUpdateSuggestions(); - mHandler.cancelUpdateOldSuggestions(); } @Override @@ -884,35 +863,23 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final boolean selectionChanged = (newSelStart != candidatesEnd || newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart; final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1; - if (!mExpectingUpdateSelection - && ((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars) - || mVoiceProxy.isVoiceInputHighlighted()) - && (selectionChanged || candidatesCleared)) { - if (candidatesCleared) { - // If the composing span has been cleared, save the typed word in the history for - // recorrection before we reset the suggestions strip. Then, we'll be able to show - // suggestions for recorrection right away. - mRecorrection.saveRecorrectionSuggestion(mWordComposer, mComposingStringBuilder); - } - mComposingStringBuilder.setLength(0); - mHasUncommittedTypedChars = false; - if (isCursorTouchingWord()) { - mHandler.cancelUpdateBigramPredictions(); - mHandler.postUpdateSuggestions(); - } else { - setPunctuationSuggestions(); - } - TextEntryState.reset(); - final InputConnection ic = getCurrentInputConnection(); - if (ic != null) { - ic.finishComposingText(); - } - mVoiceProxy.setVoiceInputHighlighted(false); - } else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection - && TextEntryState.isAcceptedDefault()) { - TextEntryState.reset(); - } if (!mExpectingUpdateSelection) { + if (((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars) + || mVoiceProxy.isVoiceInputHighlighted()) + && (selectionChanged || candidatesCleared)) { + mComposingStringBuilder.setLength(0); + mHasUncommittedTypedChars = false; + TextEntryState.reset(); + updateSuggestions(); + final InputConnection ic = getCurrentInputConnection(); + if (ic != null) { + ic.finishComposingText(); + } + mVoiceProxy.setVoiceInputHighlighted(false); + } else if (!mHasUncommittedTypedChars) { + TextEntryState.reset(); + updateSuggestions(); + } mJustAddedMagicSpace = false; // The user moved the cursor. mJustReplacedDoubleSpace = false; } @@ -922,11 +889,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Make a note of the cursor position mLastSelectionStart = newSelStart; mLastSelectionEnd = newSelEnd; - - mRecorrection.updateRecorrectionSelection(mKeyboardSwitcher, - mSuggestionsView, candidatesStart, candidatesEnd, newSelStart, - newSelEnd, oldSelStart, mLastSelectionStart, - mLastSelectionEnd, mHasUncommittedTypedChars); } public void setLastSelection(int start, int end) { @@ -944,7 +906,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ @Override public void onExtractedTextClicked() { - if (mRecorrection.isRecorrectionEnabled() && isSuggestionsRequested()) return; + if (isSuggestionsRequested()) return; super.onExtractedTextClicked(); } @@ -960,7 +922,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ @Override public void onExtractedCursorMovement(int dx, int dy) { - if (mRecorrection.isRecorrectionEnabled() && isSuggestionsRequested()) return; + if (isSuggestionsRequested()) return; super.onExtractedCursorMovement(dx, dy); } @@ -976,7 +938,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mOptionsDialog = null; } mVoiceProxy.hideVoiceWindow(mConfigurationChanging); - mRecorrection.clearWordsInHistory(); super.hideWindow(); } @@ -1332,7 +1293,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mVoiceProxy.commitVoiceInput(); final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; - mRecorrection.abortRecorrection(false); ic.beginBatchEdit(); commitTyped(ic); maybeRemovePreviousPeriod(ic, text); @@ -1448,17 +1408,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar removeTrailingSpace(); } - if (mLastSelectionStart == mLastSelectionEnd) { - mRecorrection.abortRecorrection(false); - } - int code = primaryCode; if ((isAlphabet(code) || mSettingsValues.isSymbolExcludedFromWordSeparators(code)) && isSuggestionsRequested() && !isCursorTouchingWord()) { if (!mHasUncommittedTypedChars) { mHasUncommittedTypedChars = true; mComposingStringBuilder.setLength(0); - mRecorrection.saveRecorrectionSuggestion(mWordComposer, mBestWord); mWordComposer.reset(); clearSuggestions(); } @@ -1524,7 +1479,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.beginBatchEdit(); - mRecorrection.abortRecorrection(false); } if (mHasUncommittedTypedChars) { // In certain languages where single quote is a separator, it's better @@ -1570,7 +1524,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (Keyboard.CODE_SPACE == primaryCode) { if (!isCursorTouchingWord()) { mHandler.cancelUpdateSuggestions(); - mHandler.cancelUpdateOldSuggestions(); mHandler.postUpdateBigramPredictions(); } } else { @@ -1657,6 +1610,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } + mHandler.cancelUpdateSuggestions(); + mHandler.cancelUpdateBigramPredictions(); + if (!mHasUncommittedTypedChars) { setPunctuationSuggestions(); return; @@ -1673,8 +1629,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } // getSuggestedWordBuilder handles gracefully a null value of prevWord final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( - mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord, - mKeyboardSwitcher.getLatinKeyboard().getProximityInfo()); + wordComposer, prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo()); boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection(); final CharSequence typedWord = wordComposer.getTypedWord(); @@ -1890,7 +1845,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ic.commitText(bestWord, 1); } } - mRecorrection.saveRecorrectionSuggestion(mWordComposer, bestWord); mHasUncommittedTypedChars = false; mCommittedLength = bestWord.length(); } @@ -1907,9 +1861,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(), mSettingsValues.mWordSeparators); - SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( - mKeyboardSwitcher.getKeyboardView(), sEmptyWordComposer, prevWord, - mKeyboardSwitcher.getLatinKeyboard().getProximityInfo()); + SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer, + prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo()); if (builder.size() > 0) { // Explicitly supply an empty typed word (the no-second-arg version of @@ -2214,18 +2167,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } - private void updateAutoTextEnabled() { - if (mSuggest == null) return; - // We want to use autotext if the settings are asking for auto corrections, and if - // the input language is the same as the system language (because autotext will only - // work in the system language so if we are entering text in a different language we - // do not want it on). - // We used to look at the "quick fixes" option instead of mAutoCorrectEnabled, but - // this option was redundant and confusing and therefore removed. - mSuggest.setQuickFixesEnabled(mSettingsValues.mAutoCorrectEnabled - && SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage()); - } - private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) { final String suggestionVisiblityStr = prefs.getString( Settings.PREF_SHOW_SUGGESTIONS_SETTING, diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index bd94bab34..d9508f4c1 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -64,7 +64,6 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_VIBRATE_ON = "vibrate_on"; public static final String PREF_SOUND_ON = "sound_on"; public static final String PREF_KEY_PREVIEW_POPUP_ON = "popup_on"; - public static final String PREF_RECORRECTION_ENABLED = "recorrection_enabled"; public static final String PREF_AUTO_CAP = "auto_cap"; public static final String PREF_SHOW_SETTINGS_KEY = "show_settings_key"; public static final String PREF_VOICE_SETTINGS_KEY = "voice_mode"; @@ -435,12 +434,6 @@ public class Settings extends InputMethodSettingsActivity generalSettings.removePreference(findPreference(PREF_KEY_PREVIEW_POPUP_ON)); } - final boolean showRecorrectionOption = res.getBoolean( - R.bool.config_enable_show_recorrection_option); - if (!showRecorrectionOption) { - generalSettings.removePreference(findPreference(PREF_RECORRECTION_ENABLED)); - } - final boolean showBigramSuggestionsOption = res.getBoolean( R.bool.config_enable_bigram_suggestions_option); if (!showBigramSuggestionsOption) { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 16dccf824..208fd13ec 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -17,10 +17,8 @@ package com.android.inputmethod.latin; import android.content.Context; -import android.text.AutoText; import android.text.TextUtils; import android.util.Log; -import android.view.View; import com.android.inputmethod.keyboard.ProximityInfo; @@ -97,8 +95,6 @@ public class Suggest implements Dictionary.WordCallback { private static final int PREF_MAX_BIGRAMS = 60; - private boolean mQuickFixesEnabled; - private double mAutoCorrectionThreshold; private int[] mScores = new int[mPrefMaxSuggestions]; private int[] mBigramScores = new int[PREF_MAX_BIGRAMS]; @@ -160,6 +156,7 @@ public class Suggest implements Dictionary.WordCallback { final Locale locale) { mMainDict = null; new Thread("InitializeBinaryDictionary") { + @Override public void run() { final Dictionary newMainDict = DictionaryFactory.createDictionaryFromManager( context, locale, dictionaryResId); @@ -170,11 +167,6 @@ public class Suggest implements Dictionary.WordCallback { }.start(); } - - public void setQuickFixesEnabled(boolean enabled) { - mQuickFixesEnabled = enabled; - } - public int getCorrectionMode() { return mCorrectionMode; } @@ -256,14 +248,13 @@ public class Suggest implements Dictionary.WordCallback { /** * Returns a object which represents suggested words that match the list of character codes * passed in. This object contents will be overwritten the next time this function is called. - * @param view a view for retrieving the context for AutoText * @param wordComposer contains what is currently being typed * @param prevWordForBigram previous word (used only for bigram) * @return suggested words object. */ - public SuggestedWords getSuggestions(final View view, final WordComposer wordComposer, + public SuggestedWords getSuggestions(final WordComposer wordComposer, final CharSequence prevWordForBigram, final ProximityInfo proximityInfo) { - return getSuggestedWordBuilder(view, wordComposer, prevWordForBigram, + return getSuggestedWordBuilder(wordComposer, prevWordForBigram, proximityInfo).build(); } @@ -295,7 +286,7 @@ public class Suggest implements Dictionary.WordCallback { } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder - public SuggestedWords.Builder getSuggestedWordBuilder(final View view, + public SuggestedWords.Builder getSuggestedWordBuilder( final WordComposer wordComposer, CharSequence prevWordForBigram, final ProximityInfo proximityInfo) { LatinImeLogger.onStartSuggestion(prevWordForBigram); @@ -336,6 +327,7 @@ 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 = typedWord.charAt(0); // TODO: Must pay attention to locale when changing case. final char currentCharUpper = Character.toUpperCase(currentChar); @@ -363,34 +355,14 @@ public class Suggest implements Dictionary.WordCallback { dictionary.getWords(wordComposer, this, proximityInfo); } } - CharSequence autoText = null; final String typedWordString = typedWord == null ? null : typedWord.toString(); - if (typedWord != null) { - // Apply quick fix only for the typed word. - if (mQuickFixesEnabled) { - final String lowerCaseTypedWord = typedWordString.toLowerCase(); - // Is there an AutoText (also known as Quick Fixes) correction? - // Capitalize as needed - autoText = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized, AutoText.get( - lowerCaseTypedWord, 0, lowerCaseTypedWord.length(), view)); - if (DBG) { - if (autoText != null) { - Log.d(TAG, "Auto corrected by AUTOTEXT: " + typedWord + " -> " + autoText); - } - } - } - } CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized, mWhiteListDictionary.getWhiteListedWord(typedWordString)); mAutoCorrection.updateAutoCorrectionStatus(mUnigramDictionaries, wordComposer, mSuggestions, mScores, typedWord, mAutoCorrectionThreshold, mCorrectionMode, - autoText, whitelistedWord); - - if (autoText != null) { - mSuggestions.add(0, autoText); - } + whitelistedWord); if (whitelistedWord != null) { mSuggestions.add(0, whitelistedWord); |