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.java78
1 files changed, 57 insertions, 21 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 345515e96..6d8b4d779 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -106,6 +106,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
/** Whether to use the binary version of the contacts dictionary */
public static final boolean USE_BINARY_CONTACTS_DICTIONARY = true;
+ /** Whether to use the binary version of the user dictionary */
+ public static final boolean USE_BINARY_USER_DICTIONARY = true;
+
// TODO: migrate this to SettingsValues
private int mSuggestionVisibility;
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
@@ -158,7 +161,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private boolean mShouldSwitchToLastSubtype = true;
private boolean mIsMainDictionaryAvailable;
- private UserDictionary mUserDictionary;
+ // TODO: revert this back to the concrete class after transition.
+ private Dictionary mUserDictionary;
private UserHistoryDictionary mUserHistoryDictionary;
private boolean mIsUserDictionaryAvailable;
@@ -476,9 +480,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale);
- mUserDictionary = new UserDictionary(this, localeStr);
+ if (USE_BINARY_USER_DICTIONARY) {
+ mUserDictionary = new UserBinaryDictionary(this, localeStr);
+ mIsUserDictionaryAvailable = ((UserBinaryDictionary)mUserDictionary).isEnabled();
+ } else {
+ mUserDictionary = new UserDictionary(this, localeStr);
+ mIsUserDictionaryAvailable = ((UserDictionary)mUserDictionary).isEnabled();
+ }
mSuggest.setUserDictionary(mUserDictionary);
- mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
resetContactsDictionary(oldContactsDictionary);
@@ -1045,26 +1054,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
updateSuggestions();
}
- public boolean getCurrentAutoCapsState() {
- if (!mSettingsValues.mAutoCap) return false;
+ public int getCurrentAutoCapsState() {
+ if (!mSettingsValues.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF;
final EditorInfo ei = getCurrentInputEditorInfo();
- if (ei == null) return false;
+ if (ei == null) return Constants.TextUtils.CAP_MODE_OFF;
final int inputType = ei.inputType;
- if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) return true;
+ if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) {
+ return TextUtils.CAP_MODE_CHARACTERS;
+ }
final boolean noNeedToCheckCapsMode = (inputType & (InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
| InputType.TYPE_TEXT_FLAG_CAP_WORDS)) == 0;
- if (noNeedToCheckCapsMode) return false;
+ if (noNeedToCheckCapsMode) return Constants.TextUtils.CAP_MODE_OFF;
+
+ // Avoid making heavy round-trip IPC calls of {@link InputConnection#getCursorCapsMode}
+ // unless needed.
+ if (mWordComposer.isComposingWord()) return Constants.TextUtils.CAP_MODE_OFF;
final InputConnection ic = getCurrentInputConnection();
- if (ic == null) return false;
+ if (ic == null) return Constants.TextUtils.CAP_MODE_OFF;
// TODO: This blocking IPC call is heavy. Consider doing this without using IPC calls.
// Note: getCursorCapsMode() returns the current capitalization mode that is any
// combination of CAP_MODE_CHARACTERS, CAP_MODE_WORDS, and CAP_MODE_SENTENCES. 0 means none
// of them.
- return ic.getCursorCapsMode(inputType) != 0;
+ return ic.getCursorCapsMode(inputType);
}
// "ic" may be null
@@ -1134,7 +1149,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public boolean addWordToDictionary(String word) {
- mUserDictionary.addWordToUserDictionary(word, 128);
+ if (USE_BINARY_USER_DICTIONARY) {
+ ((UserBinaryDictionary)mUserDictionary).addWordToUserDictionary(word, 128);
+ } else {
+ ((UserDictionary)mUserDictionary).addWordToUserDictionary(word, 128);
+ }
// Suggestion strip should be updated after the operation of adding word to the
// user dictionary
mHandler.postUpdateSuggestions();
@@ -1152,7 +1171,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Virtual codes representing custom requests. These are used in onCustomRequest() below.
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
- public static final int CODE_HAPTIC_AND_AUDIO_FEEDBACK = 2;
@Override
public boolean onCustomRequest(int requestCode) {
@@ -1165,9 +1183,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return true;
}
return false;
- case CODE_HAPTIC_AND_AUDIO_FEEDBACK:
- hapticAndAudioFeedback(Keyboard.CODE_UNSPECIFIED);
- return true;
}
return false;
}
@@ -1309,8 +1324,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
break;
}
switcher.onCodeInput(primaryCode);
- // Reset after any single keystroke
- if (!didAutoCorrect)
+ // Reset after any single keystroke, except shift and symbol-shift
+ if (!didAutoCorrect && primaryCode != Keyboard.CODE_SHIFT
+ && primaryCode != Keyboard.CODE_SWITCH_ALPHA_SYMBOL)
mLastComposedWord.deactivate();
mEnteredText = null;
}
@@ -1532,7 +1548,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ic != null) {
// If it's the first letter, make note of auto-caps state
if (mWordComposer.size() == 1) {
- mWordComposer.setAutoCapitalized(getCurrentAutoCapsState());
+ mWordComposer.setAutoCapitalized(
+ getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
}
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
}
@@ -1844,10 +1861,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void pickSuggestionManually(final int index, final CharSequence suggestion,
int x, int y) {
- final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
final InputConnection ic = getCurrentInputConnection();
- if (ic != null) ic.beginBatchEdit();
+ if (null != ic) ic.beginBatchEdit();
+ pickSuggestionManuallyWhileInBatchEdit(index, suggestion, x, y, ic);
+ if (null != ic) ic.endBatchEdit();
+ }
+ public void pickSuggestionManuallyWhileInBatchEdit(final int index,
+ final CharSequence suggestion, final int x, final int y, final InputConnection ic) {
+ final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
if (suggestion.length() == 1 && isShowingPunctuationList()) {
// Word separators are suggested before the user inputs something.
@@ -1943,7 +1965,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.postUpdateSuggestions();
}
}
- if (null != ic) ic.endBatchEdit();
}
/**
@@ -2255,6 +2276,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
+ // TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to
+ // {@link KeyboardSwitcher}.
public void hapticAndAudioFeedback(final int primaryCode) {
mFeedbackManager.hapticAndAudioFeedback(primaryCode, mKeyboardSwitcher.getKeyboardView());
}
@@ -2279,6 +2302,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
break;
}
}
+
+ if (Keyboard.CODE_DELETE == primaryCode) {
+ // This is a stopgap solution to avoid leaving a high surrogate alone in a text view.
+ // In the future, we need to deprecate deteleSurroundingText() and have a surrogate
+ // pair-friendly way of deleting characters in InputConnection.
+ final InputConnection ic = getCurrentInputConnection();
+ if (null != ic) {
+ final CharSequence lastChar = ic.getTextBeforeCursor(1, 0);
+ if (lastChar.length() > 0 && Character.isHighSurrogate(lastChar.charAt(0))) {
+ ic.deleteSurroundingText(1, 0);
+ }
+ }
+ }
}
// receive ringer mode change and network state change.