Merge "Separate spacing and punctuation related settings values"

This commit is contained in:
Tadashi G. Takaoka 2014-01-08 02:41:51 +00:00 committed by Android (Google) Code Review
commit 385031557b
6 changed files with 153 additions and 85 deletions

View file

@ -1299,7 +1299,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@UsedForTesting @UsedForTesting
public boolean isShowingPunctuationList() { public boolean isShowingPunctuationList() {
if (mInputLogic.mSuggestedWords == null) return false; if (mInputLogic.mSuggestedWords == null) return false;
return mSettings.getCurrent().mSuggestPuncList == mInputLogic.mSuggestedWords; return mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList
== mInputLogic.mSuggestedWords;
} }
// TODO[IL]: Define a clear interface for this // TODO[IL]: Define a clear interface for this
@ -1415,7 +1416,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private SuggestedWords getOlderSuggestions(final String typedWord) { private SuggestedWords getOlderSuggestions(final String typedWord) {
SuggestedWords previousSuggestedWords = mInputLogic.mSuggestedWords; SuggestedWords previousSuggestedWords = mInputLogic.mSuggestedWords;
if (previousSuggestedWords == mSettings.getCurrent().mSuggestPuncList) { if (previousSuggestedWords
== mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList) {
previousSuggestedWords = SuggestedWords.EMPTY; previousSuggestedWords = SuggestedWords.EMPTY;
} }
if (typedWord == null) { if (typedWord == null) {
@ -1568,7 +1570,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (currentSettings.mBigramPredictionEnabled) { if (currentSettings.mBigramPredictionEnabled) {
clearSuggestionStrip(); clearSuggestionStrip();
} else { } else {
setSuggestedWords(currentSettings.mSuggestPuncList); setSuggestedWords(currentSettings.mSpacingAndPunctuations.mSuggestPuncList);
} }
setAutoCorrectionIndicator(false); setAutoCorrectionIndicator(false);
setSuggestionStripShown(isSuggestionsStripVisible()); setSuggestionStripShown(isSuggestionsStripVisible());

View file

@ -529,7 +529,7 @@ public final class InputLogic {
// In languages with spaces, we only start composing a word when we are not already // In languages with spaces, we only start composing a word when we are not already
// touching a word. In languages without spaces, the above conditions are sufficient. // touching a word. In languages without spaces, the above conditions are sufficient.
(!mConnection.isCursorTouchingWord(settingsValues) (!mConnection.isCursorTouchingWord(settingsValues)
|| !settingsValues.mCurrentLanguageHasSpaces)) { || !settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces)) {
// Reset entirely the composing state anyway, then start composing a new word unless // Reset entirely the composing state anyway, then start composing a new word unless
// the character is a single quote or a dash. The idea here is, single quote and dash // the character is a single quote or a dash. The idea here is, single quote and dash
// are not separators and they should be treated as normal characters, except in the // are not separators and they should be treated as normal characters, except in the
@ -594,7 +594,7 @@ public final class InputLogic {
boolean didAutoCorrect = false; boolean didAutoCorrect = false;
// We avoid sending spaces in languages without spaces if we were composing. // We avoid sending spaces in languages without spaces if we were composing.
final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint
&& !settingsValues.mCurrentLanguageHasSpaces && !settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
&& mWordComposer.isComposingWord(); && mWordComposer.isComposingWord();
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) { if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection // If we are in the middle of a recorrection, we need to commit the recorrection
@ -813,7 +813,7 @@ public final class InputLogic {
} }
} }
if (settingsValues.isSuggestionStripVisible() if (settingsValues.isSuggestionStripVisible()
&& settingsValues.mCurrentLanguageHasSpaces) { && settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
restartSuggestionsOnWordTouchedByCursor(settingsValues, restartSuggestionsOnWordTouchedByCursor(settingsValues,
deleteCountAtStart - mDeleteCount /* offset */, deleteCountAtStart - mDeleteCount /* offset */,
true /* includeResumedWordInSuggestions */, keyboardSwitcher); true /* includeResumedWordInSuggestions */, keyboardSwitcher);
@ -911,8 +911,8 @@ public final class InputLogic {
if (canBeFollowedByDoubleSpacePeriod(firstCodePoint)) { if (canBeFollowedByDoubleSpacePeriod(firstCodePoint)) {
handler.cancelDoubleSpacePeriodTimer(); handler.cancelDoubleSpacePeriodTimer();
mConnection.deleteSurroundingText(2, 0); mConnection.deleteSurroundingText(2, 0);
final String textToInsert = new String( final String textToInsert =
new int[] { settingsValues.mSentenceSeparator, Constants.CODE_SPACE }, 0, 2); settingsValues.mSpacingAndPunctuations.mSentenceSeparatorAndSpace;
mConnection.commitText(textToInsert, 1); mConnection.commitText(textToInsert, 1);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert, ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
@ -966,7 +966,7 @@ public final class InputLogic {
if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection
mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd, mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd,
selectedText.toString(), selectedText.toString(),
settingsValues.mLocale, settingsValues.mWordSeparators); settingsValues.mLocale, settingsValues.mSpacingAndPunctuations.mWordSeparators);
// We trim leading and trailing whitespace. // We trim leading and trailing whitespace.
mRecapitalizeStatus.trim(); mRecapitalizeStatus.trim();
// Trimming the object may have changed the length of the string, and we need to // Trimming the object may have changed the length of the string, and we need to
@ -1065,7 +1065,7 @@ public final class InputLogic {
if (!mLatinIME.isSuggestionsStripVisible()) return; if (!mLatinIME.isSuggestionsStripVisible()) return;
// Recorrection is not supported in languages without spaces because we don't know // Recorrection is not supported in languages without spaces because we don't know
// how to segment them yet. // how to segment them yet.
if (!settingsValues.mCurrentLanguageHasSpaces) return; if (!settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) return;
// If the cursor is not touching a word, or if there is a selection, return right away. // If the cursor is not touching a word, or if there is a selection, return right away.
if (mLastSelectionStart != mLastSelectionEnd) return; if (mLastSelectionStart != mLastSelectionEnd) return;
// If we don't know the cursor location, return. // If we don't know the cursor location, return.
@ -1073,7 +1073,8 @@ public final class InputLogic {
final int expectedCursorPosition = mLastSelectionStart + offset; // We know Start == End final int expectedCursorPosition = mLastSelectionStart + offset; // We know Start == End
if (!mConnection.isCursorTouchingWord(settingsValues)) return; if (!mConnection.isCursorTouchingWord(settingsValues)) return;
final TextRange range = mConnection.getWordRangeAtCursor( final TextRange range = mConnection.getWordRangeAtCursor(
settingsValues.mWordSeparators, 0 /* additionalPrecedingWordsCount */); settingsValues.mSpacingAndPunctuations.mWordSeparators,
0 /* additionalPrecedingWordsCount */);
if (null == range) return; // Happens if we don't have an input connection at all if (null == range) return; // Happens if we don't have an input connection at all
if (range.length() <= 0) return; // Race condition. No text to resume on, so bail out. if (range.length() <= 0) return; // Race condition. No text to resume on, so bail out.
// If for some strange reason (editor bug or so) we measure the text before the cursor as // If for some strange reason (editor bug or so) we measure the text before the cursor as
@ -1195,7 +1196,7 @@ public final class InputLogic {
} }
} }
final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString; final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
if (settingsValues.mCurrentLanguageHasSpaces) { if (settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
// For languages with spaces, we revert to the typed string, but the cursor is still // For languages with spaces, we revert to the typed string, but the cursor is still
// after the separator so we don't resume suggestions. If the user wants to correct // after the separator so we don't resume suggestions. If the user wants to correct
// the word, they have to press backspace again. // the word, they have to press backspace again.
@ -1295,7 +1296,7 @@ public final class InputLogic {
// TODO: Make this private // TODO: Make this private
public String getNthPreviousWordForSuggestion(final SettingsValues currentSettings, public String getNthPreviousWordForSuggestion(final SettingsValues currentSettings,
final int nthPreviousWord) { final int nthPreviousWord) {
if (currentSettings.mCurrentLanguageHasSpaces) { if (currentSettings.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
// If we are typing in a language with spaces we can just look up the previous // If we are typing in a language with spaces we can just look up the previous
// word from textview. // word from textview.
return mConnection.getNthPreviousWord(currentSettings, nthPreviousWord); return mConnection.getNthPreviousWord(currentSettings, nthPreviousWord);
@ -1386,7 +1387,7 @@ public final class InputLogic {
if (settingsValues.mBigramPredictionEnabled) { if (settingsValues.mBigramPredictionEnabled) {
mLatinIME.clearSuggestionStrip(); mLatinIME.clearSuggestionStrip();
} else { } else {
mLatinIME.setSuggestedWords(settingsValues.mSuggestPuncList); mLatinIME.setSuggestedWords(settingsValues.mSpacingAndPunctuations.mSuggestPuncList);
} }
mConnection.resetCachesUponCursorMoveAndReturnSuccess(newSelStart, newSelEnd, mConnection.resetCachesUponCursorMoveAndReturnSuccess(newSelStart, newSelEnd,
shouldFinishComposition); shouldFinishComposition);
@ -1495,7 +1496,7 @@ public final class InputLogic {
// TODO: Make this private. // TODO: Make this private.
public void promotePhantomSpace(final SettingsValues settingsValues) { public void promotePhantomSpace(final SettingsValues settingsValues) {
if (settingsValues.shouldInsertSpacesAutomatically() if (settingsValues.shouldInsertSpacesAutomatically()
&& settingsValues.mCurrentLanguageHasSpaces && settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
&& !mConnection.textBeforeCursorLooksLikeURL()) { && !mConnection.textBeforeCursorLooksLikeURL()) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_promotePhantomSpace(); ResearchLogger.latinIME_promotePhantomSpace();

View file

@ -176,7 +176,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
} }
public String getWordSeparators() { public String getWordSeparators() {
return mSettingsValues.mWordSeparators; return mSettingsValues.mSpacingAndPunctuations.mWordSeparators;
} }
public boolean isWordSeparator(final int code) { public boolean isWordSeparator(final int code) {

View file

@ -26,20 +26,12 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.AppWorkaroundsUtils; import com.android.inputmethod.compat.AppWorkaroundsUtils;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.InputAttributes; import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.AsyncResultHolder; import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask; import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
@ -56,15 +48,9 @@ public final class SettingsValues {
private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds
// From resources: // From resources:
public final SpacingAndPunctuations mSpacingAndPunctuations;
public final int mDelayUpdateOldSuggestions; public final int mDelayUpdateOldSuggestions;
public final int[] mSymbolsPrecededBySpace;
public final int[] mSymbolsFollowedBySpace;
public final int[] mWordConnectors;
public final SuggestedWords mSuggestPuncList;
public final String mWordSeparators;
public final int mSentenceSeparator;
public final CharSequence mHintToSaveText; public final CharSequence mHintToSaveText;
public final boolean mCurrentLanguageHasSpaces;
// From preferences, in the same order as xml/prefs.xml: // From preferences, in the same order as xml/prefs.xml:
public final boolean mAutoCap; public final boolean mAutoCap;
@ -115,22 +101,8 @@ public final class SettingsValues {
mLocale = locale; mLocale = 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);
mSymbolsPrecededBySpace = mSpacingAndPunctuations = new SpacingAndPunctuations(res);
StringUtils.toCodePointArray(res.getString(R.string.symbols_preceded_by_space));
Arrays.sort(mSymbolsPrecededBySpace);
mSymbolsFollowedBySpace =
StringUtils.toCodePointArray(res.getString(R.string.symbols_followed_by_space));
Arrays.sort(mSymbolsFollowedBySpace);
mWordConnectors =
StringUtils.toCodePointArray(res.getString(R.string.symbols_word_connectors));
Arrays.sort(mWordConnectors);
final String[] suggestPuncsSpec = KeySpecParser.splitKeySpecs(res.getString(
R.string.suggested_punctuations));
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
mWordSeparators = res.getString(R.string.symbols_word_separators);
mSentenceSeparator = res.getInteger(R.integer.sentence_separator);
mHintToSaveText = res.getText(R.string.hint_add_to_dictionary); mHintToSaveText = res.getText(R.string.hint_add_to_dictionary);
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
// Store the input attributes // Store the input attributes
if (null == inputAttributes) { if (null == inputAttributes) {
@ -199,18 +171,8 @@ public final class SettingsValues {
// 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;
mSymbolsPrecededBySpace = new int[] { '(', '[', '{', '&' }; mSpacingAndPunctuations = SpacingAndPunctuations.DEFAULT;
Arrays.sort(mSymbolsPrecededBySpace);
mSymbolsFollowedBySpace = new int[] { '.', ',', ';', ':', '!', '?', ')', ']', '}', '&' };
Arrays.sort(mSymbolsFollowedBySpace);
mWordConnectors = new int[] { '\'', '-' };
Arrays.sort(mWordConnectors);
mSentenceSeparator = Constants.CODE_PERIOD;
final String[] suggestPuncsSpec = new String[] { "!", "?", ",", ":", ";" };
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
mWordSeparators = "&\t \n()[]{}*&<>+=|.,;:!?/_\"";
mHintToSaveText = "Touch again to save"; mHintToSaveText = "Touch again to save";
mCurrentLanguageHasSpaces = true;
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
mAutoCap = true; mAutoCap = true;
mVibrateOn = true; mVibrateOn = true;
@ -265,11 +227,11 @@ public final class SettingsValues {
} }
public boolean isWordSeparator(final int code) { public boolean isWordSeparator(final int code) {
return mWordSeparators.contains(String.valueOf((char)code)); return mSpacingAndPunctuations.isWordSeparator(code);
} }
public boolean isWordConnector(final int code) { public boolean isWordConnector(final int code) {
return Arrays.binarySearch(mWordConnectors, code) >= 0; return mSpacingAndPunctuations.isWordConnector(code);
} }
public boolean isWordCodePoint(final int code) { public boolean isWordCodePoint(final int code) {
@ -277,11 +239,11 @@ public final class SettingsValues {
} }
public boolean isUsuallyPrecededBySpace(final int code) { public boolean isUsuallyPrecededBySpace(final int code) {
return Arrays.binarySearch(mSymbolsPrecededBySpace, code) >= 0; return mSpacingAndPunctuations.isUsuallyPrecededBySpace(code);
} }
public boolean isUsuallyFollowedBySpace(final int code) { public boolean isUsuallyFollowedBySpace(final int code) {
return Arrays.binarySearch(mSymbolsFollowedBySpace, code) >= 0; return mSpacingAndPunctuations.isUsuallyFollowedBySpace(code);
} }
public boolean shouldInsertSpacesAutomatically() { public boolean shouldInsertSpacesAutomatically() {
@ -320,27 +282,6 @@ public final class SettingsValues {
return null == appWorkaroundUtils ? false : appWorkaroundUtils.isBrokenByRecorrection(); return null == appWorkaroundUtils ? false : appWorkaroundUtils.isBrokenByRecorrection();
} }
// Helper functions to create member values.
private static SuggestedWords createSuggestPuncList(final String[] puncs) {
final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList();
if (puncs != null) {
for (final String puncSpec : puncs) {
// TODO: Stop using KeySpceParser.getLabel().
puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED,
Dictionary.DICTIONARY_HARDCODED,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
}
}
return new SuggestedWords(puncList,
false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */,
true /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */,
false /* isPrediction */);
}
private static final int SUGGESTION_VISIBILITY_SHOW_VALUE = private static final int SUGGESTION_VISIBILITY_SHOW_VALUE =
R.string.prefs_suggestion_visibility_show_value; R.string.prefs_suggestion_visibility_show_value;
private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE = private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE =

View file

@ -0,0 +1,124 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin.settings;
import android.content.res.Resources;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
public final class SpacingAndPunctuations {
private final int[] mSymbolsPrecededBySpace;
private final int[] mSymbolsFollowedBySpace;
private final int[] mWordConnectors;
public final SuggestedWords mSuggestPuncList;
public final String mWordSeparators;
private final int mSentenceSeparator;
public final String mSentenceSeparatorAndSpace;
public final boolean mCurrentLanguageHasSpaces;
public static final SpacingAndPunctuations DEFAULT = new SpacingAndPunctuations();
private SpacingAndPunctuations() {
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;
}
public SpacingAndPunctuations(final Resources res) {
mSymbolsPrecededBySpace =
StringUtils.toCodePointArray(res.getString(R.string.symbols_preceded_by_space));
Arrays.sort(mSymbolsPrecededBySpace);
mSymbolsFollowedBySpace =
StringUtils.toCodePointArray(res.getString(R.string.symbols_followed_by_space));
Arrays.sort(mSymbolsFollowedBySpace);
mWordConnectors =
StringUtils.toCodePointArray(res.getString(R.string.symbols_word_connectors));
Arrays.sort(mWordConnectors);
final String[] suggestPuncsSpec = KeySpecParser.splitKeySpecs(res.getString(
R.string.suggested_punctuations));
mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
mWordSeparators = res.getString(R.string.symbols_word_separators);
mSentenceSeparator = res.getInteger(R.integer.sentence_separator);
mSentenceSeparatorAndSpace = new String(new int[] {
mSentenceSeparator, Constants.CODE_SPACE }, 0, 2);
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
}
// Helper functions to create member values.
private static SuggestedWords createSuggestPuncList(final String[] puncs) {
final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList();
if (puncs != null) {
for (final String puncSpec : puncs) {
// TODO: Stop using KeySpceParser.getLabel().
puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED,
Dictionary.DICTIONARY_HARDCODED,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
}
}
return new SuggestedWords(puncList,
false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */,
true /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */,
false /* isPrediction */);
}
public boolean isWordSeparator(final int code) {
return mWordSeparators.contains(String.valueOf((char)code));
}
public boolean isWordConnector(final int code) {
return Arrays.binarySearch(mWordConnectors, code) >= 0;
}
public boolean isWordCodePoint(final int code) {
return Character.isLetter(code) || isWordConnector(code);
}
public boolean isUsuallyPrecededBySpace(final int code) {
return Arrays.binarySearch(mSymbolsPrecededBySpace, code) >= 0;
}
public boolean isUsuallyFollowedBySpace(final int code) {
return Arrays.binarySearch(mSymbolsFollowedBySpace, code) >= 0;
}
public boolean isSentenceSeparator(final int code) {
return code == mSentenceSeparator;
}
}

View file

@ -191,7 +191,7 @@ public final class CapsModeUtils {
if (c == Constants.CODE_QUESTION_MARK || c == Constants.CODE_EXCLAMATION_MARK) { if (c == Constants.CODE_QUESTION_MARK || c == Constants.CODE_EXCLAMATION_MARK) {
return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_SENTENCES) & reqModes; return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_SENTENCES) & reqModes;
} }
if (settingsValues.mSentenceSeparator != c || j <= 0) { if (!settingsValues.mSpacingAndPunctuations.isSentenceSeparator(c) || j <= 0) {
return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & reqModes; return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & reqModes;
} }
@ -241,7 +241,7 @@ public final class CapsModeUtils {
case WORD: case WORD:
if (Character.isLetter(c)) { if (Character.isLetter(c)) {
state = WORD; state = WORD;
} else if (settingsValues.mSentenceSeparator == c) { } else if (settingsValues.mSpacingAndPunctuations.isSentenceSeparator(c)) {
state = PERIOD; state = PERIOD;
} else { } else {
return caps; return caps;
@ -257,7 +257,7 @@ public final class CapsModeUtils {
case LETTER: case LETTER:
if (Character.isLetter(c)) { if (Character.isLetter(c)) {
state = LETTER; state = LETTER;
} else if (settingsValues.mSentenceSeparator == c) { } else if (settingsValues.mSpacingAndPunctuations.isSentenceSeparator(c)) {
state = PERIOD; state = PERIOD;
} else { } else {
return noCaps; return noCaps;