aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableDictionary.java2
-rw-r--r--java/src/com/android/inputmethod/latin/InputAttributes.java35
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java184
-rw-r--r--java/src/com/android/inputmethod/latin/LatinImeLogger.java1
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java21
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java7
-rw-r--r--java/src/com/android/inputmethod/latin/UserDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/UserUnigramDictionary.java6
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java15
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java102
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java12
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java (renamed from java/src/com/android/inputmethod/latin/MoreSuggestions.java)9
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java (renamed from java/src/com/android/inputmethod/latin/MoreSuggestionsView.java)3
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java (renamed from java/src/com/android/inputmethod/latin/SuggestionsView.java)195
14 files changed, 354 insertions, 241 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
index cad69bb0e..7eec8e2ca 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
@@ -51,6 +51,7 @@ public class ExpandableDictionary extends Dictionary {
private Object mUpdatingLock = new Object();
private static class Node {
+ Node() {}
char mCode;
int mFrequency;
boolean mTerminal;
@@ -547,6 +548,7 @@ public class ExpandableDictionary extends Dictionary {
}
private class LoadDictionaryTask extends Thread {
+ LoadDictionaryTask() {}
@Override
public void run() {
loadDictionaryAsync();
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
new file mode 100644
index 000000000..28ce916c9
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -0,0 +1,35 @@
+/*
+ * 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.latin;
+
+import android.view.inputmethod.EditorInfo;
+
+/**
+ * Class to hold attributes of the input field.
+ */
+public class InputAttributes {
+ private final String TAG = InputAttributes.class.getSimpleName();
+
+ // TODO: make these final
+ public boolean mInsertSpaceOnPickSuggestionManually;
+ public boolean mInputTypeNoAutoCorrect;
+ public boolean mIsSettingsSuggestionStripOn;
+ public boolean mApplicationSpecifiedCompletionOn;
+
+ public InputAttributes(final EditorInfo editorInfo) {
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 98fea1b5b..71db4550c 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -67,6 +67,7 @@ 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.suggestions.SuggestionsView;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -195,12 +196,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private UserUnigramDictionary mUserUnigramDictionary;
private boolean mIsUserDictionaryAvailable;
- // TODO: Create an inner class to group options and pseudo-options to improve readability.
- // These variables are initialized according to the {@link EditorInfo#inputType}.
- private boolean mInsertSpaceOnPickSuggestionManually;
- private boolean mInputTypeNoAutoCorrect;
- private boolean mIsSettingsSuggestionStripOn;
- private boolean mApplicationSpecifiedCompletionOn;
+ private InputAttributes mInputAttributes;
private WordComposer mWordComposer = new WordComposer();
private boolean mHasUncommittedTypedChars;
@@ -297,19 +293,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|| (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked()));
break;
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
- if (inputView != null) {
- inputView.setSpacebarTextFadeFactor(
- (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
- (LatinKeyboard)msg.obj);
- }
+ setSpacebarTextFadeFactor(inputView,
+ (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
+ (LatinKeyboard)msg.obj);
sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
mDurationOfFadeoutLanguageOnSpacebar);
break;
case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
- if (inputView != null) {
- inputView.setSpacebarTextFadeFactor(mFinalFadeoutFactorOfLanguageOnSpacebar,
- (LatinKeyboard)msg.obj);
- }
+ setSpacebarTextFadeFactor(inputView, mFinalFadeoutFactorOfLanguageOnSpacebar,
+ (LatinKeyboard)msg.obj);
break;
}
}
@@ -349,6 +341,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
}
+ private static void setSpacebarTextFadeFactor(LatinKeyboardView inputView,
+ float fadeFactor, LatinKeyboard oldKeyboard) {
+ if (inputView == null) return;
+ final Keyboard keyboard = inputView.getKeyboard();
+ if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
+ final Key updatedKey = ((LatinKeyboard)keyboard).updateSpacebarLanguage(
+ fadeFactor,
+ Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
+ SubtypeSwitcher.getInstance().needsToDisplayLanguage(keyboard.mId.mLocale));
+ inputView.invalidateKey(updatedKey);
+ }
+ }
+
public void startDisplayLanguageOnSpacebar(boolean localeChanged) {
final LatinIME latinIme = getOuterInstance();
removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
@@ -361,9 +366,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|| mDelayBeforeFadeoutLanguageOnSpacebar < 0;
// The language is never displayed when the delay is zero.
if (mDelayBeforeFadeoutLanguageOnSpacebar != 0) {
- inputView.setSpacebarTextFadeFactor(needsToDisplayLanguage ? 1.0f
- : mFinalFadeoutFactorOfLanguageOnSpacebar,
- keyboard);
+ setSpacebarTextFadeFactor(inputView,
+ needsToDisplayLanguage ? 1.0f : mFinalFadeoutFactorOfLanguageOnSpacebar,
+ keyboard);
}
// The fadeout animation will start when the delay is positive.
if (localeChanged && mDelayBeforeFadeoutLanguageOnSpacebar > 0) {
@@ -489,7 +494,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
InputMethodManagerCompatWrapper.init(this);
SubtypeSwitcher.init(this);
KeyboardSwitcher.init(this, prefs);
- AccessibilityUtils.init(this, prefs);
+ AccessibilityUtils.init(this);
super.onCreate();
@@ -505,6 +510,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
loadSettings();
+ // TODO: remove the following when it's not needed by updateCorrectionMode() any more
+ mInputAttributes = new InputAttributes(null);
Utils.GCUtils.getInstance().reset();
boolean tryGC = true;
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
@@ -758,7 +765,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
loadSettings();
updateCorrectionMode();
- updateSuggestionVisibility(mPrefs, mResources);
+ updateSuggestionVisibility(mResources);
if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) {
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
@@ -788,71 +795,88 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
}
- private void initializeInputAttributes(EditorInfo editorInfo) {
- if (editorInfo == null)
- return;
- final int inputType = editorInfo.inputType;
- if (inputType == InputType.TYPE_NULL) {
- // TODO: We should honor TYPE_NULL specification.
- Log.i(TAG, "InputType.TYPE_NULL is specified");
- }
- final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
- final int variation = inputType & InputType.TYPE_MASK_VARIATION;
- if (inputClass == 0) {
- Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x imeOptions=0x%08x",
- inputType, editorInfo.imeOptions));
- }
-
- mInsertSpaceOnPickSuggestionManually = false;
- mInputTypeNoAutoCorrect = false;
- mIsSettingsSuggestionStripOn = false;
- mApplicationSpecifiedCompletionOn = false;
- mApplicationSpecifiedCompletions = null;
-
- if (inputClass == InputType.TYPE_CLASS_TEXT) {
- mIsSettingsSuggestionStripOn = true;
+ private void initializeInputAttributes(final EditorInfo editorInfo) {
+ mInputAttributes = new InputAttributes(editorInfo);
+
+ final boolean insertSpaceOnPickSuggestionManually;
+ boolean inputTypeNoAutoCorrect = false;
+ boolean isSettingsSuggestionStripOn = false;
+ boolean applicationSpecifiedCompletionOn = false;
+
+ if (editorInfo == null || editorInfo.inputType != InputType.TYPE_CLASS_TEXT) {
+ if (editorInfo.inputType == InputType.TYPE_NULL) {
+ // TODO: We should honor TYPE_NULL specification.
+ Log.i(TAG, "InputType.TYPE_NULL is specified");
+ }
+ mApplicationSpecifiedCompletions = null;
+ insertSpaceOnPickSuggestionManually = false;
+ } else {
+ final int inputType = editorInfo.inputType;
+ final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
+ final int variation = inputType & InputType.TYPE_MASK_VARIATION;
+ if (inputClass == 0) {
+ Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
+ + " imeOptions=0x%08x",
+ inputType, editorInfo.imeOptions));
+ }
+ final boolean flagNoSuggestions =
+ 0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
+ final boolean flagMultiLine =
+ 0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
+ final boolean flagAutoCorrect =
+ 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
+ final boolean flagAutoComplete =
+ 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
+
+ mApplicationSpecifiedCompletions = null;
+
+ isSettingsSuggestionStripOn = true;
// Make sure that passwords are not displayed in {@link SuggestionsView}.
if (InputTypeCompatUtils.isPasswordInputType(inputType)
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType)) {
- mIsSettingsSuggestionStripOn = false;
+ isSettingsSuggestionStripOn = false;
}
if (InputTypeCompatUtils.isEmailVariation(variation)
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
// The point in turning this off is that we don't want to insert a space after
// a name when filling a form: we can't delete trailing spaces when changing fields
- mInsertSpaceOnPickSuggestionManually = false;
+ insertSpaceOnPickSuggestionManually = false;
} else {
- mInsertSpaceOnPickSuggestionManually = true;
+ insertSpaceOnPickSuggestionManually = true;
}
if (InputTypeCompatUtils.isEmailVariation(variation)) {
- mIsSettingsSuggestionStripOn = false;
+ isSettingsSuggestionStripOn = false;
} else if (variation == InputType.TYPE_TEXT_VARIATION_URI) {
- mIsSettingsSuggestionStripOn = false;
+ isSettingsSuggestionStripOn = false;
} else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
- mIsSettingsSuggestionStripOn = false;
+ isSettingsSuggestionStripOn = false;
} else if (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) {
// If it's a browser edit field and auto correct is not ON explicitly, then
// disable auto correction, but keep suggestions on.
- if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) {
- mInputTypeNoAutoCorrect = true;
+ if (!flagAutoCorrect) {
+ inputTypeNoAutoCorrect = true;
}
}
// If NO_SUGGESTIONS is set, don't do prediction.
- if ((inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0) {
- mIsSettingsSuggestionStripOn = false;
- mInputTypeNoAutoCorrect = true;
+ if (flagNoSuggestions) {
+ isSettingsSuggestionStripOn = false;
+ inputTypeNoAutoCorrect = true;
}
// If it's not multiline and the autoCorrect flag is not set, then don't correct
- if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0
- && (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) == 0) {
- mInputTypeNoAutoCorrect = true;
+ if (!flagAutoCorrect && !flagMultiLine) {
+ inputTypeNoAutoCorrect = true;
}
- if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
- mIsSettingsSuggestionStripOn = false;
- mApplicationSpecifiedCompletionOn = isFullscreenMode();
+ if (flagAutoComplete) {
+ isSettingsSuggestionStripOn = false;
+ applicationSpecifiedCompletionOn = isFullscreenMode();
}
}
+
+ mInputAttributes.mInsertSpaceOnPickSuggestionManually = insertSpaceOnPickSuggestionManually;
+ mInputAttributes.mInputTypeNoAutoCorrect = inputTypeNoAutoCorrect;
+ mInputAttributes.mIsSettingsSuggestionStripOn = isSettingsSuggestionStripOn;
+ mInputAttributes.mApplicationSpecifiedCompletionOn = applicationSpecifiedCompletionOn;
}
@Override
@@ -1006,7 +1030,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
}
- if (mApplicationSpecifiedCompletionOn) {
+ if (mInputAttributes.mApplicationSpecifiedCompletionOn) {
mApplicationSpecifiedCompletions = applicationSpecifiedCompletions;
if (applicationSpecifiedCompletions == null) {
clearSuggestions();
@@ -1139,6 +1163,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mHasUncommittedTypedChars) return;
mHasUncommittedTypedChars = false;
final CharSequence typedWord = mWordComposer.getTypedWord();
+ mWordComposer.onCommitWord();
if (typedWord.length() > 0) {
if (ic != null) {
ic.commitText(typedWord, 1);
@@ -1229,7 +1254,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isShowingOptionDialog()) return;
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
showSubtypeSelectorAndSettings();
- } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm, false /* exclude aux subtypes */)) {
+ } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(false /* exclude aux subtypes */)) {
showOptionsMenu();
} else {
launchSettings();
@@ -1245,7 +1270,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isShowingOptionDialog()) return false;
switch (requestCode) {
case CODE_SHOW_INPUT_METHOD_PICKER:
- if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm, true /* include aux subtypes */)) {
+ if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
mImm.showInputMethodPicker();
return true;
}
@@ -1600,7 +1625,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// in Italian dov' should not be expanded to dove' because the elision
// requires the last vowel to be removed.
final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled
- && !mInputTypeNoAutoCorrect;
+ && !mInputAttributes.mInputTypeNoAutoCorrect;
if (shouldAutoCorrect && primaryCode != Keyboard.CODE_SINGLE_QUOTE) {
commitCurrentAutoCorrection(primaryCode, ic);
} else {
@@ -1677,7 +1702,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public boolean isSuggestionsRequested() {
- return mIsSettingsSuggestionStripOn
+ return mInputAttributes.mIsSettingsSuggestionStripOn
&& (mCorrectionMode > 0 || isShowingSuggestionsStrip());
}
@@ -1699,7 +1724,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return true;
if (!isShowingSuggestionsStrip())
return false;
- if (mApplicationSpecifiedCompletionOn)
+ if (mInputAttributes.mApplicationSpecifiedCompletionOn)
return true;
return isSuggestionsRequested();
}
@@ -1786,7 +1811,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
- boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
+ boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect
+ && mSuggest.hasAutoCorrection();
final CharSequence typedWord = mWordComposer.getTypedWord();
// Here, we want to promote a whitelisted word if exists.
// TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
@@ -1902,7 +1928,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (ic != null) {
ic.beginBatchEdit();
}
- if (mApplicationSpecifiedCompletionOn && mApplicationSpecifiedCompletions != null
+ if (mInputAttributes.mApplicationSpecifiedCompletionOn
+ && mApplicationSpecifiedCompletions != null
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
if (ic != null) {
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
@@ -1961,7 +1988,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
suggestion.toString(), index, suggestions.mWords);
// Follow it with a space
- if (mInsertSpaceOnPickSuggestionManually) {
+ if (mInputAttributes.mInsertSpaceOnPickSuggestionManually) {
sendMagicSpace();
}
@@ -2023,6 +2050,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
mHasUncommittedTypedChars = false;
+ mWordComposer.onCommitWord();
}
private static final WordComposer sEmptyWordComposer = new WordComposer();
@@ -2192,10 +2220,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
ic.deleteSurroundingText(cancelLength + 1, 0);
-
- // Re-insert the separator
+ mWordComposer.resumeSuggestionOnKeptWord();
ic.commitText(mWordComposer.getTypedWord(), 1);
+ // Re-insert the separator
ic.commitText(separator, 1);
+ mWordComposer.onCommitWord();
Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE);
mHandler.cancelUpdateBigramPredictions();
@@ -2224,6 +2253,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving
// the old WordComposer allows to reuse the actual typed coordinates.
mHasUncommittedTypedChars = true;
+ mWordComposer.resumeSuggestionOnKeptWord();
ic.setComposingText(mWordComposer.getTypedWord(), 1);
mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions();
@@ -2409,13 +2439,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private void updateCorrectionMode() {
// TODO: cleanup messy flags
final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled
- && !mInputTypeNoAutoCorrect;
+ && !mInputAttributes.mInputTypeNoAutoCorrect;
mCorrectionMode = shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE;
mCorrectionMode = (mSettingsValues.mBigramSuggestionEnabled && shouldAutoCorrect)
? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode;
}
- private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) {
+ private void updateSuggestionVisibility(final Resources res) {
final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting;
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
@@ -2508,12 +2538,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
p.println(" Keyboard mode = " + keyboardMode);
- p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
+ p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);
p.println(" mCorrectionMode=" + mCorrectionMode);
p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars);
p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled);
- p.println(" mInsertSpaceOnPickSuggestionManually=" + mInsertSpaceOnPickSuggestionManually);
- p.println(" mApplicationSpecifiedCompletionOn=" + mApplicationSpecifiedCompletionOn);
+ p.println(" mInsertSpaceOnPickSuggestionManually="
+ + mInputAttributes.mInsertSpaceOnPickSuggestionManually);
+ p.println(" mApplicationSpecifiedCompletionOn="
+ + mInputAttributes.mApplicationSpecifiedCompletionOn);
p.println(" mSoundOn=" + mSettingsValues.mSoundOn);
p.println(" mVibrateOn=" + mSettingsValues.mVibrateOn);
p.println(" mKeyPreviewPopupOn=" + mSettingsValues.mKeyPreviewPopupOn);
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index da5058dd4..6f1adfe71 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -29,6 +29,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
public static boolean sDBG = false;
public static boolean sVISUALDEBUG = false;
+ public static boolean sUsabilityStudy = false;
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 0ad1c1529..651d90ca4 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -52,7 +52,9 @@ public class SettingsValues {
private final String mVoiceMode;
private final String mAutoCorrectionThresholdRawValue;
public final String mShowSuggestionsSetting;
+ @SuppressWarnings("unused") // TODO: Use this
private final boolean mUsabilityStudyMode;
+ @SuppressWarnings("unused") // TODO: Use this
private final String mKeyPreviewPopupDismissDelayRawValue;
public final boolean mUseContactsDict;
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
@@ -60,7 +62,9 @@ public class SettingsValues {
// Prediction: use bigrams to predict the next word when there is no input for it yet
public final boolean mBigramPredictionEnabled;
public final boolean mEnableSuggestionSpanInsertion;
+ @SuppressWarnings("unused") // TODO: Use this
private final int mVibrationDurationSettingsRawValue;
+ @SuppressWarnings("unused") // TODO: Use this
private final float mKeypressSoundVolumeRawValue;
// Deduced settings
@@ -111,12 +115,12 @@ public class SettingsValues {
res.getString(R.string.auto_correction_threshold_mode_index_modest));
mShowSuggestionsSetting = prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING,
res.getString(R.string.prefs_suggestion_visibility_default_value));
- mUsabilityStudyMode = getUsabilityStudyMode(prefs, res);
+ mUsabilityStudyMode = getUsabilityStudyMode(prefs);
mKeyPreviewPopupDismissDelayRawValue = prefs.getString(
Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
Integer.toString(res.getInteger(R.integer.config_delay_after_preview)));
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
- mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res, mAutoCorrectionThresholdRawValue);
+ mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue);
mBigramSuggestionEnabled = mAutoCorrectEnabled
&& isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled);
mBigramPredictionEnabled = mBigramSuggestionEnabled
@@ -131,7 +135,7 @@ public class SettingsValues {
mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res);
mFxVolume = getCurrentKeypressSoundVolume(prefs, res);
mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res);
- mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res,
+ mAutoCorrectionThreshold = getAutoCorrectionThreshold(res,
mAutoCorrectionThresholdRawValue);
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
@@ -202,8 +206,8 @@ public class SettingsValues {
return mMagicSpaceSwappers.contains(String.valueOf((char)code));
}
- private static boolean isAutoCorrectEnabled(final SharedPreferences sp,
- final Resources resources, final String currentAutoCorrectionSetting) {
+ private static boolean isAutoCorrectEnabled(final Resources resources,
+ final String currentAutoCorrectionSetting) {
final String autoCorrectionOff = resources.getString(
R.string.auto_correction_threshold_mode_index_off);
return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
@@ -244,8 +248,8 @@ public class SettingsValues {
R.bool.config_default_bigram_prediction));
}
- private static double getAutoCorrectionThreshold(final SharedPreferences sp,
- final Resources resources, final String currentAutoCorrectionSetting) {
+ private static double getAutoCorrectionThreshold(final Resources resources,
+ final String currentAutoCorrectionSetting) {
final String[] autoCorrectionThresholdValues = resources.getStringArray(
R.array.auto_correction_threshold_values);
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
@@ -321,8 +325,7 @@ public class SettingsValues {
}
// Likewise
- public static boolean getUsabilityStudyMode(final SharedPreferences prefs,
- final Resources res) {
+ public static boolean getUsabilityStudyMode(final SharedPreferences prefs) {
// TODO: use mUsabilityStudyMode instead of reading it again here
return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true);
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 8a4862094..42111822d 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -35,7 +35,6 @@ import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
-import com.android.inputmethod.keyboard.LatinKeyboard;
import java.util.ArrayList;
import java.util.Arrays;
@@ -421,11 +420,7 @@ public class SubtypeSwitcher {
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
mIsNetworkConnected = !noConnection;
- final KeyboardSwitcher switcher = KeyboardSwitcher.getInstance();
- final LatinKeyboard keyboard = switcher.getLatinKeyboard();
- if (keyboard != null) {
- keyboard.updateShortcutKey(isShortcutImeReady(), switcher.getKeyboardView());
- }
+ KeyboardSwitcher.getInstance().onNetworkStateChanged();
}
//////////////////////////////////
diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java
index 8c28324d8..6d6296e10 100644
--- a/java/src/com/android/inputmethod/latin/UserDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserDictionary.java
@@ -18,13 +18,10 @@ package com.android.inputmethod.latin;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
-import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
-import android.net.Uri;
-import android.os.RemoteException;
import android.provider.UserDictionary.Words;
import android.text.TextUtils;
diff --git a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java
index 6af20c754..a7f57ae46 100644
--- a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java
@@ -172,7 +172,7 @@ public class UserUnigramDictionary extends ExpandableDictionary {
// Nothing pending? Return
if (mPendingWrites.isEmpty()) return;
// Create a background thread to write the pending entries
- new UpdateDbTask(getContext(), sOpenHelper, mPendingWrites, mLocale).execute();
+ new UpdateDbTask(sOpenHelper, mPendingWrites, mLocale).execute();
// Create a new map for writing new entries into while the old one is written to db
mPendingWrites = new HashMap<String, Integer>();
}
@@ -227,8 +227,8 @@ public class UserUnigramDictionary extends ExpandableDictionary {
private final DatabaseHelper mDbHelper;
private final String mLocale;
- public UpdateDbTask(@SuppressWarnings("unused") Context context, DatabaseHelper openHelper,
- HashMap<String, Integer> pendingWrites, String locale) {
+ public UpdateDbTask(DatabaseHelper openHelper, HashMap<String, Integer> pendingWrites,
+ String locale) {
mMap = pendingWrites;
mLocale = locale;
mDbHelper = openHelper;
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 64f4d058b..bfa51897e 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -118,8 +118,9 @@ public class Utils {
}
public static boolean hasMultipleEnabledIMEsOrSubtypes(
- final InputMethodManagerCompatWrapper imm,
final boolean shouldIncludeAuxiliarySubtypes) {
+ final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
+ if (imm == null) return false;
final List<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
// Number of the filtered IMEs
@@ -543,13 +544,13 @@ public class Utils {
final String currentDateTimeString =
new SimpleDateFormat("yyyyMMdd-HHmmssZ").format(date);
if (mFile == null) {
- Log.w(TAG, "No internal log file found.");
+ Log.w(USABILITY_TAG, "No internal log file found.");
return;
}
if (mIms.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
- Log.w(TAG, "Doesn't have the permission WRITE_EXTERNAL_STORAGE");
+ Log.w(USABILITY_TAG, "Doesn't have the permission WRITE_EXTERNAL_STORAGE");
return;
}
mWriter.flush();
@@ -563,20 +564,20 @@ public class Utils {
src.close();
dest.close();
} catch (FileNotFoundException e1) {
- Log.w(TAG, e1);
+ Log.w(USABILITY_TAG, e1);
return;
} catch (IOException e2) {
- Log.w(TAG, e2);
+ Log.w(USABILITY_TAG, e2);
return;
}
if (destFile == null || !destFile.exists()) {
- Log.w(TAG, "Dest file doesn't exist.");
+ Log.w(USABILITY_TAG, "Dest file doesn't exist.");
return;
}
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (LatinImeLogger.sDBG) {
- Log.d(TAG, "Destination file URI is " + destFile.toURI());
+ Log.d(USABILITY_TAG, "Destination file URI is " + destFile.toURI());
}
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + destPath));
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 8bbcff758..c0204c2a6 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -32,15 +32,39 @@ public class WordComposer {
public static final int NOT_A_CODE = KeyDetector.NOT_A_CODE;
public static final int NOT_A_COORDINATE = -1;
- /**
- * The list of unicode values for each keystroke (including surrounding keys)
- */
- private ArrayList<int[]> mCodes;
-
- private int[] mXCoordinates;
- private int[] mYCoordinates;
+ // Storage for all the info about the current input.
+ private static class CharacterStore {
+ /**
+ * The list of unicode values for each keystroke (including surrounding keys)
+ */
+ ArrayList<int[]> mCodes;
+ int[] mXCoordinates;
+ int[] mYCoordinates;
+ StringBuilder mTypedWord;
+ CharacterStore() {
+ final int N = BinaryDictionary.MAX_WORD_LENGTH;
+ mCodes = new ArrayList<int[]>(N);
+ mTypedWord = new StringBuilder(N);
+ mXCoordinates = new int[N];
+ mYCoordinates = new int[N];
+ }
+ CharacterStore(final CharacterStore that) {
+ mCodes = new ArrayList<int[]>(that.mCodes);
+ mTypedWord = new StringBuilder(that.mTypedWord);
+ mXCoordinates = Arrays.copyOf(that.mXCoordinates, that.mXCoordinates.length);
+ mYCoordinates = Arrays.copyOf(that.mYCoordinates, that.mYCoordinates.length);
+ }
+ void reset() {
+ // For better performance than creating a new character store.
+ mCodes.clear();
+ mTypedWord.setLength(0);
+ }
+ }
- private StringBuilder mTypedWord;
+ // The currently typing word. May not be null.
+ private CharacterStore mCurrentWord;
+ // The information being kept for resuming suggestion. May be null if wiped.
+ private CharacterStore mWordKeptForSuggestionResuming;
// An auto-correction for this word out of the dictionary.
private CharSequence mAutoCorrection;
@@ -56,11 +80,8 @@ public class WordComposer {
private boolean mIsFirstCharCapitalized;
public WordComposer() {
- final int N = BinaryDictionary.MAX_WORD_LENGTH;
- mCodes = new ArrayList<int[]>(N);
- mTypedWord = new StringBuilder(N);
- mXCoordinates = new int[N];
- mYCoordinates = new int[N];
+ mCurrentWord = new CharacterStore();
+ mWordKeptForSuggestionResuming = null;
mTrailingSingleQuotesCount = 0;
mAutoCorrection = null;
}
@@ -70,10 +91,8 @@ public class WordComposer {
}
public void init(WordComposer source) {
- mCodes = new ArrayList<int[]>(source.mCodes);
- mTypedWord = new StringBuilder(source.mTypedWord);
- mXCoordinates = Arrays.copyOf(source.mXCoordinates, source.mXCoordinates.length);
- mYCoordinates = Arrays.copyOf(source.mYCoordinates, source.mYCoordinates.length);
+ mCurrentWord = new CharacterStore(source.mCurrentWord);
+ mWordKeptForSuggestionResuming = source.mWordKeptForSuggestionResuming;
mCapsCount = source.mCapsCount;
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
mAutoCapitalized = source.mAutoCapitalized;
@@ -85,8 +104,8 @@ public class WordComposer {
* Clear out the keys registered so far.
*/
public void reset() {
- mCodes.clear();
- mTypedWord.setLength(0);
+ mCurrentWord.reset();
+ mWordKeptForSuggestionResuming = null;
mCapsCount = 0;
mIsFirstCharCapitalized = false;
mTrailingSingleQuotesCount = 0;
@@ -98,7 +117,7 @@ public class WordComposer {
* @return the number of keystrokes
*/
public final int size() {
- return mTypedWord.length();
+ return mCurrentWord.mTypedWord.length();
}
/**
@@ -107,15 +126,15 @@ public class WordComposer {
* @return the unicode for the pressed and surrounding keys
*/
public int[] getCodesAt(int index) {
- return mCodes.get(index);
+ return mCurrentWord.mCodes.get(index);
}
public int[] getXCoordinates() {
- return mXCoordinates;
+ return mCurrentWord.mXCoordinates;
}
public int[] getYCoordinates() {
- return mYCoordinates;
+ return mCurrentWord.mYCoordinates;
}
private static boolean isFirstCharCapitalized(int index, int codePoint, boolean previous) {
@@ -130,12 +149,12 @@ public class WordComposer {
*/
public void add(int primaryCode, int[] codes, int x, int y) {
final int newIndex = size();
- mTypedWord.append((char) primaryCode);
+ mCurrentWord.mTypedWord.append((char) primaryCode);
correctPrimaryJuxtapos(primaryCode, codes);
- mCodes.add(codes);
+ mCurrentWord.mCodes.add(codes);
if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
- mXCoordinates[newIndex] = x;
- mYCoordinates[newIndex] = y;
+ mCurrentWord.mXCoordinates[newIndex] = x;
+ mCurrentWord.mYCoordinates[newIndex] = y;
}
mIsFirstCharCapitalized = isFirstCharCapitalized(
newIndex, primaryCode, mIsFirstCharCapitalized);
@@ -215,9 +234,9 @@ public class WordComposer {
final int size = size();
if (size > 0) {
final int lastPos = size - 1;
- char lastChar = mTypedWord.charAt(lastPos);
- mCodes.remove(lastPos);
- mTypedWord.deleteCharAt(lastPos);
+ char lastChar = mCurrentWord.mTypedWord.charAt(lastPos);
+ mCurrentWord.mCodes.remove(lastPos);
+ mCurrentWord.mTypedWord.deleteCharAt(lastPos);
if (Character.isUpperCase(lastChar)) mCapsCount--;
}
if (size() == 0) {
@@ -226,8 +245,8 @@ public class WordComposer {
if (mTrailingSingleQuotesCount > 0) {
--mTrailingSingleQuotesCount;
} else {
- for (int i = mTypedWord.length() - 1; i >= 0; --i) {
- if (Keyboard.CODE_SINGLE_QUOTE != mTypedWord.codePointAt(i)) break;
+ for (int i = mCurrentWord.mTypedWord.length() - 1; i >= 0; --i) {
+ if (Keyboard.CODE_SINGLE_QUOTE != mCurrentWord.mTypedWord.codePointAt(i)) break;
++mTrailingSingleQuotesCount;
}
}
@@ -239,7 +258,7 @@ public class WordComposer {
* @return the word that was typed so far. Never returns null.
*/
public String getTypedWord() {
- return mTypedWord.toString();
+ return mCurrentWord.mTypedWord.toString();
}
/**
@@ -306,4 +325,21 @@ public class WordComposer {
public CharSequence getAutoCorrectionOrNull() {
return mAutoCorrection;
}
+
+ // TODO: pass the information about what was committed and how. Was it an auto-correction?
+ // Was it a completion? Was is what the user typed?
+ public void onCommitWord() {
+ mWordKeptForSuggestionResuming = mCurrentWord;
+ // TODO: improve performance by swapping buffers instead of creating a new object.
+ mCurrentWord = new CharacterStore();
+ }
+
+ public boolean hasWordKeptForSuggestionResuming() {
+ return null != mWordKeptForSuggestionResuming;
+ }
+
+ public void resumeSuggestionOnKeptWord() {
+ mCurrentWord = mWordKeptForSuggestionResuming;
+ mWordKeptForSuggestionResuming = null;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
index 9a2bebfdf..2bc2cfdf6 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
@@ -43,7 +43,7 @@ public class SpellCheckerProximityInfo {
return result;
}
- static class Latin {
+ private static class Latin {
// This is a map from the code point to the index in the PROXIMITY array.
// At the time the native code to read the binary dictionary needs the proximity info be
// passed as a flat array spaced by MAX_PROXIMITY_CHARS_SIZE columns, one for each input
@@ -62,7 +62,7 @@ public class SpellCheckerProximityInfo {
// to spell check has been entered with one of the keyboards above. Also, specifically
// to English, many spelling errors consist of the last vowel of the word being wrong
// because in English vowels tend to merge with each other in pronunciation.
- final private static int[] PROXIMITY = {
+ final static int[] PROXIMITY = {
'q', 'w', 's', 'a', 'z', NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'w', 'q', 'a', 's', 'd', 'e', 'x', NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'e', 'w', 's', 'd', 'f', 'r', 'a', 'i', 'o', 'u', NUL, NUL, NUL, NUL, NUL, NUL,
@@ -101,14 +101,14 @@ public class SpellCheckerProximityInfo {
static {
buildProximityIndices(PROXIMITY, INDICES);
}
- private static int getIndexOf(int characterCode) {
+ static int getIndexOf(int characterCode) {
return computeIndex(characterCode, INDICES);
}
}
- static class Cyrillic {
+ private static class Cyrillic {
final private static TreeMap<Integer, Integer> INDICES = new TreeMap<Integer, Integer>();
- final private static int[] PROXIMITY = {
+ final static int[] PROXIMITY = {
// TODO: This table is solely based on the keyboard layout. Consult with Russian
// speakers on commonly misspelled words/letters.
'ะน', 'ั†', 'ั„', 'ั‹', NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
@@ -150,7 +150,7 @@ public class SpellCheckerProximityInfo {
static {
buildProximityIndices(PROXIMITY, INDICES);
}
- private static int getIndexOf(int characterCode) {
+ static int getIndexOf(int characterCode) {
return computeIndex(characterCode, INDICES);
}
}
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index 86072b64b..7f5918991 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -14,7 +14,7 @@
* the License.
*/
-package com.android.inputmethod.latin;
+package com.android.inputmethod.latin.suggestions;
import android.content.res.Resources;
import android.graphics.Paint;
@@ -27,11 +27,12 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
+import com.android.inputmethod.latin.LatinImeLogger;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
public class MoreSuggestions extends Keyboard {
- private static final boolean DBG = LatinImeLogger.sDBG;
-
public static final int SUGGESTION_CODE_BASE = 1024;
private MoreSuggestions(Builder.MoreSuggestionsParam params) {
@@ -39,6 +40,8 @@ public class MoreSuggestions extends Keyboard {
}
public static class Builder extends KeyboardBuilder<Builder.MoreSuggestionsParam> {
+ private static final boolean DBG = LatinImeLogger.sDBG;
+
private final MoreSuggestionsView mPaneView;
private SuggestedWords mSuggestions;
private int mFromPos;
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
index c61dd6313..b5f67ace0 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.inputmethod.latin;
+package com.android.inputmethod.latin.suggestions;
import android.content.Context;
import android.content.res.Resources;
@@ -34,6 +34,7 @@ import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.KeyEventHandler;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
+import com.android.inputmethod.latin.R;
/**
* A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index 10f5ec9db..40d782640 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -14,7 +14,7 @@
* the License.
*/
-package com.android.inputmethod.latin;
+package com.android.inputmethod.latin.suggestions;
import android.content.Context;
import android.content.res.Resources;
@@ -57,7 +57,12 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MoreKeysPanel;
import com.android.inputmethod.keyboard.PointerTracker;
+import com.android.inputmethod.latin.LatinImeLogger;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
+import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
+import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
import java.util.List;
@@ -72,7 +77,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
// The maximum number of suggestions available. See {@link Suggest#mPrefMaxSuggestions}.
public static final int MAX_SUGGESTIONS = 18;
- private static final boolean DBG = LatinImeLogger.sDBG;
+ static final boolean DBG = LatinImeLogger.sDBG;
private final ViewGroup mSuggestionsStrip;
private KeyboardView mKeyboardView;
@@ -100,8 +105,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private static class UiHandler extends StaticInnerHandlerWrapper<SuggestionsView> {
private static final int MSG_HIDE_PREVIEW = 0;
- private static final long DELAY_HIDE_PREVIEW = 1300;
-
public UiHandler(SuggestionsView outerInstance) {
super(outerInstance);
}
@@ -116,11 +119,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
}
- public void postHidePreview() {
- cancelHidePreview();
- sendMessageDelayed(obtainMessage(MSG_HIDE_PREVIEW), DELAY_HIDE_PREVIEW);
- }
-
public void cancelHidePreview() {
removeMessages(MSG_HIDE_PREVIEW);
}
@@ -148,6 +146,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final List<View> mDividers;
private final List<TextView> mInfos;
+ private final int mColorValidTypedWord;
private final int mColorTypedWord;
private final int mColorAutoCorrect;
private final int mColorSuggested;
@@ -191,6 +190,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SuggestionsView, defStyle, R.style.SuggestionsViewStyle);
mSuggestionStripOption = a.getInt(R.styleable.SuggestionsView_suggestionStripOption, 0);
+ final float alphaValidTypedWord = getPercent(a,
+ R.styleable.SuggestionsView_alphaValidTypedWord, 100);
final float alphaTypedWord = getPercent(a,
R.styleable.SuggestionsView_alphaTypedWord, 100);
final float alphaAutoCorrect = getPercent(a,
@@ -198,6 +199,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final float alphaSuggested = getPercent(a,
R.styleable.SuggestionsView_alphaSuggested, 100);
mAlphaObsoleted = getPercent(a, R.styleable.SuggestionsView_alphaSuggested, 100);
+ mColorValidTypedWord = applyAlpha(
+ a.getColor(R.styleable.SuggestionsView_colorValidTypedWord, 0),
+ alphaValidTypedWord);
mColorTypedWord = applyAlpha(
a.getColor(R.styleable.SuggestionsView_colorTypedWord, 0), alphaTypedWord);
mColorAutoCorrect = applyAlpha(
@@ -295,6 +299,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final int color;
if (index == mCenterSuggestionIndex && Utils.willAutoCorrect(suggestions)) {
color = mColorAutoCorrect;
+ } else if (index == mCenterSuggestionIndex && suggestions.mTypedWordValid) {
+ color = mColorValidTypedWord;
} else if (isSuggested) {
color = mColorSuggested;
} else {
@@ -430,7 +436,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final TextView word = mWords.get(index);
word.setEnabled(true);
- word.setTextColor(mColorTypedWord);
+ word.setTextColor(mColorAutoCorrect);
final CharSequence text = suggestions.getWord(index);
word.setText(text);
word.setTextScaleX(1.0f);
@@ -468,6 +474,91 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
setLayoutWeight(
hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}
+
+ private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) {
+ if (DBG && pos < suggestions.size()) {
+ final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
+ if (wordInfo != null) {
+ final CharSequence debugInfo = wordInfo.getDebugString();
+ if (!TextUtils.isEmpty(debugInfo)) {
+ return debugInfo;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static void setLayoutWeight(View v, float weight, int height) {
+ final ViewGroup.LayoutParams lp = v.getLayoutParams();
+ if (lp instanceof LinearLayout.LayoutParams) {
+ final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp;
+ llp.weight = weight;
+ llp.width = 0;
+ llp.height = height;
+ }
+ }
+
+ private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) {
+ paint.setTextScaleX(1.0f);
+ final int width = getTextWidth(text, paint);
+ if (width <= maxWidth) {
+ return 1.0f;
+ }
+ return maxWidth / (float)width;
+ }
+
+ private static CharSequence getEllipsizedText(CharSequence text, int maxWidth,
+ TextPaint paint) {
+ if (text == null) return null;
+ paint.setTextScaleX(1.0f);
+ final int width = getTextWidth(text, paint);
+ if (width <= maxWidth) {
+ return text;
+ }
+ final float scaleX = maxWidth / (float)width;
+ if (scaleX >= MIN_TEXT_XSCALE) {
+ paint.setTextScaleX(scaleX);
+ return text;
+ }
+
+ // Note that TextUtils.ellipsize() use text-x-scale as 1.0 if ellipsize is needed. To
+ // get squeezed and ellipsized text, passes enlarged width (maxWidth / MIN_TEXT_XSCALE).
+ final CharSequence ellipsized = TextUtils.ellipsize(
+ text, paint, maxWidth / MIN_TEXT_XSCALE, TextUtils.TruncateAt.MIDDLE);
+ paint.setTextScaleX(MIN_TEXT_XSCALE);
+ return ellipsized;
+ }
+
+ private static int getTextWidth(CharSequence text, TextPaint paint) {
+ if (TextUtils.isEmpty(text)) return 0;
+ final Typeface savedTypeface = paint.getTypeface();
+ paint.setTypeface(getTextTypeface(text));
+ final int len = text.length();
+ final float[] widths = new float[len];
+ final int count = paint.getTextWidths(text, 0, len, widths);
+ int width = 0;
+ for (int i = 0; i < count; i++) {
+ width += Math.round(widths[i] + 0.5f);
+ }
+ paint.setTypeface(savedTypeface);
+ return width;
+ }
+
+ private static Typeface getTextTypeface(CharSequence text) {
+ if (!(text instanceof SpannableString))
+ return Typeface.DEFAULT;
+
+ final SpannableString ss = (SpannableString)text;
+ final StyleSpan[] styles = ss.getSpans(0, text.length(), StyleSpan.class);
+ if (styles.length == 0)
+ return Typeface.DEFAULT;
+
+ switch (styles[0].getStyle()) {
+ case Typeface.BOLD: return Typeface.DEFAULT_BOLD;
+ // TODO: BOLD_ITALIC, ITALIC case?
+ default: return Typeface.DEFAULT;
+ }
+ }
}
/**
@@ -554,90 +645,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
}
- private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) {
- if (DBG && pos < suggestions.size()) {
- final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
- if (wordInfo != null) {
- final CharSequence debugInfo = wordInfo.getDebugString();
- if (!TextUtils.isEmpty(debugInfo)) {
- return debugInfo;
- }
- }
- }
- return null;
- }
-
- private static void setLayoutWeight(View v, float weight, int height) {
- final ViewGroup.LayoutParams lp = v.getLayoutParams();
- if (lp instanceof LinearLayout.LayoutParams) {
- final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp;
- llp.weight = weight;
- llp.width = 0;
- llp.height = height;
- }
- }
-
- private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) {
- paint.setTextScaleX(1.0f);
- final int width = getTextWidth(text, paint);
- if (width <= maxWidth) {
- return 1.0f;
- }
- return maxWidth / (float)width;
- }
-
- private static CharSequence getEllipsizedText(CharSequence text, int maxWidth,
- TextPaint paint) {
- if (text == null) return null;
- paint.setTextScaleX(1.0f);
- final int width = getTextWidth(text, paint);
- if (width <= maxWidth) {
- return text;
- }
- final float scaleX = maxWidth / (float)width;
- if (scaleX >= MIN_TEXT_XSCALE) {
- paint.setTextScaleX(scaleX);
- return text;
- }
-
- // Note that TextUtils.ellipsize() use text-x-scale as 1.0 if ellipsize is needed. To get
- // squeezed and ellipsized text, passes enlarged width (maxWidth / MIN_TEXT_XSCALE).
- final CharSequence ellipsized = TextUtils.ellipsize(
- text, paint, maxWidth / MIN_TEXT_XSCALE, TextUtils.TruncateAt.MIDDLE);
- paint.setTextScaleX(MIN_TEXT_XSCALE);
- return ellipsized;
- }
-
- private static int getTextWidth(CharSequence text, TextPaint paint) {
- if (TextUtils.isEmpty(text)) return 0;
- final Typeface savedTypeface = paint.getTypeface();
- paint.setTypeface(getTextTypeface(text));
- final int len = text.length();
- final float[] widths = new float[len];
- final int count = paint.getTextWidths(text, 0, len, widths);
- int width = 0;
- for (int i = 0; i < count; i++) {
- width += Math.round(widths[i] + 0.5f);
- }
- paint.setTypeface(savedTypeface);
- return width;
- }
-
- private static Typeface getTextTypeface(CharSequence text) {
- if (!(text instanceof SpannableString))
- return Typeface.DEFAULT;
-
- final SpannableString ss = (SpannableString)text;
- final StyleSpan[] styles = ss.getSpans(0, text.length(), StyleSpan.class);
- if (styles.length == 0)
- return Typeface.DEFAULT;
-
- switch (styles[0].getStyle()) {
- case Typeface.BOLD: return Typeface.DEFAULT_BOLD;
- // TODO: BOLD_ITALIC, ITALIC case?
- default: return Typeface.DEFAULT;
- }
- }
public boolean isShowingAddToDictionaryHint() {
return mSuggestionsStrip.getChildCount() > 0