Merge "Refactoring"

This commit is contained in:
Jean Chalard 2014-06-04 07:43:31 +00:00 committed by Android (Google) Code Review
commit 07706dc347
3 changed files with 29 additions and 29 deletions

View file

@ -134,7 +134,7 @@ public final class InputLogic {
resetComposingState(true /* alsoResetLastComposedWord */);
mDeleteCount = 0;
mSpaceState = SpaceState.NONE;
mRecapitalizeStatus.deactivate();
mRecapitalizeStatus.stop(); // In case a recapitalization is started
mCurrentlyPressedHardwareKeys.clear();
mSuggestedWords = SuggestedWords.EMPTY;
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
@ -347,8 +347,8 @@ public final class InputLogic {
// We moved the cursor. If we are touching a word, we need to resume suggestion.
mLatinIME.mHandler.postResumeSuggestions();
// Reset the last recapitalization.
mRecapitalizeStatus.deactivate();
// Stop the last recapitalization, if started.
mRecapitalizeStatus.stop();
return true;
}
@ -1149,13 +1149,13 @@ public final class InputLogic {
// to suck possibly multiple-megabyte data.
return;
}
// If we have a recapitalize in progress, use it; otherwise, create a new one.
if (!mRecapitalizeStatus.isActive()
// If we have a recapitalize in progress, use it; otherwise, start a new one.
if (!mRecapitalizeStatus.isStarted()
|| !mRecapitalizeStatus.isSetAt(selectionStart, selectionEnd)) {
final CharSequence selectedText =
mConnection.getSelectedText(0 /* flags, 0 for no styles */);
if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection
mRecapitalizeStatus.initialize(selectionStart, selectionEnd, selectedText.toString(),
mRecapitalizeStatus.start(selectionStart, selectionEnd, selectedText.toString(),
settingsValues.mLocale,
settingsValues.mSpacingAndPunctuations.mSortedWordSeparators);
// We trim leading and trailing whitespace.
@ -1498,7 +1498,7 @@ public final class InputLogic {
}
public int getCurrentRecapitalizeState() {
if (!mRecapitalizeStatus.isActive()
if (!mRecapitalizeStatus.isStarted()
|| !mRecapitalizeStatus.isSetAt(mConnection.getExpectedSelectionStart(),
mConnection.getExpectedSelectionEnd())) {
// Not recapitalizing at the moment

View file

@ -62,17 +62,17 @@ public class RecapitalizeStatus {
private Locale mLocale;
private int[] mSortedSeparators;
private String mStringAfter;
private boolean mIsActive;
private boolean mIsStarted;
private static final int[] EMPTY_STORTED_SEPARATORS = {};
public RecapitalizeStatus() {
// By default, initialize with dummy values that won't match any real recapitalize.
initialize(-1, -1, "", Locale.getDefault(), EMPTY_STORTED_SEPARATORS);
deactivate();
start(-1, -1, "", Locale.getDefault(), EMPTY_STORTED_SEPARATORS);
stop();
}
public void initialize(final int cursorStart, final int cursorEnd, final String string,
public void start(final int cursorStart, final int cursorEnd, final String string,
final Locale locale, final int[] sortedSeparators) {
mCursorStartBefore = cursorStart;
mStringBefore = string;
@ -96,15 +96,15 @@ public class RecapitalizeStatus {
mRotationStyleCurrentIndex = currentMode;
mSkipOriginalMixedCaseMode = true;
}
mIsActive = true;
mIsStarted = true;
}
public void deactivate() {
mIsActive = false;
public void stop() {
mIsStarted = false;
}
public boolean isActive() {
return mIsActive;
public boolean isStarted() {
return mIsStarted;
}
public boolean isSetAt(final int cursorStart, final int cursorEnd) {

View file

@ -29,25 +29,25 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
public void testTrim() {
final RecapitalizeStatus status = new RecapitalizeStatus();
status.initialize(30, 40, "abcdefghij", Locale.ENGLISH, SPACE);
status.start(30, 40, "abcdefghij", Locale.ENGLISH, SPACE);
status.trim();
assertEquals("abcdefghij", status.getRecapitalizedString());
assertEquals(30, status.getNewCursorStart());
assertEquals(40, status.getNewCursorEnd());
status.initialize(30, 44, " abcdefghij", Locale.ENGLISH, SPACE);
status.start(30, 44, " abcdefghij", Locale.ENGLISH, SPACE);
status.trim();
assertEquals("abcdefghij", status.getRecapitalizedString());
assertEquals(34, status.getNewCursorStart());
assertEquals(44, status.getNewCursorEnd());
status.initialize(30, 40, "abcdefgh ", Locale.ENGLISH, SPACE);
status.start(30, 40, "abcdefgh ", Locale.ENGLISH, SPACE);
status.trim();
assertEquals("abcdefgh", status.getRecapitalizedString());
assertEquals(30, status.getNewCursorStart());
assertEquals(38, status.getNewCursorEnd());
status.initialize(30, 45, " abcdefghij ", Locale.ENGLISH, SPACE);
status.start(30, 45, " abcdefghij ", Locale.ENGLISH, SPACE);
status.trim();
assertEquals("abcdefghij", status.getRecapitalizedString());
assertEquals(33, status.getNewCursorStart());
@ -56,7 +56,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
public void testRotate() {
final RecapitalizeStatus status = new RecapitalizeStatus();
status.initialize(29, 40, "abcd efghij", Locale.ENGLISH, SPACE);
status.start(29, 40, "abcd efghij", Locale.ENGLISH, SPACE);
status.rotate();
assertEquals("Abcd Efghij", status.getRecapitalizedString());
assertEquals(29, status.getNewCursorStart());
@ -68,7 +68,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
status.rotate();
assertEquals("Abcd Efghij", status.getRecapitalizedString());
status.initialize(29, 40, "Abcd Efghij", Locale.ENGLISH, SPACE);
status.start(29, 40, "Abcd Efghij", Locale.ENGLISH, SPACE);
status.rotate();
assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
assertEquals(29, status.getNewCursorStart());
@ -80,7 +80,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
status.rotate();
assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
status.initialize(29, 40, "ABCD EFGHIJ", Locale.ENGLISH, SPACE);
status.start(29, 40, "ABCD EFGHIJ", Locale.ENGLISH, SPACE);
status.rotate();
assertEquals("abcd efghij", status.getRecapitalizedString());
assertEquals(29, status.getNewCursorStart());
@ -92,7 +92,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
status.rotate();
assertEquals("abcd efghij", status.getRecapitalizedString());
status.initialize(29, 39, "AbCDefghij", Locale.ENGLISH, SPACE);
status.start(29, 39, "AbCDefghij", Locale.ENGLISH, SPACE);
status.rotate();
assertEquals("abcdefghij", status.getRecapitalizedString());
assertEquals(29, status.getNewCursorStart());
@ -106,7 +106,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
status.rotate();
assertEquals("abcdefghij", status.getRecapitalizedString());
status.initialize(29, 40, "Abcd efghij", Locale.ENGLISH, SPACE);
status.start(29, 40, "Abcd efghij", Locale.ENGLISH, SPACE);
status.rotate();
assertEquals("abcd efghij", status.getRecapitalizedString());
assertEquals(29, status.getNewCursorStart());
@ -120,7 +120,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
status.rotate();
assertEquals("abcd efghij", status.getRecapitalizedString());
status.initialize(30, 34, "grüß", Locale.GERMAN, SPACE);
status.start(30, 34, "grüß", Locale.GERMAN, SPACE);
status.rotate();
assertEquals("Grüß", status.getRecapitalizedString());
assertEquals(30, status.getNewCursorStart());
@ -138,7 +138,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
assertEquals(30, status.getNewCursorStart());
assertEquals(34, status.getNewCursorEnd());
status.initialize(30, 33, "œuf", Locale.FRENCH, SPACE);
status.start(30, 33, "œuf", Locale.FRENCH, SPACE);
status.rotate();
assertEquals("Œuf", status.getRecapitalizedString());
assertEquals(30, status.getNewCursorStart());
@ -156,7 +156,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
assertEquals(30, status.getNewCursorStart());
assertEquals(33, status.getNewCursorEnd());
status.initialize(30, 33, "œUf", Locale.FRENCH, SPACE);
status.start(30, 33, "œUf", Locale.FRENCH, SPACE);
status.rotate();
assertEquals("œuf", status.getRecapitalizedString());
assertEquals(30, status.getNewCursorStart());
@ -178,7 +178,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
assertEquals(30, status.getNewCursorStart());
assertEquals(33, status.getNewCursorEnd());
status.initialize(30, 35, "école", Locale.FRENCH, SPACE);
status.start(30, 35, "école", Locale.FRENCH, SPACE);
status.rotate();
assertEquals("École", status.getRecapitalizedString());
assertEquals(30, status.getNewCursorStart());