am 28a59dd0: Fix a bug with double-space-to-period

* commit '28a59dd049bafa45de628e2cafda47bf46d9e22a':
  Fix a bug with double-space-to-period
main
Jean Chalard 2014-04-03 13:59:06 +00:00 committed by Android Git Automerger
commit af029cb968
3 changed files with 82 additions and 10 deletions

View File

@ -823,14 +823,12 @@ public final class InputLogic {
} }
if (Constants.CODE_SPACE == codePoint) { if (Constants.CODE_SPACE == codePoint) {
if (inputTransaction.mSettingsValues.isSuggestionsRequested()) {
if (maybeDoubleSpacePeriod(inputTransaction)) { if (maybeDoubleSpacePeriod(inputTransaction)) {
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
mSpaceState = SpaceState.DOUBLE; mSpaceState = SpaceState.DOUBLE;
} else if (!mSuggestedWords.isPunctuationSuggestions()) { } else if (!mSuggestedWords.isPunctuationSuggestions()) {
mSpaceState = SpaceState.WEAK; mSpaceState = SpaceState.WEAK;
} }
}
startDoubleSpacePeriodCountdown(inputTransaction); startDoubleSpacePeriodCountdown(inputTransaction);
inputTransaction.setRequiresUpdateSuggestions(); inputTransaction.setRequiresUpdateSuggestions();

View File

@ -16,7 +16,10 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.latin.settings.Settings;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.BaseInputConnection;
@LargeTest @LargeTest
@ -179,6 +182,8 @@ public class InputLogicTests extends InputTestsBase {
} }
public void testDoubleSpace() { public void testDoubleSpace() {
// Set default pref just in case
setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true);
// U+1F607 is an emoji // U+1F607 is an emoji
final String[] STRINGS_TO_TYPE = final String[] STRINGS_TO_TYPE =
new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " }; new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " };
@ -200,6 +205,76 @@ public class InputLogicTests extends InputTestsBase {
assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString());
} }
private void testDoubleSpacePeriodWithSettings(final boolean expectsPeriod,
final Object... settingsKeysValues) {
final Object[] oldSettings = new Object[settingsKeysValues.length / 2];
final String STRING_WITHOUT_PERIOD = "this ";
final String STRING_WITH_PERIOD = "this. ";
final String EXPECTED_RESULT = expectsPeriod ? STRING_WITH_PERIOD : STRING_WITHOUT_PERIOD;
try {
for (int i = 0; i < settingsKeysValues.length; i += 2) {
if (settingsKeysValues[i + 1] instanceof String) {
oldSettings[i / 2] = setStringPreference((String)settingsKeysValues[i],
(String)settingsKeysValues[i + 1], "0");
} else {
oldSettings[i / 2] = setBooleanPreference((String)settingsKeysValues[i],
(Boolean)settingsKeysValues[i + 1], false);
}
}
mLatinIME.loadSettings();
mEditText.setText("");
type(STRING_WITHOUT_PERIOD);
assertEquals("double-space-to-period with specific settings "
+ TextUtils.join(" ", settingsKeysValues),
EXPECTED_RESULT, mEditText.getText().toString());
} finally {
// Restore old settings
for (int i = 0; i < settingsKeysValues.length; i += 2) {
if (null == oldSettings[i / 2]) {
break;
} if (oldSettings[i / 2] instanceof String) {
setStringPreference((String)settingsKeysValues[i], (String)oldSettings[i / 2],
"");
} else {
setBooleanPreference((String)settingsKeysValues[i], (Boolean)oldSettings[i / 2],
false);
}
}
}
}
public void testDoubleSpacePeriod() {
// Reset settings to default, else these tests will go flaky.
setStringPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0", "0");
setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1");
setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true);
testDoubleSpacePeriodWithSettings(true /* expectsPeriod */);
// "Suggestion visibility" to "always hide"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "2");
// "Suggestion visibility" to "portrait only"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "1");
// "Suggestion visibility" to "always show"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0");
// "Double-space period" to "off"
testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false);
// "Auto-correction" to "off"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0");
// "Auto-correction" to "modest"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1");
// "Auto-correction" to "very aggressive"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "3");
// "Suggestion visibility" to "always hide" and "Auto-correction" to "off"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0",
Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0");
// "Suggestion visibility" to "always hide" and "Auto-correction" to "off"
testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0",
Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0",
Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false);
}
public void testBackspaceAtStartAfterAutocorrect() { public void testBackspaceAtStartAfterAutocorrect() {
final String STRING_TO_TYPE = "tgis "; final String STRING_TO_TYPE = "tgis ";
final int typedLength = STRING_TO_TYPE.length(); final int typedLength = STRING_TO_TYPE.length();

View File

@ -65,7 +65,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
protected MyEditText mEditText; protected MyEditText mEditText;
protected View mInputView; protected View mInputView;
protected InputConnection mInputConnection; protected InputConnection mInputConnection;
private boolean mPreviousDebugSetting;
private boolean mPreviousBigramPredictionSettings; private boolean mPreviousBigramPredictionSettings;
private String mPreviousAutoCorrectSetting; private String mPreviousAutoCorrectSetting;
@ -185,7 +184,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
mEditText.setEnabled(true); mEditText.setEnabled(true);
setupService(); setupService();
mLatinIME = getService(); mLatinIME = getService();
mPreviousDebugSetting = setDebugMode(true); setDebugMode(true);
mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS,
true, true /* defaultValue */); true, true /* defaultValue */);
mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD,
@ -219,7 +218,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
true /* defaultValue */); true /* defaultValue */);
setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting,
DEFAULT_AUTO_CORRECTION_THRESHOLD); DEFAULT_AUTO_CORRECTION_THRESHOLD);
setDebugMode(mPreviousDebugSetting); setDebugMode(false);
super.tearDown(); super.tearDown();
} }