Auto-added words will only be capitalized if user intended to. #2373284

If a user creates a new word at the beginning of a sentence, then don't
add it as a capitalized word in the dictionary.
main
Amith Yamasani 2010-01-24 07:34:07 -08:00
parent 39acd7e80a
commit 1c55125110
2 changed files with 41 additions and 8 deletions

View File

@ -815,15 +815,19 @@ public class LatinIME extends InputMethodService
InputConnection ic = getCurrentInputConnection();
if (attr != null && mInputView != null && mKeyboardSwitcher.isAlphabetMode()
&& ic != null) {
int caps = 0;
EditorInfo ei = getCurrentInputEditorInfo();
if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
caps = ic.getCursorCapsMode(attr.inputType);
}
mInputView.setShifted(mCapsLock || caps != 0);
mInputView.setShifted(mCapsLock || getCursorCapsMode(ic, attr) != 0);
}
}
private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
int caps = 0;
EditorInfo ei = getCurrentInputEditorInfo();
if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
caps = ic.getCursorCapsMode(attr.inputType);
}
return caps;
}
private void swapPunctuationAndSpace() {
final InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
@ -837,7 +841,7 @@ public class LatinIME extends InputMethodService
updateShiftKeyState(getCurrentInputEditorInfo());
}
}
private void doubleSpace() {
//if (!mAutoPunctuate) return;
if (mCorrectionMode == Suggest.CORRECTION_NONE) return;
@ -1014,6 +1018,11 @@ public class LatinIME extends InputMethodService
mWord.add(primaryCode, keyCodes);
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
// If it's the first letter, make note of auto-caps state
if (mWord.size() == 1) {
mWord.setAutoCapitalized(
getCursorCapsMode(ic, getCurrentInputEditorInfo()) != 0);
}
ic.setComposingText(mComposing, 1);
}
postUpdateSuggestions();
@ -1847,6 +1856,11 @@ public class LatinIME extends InputMethodService
final int length = word.length();
// Don't add very short or very long words.
if (length < 2 || length > getMaxWordLength()) return;
if (mWord.isAutoCapitalized()) {
// Remove caps before adding
word = Character.toLowerCase(word.charAt(0))
+ word.substring(1);
}
int freq = getWordFrequency(word);
freq = freq < 0 ? addFrequency : freq + addFrequency;
super.addWord(word, freq);

View File

@ -36,6 +36,8 @@ public class WordComposer {
private StringBuilder mTypedWord;
private int mCapsCount;
private boolean mAutoCapitalized;
/**
* Whether the user chose to capitalize the word.
@ -152,4 +154,21 @@ public class WordComposer {
public boolean isMostlyCaps() {
return mCapsCount > 1;
}
/**
* Saves the reason why the word is capitalized - whether it was automatic or
* due to the user hitting shift in the middle of a sentence.
* @param auto whether it was an automatic capitalization due to start of sentence
*/
public void setAutoCapitalized(boolean auto) {
mAutoCapitalized = auto;
}
/**
* Returns whether the word was automatically capitalized.
* @return whether the word was automatically capitalized
*/
public boolean isAutoCapitalized() {
return mAutoCapitalized;
}
}