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,13 +815,17 @@ public class LatinIME extends InputMethodService
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
if (attr != null && mInputView != null && mKeyboardSwitcher.isAlphabetMode() if (attr != null && mInputView != null && mKeyboardSwitcher.isAlphabetMode()
&& ic != null) { && ic != null) {
mInputView.setShifted(mCapsLock || getCursorCapsMode(ic, attr) != 0);
}
}
private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
int caps = 0; int caps = 0;
EditorInfo ei = getCurrentInputEditorInfo(); EditorInfo ei = getCurrentInputEditorInfo();
if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) { if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
caps = ic.getCursorCapsMode(attr.inputType); caps = ic.getCursorCapsMode(attr.inputType);
} }
mInputView.setShifted(mCapsLock || caps != 0); return caps;
}
} }
private void swapPunctuationAndSpace() { private void swapPunctuationAndSpace() {
@ -1014,6 +1018,11 @@ public class LatinIME extends InputMethodService
mWord.add(primaryCode, keyCodes); mWord.add(primaryCode, keyCodes);
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
if (ic != null) { 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); ic.setComposingText(mComposing, 1);
} }
postUpdateSuggestions(); postUpdateSuggestions();
@ -1847,6 +1856,11 @@ public class LatinIME extends InputMethodService
final int length = word.length(); final int length = word.length();
// Don't add very short or very long words. // Don't add very short or very long words.
if (length < 2 || length > getMaxWordLength()) return; 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); int freq = getWordFrequency(word);
freq = freq < 0 ? addFrequency : freq + addFrequency; freq = freq < 0 ? addFrequency : freq + addFrequency;
super.addWord(word, freq); super.addWord(word, freq);

View File

@ -37,6 +37,8 @@ public class WordComposer {
private int mCapsCount; private int mCapsCount;
private boolean mAutoCapitalized;
/** /**
* Whether the user chose to capitalize the word. * Whether the user chose to capitalize the word.
*/ */
@ -152,4 +154,21 @@ public class WordComposer {
public boolean isMostlyCaps() { public boolean isMostlyCaps() {
return mCapsCount > 1; 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;
}
} }