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.java108
1 files changed, 78 insertions, 30 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b6fee1170..687870622 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
@@ -192,8 +192,7 @@ 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;
@@ -448,6 +447,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);
@@ -1153,9 +1153,9 @@ public class LatinIME extends InputMethodService
}
}
- private void showInputMethodPicker() {
+ private void showInputMethodSubtypePicker() {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
- .showInputMethodPicker();
+ .showInputMethodSubtypePicker();
}
private void onOptionKeyPressed() {
@@ -1171,7 +1171,7 @@ public class LatinIME extends InputMethodService
private void onOptionKeyLongPressed() {
if (!isShowingOptionDialog()) {
if (LatinIMEUtil.hasMultipleEnabledIMEs(this)) {
- showInputMethodPicker();
+ showInputMethodSubtypePicker();
} else {
launchSettings();
}
@@ -1186,29 +1186,29 @@ 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 ||
+ if (primaryCode != BaseKeyboard.KEYCODE_DELETE ||
when > mLastKeyTime + QUICK_PRESS) {
mDeleteCount = 0;
}
mLastKeyTime = when;
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
switch (primaryCode) {
- case Keyboard.KEYCODE_DELETE:
+ case BaseKeyboard.KEYCODE_DELETE:
handleBackspace();
mDeleteCount++;
LatinImeLogger.logOnDelete();
break;
- case Keyboard.KEYCODE_SHIFT:
+ case BaseKeyboard.KEYCODE_SHIFT:
// Shift key is handled in onPress() when device has distinct multi-touch panel.
if (!distinctMultiTouch)
handleShift();
break;
- case Keyboard.KEYCODE_MODE_CHANGE:
+ case BaseKeyboard.KEYCODE_MODE_CHANGE:
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
if (!distinctMultiTouch)
changeKeyboardMode();
break;
- case Keyboard.KEYCODE_CANCEL:
+ case BaseKeyboard.KEYCODE_CANCEL:
if (!isShowingOptionDialog()) {
handleClose();
}
@@ -1864,13 +1864,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();
@@ -2285,10 +2285,10 @@ public class LatinIME extends InputMethodService
vibrate();
playKeyClick(primaryCode);
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
- if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
+ if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
mShiftKeyState.onPress();
handleShift();
- } else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
+ } else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
mSymbolKeyState.onPress();
changeKeyboardMode();
} else {
@@ -2302,11 +2302,11 @@ public class LatinIME extends InputMethodService
((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).keyReleased();
//vibrate();
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
- if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
+ if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
if (mShiftKeyState.isMomentary())
resetShift();
mShiftKeyState.onRelease();
- } else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
+ } else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
if (mSymbolKeyState.isMomentary())
changeKeyboardMode();
mSymbolKeyState.onRelease();
@@ -2329,8 +2329,8 @@ public class LatinIME extends InputMethodService
private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) {
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext)
- && !(attribute != null
- && IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions))
+ && !(attribute != null && attribute.privateImeOptions != null
+ && attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE))
&& SpeechRecognizer.isRecognitionAvailable(this);
}
@@ -2365,7 +2365,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 +2489,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 +2506,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 +2593,7 @@ public class LatinIME extends InputMethodService
launchSettings();
break;
case POS_METHOD:
- ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
- .showInputMethodPicker();
+ showInputMethodSubtypePicker();
break;
}
}