am c912b222: Merge "Add American typography boolean to SpacingAndPunctuations"
* commit 'c912b2228a340354d7f951aad25c0bdfc1dee323': Add American typography boolean to SpacingAndPunctuationsmain
commit
ff6735e481
|
@ -157,7 +157,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
|
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
|
||||||
@Override
|
@Override
|
||||||
protected SettingsValues job(final Resources res) {
|
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);
|
mSettingsValues = job.runInLocale(mRes, locale);
|
||||||
|
|
|
@ -96,9 +96,9 @@ public final class SettingsValues {
|
||||||
// Debug settings
|
// Debug settings
|
||||||
public final boolean mIsInternal;
|
public final boolean mIsInternal;
|
||||||
|
|
||||||
public SettingsValues(final Context context, final SharedPreferences prefs, final Locale locale,
|
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
|
||||||
final Resources res, final InputAttributes inputAttributes) {
|
final InputAttributes inputAttributes) {
|
||||||
mLocale = locale;
|
mLocale = res.getConfiguration().locale;
|
||||||
// Get the resources
|
// Get the resources
|
||||||
mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
|
mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
|
||||||
mSpacingAndPunctuations = new SpacingAndPunctuations(res);
|
mSpacingAndPunctuations = new SpacingAndPunctuations(res);
|
||||||
|
@ -166,12 +166,13 @@ public final class SettingsValues {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this constructor.
|
||||||
// Only for tests
|
// Only for tests
|
||||||
private SettingsValues(final Locale locale) {
|
private SettingsValues(final Locale locale) {
|
||||||
// TODO: locale is saved, but not used yet. May have to change this if tests require.
|
// TODO: locale is saved, but not used yet. May have to change this if tests require.
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mDelayUpdateOldSuggestions = 0;
|
mDelayUpdateOldSuggestions = 0;
|
||||||
mSpacingAndPunctuations = SpacingAndPunctuations.DEFAULT;
|
mSpacingAndPunctuations = new SpacingAndPunctuations(locale);
|
||||||
mHintToSaveText = "Touch again to save";
|
mHintToSaveText = "Touch again to save";
|
||||||
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
|
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
|
||||||
mAutoCap = true;
|
mAutoCap = true;
|
||||||
|
@ -206,6 +207,7 @@ public final class SettingsValues {
|
||||||
mAppWorkarounds.set(null);
|
mAppWorkarounds.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static SettingsValues makeDummySettingsValuesForTest(final Locale locale) {
|
public static SettingsValues makeDummySettingsValuesForTest(final Locale locale) {
|
||||||
return new SettingsValues(locale);
|
return new SettingsValues(locale);
|
||||||
|
|
|
@ -18,6 +18,7 @@ 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;
|
||||||
|
@ -29,6 +30,7 @@ import com.android.inputmethod.latin.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public final class SpacingAndPunctuations {
|
public final class SpacingAndPunctuations {
|
||||||
private final int[] mSymbolsPrecededBySpace;
|
private final int[] mSymbolsPrecededBySpace;
|
||||||
|
@ -39,10 +41,11 @@ public final class SpacingAndPunctuations {
|
||||||
private final int mSentenceSeparator;
|
private final int mSentenceSeparator;
|
||||||
public final String mSentenceSeparatorAndSpace;
|
public final String mSentenceSeparatorAndSpace;
|
||||||
public final boolean mCurrentLanguageHasSpaces;
|
public final boolean mCurrentLanguageHasSpaces;
|
||||||
|
public final boolean mUsesAmericanTypography;
|
||||||
|
|
||||||
public static final SpacingAndPunctuations DEFAULT = new SpacingAndPunctuations();
|
// TODO: Remove this constructor.
|
||||||
|
@UsedForTesting
|
||||||
private SpacingAndPunctuations() {
|
SpacingAndPunctuations(final Locale locale) {
|
||||||
mSymbolsPrecededBySpace = new int[] { '(', '[', '{', '&' };
|
mSymbolsPrecededBySpace = new int[] { '(', '[', '{', '&' };
|
||||||
Arrays.sort(mSymbolsPrecededBySpace);
|
Arrays.sort(mSymbolsPrecededBySpace);
|
||||||
mSymbolsFollowedBySpace = new int[] { '.', ',', ';', ':', '!', '?', ')', ']', '}', '&' };
|
mSymbolsFollowedBySpace = new int[] { '.', ',', ';', ':', '!', '?', ')', ']', '}', '&' };
|
||||||
|
@ -55,6 +58,7 @@ public final class SpacingAndPunctuations {
|
||||||
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
|
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
|
||||||
mWordSeparators = "&\t \n()[]{}*&<>+=|.,;:!?/_\"";
|
mWordSeparators = "&\t \n()[]{}*&<>+=|.,;:!?/_\"";
|
||||||
mCurrentLanguageHasSpaces = true;
|
mCurrentLanguageHasSpaces = true;
|
||||||
|
mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpacingAndPunctuations(final Resources res) {
|
public SpacingAndPunctuations(final Resources res) {
|
||||||
|
@ -75,6 +79,10 @@ public final class SpacingAndPunctuations {
|
||||||
mSentenceSeparatorAndSpace = new String(new int[] {
|
mSentenceSeparatorAndSpace = new String(new int[] {
|
||||||
mSentenceSeparator, Constants.CODE_SPACE }, 0, 2);
|
mSentenceSeparator, Constants.CODE_SPACE }, 0, 2);
|
||||||
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
|
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.
|
// 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
|
// 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,
|
// mark as the exact thing quoted and handling the surrounding punctuation independently,
|
||||||
// e.g. <<Did he say, "let's go home"?>>
|
// e.g. <<Did he say, "let's go home"?>>
|
||||||
// Hence, specifically for English, we treat this special case here.
|
if (settingsValues.mSpacingAndPunctuations.mUsesAmericanTypography) {
|
||||||
if (Locale.ENGLISH.getLanguage().equals(settingsValues.mLocale.getLanguage())) {
|
|
||||||
for (; j > 0; j--) {
|
for (; j > 0; j--) {
|
||||||
// Here we look to go over any closing punctuation. This is because in dominant
|
// 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
|
// variants of English, the final period is placed within double quotes and maybe
|
||||||
|
|
Loading…
Reference in New Issue