aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-04-16 04:57:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-04-16 04:57:35 +0000
commite259b9f57de4b3b95f5bef0d1a1566753805c926 (patch)
tree26b3c03badabecef9be8285d59e72c944da2d488 /java/src
parentfd15686ae915d9a95f1b6d52b1fc720bf745d77c (diff)
parentb794e904a3586ac5f2d31fb24d5a1a8f9aa964b8 (diff)
downloadlatinime-e259b9f57de4b3b95f5bef0d1a1566753805c926.tar.gz
latinime-e259b9f57de4b3b95f5bef0d1a1566753805c926.tar.xz
latinime-e259b9f57de4b3b95f5bef0d1a1566753805c926.zip
Merge "Clean up RecapitalizeStatus"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java10
-rw-r--r--java/src/com/android/inputmethod/latin/RecapitalizeStatus.java63
2 files changed, 44 insertions, 29 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 6cc220614..4b33867c0 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -161,7 +161,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mPositionalInfoForUserDictPendingAddition = null;
private final WordComposer mWordComposer = new WordComposer();
private final RichInputConnection mConnection = new RichInputConnection(this);
- private RecapitalizeStatus mRecapitalizeStatus = null;
+ private final RecapitalizeStatus mRecapitalizeStatus = new RecapitalizeStatus();
// Keep track of the last selection range to decide if we need to show word alternatives
private static final int NOT_A_CURSOR_POSITION = -1;
@@ -742,6 +742,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
resetComposingState(true /* alsoResetLastComposedWord */);
mDeleteCount = 0;
mSpaceState = SPACE_STATE_NONE;
+ mRecapitalizeStatus.deactivate();
mCurrentlyPressedHardwareKeys.clear();
if (mSuggestionStripView != null) {
@@ -925,7 +926,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// We moved the cursor. If we are touching a word, we need to resume suggestion.
mHandler.postResumeSuggestions();
// Reset the last recapitalization.
- mRecapitalizeStatus = null;
+ mRecapitalizeStatus.deactivate();
mKeyboardSwitcher.updateShiftState();
}
mExpectingUpdateSelection = false;
@@ -1953,10 +1954,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void handleRecapitalize() {
if (mLastSelectionStart == mLastSelectionEnd) return; // No selection
// If we have a recapitalize in progress, use it; otherwise, create a new one.
- if (null == mRecapitalizeStatus
+ if (!mRecapitalizeStatus.isActive()
|| !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
- mRecapitalizeStatus =
- new RecapitalizeStatus(mLastSelectionStart, mLastSelectionEnd,
+ mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd,
mConnection.getSelectedText(0 /* flags, 0 for no styles */).toString(),
mSettings.getCurrentLocale(), mSettings.getWordSeparators());
// We trim leading and trailing whitespace.
diff --git a/java/src/com/android/inputmethod/latin/RecapitalizeStatus.java b/java/src/com/android/inputmethod/latin/RecapitalizeStatus.java
index 9edd3a160..a121dd9e8 100644
--- a/java/src/com/android/inputmethod/latin/RecapitalizeStatus.java
+++ b/java/src/com/android/inputmethod/latin/RecapitalizeStatus.java
@@ -37,6 +37,7 @@ public class RecapitalizeStatus {
CAPS_MODE_FIRST_WORD_UPPER,
CAPS_MODE_ALL_UPPER
};
+
private static final int getStringMode(final String string, final String separators) {
if (StringUtils.isIdenticalAfterUpcase(string)) {
return CAPS_MODE_ALL_UPPER;
@@ -50,24 +51,29 @@ public class RecapitalizeStatus {
}
/**
- * We store the location of the cursor and the string that was there before the undoable
+ * We store the location of the cursor and the string that was there before the recapitalize
* action was done, and the location of the cursor and the string that was there after.
*/
private int mCursorStartBefore;
- private int mCursorEndBefore;
private String mStringBefore;
private int mCursorStartAfter;
private int mCursorEndAfter;
private int mRotationStyleCurrentIndex;
- private final boolean mSkipOriginalMixedCaseMode;
- private final Locale mLocale;
- private final String mSeparators;
+ private boolean mSkipOriginalMixedCaseMode;
+ private Locale mLocale;
+ private String mSeparators;
private String mStringAfter;
+ private boolean mIsActive;
+
+ public RecapitalizeStatus() {
+ // By default, initialize with dummy values that won't match any real recapitalize.
+ initialize(-1, -1, "", Locale.getDefault(), "");
+ deactivate();
+ }
- public RecapitalizeStatus(final int cursorStart, final int cursorEnd, final String string,
+ public void initialize(final int cursorStart, final int cursorEnd, final String string,
final Locale locale, final String separators) {
mCursorStartBefore = cursorStart;
- mCursorEndBefore = cursorEnd;
mStringBefore = string;
mCursorStartAfter = cursorStart;
mCursorEndAfter = cursorEnd;
@@ -89,6 +95,15 @@ public class RecapitalizeStatus {
mRotationStyleCurrentIndex = currentMode;
mSkipOriginalMixedCaseMode = true;
}
+ mIsActive = true;
+ }
+
+ public void deactivate() {
+ mIsActive = false;
+ }
+
+ public boolean isActive() {
+ return mIsActive;
}
public boolean isSetAt(final int cursorStart, final int cursorEnd) {
@@ -110,23 +125,23 @@ public class RecapitalizeStatus {
}
++count;
switch (ROTATION_STYLE[mRotationStyleCurrentIndex]) {
- case CAPS_MODE_ORIGINAL_MIXED_CASE:
- mStringAfter = mStringBefore;
- break;
- case CAPS_MODE_ALL_LOWER:
- mStringAfter = mStringBefore.toLowerCase(mLocale);
- break;
- case CAPS_MODE_FIRST_WORD_UPPER:
- mStringAfter = StringUtils.capitalizeEachWord(mStringBefore, mSeparators,
- mLocale);
- break;
- case CAPS_MODE_ALL_UPPER:
- mStringAfter = mStringBefore.toUpperCase(mLocale);
- break;
- default:
- mStringAfter = mStringBefore;
+ case CAPS_MODE_ORIGINAL_MIXED_CASE:
+ mStringAfter = mStringBefore;
+ break;
+ case CAPS_MODE_ALL_LOWER:
+ mStringAfter = mStringBefore.toLowerCase(mLocale);
+ break;
+ case CAPS_MODE_FIRST_WORD_UPPER:
+ mStringAfter = StringUtils.capitalizeEachWord(mStringBefore, mSeparators,
+ mLocale);
+ break;
+ case CAPS_MODE_ALL_UPPER:
+ mStringAfter = mStringBefore.toUpperCase(mLocale);
+ break;
+ default:
+ mStringAfter = mStringBefore;
}
- } while (mStringAfter.equals(oldResult) && count < 5);
+ } while (mStringAfter.equals(oldResult) && count < ROTATION_STYLE.length + 1);
mCursorEndAfter = mCursorStartAfter + mStringAfter.length();
}
@@ -148,7 +163,7 @@ public class RecapitalizeStatus {
if (!Character.isWhitespace(codePoint)) break;
}
if (0 != nonWhitespaceStart || len != nonWhitespaceEnd) {
- mCursorEndBefore = mCursorEndAfter = mCursorStartBefore + nonWhitespaceEnd;
+ mCursorEndAfter = mCursorStartBefore + nonWhitespaceEnd;
mCursorStartBefore = mCursorStartAfter = mCursorStartBefore + nonWhitespaceStart;
mStringAfter = mStringBefore =
mStringBefore.substring(nonWhitespaceStart, nonWhitespaceEnd);