am 487e038f: Use Keyboard in several interfaces.

* commit '487e038ff329b6099ff5343fb2d7bdc60a6fd699':
  Use Keyboard in several interfaces.
main
Mario Tanev 2015-02-26 01:34:54 +00:00 committed by Android Git Automerger
commit 86ae0ffe9d
7 changed files with 42 additions and 64 deletions

View File

@ -20,7 +20,7 @@ import android.content.Context;
import android.util.Pair; import android.util.Pair;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.KeyboardLayout; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.common.ComposedData; import com.android.inputmethod.latin.common.ComposedData;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion; import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
import com.android.inputmethod.latin.utils.SuggestionResults; import com.android.inputmethod.latin.utils.SuggestionResults;
@ -157,9 +157,9 @@ public interface DictionaryFacilitator {
// TODO: Revise the way to fusion suggestion results. // TODO: Revise the way to fusion suggestion results.
SuggestionResults getSuggestionResults(final ComposedData composedData, SuggestionResults getSuggestionResults(final ComposedData composedData,
final NgramContext ngramContext, final long proximityInfoHandle, final NgramContext ngramContext, @Nonnull final Keyboard keyboard,
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId, final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId,
final int inputStyle, final KeyboardLayout keyboardLayout); final int inputStyle);
boolean isValidSpellingWord(final String word); boolean isValidSpellingWord(final String word);

View File

@ -22,7 +22,7 @@ import android.util.Log;
import android.util.Pair; import android.util.Pair;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.KeyboardLayout; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.NgramContext.WordInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.ComposedData; import com.android.inputmethod.latin.common.ComposedData;
@ -668,9 +668,10 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
// TODO: Revise the way to fusion suggestion results. // TODO: Revise the way to fusion suggestion results.
@Override @Override
public SuggestionResults getSuggestionResults(ComposedData composedData, public SuggestionResults getSuggestionResults(ComposedData composedData,
NgramContext ngramContext, long proximityInfoHandle, NgramContext ngramContext, @Nonnull final Keyboard keyboard,
SettingsValuesForSuggestion settingsValuesForSuggestion, int sessionId, SettingsValuesForSuggestion settingsValuesForSuggestion, int sessionId,
int inputStyle, KeyboardLayout keyboardLayout) { int inputStyle) {
long proximityInfoHandle = keyboard.getProximityInfo().getNativeProximityInfo();
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups; final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
final SuggestionResults suggestionResults = new SuggestionResults( final SuggestionResults suggestionResults = new SuggestionResults(
SuggestedWords.MAX_SUGGESTIONS, ngramContext.isBeginningOfSentenceContext()); SuggestedWords.MAX_SUGGESTIONS, ngramContext.isBeginningOfSentenceContext());

View File

@ -1514,9 +1514,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance()); callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance());
return; return;
} }
mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard.getProximityInfo(), mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard,
mKeyboardSwitcher.getKeyboardShiftMode(), inputStyle, sequenceNumber, callback, mKeyboardSwitcher.getKeyboardShiftMode(), inputStyle, sequenceNumber, callback);
keyboard.getKeyboardLayout());
} }
@Override @Override

View File

@ -20,8 +20,7 @@ import android.text.TextUtils;
import static com.android.inputmethod.latin.define.DecoderSpecificConstants.SHOULD_AUTO_CORRECT_USING_NON_WHITE_LISTED_SUGGESTION; import static com.android.inputmethod.latin.define.DecoderSpecificConstants.SHOULD_AUTO_CORRECT_USING_NON_WHITE_LISTED_SUGGESTION;
import com.android.inputmethod.keyboard.KeyboardLayout; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.StringUtils; import com.android.inputmethod.latin.common.StringUtils;
@ -97,19 +96,17 @@ public final class Suggest {
} }
public void getSuggestedWords(final WordComposer wordComposer, public void getSuggestedWords(final WordComposer wordComposer,
final NgramContext ngramContext, final ProximityInfo proximityInfo, final NgramContext ngramContext, final Keyboard keyboard,
final SettingsValuesForSuggestion settingsValuesForSuggestion, final SettingsValuesForSuggestion settingsValuesForSuggestion,
final boolean isCorrectionEnabled, final int inputStyle, final int sequenceNumber, final boolean isCorrectionEnabled, final int inputStyle, final int sequenceNumber,
final OnGetSuggestedWordsCallback callback, final OnGetSuggestedWordsCallback callback) {
final KeyboardLayout keyboardLayout) {
if (wordComposer.isBatchMode()) { if (wordComposer.isBatchMode()) {
getSuggestedWordsForBatchInput(wordComposer, ngramContext, proximityInfo, getSuggestedWordsForBatchInput(wordComposer, ngramContext, keyboard,
settingsValuesForSuggestion, inputStyle, sequenceNumber, callback, settingsValuesForSuggestion, inputStyle, sequenceNumber, callback);
keyboardLayout);
} else { } else {
getSuggestedWordsForNonBatchInput(wordComposer, ngramContext, proximityInfo, getSuggestedWordsForNonBatchInput(wordComposer, ngramContext, keyboard,
settingsValuesForSuggestion, inputStyle, isCorrectionEnabled, settingsValuesForSuggestion, inputStyle, isCorrectionEnabled,
sequenceNumber, callback, keyboardLayout); sequenceNumber, callback);
} }
} }
@ -165,11 +162,10 @@ public final class Suggest {
// Retrieves suggestions for non-batch input (typing, recorrection, predictions...) // Retrieves suggestions for non-batch input (typing, recorrection, predictions...)
// and calls the callback function with the suggestions. // and calls the callback function with the suggestions.
private void getSuggestedWordsForNonBatchInput(final WordComposer wordComposer, private void getSuggestedWordsForNonBatchInput(final WordComposer wordComposer,
final NgramContext ngramContext, final ProximityInfo proximityInfo, final NgramContext ngramContext, final Keyboard keyboard,
final SettingsValuesForSuggestion settingsValuesForSuggestion, final SettingsValuesForSuggestion settingsValuesForSuggestion,
final int inputStyleIfNotPrediction, final boolean isCorrectionEnabled, final int inputStyleIfNotPrediction, final boolean isCorrectionEnabled,
final int sequenceNumber, final OnGetSuggestedWordsCallback callback, final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
final KeyboardLayout keyboardLayout) {
final String typedWordString = wordComposer.getTypedWord(); final String typedWordString = wordComposer.getTypedWord();
final int trailingSingleQuotesCount = final int trailingSingleQuotesCount =
StringUtils.getTrailingSingleQuotesCount(typedWordString); StringUtils.getTrailingSingleQuotesCount(typedWordString);
@ -178,9 +174,8 @@ public final class Suggest {
: typedWordString; : typedWordString;
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults( final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer.getComposedDataSnapshot(), ngramContext, wordComposer.getComposedDataSnapshot(), ngramContext, keyboard,
proximityInfo.getNativeProximityInfo(), settingsValuesForSuggestion, settingsValuesForSuggestion, SESSION_ID_TYPING, inputStyleIfNotPrediction);
SESSION_ID_TYPING, inputStyleIfNotPrediction, keyboardLayout);
final Locale mostProbableLocale = mDictionaryFacilitator.getMostProbableLocale(); final Locale mostProbableLocale = mDictionaryFacilitator.getMostProbableLocale();
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
getTransformedSuggestedWordInfoList(wordComposer, suggestionResults, getTransformedSuggestedWordInfoList(wordComposer, suggestionResults,
@ -346,15 +341,13 @@ public final class Suggest {
// Retrieves suggestions for the batch input // Retrieves suggestions for the batch input
// and calls the callback function with the suggestions. // and calls the callback function with the suggestions.
private void getSuggestedWordsForBatchInput(final WordComposer wordComposer, private void getSuggestedWordsForBatchInput(final WordComposer wordComposer,
final NgramContext ngramContext, final ProximityInfo proximityInfo, final NgramContext ngramContext, final Keyboard keyboard,
final SettingsValuesForSuggestion settingsValuesForSuggestion, final SettingsValuesForSuggestion settingsValuesForSuggestion,
final int inputStyle, final int sequenceNumber, final int inputStyle, final int sequenceNumber,
final OnGetSuggestedWordsCallback callback, final OnGetSuggestedWordsCallback callback) {
final KeyboardLayout keyboardLayout) {
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults( final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer.getComposedDataSnapshot(), ngramContext, wordComposer.getComposedDataSnapshot(), ngramContext, keyboard,
proximityInfo.getNativeProximityInfo(), settingsValuesForSuggestion, settingsValuesForSuggestion, SESSION_ID_GESTURE, inputStyle);
SESSION_ID_GESTURE, inputStyle, keyboardLayout);
// For transforming words that don't come from a dictionary, because it's our best bet // For transforming words that don't come from a dictionary, because it's our best bet
final Locale defaultLocale = mDictionaryFacilitator.getMostProbableLocale(); final Locale defaultLocale = mDictionaryFacilitator.getMostProbableLocale();
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =

View File

@ -32,9 +32,8 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.event.Event; import com.android.inputmethod.event.Event;
import com.android.inputmethod.event.InputTransaction; import com.android.inputmethod.event.InputTransaction;
import com.android.inputmethod.keyboard.KeyboardLayout; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitator; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.LastComposedWord; import com.android.inputmethod.latin.LastComposedWord;
@ -2165,9 +2164,8 @@ public final class InputLogic {
} }
public void getSuggestedWords(final SettingsValues settingsValues, public void getSuggestedWords(final SettingsValues settingsValues,
final ProximityInfo proximityInfo, final int keyboardShiftMode, final int inputStyle, final Keyboard keyboard, final int keyboardShiftMode, final int inputStyle,
final int sequenceNumber, final OnGetSuggestedWordsCallback callback, final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
final KeyboardLayout keyboardLayout) {
mWordComposer.adviseCapitalizedModeBeforeFetchingSuggestions( mWordComposer.adviseCapitalizedModeBeforeFetchingSuggestions(
getActualCapsMode(settingsValues, keyboardShiftMode)); getActualCapsMode(settingsValues, keyboardShiftMode));
mSuggest.getSuggestedWords(mWordComposer, mSuggest.getSuggestedWords(mWordComposer,
@ -2177,11 +2175,11 @@ public final class InputLogic {
// a word, it's whatever is *before* the half-committed word in the buffer, // a word, it's whatever is *before* the half-committed word in the buffer,
// hence 2; if we aren't, we should just skip whitespace if any, so 1. // hence 2; if we aren't, we should just skip whitespace if any, so 1.
mWordComposer.isComposingWord() ? 2 : 1), mWordComposer.isComposingWord() ? 2 : 1),
proximityInfo, keyboard,
new SettingsValuesForSuggestion(settingsValues.mBlockPotentiallyOffensive, new SettingsValuesForSuggestion(settingsValues.mBlockPotentiallyOffensive,
settingsValues.mPhraseGestureEnabled), settingsValues.mPhraseGestureEnabled),
settingsValues.mAutoCorrectionEnabledPerUserSettings, settingsValues.mAutoCorrectionEnabledPerUserSettings,
inputStyle, sequenceNumber, callback, keyboardLayout); inputStyle, sequenceNumber, callback);
} }
/** /**

View File

@ -28,9 +28,7 @@ import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardLayout;
import com.android.inputmethod.keyboard.KeyboardLayoutSet; import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.DictionaryFacilitator; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.DictionaryFacilitatorLruCache; import com.android.inputmethod.latin.DictionaryFacilitatorLruCache;
import com.android.inputmethod.latin.NgramContext; import com.android.inputmethod.latin.NgramContext;
@ -48,6 +46,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import javax.annotation.Nonnull;
/** /**
* Service for spell checking, using LatinIME's dictionaries and mechanisms. * Service for spell checking, using LatinIME's dictionaries and mechanisms.
*/ */
@ -193,7 +193,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
public SuggestionResults getSuggestionResults(final Locale locale, public SuggestionResults getSuggestionResults(final Locale locale,
final ComposedData composedData, final NgramContext ngramContext, final ComposedData composedData, final NgramContext ngramContext,
final ProximityInfo proximityInfo, final KeyboardLayout keyboardLayout) { @Nonnull final Keyboard keyboard) {
Integer sessionId = null; Integer sessionId = null;
mSemaphore.acquireUninterruptibly(); mSemaphore.acquireUninterruptibly();
try { try {
@ -201,8 +201,8 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
DictionaryFacilitator dictionaryFacilitatorForLocale = DictionaryFacilitator dictionaryFacilitatorForLocale =
mDictionaryFacilitatorCache.get(locale); mDictionaryFacilitatorCache.get(locale);
return dictionaryFacilitatorForLocale.getSuggestionResults(composedData, ngramContext, return dictionaryFacilitatorForLocale.getSuggestionResults(composedData, ngramContext,
proximityInfo.getNativeProximityInfo(), mSettingsValuesForSuggestion, keyboard, mSettingsValuesForSuggestion,
sessionId, SuggestedWords.INPUT_STYLE_TYPING, keyboardLayout); sessionId, SuggestedWords.INPUT_STYLE_TYPING);
} finally { } finally {
if (sessionId != null) { if (sessionId != null) {
mSessionIdPool.add(sessionId); mSessionIdPool.add(sessionId);

View File

@ -29,18 +29,11 @@ import android.view.textservice.TextInfo;
import com.android.inputmethod.compat.SuggestionsInfoCompatUtils; import com.android.inputmethod.compat.SuggestionsInfoCompatUtils;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardLayout;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.NgramContext; import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer; import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.common.ComposedData;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.CoordinateUtils;
import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.common.LocaleUtils; import com.android.inputmethod.latin.common.LocaleUtils;
import com.android.inputmethod.latin.common.ResizableIntArray;
import com.android.inputmethod.latin.common.StringUtils; import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
import com.android.inputmethod.latin.utils.ScriptUtils; import com.android.inputmethod.latin.utils.ScriptUtils;
@ -272,26 +265,20 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
false /* reportAsTypo */); false /* reportAsTypo */);
} }
final Keyboard keyboard = mService.getKeyboardForLocale(mLocale); final Keyboard keyboard = mService.getKeyboardForLocale(mLocale);
if (null == keyboard) {
Log.d(TAG, "No keyboard for locale: " + mLocale);
// If there is no keyboard for this locale, don't do any spell-checking.
return AndroidSpellCheckerService.getNotInDictEmptySuggestions(
false /* reportAsTypo */);
}
final WordComposer composer = new WordComposer(); final WordComposer composer = new WordComposer();
final int[] codePoints = StringUtils.toCodePointArray(text); final int[] codePoints = StringUtils.toCodePointArray(text);
final int[] coordinates; final int[] coordinates;
final ProximityInfo proximityInfo;
final KeyboardLayout keyboardLayout;
if (null == keyboard) {
coordinates = CoordinateUtils.newCoordinateArray(codePoints.length,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
proximityInfo = null;
keyboardLayout = null;
} else {
coordinates = keyboard.getCoordinates(codePoints); coordinates = keyboard.getCoordinates(codePoints);
proximityInfo = keyboard.getProximityInfo();
keyboardLayout = keyboard.getKeyboardLayout();
}
composer.setComposingWord(codePoints, coordinates); composer.setComposingWord(codePoints, coordinates);
// TODO: Don't gather suggestions if the limit is <= 0 unless necessary // TODO: Don't gather suggestions if the limit is <= 0 unless necessary
final SuggestionResults suggestionResults = mService.getSuggestionResults( final SuggestionResults suggestionResults = mService.getSuggestionResults(
mLocale, composer.getComposedDataSnapshot(), ngramContext, proximityInfo, mLocale, composer.getComposedDataSnapshot(), ngramContext, keyboard);
keyboardLayout);
final Result result = getResult(capitalizeType, mLocale, suggestionsLimit, final Result result = getResult(capitalizeType, mLocale, suggestionsLimit,
mService.getRecommendedThreshold(), text, suggestionResults); mService.getRecommendedThreshold(), text, suggestionResults);
isInDict = isInDictForAnyCapitalization(text, capitalizeType); isInDict = isInDictForAnyCapitalization(text, capitalizeType);