Merge "Add American typography boolean to SpacingAndPunctuations"
This commit is contained in:
commit
c912b2228a
4 changed files with 19 additions and 10 deletions
|
@ -157,7 +157,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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. <<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
|
||||
|
|
Loading…
Reference in a new issue