@Override public void setShifted(boolean shifted) { final Keyboard keyboard = getKeyboard(); if (keyboard.setShifted(shifted)) { invalidateAllKeys(); } }
private void doTestMoreKeysOf( final int code, final InputMethodSubtype subtype, final int elementId, final int inputType, final int imeOptions, final ExpectedMoreKey... expectedMoreKeys) { final EditorInfo editorInfo = new EditorInfo(); editorInfo.inputType = inputType; editorInfo.imeOptions = imeOptions; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Key actualKey = keyboard.getKey(code); final MoreKeySpec[] actualMoreKeys = actualKey.getMoreKeys(); final String tag = actualKey.toString() + " moreKeys=" + Arrays.toString(actualMoreKeys); if (expectedMoreKeys.length == 0) { assertEquals(tag, null, actualMoreKeys); return; } if (expectedMoreKeys.length == 1) { assertEquals(tag + " fixedOrder", false, actualKey.isMoreKeysFixedOrder()); assertEquals(tag + " fixedColumn", false, actualKey.isMoreKeysFixedColumn()); } else { assertEquals(tag + " fixedOrder", true, actualKey.isMoreKeysFixedOrder()); assertEquals(tag + " fixedColumn", true, actualKey.isMoreKeysFixedColumn()); // TODO: Can't handle multiple rows of more keys. assertEquals(tag + " column", expectedMoreKeys.length, actualKey.getMoreKeysColumnNumber()); } assertNotNull(tag + " moreKeys", actualMoreKeys); assertEquals(tag, expectedMoreKeys.length, actualMoreKeys.length); for (int index = 0; index < actualMoreKeys.length; index++) { final int expectedLabelResId = expectedMoreKeys[index].mLabelResId; if (expectedLabelResId == ExpectedMoreKey.NO_LABEL) { assertEquals(tag + " label " + index, null, actualMoreKeys[index].mLabel); } else { final CharSequence expectedLabel = getContext().getText(expectedLabelResId); assertEquals(tag + " label " + index, expectedLabel, actualMoreKeys[index].mLabel); } final int expectedIconId = expectedMoreKeys[index].mIconId; assertEquals(tag + " icon " + index, expectedIconId, actualMoreKeys[index].mIconId); } }
private void assertParser( String message, String moreKeySpec, String expectedLabel, String expectedOutputText, int expectedIcon, int expectedCode) { final String labelResolved = KeySpecParser.resolveTextReference(moreKeySpec, mTextsSet); final MoreKeySpec spec = new MoreKeySpec(labelResolved, false /* needsToUpperCase */, Locale.US, mCodesSet); assertEquals(message + " [label]", expectedLabel, spec.mLabel); assertEquals(message + " [ouptputText]", expectedOutputText, spec.mOutputText); assertEquals( message + " [icon]", KeyboardIconsSet.getIconName(expectedIcon), KeyboardIconsSet.getIconName(spec.mIconId)); assertEquals( message + " [code]", Keyboard.printableCode(expectedCode), Keyboard.printableCode(spec.mCode)); }
private boolean checkDistracterUsingGetSuggestions(final String testedWord) { if (mKeyboard == null) { return false; } final SettingsValuesForSuggestion settingsValuesForSuggestion = new SettingsValuesForSuggestion( false /* blockPotentiallyOffensive */, false /* spaceAwareGestureEnabled */, null /* additionalFeaturesSettingValues */); final int trailingSingleQuotesCount = StringUtils.getTrailingSingleQuotesCount(testedWord); final String consideredWord = trailingSingleQuotesCount > 0 ? testedWord.substring(0, testedWord.length() - trailingSingleQuotesCount) : testedWord; final WordComposer composer = new WordComposer(); final int[] codePoints = StringUtils.toCodePointArray(testedWord); synchronized (mLock) { final int[] coordinates = mKeyboard.getCoordinates(codePoints); composer.setComposingWord(codePoints, coordinates); final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults( composer, PrevWordsInfo.EMPTY_PREV_WORDS_INFO, mKeyboard.getProximityInfo(), settingsValuesForSuggestion, 0 /* sessionId */); if (suggestionResults.isEmpty()) { return false; } final SuggestedWordInfo firstSuggestion = suggestionResults.first(); final boolean isDistractor = suggestionExceedsDistracterThreshold( firstSuggestion, consideredWord, DISTRACTER_WORD_SCORE_THRESHOLD); if (DEBUG) { Log.d(TAG, "isDistracter: " + isDistractor); } return isDistractor; } }
@Override public String toString() { return String.format( "%s/%s %d,%d %dx%d %s/%s/%s", Keyboard.printableCode(mCode), mLabel, mX, mY, mWidth, mHeight, mHintLabel, KeyboardIconsSet.getIconName(mIconId), backgroundName(mBackgroundType)); }