am ee35e69e: Passing SpacingAndPunctuations to StringUtils.looksValidForDictionaryInsertion

* commit 'ee35e69eae734448d0aa90e46037273cc3f1e6ad':
  Passing SpacingAndPunctuations to StringUtils.looksValidForDictionaryInsertion
main
Tadashi G. Takaoka 2014-01-09 02:18:36 -08:00 committed by Android Git Automerger
commit 34e4149068
4 changed files with 21 additions and 84 deletions

View File

@ -24,7 +24,6 @@ import android.content.res.Resources;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.AppWorkaroundsUtils; import com.android.inputmethod.compat.AppWorkaroundsUtils;
import com.android.inputmethod.latin.InputAttributes; import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -166,53 +165,6 @@ public final class SettingsValues {
} }
} }
// TODO: Remove this constructor.
// Only for tests
private SettingsValues(final Locale locale) {
// TODO: locale is saved, but not used yet. May have to change this if tests require.
mLocale = locale;
mDelayUpdateOldSuggestions = 0;
mSpacingAndPunctuations = new SpacingAndPunctuations(locale);
mHintToSaveText = "Touch again to save";
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
mAutoCap = true;
mVibrateOn = true;
mSoundOn = true;
mKeyPreviewPopupOn = true;
mSlidingKeyInputPreviewEnabled = true;
mShowsVoiceInputKey = true;
mIncludesOtherImesInLanguageSwitchList = false;
mShowsLanguageSwitchKey = true;
mUseContactsDict = true;
mUsePersonalizedDicts = true;
mUseDoubleSpacePeriod = true;
mBlockPotentiallyOffensive = true;
mAutoCorrectEnabled = true;
mBigramPredictionEnabled = true;
mKeyLongpressTimeout = 300;
mKeypressVibrationDuration = 5;
mKeypressSoundVolume = 1;
mKeyPreviewPopupDismissDelay = 70;
mAutoCorrectionThreshold = 1;
mGestureInputEnabled = true;
mGestureTrailEnabled = true;
mGestureFloatingPreviewTextEnabled = true;
mPhraseGestureEnabled = true;
mCorrectionEnabled = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect;
mSuggestionVisibility = 0;
mIsInternal = false;
mUseOnlyPersonalizationDictionaryForDebug = false;
mDisplayOrientation = Configuration.ORIENTATION_PORTRAIT;
mAppWorkarounds = new AsyncResultHolder<AppWorkaroundsUtils>();
mAppWorkarounds.set(null);
}
// TODO: Remove this method.
@UsedForTesting
public static SettingsValues makeDummySettingsValuesForTest(final Locale locale) {
return new SettingsValues(locale);
}
public boolean isApplicationSpecifiedCompletionsOn() { public boolean isApplicationSpecifiedCompletionsOn() {
return mInputAttributes.mApplicationSpecifiedCompletionOn; return mInputAttributes.mApplicationSpecifiedCompletionOn;
} }

View File

@ -18,7 +18,6 @@ package com.android.inputmethod.latin.settings;
import android.content.res.Resources; import android.content.res.Resources;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
@ -43,24 +42,6 @@ public final class SpacingAndPunctuations {
public final boolean mCurrentLanguageHasSpaces; public final boolean mCurrentLanguageHasSpaces;
public final boolean mUsesAmericanTypography; public final boolean mUsesAmericanTypography;
// TODO: Remove this constructor.
@UsedForTesting
SpacingAndPunctuations(final Locale locale) {
mSymbolsPrecededBySpace = new int[] { '(', '[', '{', '&' };
Arrays.sort(mSymbolsPrecededBySpace);
mSymbolsFollowedBySpace = new int[] { '.', ',', ';', ':', '!', '?', ')', ']', '}', '&' };
Arrays.sort(mSymbolsFollowedBySpace);
mWordConnectors = new int[] { '\'', '-' };
Arrays.sort(mWordConnectors);
mSentenceSeparator = Constants.CODE_PERIOD;
mSentenceSeparatorAndSpace = ". ";
final String[] suggestPuncsSpec = new String[] { "!", "?", ",", ":", ";" };
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
mWordSeparators = "&\t \n()[]{}*&<>+=|.,;:!?/_\"";
mCurrentLanguageHasSpaces = true;
mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage());
}
public SpacingAndPunctuations(final Resources res) { public SpacingAndPunctuations(final Resources res) {
mSymbolsPrecededBySpace = mSymbolsPrecededBySpace =
StringUtils.toCodePointArray(res.getString(R.string.symbols_preceded_by_space)); StringUtils.toCodePointArray(res.getString(R.string.symbols_preceded_by_space));

View File

@ -17,15 +17,12 @@
package com.android.inputmethod.latin.utils; package com.android.inputmethod.latin.utils;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
public final class StringUtils { public final class StringUtils {
@ -270,7 +267,7 @@ public final class StringUtils {
@UsedForTesting @UsedForTesting
public static boolean looksValidForDictionaryInsertion(final CharSequence text, public static boolean looksValidForDictionaryInsertion(final CharSequence text,
final SettingsValues settings) { final SpacingAndPunctuations spacingAndPunctuations) {
if (TextUtils.isEmpty(text)) return false; if (TextUtils.isEmpty(text)) return false;
final int length = text.length(); final int length = text.length();
int i = 0; int i = 0;
@ -284,7 +281,7 @@ public final class StringUtils {
digitCount += charCount; digitCount += charCount;
continue; continue;
} }
if (!settings.isWordCodePoint(codePoint)) return false; if (!spacingAndPunctuations.isWordCodePoint(codePoint)) return false;
} }
// We reject strings entirely comprised of digits to avoid using PIN codes or credit // We reject strings entirely comprised of digits to avoid using PIN codes or credit
// card numbers. It would come in handy for word prediction though; a good example is // card numbers. It would come in handy for word prediction though; a good example is

View File

@ -16,11 +16,12 @@
package com.android.inputmethod.latin.utils; package com.android.inputmethod.latin.utils;
import com.android.inputmethod.latin.settings.SettingsValues; import android.content.res.Resources;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -209,15 +210,21 @@ public class StringAndJsonUtilsTests extends AndroidTestCase {
} }
public void testLooksValidForDictionaryInsertion() { public void testLooksValidForDictionaryInsertion() {
final SettingsValues settings = final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
SettingsValues.makeDummySettingsValuesForTest(Locale.ENGLISH); @Override
assertTrue(StringUtils.looksValidForDictionaryInsertion("aochaueo", settings)); protected SpacingAndPunctuations job(final Resources res) {
assertFalse(StringUtils.looksValidForDictionaryInsertion("", settings)); return new SpacingAndPunctuations(res);
assertTrue(StringUtils.looksValidForDictionaryInsertion("ao-ch'aueo", settings)); }
assertFalse(StringUtils.looksValidForDictionaryInsertion("2908743256", settings)); };
assertTrue(StringUtils.looksValidForDictionaryInsertion("31aochaueo", settings)); final Resources res = getContext().getResources();
assertFalse(StringUtils.looksValidForDictionaryInsertion("akeo raeoch oerch .", settings)); final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
assertFalse(StringUtils.looksValidForDictionaryInsertion("!!!", settings)); assertTrue(StringUtils.looksValidForDictionaryInsertion("aochaueo", sp));
assertFalse(StringUtils.looksValidForDictionaryInsertion("", sp));
assertTrue(StringUtils.looksValidForDictionaryInsertion("ao-ch'aueo", sp));
assertFalse(StringUtils.looksValidForDictionaryInsertion("2908743256", sp));
assertTrue(StringUtils.looksValidForDictionaryInsertion("31aochaueo", sp));
assertFalse(StringUtils.looksValidForDictionaryInsertion("akeo raeoch oerch .", sp));
assertFalse(StringUtils.looksValidForDictionaryInsertion("!!!", sp));
} }
private static void checkCapitalize(final String src, final String dst, final String separators, private static void checkCapitalize(final String src, final String dst, final String separators,