am 07706dc3: Merge "Refactoring"
* commit '07706dc3476845b5e05e0f04a326437a0304fd33': Refactoringmain
commit
04d9d50a60
|
@ -134,7 +134,7 @@ public final class InputLogic {
|
||||||
resetComposingState(true /* alsoResetLastComposedWord */);
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
mSpaceState = SpaceState.NONE;
|
mSpaceState = SpaceState.NONE;
|
||||||
mRecapitalizeStatus.deactivate();
|
mRecapitalizeStatus.stop(); // In case a recapitalization is started
|
||||||
mCurrentlyPressedHardwareKeys.clear();
|
mCurrentlyPressedHardwareKeys.clear();
|
||||||
mSuggestedWords = SuggestedWords.EMPTY;
|
mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
|
// 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.
|
// We moved the cursor. If we are touching a word, we need to resume suggestion.
|
||||||
mLatinIME.mHandler.postResumeSuggestions();
|
mLatinIME.mHandler.postResumeSuggestions();
|
||||||
// Reset the last recapitalization.
|
// Stop the last recapitalization, if started.
|
||||||
mRecapitalizeStatus.deactivate();
|
mRecapitalizeStatus.stop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1149,13 +1149,13 @@ public final class InputLogic {
|
||||||
// to suck possibly multiple-megabyte data.
|
// to suck possibly multiple-megabyte data.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If we have a recapitalize in progress, use it; otherwise, create a new one.
|
// If we have a recapitalize in progress, use it; otherwise, start a new one.
|
||||||
if (!mRecapitalizeStatus.isActive()
|
if (!mRecapitalizeStatus.isStarted()
|
||||||
|| !mRecapitalizeStatus.isSetAt(selectionStart, selectionEnd)) {
|
|| !mRecapitalizeStatus.isSetAt(selectionStart, selectionEnd)) {
|
||||||
final CharSequence selectedText =
|
final CharSequence selectedText =
|
||||||
mConnection.getSelectedText(0 /* flags, 0 for no styles */);
|
mConnection.getSelectedText(0 /* flags, 0 for no styles */);
|
||||||
if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection
|
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.mLocale,
|
||||||
settingsValues.mSpacingAndPunctuations.mSortedWordSeparators);
|
settingsValues.mSpacingAndPunctuations.mSortedWordSeparators);
|
||||||
// We trim leading and trailing whitespace.
|
// We trim leading and trailing whitespace.
|
||||||
|
@ -1498,7 +1498,7 @@ public final class InputLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentRecapitalizeState() {
|
public int getCurrentRecapitalizeState() {
|
||||||
if (!mRecapitalizeStatus.isActive()
|
if (!mRecapitalizeStatus.isStarted()
|
||||||
|| !mRecapitalizeStatus.isSetAt(mConnection.getExpectedSelectionStart(),
|
|| !mRecapitalizeStatus.isSetAt(mConnection.getExpectedSelectionStart(),
|
||||||
mConnection.getExpectedSelectionEnd())) {
|
mConnection.getExpectedSelectionEnd())) {
|
||||||
// Not recapitalizing at the moment
|
// Not recapitalizing at the moment
|
||||||
|
|
|
@ -62,17 +62,17 @@ public class RecapitalizeStatus {
|
||||||
private Locale mLocale;
|
private Locale mLocale;
|
||||||
private int[] mSortedSeparators;
|
private int[] mSortedSeparators;
|
||||||
private String mStringAfter;
|
private String mStringAfter;
|
||||||
private boolean mIsActive;
|
private boolean mIsStarted;
|
||||||
|
|
||||||
private static final int[] EMPTY_STORTED_SEPARATORS = {};
|
private static final int[] EMPTY_STORTED_SEPARATORS = {};
|
||||||
|
|
||||||
public RecapitalizeStatus() {
|
public RecapitalizeStatus() {
|
||||||
// By default, initialize with dummy values that won't match any real recapitalize.
|
// By default, initialize with dummy values that won't match any real recapitalize.
|
||||||
initialize(-1, -1, "", Locale.getDefault(), EMPTY_STORTED_SEPARATORS);
|
start(-1, -1, "", Locale.getDefault(), EMPTY_STORTED_SEPARATORS);
|
||||||
deactivate();
|
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) {
|
final Locale locale, final int[] sortedSeparators) {
|
||||||
mCursorStartBefore = cursorStart;
|
mCursorStartBefore = cursorStart;
|
||||||
mStringBefore = string;
|
mStringBefore = string;
|
||||||
|
@ -96,15 +96,15 @@ public class RecapitalizeStatus {
|
||||||
mRotationStyleCurrentIndex = currentMode;
|
mRotationStyleCurrentIndex = currentMode;
|
||||||
mSkipOriginalMixedCaseMode = true;
|
mSkipOriginalMixedCaseMode = true;
|
||||||
}
|
}
|
||||||
mIsActive = true;
|
mIsStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() {
|
public void stop() {
|
||||||
mIsActive = false;
|
mIsStarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isStarted() {
|
||||||
return mIsActive;
|
return mIsStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSetAt(final int cursorStart, final int cursorEnd) {
|
public boolean isSetAt(final int cursorStart, final int cursorEnd) {
|
||||||
|
|
|
@ -29,25 +29,25 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
|
|
||||||
public void testTrim() {
|
public void testTrim() {
|
||||||
final RecapitalizeStatus status = new RecapitalizeStatus();
|
final RecapitalizeStatus status = new RecapitalizeStatus();
|
||||||
status.initialize(30, 40, "abcdefghij", Locale.ENGLISH, SPACE);
|
status.start(30, 40, "abcdefghij", Locale.ENGLISH, SPACE);
|
||||||
status.trim();
|
status.trim();
|
||||||
assertEquals("abcdefghij", status.getRecapitalizedString());
|
assertEquals("abcdefghij", status.getRecapitalizedString());
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
assertEquals(40, status.getNewCursorEnd());
|
assertEquals(40, status.getNewCursorEnd());
|
||||||
|
|
||||||
status.initialize(30, 44, " abcdefghij", Locale.ENGLISH, SPACE);
|
status.start(30, 44, " abcdefghij", Locale.ENGLISH, SPACE);
|
||||||
status.trim();
|
status.trim();
|
||||||
assertEquals("abcdefghij", status.getRecapitalizedString());
|
assertEquals("abcdefghij", status.getRecapitalizedString());
|
||||||
assertEquals(34, status.getNewCursorStart());
|
assertEquals(34, status.getNewCursorStart());
|
||||||
assertEquals(44, status.getNewCursorEnd());
|
assertEquals(44, status.getNewCursorEnd());
|
||||||
|
|
||||||
status.initialize(30, 40, "abcdefgh ", Locale.ENGLISH, SPACE);
|
status.start(30, 40, "abcdefgh ", Locale.ENGLISH, SPACE);
|
||||||
status.trim();
|
status.trim();
|
||||||
assertEquals("abcdefgh", status.getRecapitalizedString());
|
assertEquals("abcdefgh", status.getRecapitalizedString());
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
assertEquals(38, status.getNewCursorEnd());
|
assertEquals(38, status.getNewCursorEnd());
|
||||||
|
|
||||||
status.initialize(30, 45, " abcdefghij ", Locale.ENGLISH, SPACE);
|
status.start(30, 45, " abcdefghij ", Locale.ENGLISH, SPACE);
|
||||||
status.trim();
|
status.trim();
|
||||||
assertEquals("abcdefghij", status.getRecapitalizedString());
|
assertEquals("abcdefghij", status.getRecapitalizedString());
|
||||||
assertEquals(33, status.getNewCursorStart());
|
assertEquals(33, status.getNewCursorStart());
|
||||||
|
@ -56,7 +56,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
|
|
||||||
public void testRotate() {
|
public void testRotate() {
|
||||||
final RecapitalizeStatus status = new RecapitalizeStatus();
|
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();
|
status.rotate();
|
||||||
assertEquals("Abcd Efghij", status.getRecapitalizedString());
|
assertEquals("Abcd Efghij", status.getRecapitalizedString());
|
||||||
assertEquals(29, status.getNewCursorStart());
|
assertEquals(29, status.getNewCursorStart());
|
||||||
|
@ -68,7 +68,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("Abcd Efghij", status.getRecapitalizedString());
|
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();
|
status.rotate();
|
||||||
assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
|
assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
|
||||||
assertEquals(29, status.getNewCursorStart());
|
assertEquals(29, status.getNewCursorStart());
|
||||||
|
@ -80,7 +80,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
|
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();
|
status.rotate();
|
||||||
assertEquals("abcd efghij", status.getRecapitalizedString());
|
assertEquals("abcd efghij", status.getRecapitalizedString());
|
||||||
assertEquals(29, status.getNewCursorStart());
|
assertEquals(29, status.getNewCursorStart());
|
||||||
|
@ -92,7 +92,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("abcd efghij", status.getRecapitalizedString());
|
assertEquals("abcd efghij", status.getRecapitalizedString());
|
||||||
|
|
||||||
status.initialize(29, 39, "AbCDefghij", Locale.ENGLISH, SPACE);
|
status.start(29, 39, "AbCDefghij", Locale.ENGLISH, SPACE);
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("abcdefghij", status.getRecapitalizedString());
|
assertEquals("abcdefghij", status.getRecapitalizedString());
|
||||||
assertEquals(29, status.getNewCursorStart());
|
assertEquals(29, status.getNewCursorStart());
|
||||||
|
@ -106,7 +106,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("abcdefghij", status.getRecapitalizedString());
|
assertEquals("abcdefghij", status.getRecapitalizedString());
|
||||||
|
|
||||||
status.initialize(29, 40, "Abcd efghij", Locale.ENGLISH, SPACE);
|
status.start(29, 40, "Abcd efghij", Locale.ENGLISH, SPACE);
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("abcd efghij", status.getRecapitalizedString());
|
assertEquals("abcd efghij", status.getRecapitalizedString());
|
||||||
assertEquals(29, status.getNewCursorStart());
|
assertEquals(29, status.getNewCursorStart());
|
||||||
|
@ -120,7 +120,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("abcd efghij", status.getRecapitalizedString());
|
assertEquals("abcd efghij", status.getRecapitalizedString());
|
||||||
|
|
||||||
status.initialize(30, 34, "grüß", Locale.GERMAN, SPACE);
|
status.start(30, 34, "grüß", Locale.GERMAN, SPACE);
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("Grüß", status.getRecapitalizedString());
|
assertEquals("Grüß", status.getRecapitalizedString());
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
|
@ -138,7 +138,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
assertEquals(34, status.getNewCursorEnd());
|
assertEquals(34, status.getNewCursorEnd());
|
||||||
|
|
||||||
status.initialize(30, 33, "œuf", Locale.FRENCH, SPACE);
|
status.start(30, 33, "œuf", Locale.FRENCH, SPACE);
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("Œuf", status.getRecapitalizedString());
|
assertEquals("Œuf", status.getRecapitalizedString());
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
|
@ -156,7 +156,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
assertEquals(33, status.getNewCursorEnd());
|
assertEquals(33, status.getNewCursorEnd());
|
||||||
|
|
||||||
status.initialize(30, 33, "œUf", Locale.FRENCH, SPACE);
|
status.start(30, 33, "œUf", Locale.FRENCH, SPACE);
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("œuf", status.getRecapitalizedString());
|
assertEquals("œuf", status.getRecapitalizedString());
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
|
@ -178,7 +178,7 @@ public class RecapitalizeStatusTests extends AndroidTestCase {
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
assertEquals(33, status.getNewCursorEnd());
|
assertEquals(33, status.getNewCursorEnd());
|
||||||
|
|
||||||
status.initialize(30, 35, "école", Locale.FRENCH, SPACE);
|
status.start(30, 35, "école", Locale.FRENCH, SPACE);
|
||||||
status.rotate();
|
status.rotate();
|
||||||
assertEquals("École", status.getRecapitalizedString());
|
assertEquals("École", status.getRecapitalizedString());
|
||||||
assertEquals(30, status.getNewCursorStart());
|
assertEquals(30, status.getNewCursorStart());
|
||||||
|
|
Loading…
Reference in New Issue