am 0b4ae1f5: Capitalize the displayed text in the suggestion bar when all of the user typed chars are upper case

Merge commit '0b4ae1f578e768eec4ada90aeb81d11acb10eb2e' into gingerbread-plus-aosp

* commit '0b4ae1f578e768eec4ada90aeb81d11acb10eb2e':
  Capitalize the displayed text in the suggestion bar when all of the user typed chars are upper case
main
Ken Wakasa 2010-09-27 09:26:39 -07:00 committed by Android Git Automerger
commit 7f2a6a056b
3 changed files with 29 additions and 15 deletions

View File

@ -1389,7 +1389,7 @@ public class LatinIME extends InputMethodService
if (mKeyboardSwitcher.getInputView().isShifted() if (mKeyboardSwitcher.getInputView().isShifted()
&& mKeyboardSwitcher.isAlphabetMode() && mKeyboardSwitcher.isAlphabetMode()
&& mComposing.length() == 0) { && mComposing.length() == 0) {
mWord.setCapitalized(true); mWord.setFirstCharCapitalized(true);
} }
mComposing.append((char) primaryCode); mComposing.append((char) primaryCode);
mWord.add(primaryCode, keyCodes); mWord.add(primaryCode, keyCodes);
@ -2020,7 +2020,7 @@ public class LatinIME extends InputMethodService
touching.word.charAt(i) touching.word.charAt(i)
}); });
} }
foundWord.setCapitalized(Character.isUpperCase(touching.word.charAt(0))); foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.word.charAt(0)));
} }
// Found a match, show suggestions // Found a match, show suggestions
if (foundWord != null || alternatives != null) { if (foundWord != null || alternatives != null) {
@ -2177,7 +2177,7 @@ public class LatinIME extends InputMethodService
} }
public boolean preferCapitalization() { public boolean preferCapitalization() {
return mWord.isCapitalized(); return mWord.isFirstCharCapitalized();
} }
private void toggleLanguage(boolean reset, boolean next) { private void toggleLanguage(boolean reset, boolean next) {

View File

@ -96,7 +96,10 @@ public class Suggest implements Dictionary.WordCallback {
private boolean mHaveCorrection; private boolean mHaveCorrection;
private CharSequence mOriginalWord; private CharSequence mOriginalWord;
private String mLowerOriginalWord; private String mLowerOriginalWord;
private boolean mCapitalize;
// TODO: Remove these member variables by passing more context to addWord() callback method
private boolean mIsFirstCharCapitalized;
private boolean mIsAllUpperCase;
private int mCorrectionMode = CORRECTION_BASIC; private int mCorrectionMode = CORRECTION_BASIC;
@ -219,7 +222,8 @@ public class Suggest implements Dictionary.WordCallback {
boolean includeTypedWordIfValid, CharSequence prevWordForBigram) { boolean includeTypedWordIfValid, CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram); LatinImeLogger.onStartSuggestion(prevWordForBigram);
mHaveCorrection = false; mHaveCorrection = false;
mCapitalize = wordComposer.isCapitalized(); mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
mIsAllUpperCase = wordComposer.isAllUpperCase();
collectGarbage(mSuggestions, mPrefMaxSuggestions); collectGarbage(mSuggestions, mPrefMaxSuggestions);
Arrays.fill(mPriorities, 0); Arrays.fill(mPriorities, 0);
Arrays.fill(mNextLettersFrequencies, 0); Arrays.fill(mNextLettersFrequencies, 0);
@ -453,7 +457,9 @@ public class Suggest implements Dictionary.WordCallback {
StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1) StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength()); : new StringBuilder(getApproxMaxWordLength());
sb.setLength(0); sb.setLength(0);
if (mCapitalize) { if (mIsAllUpperCase) {
sb.append(new String(word, offset, length).toUpperCase());
} else if (mIsFirstCharCapitalized) {
sb.append(Character.toUpperCase(word[offset])); sb.append(Character.toUpperCase(word[offset]));
if (length > 1) { if (length > 1) {
sb.append(word, offset + 1, length - 1); sb.append(word, offset + 1, length - 1);

View File

@ -39,9 +39,9 @@ public class WordComposer {
private boolean mAutoCapitalized; private boolean mAutoCapitalized;
/** /**
* Whether the user chose to capitalize the word. * Whether the user chose to capitalize the first char of the word.
*/ */
private boolean mIsCapitalized; private boolean mIsFirstCharCapitalized;
public WordComposer() { public WordComposer() {
mCodes = new ArrayList<int[]>(12); mCodes = new ArrayList<int[]>(12);
@ -54,7 +54,7 @@ public class WordComposer {
mTypedWord = new StringBuilder(copy.mTypedWord); mTypedWord = new StringBuilder(copy.mTypedWord);
mCapsCount = copy.mCapsCount; mCapsCount = copy.mCapsCount;
mAutoCapitalized = copy.mAutoCapitalized; mAutoCapitalized = copy.mAutoCapitalized;
mIsCapitalized = copy.mIsCapitalized; mIsFirstCharCapitalized = copy.mIsFirstCharCapitalized;
} }
/** /**
@ -62,7 +62,7 @@ public class WordComposer {
*/ */
public void reset() { public void reset() {
mCodes.clear(); mCodes.clear();
mIsCapitalized = false; mIsFirstCharCapitalized = false;
mPreferredWord = null; mPreferredWord = null;
mTypedWord.setLength(0); mTypedWord.setLength(0);
mCapsCount = 0; mCapsCount = 0;
@ -138,16 +138,24 @@ public class WordComposer {
return mTypedWord; return mTypedWord;
} }
public void setCapitalized(boolean capitalized) { public void setFirstCharCapitalized(boolean capitalized) {
mIsCapitalized = capitalized; mIsFirstCharCapitalized = capitalized;
} }
/** /**
* Whether or not the user typed a capital letter as the first letter in the word * Whether or not the user typed a capital letter as the first letter in the word
* @return capitalization preference * @return capitalization preference
*/ */
public boolean isCapitalized() { public boolean isFirstCharCapitalized() {
return mIsCapitalized; return mIsFirstCharCapitalized;
}
/**
* Whether or not all of the user typed chars are upper case
* @return true if all user typed chars are upper case, false otherwise
*/
public boolean isAllUpperCase() {
return (mCapsCount > 0) && (mCapsCount == size());
} }
/** /**