Add American typography boolean to SpacingAndPunctuations
Change-Id: Ic2663eaef38fbe7c5bd1fb3a81771e94c2d4de52
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 84ba722..add983b 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -157,7 +157,7 @@
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
@Override
protected SettingsValues job(final Resources res) {
- return new SettingsValues(context, prefs, locale, res, inputAttributes);
+ return new SettingsValues(context, prefs, res, inputAttributes);
}
};
mSettingsValues = job.runInLocale(mRes, locale);
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 3fa686b..6ecee81 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -96,9 +96,9 @@
// Debug settings
public final boolean mIsInternal;
- public SettingsValues(final Context context, final SharedPreferences prefs, final Locale locale,
- final Resources res, final InputAttributes inputAttributes) {
- mLocale = locale;
+ public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
+ final InputAttributes inputAttributes) {
+ mLocale = res.getConfiguration().locale;
// Get the resources
mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
mSpacingAndPunctuations = new SpacingAndPunctuations(res);
@@ -166,12 +166,13 @@
}
}
+ // 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 = SpacingAndPunctuations.DEFAULT;
+ mSpacingAndPunctuations = new SpacingAndPunctuations(locale);
mHintToSaveText = "Touch again to save";
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
mAutoCap = true;
@@ -206,6 +207,7 @@
mAppWorkarounds.set(null);
}
+ // TODO: Remove this method.
@UsedForTesting
public static SettingsValues makeDummySettingsValuesForTest(final Locale locale) {
return new SettingsValues(locale);
diff --git a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
index 0500f4a..124c975 100644
--- a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
+++ b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
@@ -18,6 +18,7 @@
import android.content.res.Resources;
+import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary;
@@ -29,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Locale;
public final class SpacingAndPunctuations {
private final int[] mSymbolsPrecededBySpace;
@@ -39,10 +41,11 @@
private final int mSentenceSeparator;
public final String mSentenceSeparatorAndSpace;
public final boolean mCurrentLanguageHasSpaces;
+ public final boolean mUsesAmericanTypography;
- public static final SpacingAndPunctuations DEFAULT = new SpacingAndPunctuations();
-
- private SpacingAndPunctuations() {
+ // TODO: Remove this constructor.
+ @UsedForTesting
+ SpacingAndPunctuations(final Locale locale) {
mSymbolsPrecededBySpace = new int[] { '(', '[', '{', '&' };
Arrays.sort(mSymbolsPrecededBySpace);
mSymbolsFollowedBySpace = new int[] { '.', ',', ';', ':', '!', '?', ')', ']', '}', '&' };
@@ -55,6 +58,7 @@
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
mWordSeparators = "&\t \n()[]{}*&<>+=|.,;:!?/_\"";
mCurrentLanguageHasSpaces = true;
+ mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage());
}
public SpacingAndPunctuations(final Resources res) {
@@ -75,6 +79,10 @@
mSentenceSeparatorAndSpace = new String(new int[] {
mSentenceSeparator, Constants.CODE_SPACE }, 0, 2);
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
+ final Locale locale = res.getConfiguration().locale;
+ // Heuristic: we use American Typography rules because it's the most common rules for all
+ // English variants.
+ mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage());
}
// Helper functions to create member values.
diff --git a/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java b/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
index 6ad5c77..c741672 100644
--- a/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
@@ -167,8 +167,7 @@
// No other language has such a rule as far as I know, instead putting inside the quotation
// mark as the exact thing quoted and handling the surrounding punctuation independently,
// e.g. <<Did he say, "let's go home"?>>
- // Hence, specifically for English, we treat this special case here.
- if (Locale.ENGLISH.getLanguage().equals(settingsValues.mLocale.getLanguage())) {
+ if (settingsValues.mSpacingAndPunctuations.mUsesAmericanTypography) {
for (; j > 0; j--) {
// Here we look to go over any closing punctuation. This is because in dominant
// variants of English, the final period is placed within double quotes and maybe