use of com.android.inputmethod.latin.SuggestedWords in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class SpacingAndPunctuationsTests method testingStandardPunctuationSuggestions.
private static void testingStandardPunctuationSuggestions(final SpacingAndPunctuations sp, final String[] punctuationLabels, final String[] punctuationWords) {
final SuggestedWords suggestedWords = sp.mSuggestPuncList;
assertFalse("typedWordValid", suggestedWords.mTypedWordValid);
assertFalse("willAutoCorrect", suggestedWords.mWillAutoCorrect);
assertTrue("isPunctuationSuggestions", suggestedWords.isPunctuationSuggestions());
assertFalse("isObsoleteSuggestions", suggestedWords.mIsObsoleteSuggestions);
assertFalse("isPrediction", suggestedWords.isPrediction());
assertEquals("size", punctuationLabels.length, suggestedWords.size());
for (int index = 0; index < suggestedWords.size(); index++) {
assertEquals("punctuation label at " + index, punctuationLabels[index], suggestedWords.getLabel(index));
assertEquals("punctuation word at " + index, punctuationWords[index], suggestedWords.getWord(index));
}
}
use of com.android.inputmethod.latin.SuggestedWords in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class InputLogic method retrieveOlderSuggestions.
/**
* Make a {@link com.android.inputmethod.latin.SuggestedWords} object containing a typed word
* and obsolete suggestions.
* See {@link com.android.inputmethod.latin.SuggestedWords#getTypedWordAndPreviousSuggestions(
* SuggestedWordInfo, com.android.inputmethod.latin.SuggestedWords)}.
* @param typedWordInfo The typed word as a SuggestedWordInfo.
* @param previousSuggestedWords The previously suggested words.
* @return Obsolete suggestions with the newly typed word.
*/
static SuggestedWords retrieveOlderSuggestions(final SuggestedWordInfo typedWordInfo, final SuggestedWords previousSuggestedWords) {
final SuggestedWords oldSuggestedWords = previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.getEmptyInstance() : previousSuggestedWords;
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = SuggestedWords.getTypedWordAndPreviousSuggestions(typedWordInfo, oldSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions, null, /* rawSuggestions */
typedWordInfo, false, /* typedWordValid */
false, /* hasAutoCorrectionCandidate */
true, /* isObsoleteSuggestions */
oldSuggestedWords.mInputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
}
use of com.android.inputmethod.latin.SuggestedWords in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class InputLogic method performUpdateSuggestionStripSync.
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, final int inputStyle) {
long startTimeMillis = 0;
if (DebugFlags.DEBUG_ENABLED) {
startTimeMillis = System.currentTimeMillis();
Log.d(TAG, "performUpdateSuggestionStripSync()");
}
// Check if we have a suggestion engine attached.
if (!settingsValues.needsToLookupSuggestions()) {
if (mWordComposer.isComposingWord()) {
Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + "requested!");
}
// Clear the suggestions strip.
mSuggestionStripViewAccessor.showSuggestionStrip(SuggestedWords.getEmptyInstance());
return;
}
if (!mWordComposer.isComposingWord() && !settingsValues.mBigramPredictionEnabled) {
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
return;
}
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>("Suggest");
mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
@Override
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
final String typedWordString = mWordComposer.getTypedWord();
final SuggestedWordInfo typedWordInfo = new SuggestedWordInfo(typedWordString, "", /* prevWordsContext */
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX, /* indexOfTouchPointOfSecondWord */
SuggestedWordInfo.NOT_A_CONFIDENCE);
// typed word is <= 1 (after a deletion typically) we clear old suggestions.
if (suggestedWords.size() > 1 || typedWordString.length() <= 1) {
holder.set(suggestedWords);
} else {
holder.set(retrieveOlderSuggestions(typedWordInfo, mSuggestedWords));
}
}
});
// This line may cause the current thread to wait.
final SuggestedWords suggestedWords = holder.get(null, Constants.GET_SUGGESTED_WORDS_TIMEOUT);
if (suggestedWords != null) {
mSuggestionStripViewAccessor.showSuggestionStrip(suggestedWords);
}
if (DebugFlags.DEBUG_ENABLED) {
long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
Log.d(TAG, "performUpdateSuggestionStripSync() : " + runTimeMillis + " ms to finish");
}
}
use of com.android.inputmethod.latin.SuggestedWords in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class SuggestionSpanUtilsTest method testGetTextWithSuggestionSpan.
public void testGetTextWithSuggestionSpan() {
final SuggestedWordInfo prediction1 = createWordInfo("Quality", SuggestedWordInfo.KIND_PREDICTION);
final SuggestedWordInfo prediction2 = createWordInfo("Speed", SuggestedWordInfo.KIND_PREDICTION);
final SuggestedWordInfo prediction3 = createWordInfo("Price", SuggestedWordInfo.KIND_PREDICTION);
final SuggestedWordInfo typed = createWordInfo("Hey", SuggestedWordInfo.KIND_TYPED);
final SuggestedWordInfo[] corrections = new SuggestedWordInfo[SuggestionSpan.SUGGESTIONS_MAX_SIZE * 2];
for (int i = 0; i < corrections.length; ++i) {
corrections[i] = createWordInfo("correction" + i, SuggestedWordInfo.KIND_CORRECTION);
}
final Locale NONNULL_LOCALE = new Locale("en", "GB");
// SuggestionSpan will not be attached when {@link SuggestedWords#INPUT_STYLE_PREDICTION}
// is specified.
{
final SuggestedWords predictedWords = new SuggestedWords(new ArrayList<>(Arrays.asList(prediction1, prediction2, prediction3)), null, /* rawSuggestions */
null, /* typedWord */
false, /* typedWordValid */
false, /* willAutoCorrect */
false, /* isObsoleteSuggestions */
SuggestedWords.INPUT_STYLE_PREDICTION, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
final String PICKED_WORD = prediction2.mWord;
// Note that the framework uses the context locale as a fallback locale.
assertNotSuggestionSpan(PICKED_WORD, SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD, predictedWords, NONNULL_LOCALE));
}
final ArrayList<SuggestedWordInfo> suggestedWordList = new ArrayList<>();
suggestedWordList.add(typed);
suggestedWordList.add(prediction1);
suggestedWordList.add(prediction2);
suggestedWordList.add(prediction3);
suggestedWordList.addAll(Arrays.asList(corrections));
final SuggestedWords typedAndCollectedWords = new SuggestedWords(suggestedWordList, null, /* rawSuggestions */
null, /* typedWord */
false, /* typedWordValid */
false, /* willAutoCorrect */
false, /* isObsoleteSuggestions */
SuggestedWords.INPUT_STYLE_TYPING, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
for (final SuggestedWordInfo pickedWord : suggestedWordList) {
final String PICKED_WORD = pickedWord.mWord;
final ArrayList<String> expectedSuggestions = new ArrayList<>();
for (SuggestedWordInfo suggestedWordInfo : suggestedWordList) {
if (expectedSuggestions.size() >= SuggestionSpan.SUGGESTIONS_MAX_SIZE) {
break;
}
if (suggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_PREDICTION)) {
// Currently predictions are not filled into SuggestionSpan.
continue;
}
final String suggestedWord = suggestedWordInfo.mWord;
if (TextUtils.equals(PICKED_WORD, suggestedWord)) {
// Typed word itself is not added to SuggestionSpan.
continue;
}
expectedSuggestions.add(suggestedWord);
}
// non-null locale
assertSuggestionSpan(PICKED_WORD, 0, /* reuiredSuggestionSpanFlags */
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE, /* requiredSpanFlags */
expectedSuggestions.toArray(new String[expectedSuggestions.size()]), NONNULL_LOCALE, SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD, typedAndCollectedWords, NONNULL_LOCALE));
// root locale
assertSuggestionSpan(PICKED_WORD, 0, /* reuiredSuggestionSpanFlags */
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE, /* requiredSpanFlags */
expectedSuggestions.toArray(new String[expectedSuggestions.size()]), Locale.ROOT, SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD, typedAndCollectedWords, Locale.ROOT));
}
}
use of com.android.inputmethod.latin.SuggestedWords in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class MoreSuggestionsView method onKeyInput.
@Override
protected void onKeyInput(final Key key, final int x, final int y) {
if (!(key instanceof MoreSuggestionKey)) {
Log.e(TAG, "Expected key is MoreSuggestionKey, but found " + key.getClass().getName());
return;
}
final Keyboard keyboard = getKeyboard();
if (!(keyboard instanceof MoreSuggestions)) {
Log.e(TAG, "Expected keyboard is MoreSuggestions, but found " + keyboard.getClass().getName());
return;
}
final SuggestedWords suggestedWords = ((MoreSuggestions) keyboard).mSuggestedWords;
final int index = ((MoreSuggestionKey) key).mSuggestedWordIndex;
if (index < 0 || index >= suggestedWords.size()) {
Log.e(TAG, "Selected suggestion has an illegal index: " + index);
return;
}
if (!(mListener instanceof MoreSuggestionsListener)) {
Log.e(TAG, "Expected mListener is MoreSuggestionsListener, but found " + mListener.getClass().getName());
return;
}
((MoreSuggestionsListener) mListener).onSuggestionSelected(suggestedWords.getInfo(index));
}
Aggregations