Search in sources :

Example 6 with Keyboard

use of com.android.inputmethod.keyboard.Keyboard in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LayoutTestsBase method doKeyboardTests.

// Comparing expected keyboard and actual keyboard.
private void doKeyboardTests(final int elementId) {
    final ExpectedKey[][] expectedKeyboard = mLayout.getLayout(isPhone(), elementId);
    // Skip test if no keyboard is defined.
    if (expectedKeyboard == null) {
        return;
    }
    final String tag = mLogTag + "/" + KeyboardId.elementIdToName(elementId);
    // Create actual keyboard object.
    final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(elementId);
    // Create actual keyboard to be compared with the expected keyboard.
    final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(keyboard.getSortedKeys());
    // Dump human readable definition of expected/actual keyboards.
    Log.d(tag, "expected=\n" + ExpectedKeyboardBuilder.toString(expectedKeyboard));
    Log.d(tag, "actual  =\n" + ActualKeyboardBuilder.toString(actualKeyboard));
    // Test both keyboards have the same number of rows.
    assertEquals(tag + " labels" + "\nexpected=" + ExpectedKeyboardBuilder.toString(expectedKeyboard) + "\nactual  =" + ActualKeyboardBuilder.toString(actualKeyboard), expectedKeyboard.length, actualKeyboard.length);
    for (int r = 0; r < actualKeyboard.length; r++) {
        final int row = r + 1;
        // Test both keyboards' rows have the same number of columns.
        assertEquals(tag + " labels row=" + row + "\nexpected=" + Arrays.toString(expectedKeyboard[r]) + "\nactual  =" + ActualKeyboardBuilder.toString(actualKeyboard[r]), expectedKeyboard[r].length, actualKeyboard[r].length);
        for (int c = 0; c < actualKeyboard[r].length; c++) {
            final int column = c + 1;
            final Key actualKey = actualKeyboard[r][c];
            final ExpectedKey expectedKey = expectedKeyboard[r][c];
            // Test both keyboards' keys have the same visual outlook and key output.
            assertTrue(tag + " labels row,column=" + row + "," + column + "\nexpected=" + expectedKey + "\nactual  =" + ActualKeyboardBuilder.toString(actualKey), expectedKey.equalsTo(actualKey));
        }
    }
}
Also used : ExpectedKey(com.android.inputmethod.keyboard.layout.expected.ExpectedKey) Keyboard(com.android.inputmethod.keyboard.Keyboard) ExpectedAdditionalMoreKey(com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey) ExpectedKey(com.android.inputmethod.keyboard.layout.expected.ExpectedKey) Key(com.android.inputmethod.keyboard.Key)

Example 7 with Keyboard

use of com.android.inputmethod.keyboard.Keyboard in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class MainKeyboardAccessibilityDelegate method setKeyboard.

/**
 * {@inheritDoc}
 */
@Override
public void setKeyboard(final Keyboard keyboard) {
    if (keyboard == null) {
        return;
    }
    final Keyboard lastKeyboard = getKeyboard();
    super.setKeyboard(keyboard);
    final int lastKeyboardMode = mLastKeyboardMode;
    mLastKeyboardMode = keyboard.mId.mMode;
    // to check the state before announcing anything.
    if (!AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
        return;
    }
    // Announce the language name only when the language is changed.
    if (lastKeyboard == null || !keyboard.mId.mSubtype.equals(lastKeyboard.mId.mSubtype)) {
        announceKeyboardLanguage(keyboard);
        return;
    }
    // Announce the mode only when the mode is changed.
    if (keyboard.mId.mMode != lastKeyboardMode) {
        announceKeyboardMode(keyboard);
        return;
    }
    // Announce the keyboard type only when the type is changed.
    if (keyboard.mId.mElementId != lastKeyboard.mId.mElementId) {
        announceKeyboardType(keyboard, lastKeyboard);
        return;
    }
}
Also used : Keyboard(com.android.inputmethod.keyboard.Keyboard)

Example 8 with Keyboard

use of com.android.inputmethod.keyboard.Keyboard in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LatinIME method getSuggestedWords.

// TODO[IL]: Move this out of LatinIME.
public void getSuggestedWords(final int inputStyle, final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
    final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
    if (keyboard == null) {
        callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance());
        return;
    }
    mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard, mKeyboardSwitcher.getKeyboardShiftMode(), inputStyle, sequenceNumber, callback);
}
Also used : Keyboard(com.android.inputmethod.keyboard.Keyboard)

Example 9 with Keyboard

use of com.android.inputmethod.keyboard.Keyboard 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));
}
Also used : Keyboard(com.android.inputmethod.keyboard.Keyboard) MoreSuggestionKey(com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionKey) SuggestedWords(com.android.inputmethod.latin.SuggestedWords)

Example 10 with Keyboard

use of com.android.inputmethod.keyboard.Keyboard in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class AndroidWordLevelSpellCheckerSession method onGetSuggestionsInternal.

protected SuggestionsInfo onGetSuggestionsInternal(final TextInfo textInfo, final NgramContext ngramContext, final int suggestionsLimit) {
    try {
        final String text = textInfo.getText().replaceAll(AndroidSpellCheckerService.APOSTROPHE, AndroidSpellCheckerService.SINGLE_QUOTE).replaceAll("^" + quotesRegexp, "").replaceAll(quotesRegexp + "$", "");
        if (!mService.hasMainDictionaryForLocale(mLocale)) {
            return AndroidSpellCheckerService.getNotInDictEmptySuggestions(false);
        }
        // Handle special patterns like email, URI, telephone number.
        final int checkability = getCheckabilityInScript(text, mScript);
        if (CHECKABILITY_CHECKABLE != checkability) {
            if (CHECKABILITY_CONTAINS_PERIOD == checkability) {
                final String[] splitText = text.split(Constants.REGEXP_PERIOD);
                boolean allWordsAreValid = true;
                for (final String word : splitText) {
                    if (!mService.isValidWord(mLocale, word)) {
                        allWordsAreValid = false;
                        break;
                    }
                }
                if (allWordsAreValid) {
                    return new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO | SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS, new String[] { TextUtils.join(Constants.STRING_SPACE, splitText) });
                }
            }
            return mService.isValidWord(mLocale, text) ? AndroidSpellCheckerService.getInDictEmptySuggestions() : AndroidSpellCheckerService.getNotInDictEmptySuggestions(CHECKABILITY_CONTAINS_PERIOD == checkability);
        }
        // Handle normal words.
        final int capitalizeType = StringUtils.getCapitalizationType(text);
        if (isInDictForAnyCapitalization(text, capitalizeType)) {
            if (DebugFlags.DEBUG_ENABLED) {
                Log.i(TAG, "onGetSuggestionsInternal() : [" + text + "] is a valid word");
            }
            return AndroidSpellCheckerService.getInDictEmptySuggestions();
        }
        if (DebugFlags.DEBUG_ENABLED) {
            Log.i(TAG, "onGetSuggestionsInternal() : [" + text + "] is NOT a valid word");
        }
        final Keyboard keyboard = mService.getKeyboardForLocale(mLocale);
        if (null == keyboard) {
            Log.w(TAG, "onGetSuggestionsInternal() : No keyboard for locale: " + mLocale);
            // If there is no keyboard for this locale, don't do any spell-checking.
            return AndroidSpellCheckerService.getNotInDictEmptySuggestions(false);
        }
        final WordComposer composer = new WordComposer();
        final int[] codePoints = StringUtils.toCodePointArray(text);
        final int[] coordinates;
        coordinates = keyboard.getCoordinates(codePoints);
        composer.setComposingWord(codePoints, coordinates);
        // TODO: Don't gather suggestions if the limit is <= 0 unless necessary
        final SuggestionResults suggestionResults = mService.getSuggestionResults(mLocale, composer.getComposedDataSnapshot(), ngramContext, keyboard);
        final Result result = getResult(capitalizeType, mLocale, suggestionsLimit, mService.getRecommendedThreshold(), text, suggestionResults);
        if (DebugFlags.DEBUG_ENABLED) {
            if (result.mSuggestions != null && result.mSuggestions.length > 0) {
                final StringBuilder builder = new StringBuilder();
                for (String suggestion : result.mSuggestions) {
                    builder.append(" [");
                    builder.append(suggestion);
                    builder.append("]");
                }
                Log.i(TAG, "onGetSuggestionsInternal() : Suggestions =" + builder);
            }
        }
        // Handle word not in dictionary.
        // This is called only once per unique word, so entering multiple
        // instances of the same word does not result in more than one call
        // to this method.
        // Also, upon changing the orientation of the device, this is called
        // again for every unique invalid word in the text box.
        StatsUtils.onInvalidWordIdentification(text);
        final int flags = SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO | (result.mHasRecommendedSuggestions ? SuggestionsInfoCompatUtils.getValueOf_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS() : 0);
        final SuggestionsInfo retval = new SuggestionsInfo(flags, result.mSuggestions);
        mSuggestionsCache.putSuggestionsToCache(text, result.mSuggestions, flags);
        return retval;
    } catch (RuntimeException e) {
        // Don't kill the keyboard if there is a bug in the spell checker
        Log.e(TAG, "Exception while spellchecking", e);
        return AndroidSpellCheckerService.getNotInDictEmptySuggestions(false);
    }
}
Also used : WordComposer(com.android.inputmethod.latin.WordComposer) SuggestionResults(com.android.inputmethod.latin.utils.SuggestionResults) Keyboard(com.android.inputmethod.keyboard.Keyboard) SuggestionsInfo(android.view.textservice.SuggestionsInfo)

Aggregations

Keyboard (com.android.inputmethod.keyboard.Keyboard)10 Key (com.android.inputmethod.keyboard.Key)3 Paint (android.graphics.Paint)1 PrintWriterPrinter (android.util.PrintWriterPrinter)1 Printer (android.util.Printer)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 SuggestionsInfo (android.view.textservice.SuggestionsInfo)1 TextView (android.widget.TextView)1 MainKeyboardView (com.android.inputmethod.keyboard.MainKeyboardView)1 MoreKeysPanel (com.android.inputmethod.keyboard.MoreKeysPanel)1 ExpectedKey (com.android.inputmethod.keyboard.layout.expected.ExpectedKey)1 ExpectedAdditionalMoreKey (com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey)1 SuggestedWords (com.android.inputmethod.latin.SuggestedWords)1 WordComposer (com.android.inputmethod.latin.WordComposer)1 SettingsValues (com.android.inputmethod.latin.settings.SettingsValues)1 MoreSuggestionKey (com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionKey)1 SuggestionResults (com.android.inputmethod.latin.utils.SuggestionResults)1