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.java508
1 files changed, 299 insertions, 209 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 6e76cadf2..105ec5a62 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -16,14 +16,21 @@
package com.android.inputmethod.latin;
+import com.android.inputmethod.compat.CompatUtils;
+import com.android.inputmethod.compat.EditorInfoCompatUtils;
+import com.android.inputmethod.compat.InputConnectionCompatUtils;
+import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
+import com.android.inputmethod.compat.InputTypeCompatUtils;
+import com.android.inputmethod.compat.VibratorCompatWrapper;
+import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
+import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.LatinKeyboardView;
-import com.android.inputmethod.latin.Utils.RingCharBuffer;
-import com.android.inputmethod.voice.VoiceIMEConnector;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@@ -42,7 +49,6 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
-import android.os.Vibrator;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.text.InputType;
@@ -51,7 +57,6 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
-import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -61,15 +66,10 @@ import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo;
-import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
-import android.view.inputmethod.InputMethodManager;
-import android.view.inputmethod.InputMethodSubtype;
-import android.widget.FrameLayout;
-import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import java.io.FileDescriptor;
@@ -81,7 +81,7 @@ import java.util.Locale;
/**
* Input method implementation for Qwerty'ish keyboard.
*/
-public class LatinIME extends InputMethodService implements KeyboardActionListener {
+public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener {
private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean PERF_DEBUG = false;
private static final boolean TRACE = false;
@@ -94,6 +94,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
*
* @deprecated Use {@link LatinIME#IME_OPTION_NO_MICROPHONE} with package name prefixed.
*/
+ @SuppressWarnings("dep-ann")
public static final String IME_OPTION_NO_MICROPHONE_COMPAT = "nm";
/**
@@ -111,7 +112,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static final int DELAY_UPDATE_SUGGESTIONS = 180;
private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300;
- private static final int DELAY_UPDATE_SHIFT_STATE = 300;
+ private static final int DELAY_UPDATE_SHIFT_STATE = 100;
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
// How many continuous deletes at which to start deleting at a higher speed.
@@ -119,6 +120,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Key events coming any faster than this are long-presses.
private static final int QUICK_PRESS = 200;
+ /**
+ * The name of the scheme used by the Package Manager to warn of a new package installation,
+ * replacement or removal.
+ */
+ private static final String SCHEME_PACKAGE = "package";
+
private int mSuggestionVisibility;
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
= R.string.prefs_suggestion_visibility_show_value;
@@ -134,19 +141,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
};
private View mCandidateViewContainer;
+ private int mCandidateStripHeight;
private CandidateView mCandidateView;
private Suggest mSuggest;
private CompletionInfo[] mApplicationSpecifiedCompletions;
private AlertDialog mOptionsDialog;
- private InputMethodManager mImm;
+ private InputMethodManagerCompatWrapper mImm;
private Resources mResources;
private SharedPreferences mPrefs;
private String mInputMethodId;
private KeyboardSwitcher mKeyboardSwitcher;
private SubtypeSwitcher mSubtypeSwitcher;
- private VoiceIMEConnector mVoiceConnector;
+ private VoiceProxy mVoiceProxy;
private UserDictionary mUserDictionary;
private UserBigramDictionary mUserBigramDictionary;
@@ -164,12 +172,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final StringBuilder mComposing = new StringBuilder();
private WordComposer mWord = new WordComposer();
private CharSequence mBestWord;
- private boolean mHasValidSuggestions;
+ private boolean mHasUncommittedTypedChars;
private boolean mHasDictionary;
private boolean mJustAddedAutoSpace;
private boolean mAutoCorrectEnabled;
private boolean mRecorrectionEnabled;
+ // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
private boolean mBigramSuggestionEnabled;
+ // Prediction: use bigrams to predict the next word when there is no input for it yet
+ private boolean mBigramPredictionEnabled;
private boolean mAutoCorrectOn;
private boolean mVibrateOn;
private boolean mSoundOn;
@@ -204,59 +215,47 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
/* package */ String mWordSeparators;
private String mSentenceSeparators;
private String mSuggestPuncs;
- // TODO: Move this flag to VoiceIMEConnector
+ // TODO: Move this flag to VoiceProxy
private boolean mConfigurationChanging;
+ // Object for reacting to adding/removing a dictionary pack.
+ private BroadcastReceiver mDictionaryPackInstallReceiver =
+ new DictionaryPackInstallBroadcastReceiver(this);
+
// Keeps track of most recently inserted text (multi-character key) for reverting
private CharSequence mEnteredText;
private final ArrayList<WordAlternatives> mWordHistory = new ArrayList<WordAlternatives>();
- public abstract static class WordAlternatives {
- protected CharSequence mChosenWord;
-
- public WordAlternatives() {
- // Nothing
- }
+ public class WordAlternatives {
+ private final CharSequence mChosenWord;
+ private final WordComposer mWordComposer;
- public WordAlternatives(CharSequence chosenWord) {
+ public WordAlternatives(CharSequence chosenWord, WordComposer wordComposer) {
mChosenWord = chosenWord;
+ mWordComposer = wordComposer;
}
- @Override
- public int hashCode() {
- return mChosenWord.hashCode();
- }
-
- public abstract CharSequence getOriginalWord();
-
public CharSequence getChosenWord() {
return mChosenWord;
}
- public abstract SuggestedWords.Builder getAlternatives();
- }
-
- public class TypedWordAlternatives extends WordAlternatives {
- private WordComposer word;
-
- public TypedWordAlternatives() {
- // Nothing
+ public CharSequence getOriginalWord() {
+ return mWordComposer.getTypedWord();
}
- public TypedWordAlternatives(CharSequence chosenWord, WordComposer wordComposer) {
- super(chosenWord);
- word = wordComposer;
+ public SuggestedWords.Builder getAlternatives() {
+ return getTypedSuggestions(mWordComposer);
}
@Override
- public CharSequence getOriginalWord() {
- return word.getTypedWord();
+ public int hashCode() {
+ return mChosenWord.hashCode();
}
@Override
- public SuggestedWords.Builder getAlternatives() {
- return getTypedSuggestions(word);
+ public boolean equals(Object o) {
+ return o instanceof CharSequence && TextUtils.equals(mChosenWord, (CharSequence)o);
}
}
@@ -270,6 +269,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
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;
@Override
public void handleMessage(Message msg) {
@@ -285,8 +285,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
case MSG_UPDATE_SHIFT_STATE:
switcher.updateShiftState();
break;
+ case MSG_SET_BIGRAM_PREDICTIONS:
+ updateBigramPredictions();
+ break;
case MSG_VOICE_RESULTS:
- mVoiceConnector.handleVoiceResults(preferCapitalization()
+ mVoiceProxy.handleVoiceResults(preferCapitalization()
|| (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked()));
break;
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
@@ -337,6 +340,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
removeMessages(MSG_UPDATE_SHIFT_STATE);
}
+ public void postUpdateBigramPredictions() {
+ removeMessages(MSG_SET_BIGRAM_PREDICTIONS);
+ sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), DELAY_UPDATE_SUGGESTIONS);
+ }
+
+ public void cancelUpdateBigramPredictions() {
+ removeMessages(MSG_SET_BIGRAM_PREDICTIONS);
+ }
+
public void updateVoiceResults() {
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
}
@@ -347,11 +359,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
if (inputView != null) {
final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
+ // The language is always displayed when the delay is negative.
+ final boolean needsToDisplayLanguage = localeChanged
+ || mConfigDelayBeforeFadeoutLanguageOnSpacebar < 0;
// The language is never displayed when the delay is zero.
if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0)
- inputView.setSpacebarTextFadeFactor(localeChanged ? 1.0f
+ inputView.setSpacebarTextFadeFactor(needsToDisplayLanguage ? 1.0f
: mConfigFinalFadeoutFactorOfLanguageOnSpacebar, keyboard);
- // The language is always displayed when the delay is negative.
+ // The fadeout animation will start when the delay is positive.
if (localeChanged && mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) {
sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard),
mConfigDelayBeforeFadeoutLanguageOnSpacebar);
@@ -379,13 +394,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mPrefs = prefs;
LatinImeLogger.init(this, prefs);
+ LanguageSwitcherProxy.init(this, prefs);
SubtypeSwitcher.init(this, prefs);
KeyboardSwitcher.init(this, prefs);
AccessibilityUtils.init(this, prefs);
super.onCreate();
- mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
+ mImm = InputMethodManagerCompatWrapper.getInstance(this);
mInputMethodId = Utils.getInputMethodId(mImm, getPackageName());
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
@@ -430,47 +446,67 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mOrientation = res.getConfiguration().orientation;
initSuggestPuncList();
- // register to receive ringer mode change and network state change.
+ // Register to receive ringer mode change and network state change.
+ // Also receive installation and removal of a dictionary pack.
final IntentFilter filter = new IntentFilter();
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mReceiver, filter);
- mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
+ mVoiceProxy = VoiceProxy.init(this, prefs, mHandler);
+
+ final IntentFilter packageFilter = new IntentFilter();
+ packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
+ packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ packageFilter.addDataScheme(SCHEME_PACKAGE);
+ registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
+
+ final IntentFilter newDictFilter = new IntentFilter();
+ newDictFilter.addAction(
+ DictionaryPackInstallBroadcastReceiver.NEW_DICTIONARY_INTENT_ACTION);
+ registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
}
private void initSuggest() {
- String locale = mSubtypeSwitcher.getInputLocaleStr();
+ final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
+ final Locale keyboardLocale = new Locale(localeStr);
- Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
+ final Resources res = mResources;
+ final Locale savedLocale = Utils.setSystemLocale(res, keyboardLocale);
if (mSuggest != null) {
mSuggest.close();
}
final SharedPreferences prefs = mPrefs;
mQuickFixes = isQuickFixesEnabled(prefs);
- final Resources res = mResources;
int mainDicResId = Utils.getMainDictionaryResourceId(res);
- mSuggest = new Suggest(this, mainDicResId);
+ mSuggest = new Suggest(this, mainDicResId, keyboardLocale);
loadAndSetAutoCorrectionThreshold(prefs);
updateAutoTextEnabled();
- mUserDictionary = new UserDictionary(this, locale);
+ mUserDictionary = new UserDictionary(this, localeStr);
mSuggest.setUserDictionary(mUserDictionary);
mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
mSuggest.setContactsDictionary(mContactsDictionary);
- mAutoDictionary = new AutoDictionary(this, this, locale, Suggest.DIC_AUTO);
+ mAutoDictionary = new AutoDictionary(this, this, localeStr, Suggest.DIC_AUTO);
mSuggest.setAutoDictionary(mAutoDictionary);
- mUserBigramDictionary = new UserBigramDictionary(this, this, locale, Suggest.DIC_USER);
+ mUserBigramDictionary = new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER);
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
updateCorrectionMode();
mWordSeparators = res.getString(R.string.word_separators);
mSentenceSeparators = res.getString(R.string.sentence_separators);
- mSubtypeSwitcher.changeSystemLocale(savedLocale);
+ Utils.setSystemLocale(res, savedLocale);
+ }
+
+ /* package private */ void resetSuggestMainDict() {
+ final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
+ final Locale keyboardLocale = new Locale(localeStr);
+ int mainDicResId = Utils.getMainDictionaryResourceId(mResources);
+ mSuggest.resetMainDict(this, mainDicResId, keyboardLocale);
}
@Override
@@ -480,7 +516,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSuggest = null;
}
unregisterReceiver(mReceiver);
- mVoiceConnector.destroy();
+ unregisterReceiver(mDictionaryPackInstallReceiver);
+ mVoiceProxy.destroy();
LatinImeLogger.commit();
LatinImeLogger.onDestroy();
super.onDestroy();
@@ -501,8 +538,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mConfigurationChanging = true;
super.onConfigurationChanged(conf);
- mVoiceConnector.onConfigurationChanged(conf);
+ mVoiceProxy.onConfigurationChanged(conf);
mConfigurationChanging = false;
+
+ // This will work only when the subtype is not supported.
+ LanguageSwitcherProxy.onConfigurationChanged(conf);
}
@Override
@@ -515,12 +555,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
LayoutInflater inflater = getLayoutInflater();
LinearLayout container = (LinearLayout)inflater.inflate(R.layout.candidates, null);
mCandidateViewContainer = container;
- if (container.getPaddingRight() != 0) {
- HorizontalScrollView scrollView =
- (HorizontalScrollView) container.findViewById(R.id.candidates_scroll_view);
- scrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
- container.setGravity(Gravity.CENTER_HORIZONTAL);
- }
+ mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
mCandidateView = (CandidateView) container.findViewById(R.id.candidates);
mCandidateView.setService(this);
setCandidatesViewShown(true);
@@ -532,7 +567,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final KeyboardSwitcher switcher = mKeyboardSwitcher;
LatinKeyboardView inputView = switcher.getInputView();
- if(DEBUG) {
+ if (DEBUG) {
Log.d(TAG, "onStartInputView: " + inputView);
}
// In landscape mode, this method gets called without the input view being created.
@@ -547,16 +582,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// 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 VoiceIMEConnector voiceIme = mVoiceConnector;
- voiceIme.resetVoiceStates(Utils.isPasswordInputType(attribute.inputType)
- || Utils.isVisiblePasswordInputType(attribute.inputType));
+ final VoiceProxy voiceIme = mVoiceProxy;
+ voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(attribute.inputType)
+ || InputTypeCompatUtils.isVisiblePasswordInputType(attribute.inputType));
initializeInputAttributes(attribute);
inputView.closing();
mEnteredText = null;
mComposing.setLength(0);
- mHasValidSuggestions = false;
+ mHasUncommittedTypedChars = false;
mDeleteCount = 0;
mJustAddedAutoSpace = false;
@@ -568,8 +603,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
switcher.updateShiftState();
}
- setCandidatesViewShownInternal(isCandidateStripVisible(),
- false /* needsInputViewShown */ );
+ setCandidatesViewShownInternal(isCandidateStripVisible(), false /* needsInputViewShown */ );
// Delay updating suggestions because keyboard input view may not be shown at this point.
mHandler.postUpdateSuggestions();
@@ -577,7 +611,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final boolean accessibilityEnabled = mAccessibilityUtils.isAccessibilityEnabled();
- inputView.setPreviewEnabled(mPopupOn);
+ inputView.setKeyPreviewEnabled(mPopupOn);
inputView.setProximityCorrectionEnabled(true);
inputView.setAccessibilityEnabled(accessibilityEnabled);
// If we just entered a text field, maybe it has some old text that requires correction
@@ -603,17 +637,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if ((inputType & InputType.TYPE_MASK_CLASS) == InputType.TYPE_CLASS_TEXT) {
mIsSettingsSuggestionStripOn = true;
// Make sure that passwords are not displayed in candidate view
- if (Utils.isPasswordInputType(inputType)
- || Utils.isVisiblePasswordInputType(inputType)) {
+ if (InputTypeCompatUtils.isPasswordInputType(inputType)
+ || InputTypeCompatUtils.isVisiblePasswordInputType(inputType)) {
mIsSettingsSuggestionStripOn = false;
}
- if (Utils.isEmailVariation(variation)
+ if (InputTypeCompatUtils.isEmailVariation(variation)
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
mAutoSpace = false;
} else {
mAutoSpace = true;
}
- if (Utils.isEmailVariation(variation)) {
+ if (InputTypeCompatUtils.isEmailVariation(variation)) {
mIsSettingsSuggestionStripOn = false;
} else if (variation == InputType.TYPE_TEXT_VARIATION_URI) {
mIsSettingsSuggestionStripOn = false;
@@ -679,7 +713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
LatinImeLogger.commit();
mKeyboardSwitcher.onAutoCorrectionStateChanged(false);
- mVoiceConnector.flushVoiceInputLogs(mConfigurationChanging);
+ mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging);
KeyboardView inputView = mKeyboardSwitcher.getInputView();
if (inputView != null) inputView.closing();
@@ -700,7 +734,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onUpdateExtractedText(int token, ExtractedText text) {
super.onUpdateExtractedText(token, text);
- mVoiceConnector.showPunctuationHintIfNecessary();
+ mVoiceProxy.showPunctuationHintIfNecessary();
}
@Override
@@ -721,15 +755,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
+ ", ce=" + candidatesEnd);
}
- mVoiceConnector.setCursorAndSelection(newSelEnd, newSelStart);
+ mVoiceProxy.setCursorAndSelection(newSelEnd, newSelStart);
// If the current selection in the text view changes, we should
// clear whatever candidate text we have.
final boolean selectionChanged = (newSelStart != candidatesEnd
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
- if (((mComposing.length() > 0 && mHasValidSuggestions)
- || mVoiceConnector.isVoiceInputHighlighted())
+ if (((mComposing.length() > 0 && mHasUncommittedTypedChars)
+ || mVoiceProxy.isVoiceInputHighlighted())
&& (selectionChanged || candidatesCleared)) {
if (candidatesCleared) {
// If the composing span has been cleared, save the typed word in the history for
@@ -738,15 +772,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
saveWordInHistory(mComposing);
}
mComposing.setLength(0);
- mHasValidSuggestions = false;
- mHandler.postUpdateSuggestions();
+ mHasUncommittedTypedChars = false;
+ if (isCursorTouchingWord()) {
+ mHandler.cancelUpdateBigramPredictions();
+ mHandler.postUpdateSuggestions();
+ } else {
+ setPunctuationSuggestions();
+ }
TextEntryState.reset();
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.finishComposingText();
}
- mVoiceConnector.setVoiceInputHighlighted(false);
- } else if (!mHasValidSuggestions && !mJustAccepted) {
+ mVoiceProxy.setVoiceInputHighlighted(false);
+ } else if (!mHasUncommittedTypedChars && !mJustAccepted) {
if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) {
if (TextEntryState.isAcceptedDefault())
TextEntryState.reset();
@@ -767,16 +806,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (isSuggestionsRequested()
&& (candidatesStart == candidatesEnd || newSelStart != oldSelStart
|| TextEntryState.isRecorrecting())
- && (newSelStart < newSelEnd - 1 || !mHasValidSuggestions)) {
+ && (newSelStart < newSelEnd - 1 || !mHasUncommittedTypedChars)) {
if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) {
+ mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateOldSuggestions();
} else {
abortRecorrection(false);
- // Show the punctuation suggestions list if the current one is not
- // and if not showing "Touch again to save".
- if (mCandidateView != null && !isShowingPunctuationList()
+ // 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 (mCandidateView != null
&& !mCandidateView.isShowingAddToDictionaryHint()) {
- setPunctuationSuggestions();
+ InputConnection ic = getCurrentInputConnection();
+ if (null == ic || !TextUtils.isEmpty(ic.getTextAfterCursor(1, 0))) {
+ if (!isShowingPunctuationList()) setPunctuationSuggestions();
+ } else {
+ mHandler.postUpdateBigramPredictions();
+ }
}
}
}
@@ -825,7 +870,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mOptionsDialog.dismiss();
mOptionsDialog = null;
}
- mVoiceConnector.hideVoiceWindow(mConfigurationChanging);
+ mVoiceProxy.hideVoiceWindow(mConfigurationChanging);
mWordHistory.clear();
super.hideWindow();
}
@@ -859,10 +904,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void setCandidatesViewShownInternal(boolean shown, boolean needsInputViewShown) {
- // TODO: Remove this if we support candidates with hard keyboard
+ // TODO: Modify this if we support candidates with hard keyboard
if (onEvaluateInputViewShown()) {
- super.setCandidatesViewShown(shown
- && (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true));
+ final boolean shouldShowCandidates = shown
+ && (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true);
+ if (isExtractViewShown()) {
+ // No need to have extra space to show the key preview.
+ mCandidateViewContainer.setMinimumHeight(0);
+ super.setCandidatesViewShown(shown);
+ } else {
+ // We must control the visibility of the suggestion strip in order to avoid clipped
+ // key previews, even when we don't show the suggestion strip.
+ mCandidateViewContainer.setVisibility(
+ shouldShowCandidates ? View.VISIBLE : View.INVISIBLE);
+ super.setCandidatesViewShown(true);
+ }
}
}
@@ -874,37 +930,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
- if (!isFullscreenMode()) {
- outInsets.contentTopInsets = outInsets.visibleTopInsets;
- }
- KeyboardView inputView = mKeyboardSwitcher.getInputView();
+ final KeyboardView inputView = mKeyboardSwitcher.getInputView();
+ if (inputView == null)
+ return;
+ final int containerHeight = mCandidateViewContainer.getHeight();
+ int touchY = containerHeight;
// Need to set touchable region only if input view is being shown
- if (inputView != null && mKeyboardSwitcher.isInputViewShown()) {
- final int x = 0;
- int y = 0;
- final int width = inputView.getWidth();
- int height = inputView.getHeight() + EXTENDED_TOUCHABLE_REGION_HEIGHT;
- if (mCandidateViewContainer != null) {
- ViewParent candidateParent = mCandidateViewContainer.getParent();
- if (candidateParent instanceof FrameLayout) {
- FrameLayout fl = (FrameLayout) candidateParent;
- if (fl != null) {
- // Check frame layout's visibility
- if (fl.getVisibility() == View.INVISIBLE) {
- y = fl.getHeight();
- height += y;
- } else if (fl.getVisibility() == View.VISIBLE) {
- height += fl.getHeight();
- }
- }
- }
+ if (mKeyboardSwitcher.isInputViewShown()) {
+ if (mCandidateViewContainer.getVisibility() == View.VISIBLE) {
+ touchY -= mCandidateStripHeight;
}
+ final int touchWidth = inputView.getWidth();
+ final int touchHeight = inputView.getHeight() + containerHeight
+ // Extend touchable region below the keyboard.
+ + EXTENDED_TOUCHABLE_REGION_HEIGHT;
if (DEBUG) {
- Log.d(TAG, "Touchable region " + x + ", " + y + ", " + width + ", " + height);
+ Log.d(TAG, "Touchable region: y=" + touchY + " width=" + touchWidth
+ + " height=" + touchHeight);
}
- outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
- outInsets.touchableRegion.set(x, y, width, height);
+ setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight);
}
+ outInsets.contentTopInsets = touchY;
+ outInsets.visibleTopInsets = touchY;
}
@Override
@@ -960,8 +1007,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
public void commitTyped(InputConnection inputConnection) {
- if (mHasValidSuggestions) {
- mHasValidSuggestions = false;
+ if (mHasUncommittedTypedChars) {
+ mHasUncommittedTypedChars = false;
if (mComposing.length() > 0) {
if (inputConnection != null) {
inputConnection.commitText(mComposing, 1);
@@ -1142,16 +1189,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
case Keyboard.CODE_SETTINGS_LONGPRESS:
onSettingsKeyLongPressed();
break;
- case Keyboard.CODE_NEXT_LANGUAGE:
- toggleLanguage(false, true);
+ case LatinKeyboard.CODE_NEXT_LANGUAGE:
+ toggleLanguage(true);
break;
- case Keyboard.CODE_PREV_LANGUAGE:
- toggleLanguage(false, false);
+ case LatinKeyboard.CODE_PREV_LANGUAGE:
+ toggleLanguage(false);
break;
case Keyboard.CODE_CAPSLOCK:
switcher.toggleCapsLock();
break;
- case Keyboard.CODE_VOICE:
+ case Keyboard.CODE_SHORTCUT:
mSubtypeSwitcher.switchToShortcutIME();
break;
case Keyboard.CODE_TAB:
@@ -1161,10 +1208,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (primaryCode != Keyboard.CODE_ENTER) {
mJustAddedAutoSpace = false;
}
- RingCharBuffer.getInstance().push((char)primaryCode, x, y);
- LatinImeLogger.logOnInputChar();
if (isWordSeparator(primaryCode)) {
- handleSeparator(primaryCode);
+ handleSeparator(primaryCode, x, y);
} else {
handleCharacter(primaryCode, keyCodes, x, y);
}
@@ -1176,7 +1221,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onTextInput(CharSequence text) {
- mVoiceConnector.commitVoiceInput();
+ mVoiceProxy.commitVoiceInput();
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
abortRecorrection(false);
@@ -1198,25 +1243,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void handleBackspace() {
- if (mVoiceConnector.logAndRevertVoiceInput()) return;
+ if (mVoiceProxy.logAndRevertVoiceInput()) return;
final InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
ic.beginBatchEdit();
- mVoiceConnector.handleBackspace();
+ mVoiceProxy.handleBackspace();
boolean deleteChar = false;
- if (mHasValidSuggestions) {
+ if (mHasUncommittedTypedChars) {
final int length = mComposing.length();
if (length > 0) {
mComposing.delete(length - 1, length);
mWord.deleteLast();
ic.setComposingText(mComposing, 1);
if (mComposing.length() == 0) {
- mHasValidSuggestions = false;
+ mHasUncommittedTypedChars = false;
+ }
+ if (1 == length) {
+ // 1 == length means we are about to erase the last character of the word,
+ // so we can show bigrams.
+ mHandler.postUpdateBigramPredictions();
+ } else {
+ // length > 1, so we still have letters to deduce a suggestion from.
+ mHandler.postUpdateSuggestions();
}
- mHandler.postUpdateSuggestions();
} else {
ic.deleteSurroundingText(1, 0);
}
@@ -1256,9 +1308,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void handleTab() {
final int imeOptions = getCurrentInputEditorInfo().imeOptions;
- final int navigationFlags =
- EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
- if ((imeOptions & navigationFlags) == 0) {
+ if (!EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions)
+ && !EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions)) {
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
return;
}
@@ -1269,12 +1320,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// True if keyboard is in either chording shift or manual temporary upper case mode.
final boolean isManualTemporaryUpperCase = mKeyboardSwitcher.isManualTemporaryUpperCase();
- if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0
+ if (EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions)
&& !isManualTemporaryUpperCase) {
+ EditorInfoCompatUtils.performEditorActionNext(ic);
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
- } else if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0
+ } else if (EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions)
&& isManualTemporaryUpperCase) {
- ic.performEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
+ EditorInfoCompatUtils.performEditorActionPrevious(ic);
}
}
@@ -1288,7 +1340,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void handleCharacter(int primaryCode, int[] keyCodes, int x, int y) {
- mVoiceConnector.handleCharacter();
+ mVoiceProxy.handleCharacter();
if (mLastSelectionStart == mLastSelectionEnd && TextEntryState.isRecorrecting()) {
abortRecorrection(false);
@@ -1296,8 +1348,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
int code = primaryCode;
if (isAlphabet(code) && isSuggestionsRequested() && !isCursorTouchingWord()) {
- if (!mHasValidSuggestions) {
- mHasValidSuggestions = true;
+ if (!mHasUncommittedTypedChars) {
+ mHasUncommittedTypedChars = true;
mComposing.setLength(0);
saveWordInHistory(mBestWord);
mWord.reset();
@@ -1323,7 +1375,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
}
- if (mHasValidSuggestions) {
+ if (mHasUncommittedTypedChars) {
if (mComposing.length() == 0 && switcher.isAlphabetMode()
&& switcher.isShiftedOrShiftLocked()) {
mWord.setFirstCharCapitalized(true);
@@ -1344,14 +1396,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
switcher.updateShiftState();
if (LatinIME.PERF_DEBUG) measureCps();
- TextEntryState.typedCharacter((char) code, isWordSeparator(code));
+ TextEntryState.typedCharacter((char) code, isWordSeparator(code), x, y);
}
- private void handleSeparator(int primaryCode) {
- mVoiceConnector.handleSeparator();
+ private void handleSeparator(int primaryCode, int x, int y) {
+ mVoiceProxy.handleSeparator();
// Should dismiss the "Touch again to save" message when handling separator
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
+ mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions();
}
@@ -1362,13 +1415,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ic.beginBatchEdit();
abortRecorrection(false);
}
- if (mHasValidSuggestions) {
+ if (mHasUncommittedTypedChars) {
// In certain languages where single quote is a separator, it's better
// not to auto correct, but accept the typed word. For instance,
// in Italian dov' should not be expanded to dove' because the elision
// requires the last vowel to be removed.
if (mAutoCorrectOn && primaryCode != '\'') {
- pickedDefault = pickDefaultSuggestion();
+ pickedDefault = pickDefaultSuggestion(primaryCode);
// Picked the suggestion by the space key. We consider this
// as "added an auto space".
if (primaryCode == Keyboard.CODE_SPACE) {
@@ -1390,7 +1443,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
reswapPeriodAndSpace();
}
- TextEntryState.typedCharacter((char) primaryCode, true);
+ TextEntryState.typedCharacter((char) primaryCode, true, x, y);
+
if (TextEntryState.isPunctuationAfterAccepted() && primaryCode != Keyboard.CODE_ENTER) {
swapPunctuationAndSpace();
} else if (isSuggestionsRequested() && primaryCode == Keyboard.CODE_SPACE) {
@@ -1400,14 +1454,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
CharSequence typedWord = mWord.getTypedWord();
TextEntryState.backToAcceptedDefault(typedWord);
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
- if (ic != null) {
- CorrectionInfo correctionInfo = new CorrectionInfo(
- mLastSelectionEnd - typedWord.length(), typedWord, mBestWord);
- ic.commitCorrection(correctionInfo);
- }
+ InputConnectionCompatUtils.commitCorrection(
+ ic, mLastSelectionEnd - typedWord.length(), typedWord, mBestWord);
if (mCandidateView != null)
mCandidateView.onAutoCorrectionInverted(mBestWord);
}
+ }
+ if (Keyboard.CODE_SPACE == primaryCode) {
+ if (!isCursorTouchingWord()) {
+ mHandler.cancelUpdateSuggestions();
+ mHandler.cancelUpdateOldSuggestions();
+ mHandler.postUpdateBigramPredictions();
+ }
+ } else {
+ // Set punctuation right away. onUpdateSelection will fire but tests whether it is
+ // already displayed or not, so it's okay.
setPunctuationSuggestions();
}
mKeyboardSwitcher.updateShiftState();
@@ -1418,7 +1479,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void handleClose() {
commitTyped(getCurrentInputConnection());
- mVoiceConnector.handleClose();
+ mVoiceProxy.handleClose();
requestHideSelf(0);
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
if (inputView != null)
@@ -1436,7 +1497,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Make a copy of the CharSequence, since it is/could be a mutable CharSequence
final String resultCopy = result.toString();
- TypedWordAlternatives entry = new TypedWordAlternatives(resultCopy,
+ WordAlternatives entry = new WordAlternatives(resultCopy,
new WordComposer(mWord));
mWordHistory.add(entry);
}
@@ -1491,7 +1552,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
public void setSuggestions(SuggestedWords words) {
- if (mVoiceConnector.getAndResetIsShowingHint()) {
+ if (mVoiceProxy.getAndResetIsShowingHint()) {
setCandidatesView(mCandidateViewContainer);
}
@@ -1507,11 +1568,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void updateSuggestions() {
// Check if we have a suggestion engine attached.
if ((mSuggest == null || !isSuggestionsRequested())
- && !mVoiceConnector.isVoiceInputHighlighted()) {
+ && !mVoiceProxy.isVoiceInputHighlighted()) {
return;
}
- if (!mHasValidSuggestions) {
+ if (!mHasUncommittedTypedChars) {
setPunctuationSuggestions();
return;
}
@@ -1582,14 +1643,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setCandidatesViewShown(isCandidateStripVisible());
}
- private boolean pickDefaultSuggestion() {
+ private boolean pickDefaultSuggestion(int separatorCode) {
// Complete any pending candidate query first
if (mHandler.hasPendingUpdateSuggestions()) {
mHandler.cancelUpdateSuggestions();
updateSuggestions();
}
if (mBestWord != null && mBestWord.length() > 0) {
- TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord);
+ TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode);
mJustAccepted = true;
pickSuggestion(mBestWord);
// Add the word to the auto dictionary if it's not a known word
@@ -1602,7 +1663,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void pickSuggestionManually(int index, CharSequence suggestion) {
SuggestedWords suggestions = mCandidateView.getSuggestions();
- mVoiceConnector.flushAndLogAllTextModificationCounters(index, suggestion, mWordSeparators);
+ mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mWordSeparators);
final boolean recorrecting = TextEntryState.isRecorrecting();
InputConnection ic = getCurrentInputConnection();
@@ -1642,6 +1703,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
return;
}
+ if (!mHasUncommittedTypedChars) {
+ // If we are not composing a word, then it was a suggestion inferred from
+ // context - no user input. We should reset the word composer.
+ mWord.reset();
+ }
mJustAccepted = true;
pickSuggestion(suggestion);
// Add the word to the auto dictionary if it's not a known word
@@ -1678,8 +1744,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Fool the state watcher so that a subsequent backspace will not do a revert, unless
// we just did a correction, in which case we need to stay in
// TextEntryState.State.PICKED_SUGGESTION state.
- TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true);
- setPunctuationSuggestions();
+ TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true,
+ WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
+ // From there on onUpdateSelection() will fire so suggestions will be updated
} else if (!showingAddToDictionaryHint) {
// If we're not showing the "Touch again to save", then show corrections again.
// In case the cursor position doesn't change, make sure we show the suggestions again.
@@ -1706,11 +1773,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return;
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
- mVoiceConnector.rememberReplacedWord(suggestion, mWordSeparators);
+ mVoiceProxy.rememberReplacedWord(suggestion, mWordSeparators);
ic.commitText(suggestion, 1);
}
saveWordInHistory(suggestion);
- mHasValidSuggestions = false;
+ mHasUncommittedTypedChars = false;
mCommittedLength = suggestion.length();
}
@@ -1727,9 +1794,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Search old suggestions to suggest re-corrected suggestions.
for (WordAlternatives entry : mWordHistory) {
if (TextUtils.equals(entry.getChosenWord(), touching.mWord)) {
- if (entry instanceof TypedWordAlternatives) {
- foundWord = ((TypedWordAlternatives) entry).word;
- }
+ foundWord = entry.mWordComposer;
alternatives = entry;
break;
}
@@ -1749,7 +1814,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Found a match, show suggestions
if (foundWord != null || alternatives != null) {
if (alternatives == null) {
- alternatives = new TypedWordAlternatives(touching.mWord, foundWord);
+ alternatives = new WordAlternatives(touching.mWord, foundWord);
}
showCorrections(alternatives);
if (foundWord != null) {
@@ -1763,13 +1828,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void setOldSuggestions() {
- mVoiceConnector.setShowingVoiceSuggestions(false);
+ if (!InputConnectionCompatUtils.RECORRECTION_SUPPORTED) return;
+ mVoiceProxy.setShowingVoiceSuggestions(false);
if (mCandidateView != null && mCandidateView.isShowingAddToDictionaryHint()) {
return;
}
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
- if (!mHasValidSuggestions) {
+ if (!mHasUncommittedTypedChars) {
// Extract the selected or touching text
EditingUtils.SelectedWord touching = EditingUtils.getWordAtCursorOrSelection(ic,
mLastSelectionStart, mLastSelectionEnd, mWordSeparators);
@@ -1777,12 +1843,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (touching != null && touching.mWord.length() > 1) {
ic.beginBatchEdit();
- if (!mVoiceConnector.applyVoiceAlternatives(touching)
+ if (!mVoiceProxy.applyVoiceAlternatives(touching)
&& !applyTypedAlternatives(touching)) {
abortRecorrection(true);
} else {
TextEntryState.selectedForRecorrection();
- EditingUtils.underlineWord(ic, touching);
+ InputConnectionCompatUtils.underlineWord(ic, touching);
}
ic.endBatchEdit();
@@ -1795,6 +1861,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
+ private static final WordComposer sEmptyWordComposer = new WordComposer();
+ private void updateBigramPredictions() {
+ if (mSuggest == null || !isSuggestionsRequested())
+ return;
+
+ if (!mBigramPredictionEnabled) {
+ setPunctuationSuggestions();
+ return;
+ }
+
+ final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
+ mWordSeparators);
+ SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
+ mKeyboardSwitcher.getInputView(), sEmptyWordComposer, prevWord);
+
+ if (builder.size() > 0) {
+ // Explicitly supply an empty typed word (the no-second-arg version of
+ // showSuggestions will retrieve the word near the cursor, we don't want that here)
+ showSuggestions(builder.build(), "");
+ } else {
+ if (!isShowingPunctuationList()) setPunctuationSuggestions();
+ }
+ }
+
private void setPunctuationSuggestions() {
setSuggestions(mSuggestPuncList);
setCandidatesViewShown(isCandidateStripVisible());
@@ -1868,7 +1958,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void revertLastWord(boolean deleteChar) {
final int length = mComposing.length();
- if (!mHasValidSuggestions && length > 0) {
+ if (!mHasUncommittedTypedChars && length > 0) {
final InputConnection ic = getCurrentInputConnection();
final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
if (deleteChar) ic.deleteSurroundingText(1, 0);
@@ -1886,14 +1976,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ic.commitText(mComposing, 1);
TextEntryState.acceptedTyped(mComposing);
ic.commitText(punctuation, 1);
- TextEntryState.typedCharacter(punctuation.charAt(0), true);
+ TextEntryState.typedCharacter(punctuation.charAt(0), true,
+ WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
// Clear composing text
mComposing.setLength(0);
} else {
- mHasValidSuggestions = true;
+ mHasUncommittedTypedChars = true;
ic.setComposingText(mComposing, 1);
TextEntryState.backspace();
}
+ mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions();
} else {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
@@ -1922,23 +2014,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return mWord.isFirstCharCapitalized();
}
- // Notify that language or mode have been changed and toggleLanguage will update KeyboaredID
+ // Notify that language or mode have been changed and toggleLanguage will update KeyboardID
// according to new language or mode.
public void onRefreshKeyboard() {
- toggleLanguage(true, true);
+ // Reload keyboard because the current language has been changed.
+ mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(),
+ mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(),
+ mVoiceProxy.isVoiceButtonOnPrimary());
+ initSuggest();
+ mKeyboardSwitcher.updateShiftState();
}
// "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER.
- private void toggleLanguage(boolean reset, boolean next) {
+ private void toggleLanguage(boolean next) {
if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) {
- mSubtypeSwitcher.toggleLanguage(reset, next);
+ mSubtypeSwitcher.toggleLanguage(next);
}
- // Reload keyboard because the current language has been changed.
- mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(),
- mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceConnector.isVoiceButtonEnabled(),
- mVoiceConnector.isVoiceButtonOnPrimary());
- initSuggest();
- mKeyboardSwitcher.updateShiftState();
+ onRefreshKeyboard();// no need??
}
@Override
@@ -1969,7 +2061,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onRelease(int primaryCode, boolean withSliding) {
KeyboardSwitcher switcher = mKeyboardSwitcher;
// Reset any drag flags in the keyboard
- switcher.keyReleased();
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
switcher.onReleaseShift(withSliding);
@@ -2108,9 +2199,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void loadSettings(EditorInfo attribute) {
// Get the settings preferences
final SharedPreferences prefs = mPrefs;
- Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
- mVibrateOn = vibrator != null && vibrator.hasVibrator()
- && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
+ final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator();
+ mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
mResources.getBoolean(R.bool.config_default_sound_enabled));
@@ -2120,14 +2210,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs);
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs);
+ mBigramPredictionEnabled = mBigramSuggestionEnabled && isBigramPredictionEnabled(prefs);
loadAndSetAutoCorrectionThreshold(prefs);
- mVoiceConnector.loadSettings(attribute, prefs);
+ mVoiceProxy.loadSettings(attribute, prefs);
updateCorrectionMode();
updateAutoTextEnabled();
updateSuggestionVisibility(prefs);
- SubtypeSwitcher.getInstance().loadSettings();
+
+ // This will work only when the subtype is not supported.
+ LanguageSwitcherProxy.loadSettings();
}
/**
@@ -2202,6 +2295,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
R.bool.config_default_bigram_suggestions));
}
+ private boolean isBigramPredictionEnabled(SharedPreferences sp) {
+ return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, mResources.getBoolean(
+ R.bool.config_default_bigram_prediction));
+ }
+
private void initSuggestPuncList() {
if (mSuggestPuncs != null || mSuggestPuncList != null)
return;
@@ -2233,13 +2331,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
di.dismiss();
switch (position) {
case 0:
- Intent intent = new Intent(
- android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ Intent intent = CompatUtils.getInputLanguageSelectionIntent(
+ mInputMethodId, Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.putExtra(android.provider.Settings.EXTRA_INPUT_METHOD_ID,
- mInputMethodId);
startActivity(intent);
break;
case 1:
@@ -2305,7 +2400,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
p.println(" mComposing=" + mComposing.toString());
p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
p.println(" mCorrectionMode=" + mCorrectionMode);
- p.println(" mHasValidSuggestions=" + mHasValidSuggestions);
+ p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars);
p.println(" mAutoCorrectOn=" + mAutoCorrectOn);
p.println(" mAutoSpace=" + mAutoSpace);
p.println(" mApplicationSpecifiedCompletionOn=" + mApplicationSpecifiedCompletionOn);
@@ -2332,9 +2427,4 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
for (int i = 0; i < CPS_BUFFER_SIZE; i++) total += mCpsIntervals[i];
System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total));
}
-
- @Override
- public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
- SubtypeSwitcher.getInstance().updateSubtype(subtype);
- }
}