From 860c3b8e8cc65e2a2b26b4da0356b5bcff6450e6 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 9 Jan 2014 16:59:23 +0900 Subject: [PATCH] Add American typography boolean to SpacingAndPunctuations Change-Id: Ic2663eaef38fbe7c5bd1fb3a81771e94c2d4de52 --- .../inputmethod/latin/settings/Settings.java | 2 +- .../inputmethod/latin/settings/SettingsValues.java | 10 ++++++---- .../latin/settings/SpacingAndPunctuations.java | 14 +++++++++++--- .../inputmethod/latin/utils/CapsModeUtils.java | 3 +-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 84ba7223a..add983b3b 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 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang final RunInLocale job = new RunInLocale() { @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 3fa686ba7..6ecee8167 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 @@ public final class SettingsValues { // 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 @@ 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 = SpacingAndPunctuations.DEFAULT; + mSpacingAndPunctuations = new SpacingAndPunctuations(locale); mHintToSaveText = "Touch again to save"; mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); mAutoCap = true; @@ -206,6 +207,7 @@ public final class SettingsValues { 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 0500f4ad4..124c97517 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 @@ package com.android.inputmethod.latin.settings; 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 com.android.inputmethod.latin.utils.StringUtils; import java.util.ArrayList; import java.util.Arrays; +import java.util.Locale; public final class SpacingAndPunctuations { private final int[] mSymbolsPrecededBySpace; @@ -39,10 +41,11 @@ public final class SpacingAndPunctuations { 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 @@ public final class SpacingAndPunctuations { mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec); mWordSeparators = "&\t \n()[]{}*&<>+=|.,;:!?/_\""; mCurrentLanguageHasSpaces = true; + mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage()); } public SpacingAndPunctuations(final Resources res) { @@ -75,6 +79,10 @@ public final class SpacingAndPunctuations { 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 6ad5c77d5..c7416727a 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 @@ public final class CapsModeUtils { // 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. <> - // 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