aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java368
1 files changed, 242 insertions, 126 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b6fee1170..3663442d4 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -34,7 +34,6 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.inputmethodservice.InputMethodService;
-import android.inputmethodservice.Keyboard;
import android.media.AudioManager;
import android.os.Debug;
import android.os.Handler;
@@ -69,6 +68,7 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -95,8 +95,8 @@ public class LatinIME extends InputMethodService
private static final String PREF_AUTO_CAP = "auto_cap";
private static final String PREF_QUICK_FIXES = "quick_fixes";
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
- private static final String PREF_AUTO_COMPLETE = "auto_complete";
- //private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
+ private static final String PREF_AUTO_COMPLETION_THRESHOLD = "auto_completion_threshold";
+ private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
private static final String PREF_VOICE_MODE = "voice_mode";
// Whether or not the user has used voice input before (and thus, whether to show the
@@ -137,20 +137,23 @@ public class LatinIME extends InputMethodService
private static final int MSG_VOICE_RESULTS = 3;
private static final int MSG_UPDATE_OLD_SUGGESTIONS = 4;
+ private static final int DELAY_UPDATE_SUGGESTIONS = 180;
+ private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300;
+
// How many continuous deletes at which to start deleting at a higher speed.
private static final int DELETE_ACCELERATE_AT = 20;
// Key events coming any faster than this are long-presses.
private static final int QUICK_PRESS = 200;
- static final int KEYCODE_ENTER = '\n';
- static final int KEYCODE_SPACE = ' ';
- static final int KEYCODE_PERIOD = '.';
+ public static final int KEYCODE_ENTER = '\n';
+ public static final int KEYCODE_TAB = '\t';
+ public static final int KEYCODE_SPACE = ' ';
+ public static final int KEYCODE_PERIOD = '.';
// Contextual menu positions
private static final int POS_METHOD = 0;
private static final int POS_SETTINGS = 1;
- //private LatinKeyboardView mInputView;
private LinearLayout mCandidateViewContainer;
private CandidateView mCandidateView;
private Suggest mSuggest;
@@ -192,11 +195,8 @@ public class LatinIME extends InputMethodService
private boolean mJustAddedAutoSpace;
private boolean mAutoCorrectEnabled;
private boolean mReCorrectionEnabled;
- // Bigram Suggestion is disabled in this version.
- private final boolean mBigramSuggestionEnabled = false;
+ private boolean mBigramSuggestionEnabled;
private boolean mAutoCorrectOn;
- // TODO move this state variable outside LatinIME
- private boolean mCapsLock;
private boolean mPasswordText;
private boolean mVibrateOn;
private boolean mSoundOn;
@@ -448,6 +448,7 @@ public class LatinIME extends InputMethodService
int[] dictionaries = getDictionary(orig);
mSuggest = new Suggest(this, dictionaries);
+ loadAndSetAutoCompletionThreshold(sp);
updateAutoTextEnabled(saveLocale);
if (mUserDictionary != null) mUserDictionary.close();
mUserDictionary = new UserDictionary(this, mInputLocale);
@@ -585,7 +586,6 @@ public class LatinIME extends InputMethodService
mPredictionOn = false;
mCompletionOn = false;
mCompletions = null;
- mCapsLock = false;
mEnteredText = null;
switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) {
@@ -680,6 +680,7 @@ public class LatinIME extends InputMethodService
// If we just entered a text field, maybe it has some old text that requires correction
checkReCorrectionOnStart();
checkTutorial(attribute.privateImeOptions);
+ inputView.setForeground(true);
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
}
@@ -731,6 +732,9 @@ public class LatinIME extends InputMethodService
@Override
public void onFinishInputView(boolean finishingInput) {
super.onFinishInputView(finishingInput);
+ LatinKeyboardBaseView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView != null)
+ inputView.setForeground(false);
// Remove penging messages related to update suggestions
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
mHandler.removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
@@ -986,9 +990,11 @@ public class LatinIME extends InputMethodService
return true;
}
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView == null) break;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) break;
// Enable shift key and DPAD to do selections
- if (inputView != null && inputView.isShown()
- && inputView.isShifted()) {
+ if (inputView.isShown() && latinKeyboard.isShifted()) {
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
event.getDeviceId(), event.getScanCode(),
@@ -1048,9 +1054,14 @@ public class LatinIME extends InputMethodService
public void updateShiftKeyState(EditorInfo attr) {
InputConnection ic = getCurrentInputConnection();
- if (ic != null && attr != null && mKeyboardSwitcher.isAlphabetMode()) {
- mKeyboardSwitcher.setShifted(mShiftKeyState.isMomentary() || mCapsLock
- || getCursorCapsMode(ic, attr) != 0);
+ LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
+ if (ic != null && attr != null && mKeyboardSwitcher.isAlphabetMode()
+ && !mShiftKeyState.isIgnoring()) {
+ mKeyboardSwitcher.setShifted(mShiftKeyState.isMomentary()
+ || latinKeyboard.isShiftLocked() || getCursorCapsMode(ic, attr) != 0);
}
}
@@ -1153,9 +1164,9 @@ public class LatinIME extends InputMethodService
}
}
- private void showInputMethodPicker() {
+ private void showInputMethodSubtypePicker() {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
- .showInputMethodPicker();
+ .showInputMethodSubtypePicker();
}
private void onOptionKeyPressed() {
@@ -1171,7 +1182,7 @@ public class LatinIME extends InputMethodService
private void onOptionKeyLongPressed() {
if (!isShowingOptionDialog()) {
if (LatinIMEUtil.hasMultipleEnabledIMEs(this)) {
- showInputMethodPicker();
+ showInputMethodSubtypePicker();
} else {
launchSettings();
}
@@ -1186,66 +1197,68 @@ public class LatinIME extends InputMethodService
public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
long when = SystemClock.uptimeMillis();
- if (primaryCode != Keyboard.KEYCODE_DELETE ||
- when > mLastKeyTime + QUICK_PRESS) {
+ if (primaryCode != BaseKeyboard.KEYCODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
mDeleteCount = 0;
}
mLastKeyTime = when;
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
switch (primaryCode) {
- case Keyboard.KEYCODE_DELETE:
- handleBackspace();
- mDeleteCount++;
- LatinImeLogger.logOnDelete();
- break;
- case Keyboard.KEYCODE_SHIFT:
- // Shift key is handled in onPress() when device has distinct multi-touch panel.
- if (!distinctMultiTouch)
- handleShift();
- break;
- case Keyboard.KEYCODE_MODE_CHANGE:
- // Symbol key is handled in onPress() when device has distinct multi-touch panel.
- if (!distinctMultiTouch)
- changeKeyboardMode();
- break;
- case Keyboard.KEYCODE_CANCEL:
- if (!isShowingOptionDialog()) {
- handleClose();
- }
- break;
- case LatinKeyboardView.KEYCODE_OPTIONS:
- onOptionKeyPressed();
- break;
- case LatinKeyboardView.KEYCODE_OPTIONS_LONGPRESS:
- onOptionKeyLongPressed();
- break;
- case LatinKeyboardView.KEYCODE_NEXT_LANGUAGE:
- toggleLanguage(false, true);
- break;
- case LatinKeyboardView.KEYCODE_PREV_LANGUAGE:
- toggleLanguage(false, false);
- break;
- case LatinKeyboardView.KEYCODE_VOICE:
- if (VOICE_INSTALLED) {
- startListening(false /* was a button press, was not a swipe */);
- }
- break;
- case 9 /*Tab*/:
- sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
- break;
- default:
- if (primaryCode != KEYCODE_ENTER) {
- mJustAddedAutoSpace = false;
- }
- RingCharBuffer.getInstance().push((char)primaryCode, x, y);
- LatinImeLogger.logOnInputChar();
- if (isWordSeparator(primaryCode)) {
- handleSeparator(primaryCode);
- } else {
- handleCharacter(primaryCode, keyCodes);
- }
- // Cancel the just reverted state
- mJustRevertedSeparator = null;
+ case BaseKeyboard.KEYCODE_DELETE:
+ handleBackspace();
+ mDeleteCount++;
+ LatinImeLogger.logOnDelete();
+ break;
+ case BaseKeyboard.KEYCODE_SHIFT:
+ // Shift key is handled in onPress() when device has distinct multi-touch panel.
+ if (!distinctMultiTouch)
+ handleShift();
+ break;
+ case BaseKeyboard.KEYCODE_MODE_CHANGE:
+ // Symbol key is handled in onPress() when device has distinct multi-touch panel.
+ if (!distinctMultiTouch)
+ changeKeyboardMode();
+ break;
+ case BaseKeyboard.KEYCODE_CANCEL:
+ if (!isShowingOptionDialog()) {
+ handleClose();
+ }
+ break;
+ case LatinKeyboardView.KEYCODE_OPTIONS:
+ onOptionKeyPressed();
+ break;
+ case LatinKeyboardView.KEYCODE_OPTIONS_LONGPRESS:
+ onOptionKeyLongPressed();
+ break;
+ case LatinKeyboardView.KEYCODE_NEXT_LANGUAGE:
+ toggleLanguage(false, true);
+ break;
+ case LatinKeyboardView.KEYCODE_PREV_LANGUAGE:
+ toggleLanguage(false, false);
+ break;
+ case LatinKeyboardView.KEYCODE_CAPSLOCK:
+ handleCapsLock();
+ break;
+ case LatinKeyboardView.KEYCODE_VOICE:
+ if (VOICE_INSTALLED) {
+ startListening(false /* was a button press, was not a swipe */);
+ }
+ break;
+ case KEYCODE_TAB:
+ sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
+ break;
+ default:
+ if (primaryCode != KEYCODE_ENTER) {
+ mJustAddedAutoSpace = false;
+ }
+ RingCharBuffer.getInstance().push((char)primaryCode, x, y);
+ LatinImeLogger.logOnInputChar();
+ if (isWordSeparator(primaryCode)) {
+ handleSeparator(primaryCode);
+ } else {
+ handleCharacter(primaryCode, keyCodes);
+ }
+ // Cancel the just reverted state
+ mJustRevertedSeparator = null;
}
if (mKeyboardSwitcher.onKey(primaryCode)) {
changeKeyboardMode();
@@ -1359,24 +1372,41 @@ public class LatinIME extends InputMethodService
private void handleShiftInternal(boolean forceNormal) {
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
KeyboardSwitcher switcher = mKeyboardSwitcher;
- LatinKeyboardView inputView = switcher.getInputView();
if (switcher.isAlphabetMode()) {
- if (mCapsLock || forceNormal) {
- mCapsLock = false;
+ LatinKeyboardView inputView = switcher.getInputView();
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
+ if (latinKeyboard.isShiftLocked() || forceNormal) {
switcher.setShifted(false);
- } else if (inputView != null) {
- if (inputView.isShifted()) {
- mCapsLock = true;
- switcher.setShiftLocked(true);
- } else {
- switcher.setShifted(true);
- }
+ } else {
+ switcher.setShifted(!latinKeyboard.isShifted());
}
} else {
switcher.toggleShift();
}
}
+ private void handleCapsLock() {
+ mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
+ KeyboardSwitcher switcher = mKeyboardSwitcher;
+ if (switcher.isAlphabetMode()) {
+ LatinKeyboardView inputView = switcher.getInputView();
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
+ if (latinKeyboard.isShiftLocked()) {
+ // LatinKeyboard.setShifted(false) also disable shift locked state.
+ // Note: Caps lock LED is off when Key.on is false.
+ switcher.setShifted(false);
+ } else {
+ // LatinKeyboard.setShiftLocked(true) enable shift state too.
+ // Note: Caps lock LED is on when Key.on is true.
+ switcher.setShiftLocked(true);
+ }
+ }
+ }
+
private void abortCorrection(boolean force) {
if (force || TextEntryState.isCorrecting()) {
getCurrentInputConnection().finishComposingText();
@@ -1405,7 +1435,8 @@ public class LatinIME extends InputMethodService
mWord.reset();
}
}
- if (mKeyboardSwitcher.getInputView().isShifted()) {
+ LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
+ if (latinKeyboard != null && latinKeyboard.isShifted()) {
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|| keyCodes[0] > Character.MAX_CODE_POINT) {
return;
@@ -1424,7 +1455,7 @@ public class LatinIME extends InputMethodService
}
}
if (mPredicting) {
- if (mKeyboardSwitcher.getInputView().isShifted()
+ if (latinKeyboard != null && latinKeyboard.isShifted()
&& mKeyboardSwitcher.isAlphabetMode()
&& mComposing.length() == 0) {
mWord.setFirstCharCapitalized(true);
@@ -1553,12 +1584,14 @@ public class LatinIME extends InputMethodService
private void postUpdateSuggestions() {
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
- mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS),
+ DELAY_UPDATE_SUGGESTIONS);
}
private void postUpdateOldSuggestions() {
mHandler.removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
- mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_OLD_SUGGESTIONS), 300);
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_OLD_SUGGESTIONS),
+ DELAY_UPDATE_OLD_SUGGESTIONS);
}
private boolean isPredictionOn() {
@@ -1719,7 +1752,8 @@ public class LatinIME extends InputMethodService
final List<CharSequence> nBest = new ArrayList<CharSequence>();
boolean capitalizeFirstWord = preferCapitalization()
|| (mKeyboardSwitcher.isAlphabetMode()
- && mKeyboardSwitcher.getInputView().isShifted());
+ && mKeyboardSwitcher.getInputView().getLatinKeyboard() != null
+ && mKeyboardSwitcher.getInputView().getLatinKeyboard().isShifted());
for (String c : mVoiceResults.candidates) {
if (capitalizeFirstWord) {
c = Character.toUpperCase(c.charAt(0)) + c.substring(1, c.length());
@@ -1771,7 +1805,10 @@ public class LatinIME extends InputMethodService
private void updateSuggestions() {
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
- ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null);
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard != null) {
+ latinKeyboard.setPreferredLetters(null);
+ }
// Check if we have a suggestion engine attached.
if ((mSuggest == null || !isPredictionOn()) && !mVoiceInputHighlighted) {
@@ -1793,7 +1830,10 @@ public class LatinIME extends InputMethodService
private void showCorrections(WordAlternatives alternatives) {
List<CharSequence> stringList = alternatives.getAlternatives();
- ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setPreferredLetters(null);
+ LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
+ if (latinKeyboard != null) {
+ latinKeyboard.setPreferredLetters(null);
+ }
showSuggestions(stringList, alternatives.getOriginalWord(), false, false);
}
@@ -1809,8 +1849,10 @@ public class LatinIME extends InputMethodService
int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
- ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setPreferredLetters(
- nextLettersFrequencies);
+ LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
+ if (latinKeyboard != null) {
+ latinKeyboard.setPreferredLetters(nextLettersFrequencies);
+ }
boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasMinimalCorrection();
//|| mCorrectionMode == mSuggest.CORRECTION_FULL;
@@ -1864,13 +1906,13 @@ public class LatinIME extends InputMethodService
}
public void pickSuggestionManually(int index, CharSequence suggestion) {
- if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
List<CharSequence> suggestions = mCandidateView.getSuggestions();
-
- if (mAfterVoiceInput && !mShowingVoiceSuggestions) {
+ if (mAfterVoiceInput && mShowingVoiceSuggestions) {
mVoiceInput.flushAllTextModificationCounters();
// send this intent AFTER logging any prior aggregated edits.
- mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.length());
+ mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index,
+ mWordSeparators,
+ getCurrentInputConnection());
}
final boolean correcting = TextEntryState.isCorrecting();
@@ -1982,14 +2024,9 @@ public class LatinIME extends InputMethodService
*/
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
- if (mCapsLock) {
- suggestion = suggestion.toString().toUpperCase();
- } else if (preferCapitalization()
- || (mKeyboardSwitcher.isAlphabetMode()
- && inputView.isShifted())) {
- suggestion = suggestion.toString().toUpperCase().charAt(0)
- + suggestion.subSequence(1, suggestion.length()).toString();
- }
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
rememberReplacedWord(suggestion);
@@ -1998,7 +2035,9 @@ public class LatinIME extends InputMethodService
saveWordInHistory(suggestion);
mPredicting = false;
mCommittedLength = suggestion.length();
- ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null);
+ if (latinKeyboard != null) {
+ latinKeyboard.setPreferredLetters(null);
+ }
// If we just corrected a word, then don't show punctuations
if (!correcting) {
setNextSuggestions();
@@ -2285,10 +2324,20 @@ public class LatinIME extends InputMethodService
vibrate();
playKeyClick(primaryCode);
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
- if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
- mShiftKeyState.onPress();
- handleShift();
- } else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
+ LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
+ if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
+ // In alphabet mode, we call handleShift() to go into the shifted mode in this
+ // method, onPress(), only when we are in the small letter mode.
+ if (mKeyboardSwitcher.isAlphabetMode() && latinKeyboard.isShifted()) {
+ mShiftKeyState.onPressOnShifted();
+ } else {
+ mShiftKeyState.onPress();
+ handleShift();
+ }
+ } else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
mSymbolKeyState.onPress();
changeKeyboardMode();
} else {
@@ -2297,18 +2346,34 @@ public class LatinIME extends InputMethodService
}
}
+ // TODO: Bug - onRelease() could be dropped if the user slides finger out of the key. It's OK
+ // for general keys, but we need to obtain onRelease() for the shift key even in such case.
public void onRelease(int primaryCode) {
// Reset any drag flags in the keyboard
- ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).keyReleased();
+ LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
+ latinKeyboard.keyReleased();
//vibrate();
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
- if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
- if (mShiftKeyState.isMomentary())
+ if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
+ if (mShiftKeyState.isMomentary()) {
resetShift();
+ }
+ if (mKeyboardSwitcher.isAlphabetMode()) {
+ // In alphabet mode, we call handleShift() to go into the small letter mode in this
+ // method, onRelease(), only when we are in the shifted modes -- temporary shifted
+ // mode or caps lock mode.
+ if (latinKeyboard.isShifted() && mShiftKeyState.isPressingOnShifted()) {
+ handleShift();
+ }
+ }
mShiftKeyState.onRelease();
- } else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
- if (mSymbolKeyState.isMomentary())
+ } else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
+ if (mSymbolKeyState.isMomentary()) {
changeKeyboardMode();
+ }
mSymbolKeyState.onRelease();
}
}
@@ -2365,7 +2430,7 @@ public class LatinIME extends InputMethodService
// FIXME: These should be triggered after auto-repeat logic
int sound = AudioManager.FX_KEYPRESS_STANDARD;
switch (primaryCode) {
- case Keyboard.KEYCODE_DELETE:
+ case BaseKeyboard.KEYCODE_DELETE:
sound = AudioManager.FX_KEYPRESS_DELETE;
break;
case KEYCODE_ENTER:
@@ -2489,6 +2554,9 @@ public class LatinIME extends InputMethodService
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mInputLocale);
mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true);
+ mAutoCorrectEnabled = mShowSuggestions && isAutoCorrectEnabled(sp);
+ mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp);
+ loadAndSetAutoCompletionThreshold(sp);
if (VOICE_INSTALLED) {
final String voiceMode = sp.getString(PREF_VOICE_MODE,
@@ -2503,15 +2571,61 @@ public class LatinIME extends InputMethodService
mEnableVoice = enableVoice;
mVoiceOnPrimary = voiceOnPrimary;
}
- mAutoCorrectEnabled = sp.getBoolean(PREF_AUTO_COMPLETE,
- mResources.getBoolean(R.bool.enable_autocorrect)) & mShowSuggestions;
- //mBigramSuggestionEnabled = sp.getBoolean(
- // PREF_BIGRAM_SUGGESTIONS, true) & mShowSuggestions;
updateCorrectionMode();
updateAutoTextEnabled(mResources.getConfiguration().locale);
mLanguageSwitcher.loadLocales(sp);
}
+ /**
+ * load Auto completion threshold from SharedPreferences,
+ * and modify mSuggest's threshold.
+ */
+ private void loadAndSetAutoCompletionThreshold(SharedPreferences sp) {
+ // When mSuggest is not initialized, cannnot modify mSuggest's threshold.
+ if (mSuggest == null) return;
+ // When auto completion setting is turned off, the threshold is ignored.
+ if (!isAutoCorrectEnabled(sp)) return;
+
+ final String currentAutoCompletionSetting = sp.getString(PREF_AUTO_COMPLETION_THRESHOLD,
+ mResources.getString(R.string.auto_completion_threshold_mode_value_modest));
+ final String[] autoCompletionThresholdValues = mResources.getStringArray(
+ R.array.auto_complete_threshold_values);
+ // When autoCompletionThreshold is greater than 1.0,
+ // auto completion is virtually turned off.
+ double autoCompletionThreshold = Double.MAX_VALUE;
+ try {
+ final int arrayIndex = Integer.valueOf(currentAutoCompletionSetting);
+ if (arrayIndex >= 0 && arrayIndex < autoCompletionThresholdValues.length) {
+ autoCompletionThreshold = Double.parseDouble(
+ autoCompletionThresholdValues[arrayIndex]);
+ }
+ } catch (NumberFormatException e) {
+ // Whenever the threshold settings are correct,
+ // never come here.
+ autoCompletionThreshold = Double.MAX_VALUE;
+ Log.w(TAG, "Cannot load auto completion threshold setting."
+ + " currentAutoCompletionSetting: " + currentAutoCompletionSetting
+ + ", autoCompletionThresholdValues: "
+ + Arrays.toString(autoCompletionThresholdValues));
+ }
+ // TODO: This should be refactored :
+ // setAutoCompleteThreshold should be called outside of this method.
+ mSuggest.setAutoCompleteThreshold(autoCompletionThreshold);
+ }
+
+ private boolean isAutoCorrectEnabled(SharedPreferences sp) {
+ final String currentAutoCompletionSetting = sp.getString(PREF_AUTO_COMPLETION_THRESHOLD,
+ mResources.getString(R.string.auto_completion_threshold_mode_value_modest));
+ final String autoCompletionOff = mResources.getString(
+ R.string.auto_completion_threshold_mode_value_off);
+ return !currentAutoCompletionSetting.equals(autoCompletionOff);
+ }
+
+ private boolean isBigramSuggestionEnabled(SharedPreferences sp) {
+ // TODO: Define default value instead of 'true'.
+ return sp.getBoolean(PREF_BIGRAM_SUGGESTIONS, true);
+ }
+
private void initSuggestPuncList() {
mSuggestPuncList = new ArrayList<CharSequence>();
mSuggestPuncs = mResources.getString(R.string.suggested_punctuations);
@@ -2544,8 +2658,7 @@ public class LatinIME extends InputMethodService
launchSettings();
break;
case POS_METHOD:
- ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
- .showInputMethodPicker();
+ showInputMethodSubtypePicker();
break;
}
}
@@ -2563,8 +2676,12 @@ public class LatinIME extends InputMethodService
private void changeKeyboardMode() {
mKeyboardSwitcher.toggleSymbols();
- if (mCapsLock && mKeyboardSwitcher.isAlphabetMode()) {
- mKeyboardSwitcher.setShiftLocked(mCapsLock);
+ LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView == null) return;
+ LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
+ if (latinKeyboard == null) return;
+ if (latinKeyboard.isShiftLocked() && mKeyboardSwitcher.isAlphabetMode()) {
+ mKeyboardSwitcher.setShiftLocked(true);
}
updateShiftKeyState(getCurrentInputEditorInfo());
@@ -2584,7 +2701,6 @@ public class LatinIME extends InputMethodService
final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :");
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
- p.println(" mCapsLock=" + mCapsLock);
p.println(" mComposing=" + mComposing.toString());
p.println(" mPredictionOn=" + mPredictionOn);
p.println(" mCorrectionMode=" + mCorrectionMode);