aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/inputmethod/latin/LatinIME.java30
-rw-r--r--src/com/android/inputmethod/latin/WordComposer.java19
2 files changed, 41 insertions, 8 deletions
diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java
index a71f3d867..a9a61c3a2 100644
--- a/src/com/android/inputmethod/latin/LatinIME.java
+++ b/src/com/android/inputmethod/latin/LatinIME.java
@@ -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);
diff --git a/src/com/android/inputmethod/latin/WordComposer.java b/src/com/android/inputmethod/latin/WordComposer.java
index 50725d481..e97cb24ba 100644
--- a/src/com/android/inputmethod/latin/WordComposer.java
+++ b/src/com/android/inputmethod/latin/WordComposer.java
@@ -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;
+ }
}