diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/WordComposer.java | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 6772d53ea..2e415b771 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -25,23 +25,23 @@ public class WordComposer { /** * The list of unicode values for each keystroke (including surrounding keys) */ - private ArrayList<int[]> mCodes; + private final ArrayList<int[]> mCodes; /** * The word chosen from the candidate list, until it is committed. */ private String mPreferredWord; - private StringBuilder mTypedWord; + private final StringBuilder mTypedWord; private int mCapsCount; 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() { mCodes = new ArrayList<int[]>(12); @@ -54,7 +54,7 @@ public class WordComposer { mTypedWord = new StringBuilder(copy.mTypedWord); mCapsCount = copy.mCapsCount; mAutoCapitalized = copy.mAutoCapitalized; - mIsCapitalized = copy.mIsCapitalized; + mIsFirstCharCapitalized = copy.mIsFirstCharCapitalized; } /** @@ -62,7 +62,7 @@ public class WordComposer { */ public void reset() { mCodes.clear(); - mIsCapitalized = false; + mIsFirstCharCapitalized = false; mPreferredWord = null; mTypedWord.setLength(0); mCapsCount = 0; @@ -116,11 +116,14 @@ public class WordComposer { * Delete the last keystroke as a result of hitting backspace. */ public void deleteLast() { - mCodes.remove(mCodes.size() - 1); - final int lastPos = mTypedWord.length() - 1; - char last = mTypedWord.charAt(lastPos); - mTypedWord.deleteCharAt(lastPos); - if (Character.isUpperCase(last)) mCapsCount--; + final int codesSize = mCodes.size(); + if (codesSize > 0) { + mCodes.remove(codesSize - 1); + final int lastPos = mTypedWord.length() - 1; + char last = mTypedWord.charAt(lastPos); + mTypedWord.deleteCharAt(lastPos); + if (Character.isUpperCase(last)) mCapsCount--; + } } /** @@ -132,30 +135,29 @@ public class WordComposer { if (wordSize == 0) { return null; } -// StringBuffer sb = new StringBuffer(wordSize); -// for (int i = 0; i < wordSize; i++) { -// char c = (char) mCodes.get(i)[0]; -// if (i == 0 && mIsCapitalized) { -// c = Character.toUpperCase(c); -// } -// sb.append(c); -// } -// return sb; return mTypedWord; } - public void setCapitalized(boolean capitalized) { - mIsCapitalized = capitalized; + public void setFirstCharCapitalized(boolean capitalized) { + mIsFirstCharCapitalized = capitalized; } /** * Whether or not the user typed a capital letter as the first letter in the word * @return capitalization preference */ - public boolean isCapitalized() { - return mIsCapitalized; + public boolean isFirstCharCapitalized() { + 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()); + } + /** * Stores the user's selected word, before it is actually committed to the text field. * @param preferred |