private static boolean matchTypedValue( final TypedArray a, final int index, final int intValue, final String strValue) { // If <case> does not have "index" attribute, that means this <case> is wild-card for // the attribute. final TypedValue v = a.peekValue(index); if (v == null) { return true; } if (ResourceUtils.isIntegerValue(v)) { return intValue == a.getInt(index, 0); } if (ResourceUtils.isStringValue(v)) { return StringUtils.containsInArray(strValue, a.getString(index).split("\\|")); } return false; }
public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues) { final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(mThemeContext, editorInfo); final Resources res = mThemeContext.getResources(); final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype()); builder.setOptions( settingsValues.isVoiceKeyEnabled(editorInfo), true /* always show a voice key on the main keyboard */, settingsValues.isLanguageSwitchKeyEnabled()); mKeyboardLayoutSet = builder.build(); try { mState.onLoadKeyboard(); } catch (KeyboardLayoutSetException e) { Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause()); return; } }
private void parseKeyboardAttributes(final XmlPullParser parser) { final AttributeSet attr = Xml.asAttributeSet(parser); final TypedArray keyboardAttr = mContext.obtainStyledAttributes( attr, R.styleable.Keyboard, R.attr.keyboardStyle, R.style.Keyboard); final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key); try { final KeyboardParams params = mParams; final int height = params.mId.mHeight; final int width = params.mId.mWidth; params.mOccupiedHeight = height; params.mOccupiedWidth = width; params.mTopPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardTopPadding, height, height, 0); params.mBottomPadding = (int) keyboardAttr.getFraction( R.styleable.Keyboard_keyboardBottomPadding, height, height, 0); params.mLeftPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardLeftPadding, width, width, 0); params.mRightPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardRightPadding, width, width, 0); final int baseWidth = params.mOccupiedWidth - params.mLeftPadding - params.mRightPadding; params.mBaseWidth = baseWidth; params.mDefaultKeyWidth = (int) keyAttr.getFraction( R.styleable.Keyboard_Key_keyWidth, baseWidth, baseWidth, baseWidth / DEFAULT_KEYBOARD_COLUMNS); params.mHorizontalGap = (int) keyboardAttr.getFraction(R.styleable.Keyboard_horizontalGap, baseWidth, baseWidth, 0); // TODO: Fix keyboard geometry calculation clearer. Historically vertical gap between // rows are determined based on the entire keyboard height including top and bottom // paddings. params.mVerticalGap = (int) keyboardAttr.getFraction(R.styleable.Keyboard_verticalGap, height, height, 0); final int baseHeight = params.mOccupiedHeight - params.mTopPadding - params.mBottomPadding + params.mVerticalGap; params.mBaseHeight = baseHeight; params.mDefaultRowHeight = (int) ResourceUtils.getDimensionOrFraction( keyboardAttr, R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS); params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr); params.mMoreKeysTemplate = keyboardAttr.getResourceId(R.styleable.Keyboard_moreKeysTemplate, 0); params.mMaxMoreKeysKeyboardColumn = keyAttr.getInt(R.styleable.Keyboard_Key_maxMoreKeysColumn, 5); params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0); params.mIconsSet.loadIcons(keyboardAttr); final String language = params.mId.mLocale.getLanguage(); params.mCodesSet.setLanguage(language); params.mTextsSet.setLanguage(language); final RunInLocale<Void> job = new RunInLocale<Void>() { @Override protected Void job(final Resources res) { params.mTextsSet.loadStringResources(mContext); return null; } }; // Null means the current system locale. final Locale locale = SubtypeLocaleUtils.isNoLanguage(params.mId.mSubtype) ? null : params.mId.mLocale; job.runInLocale(mResources, locale); final int resourceId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0); if (resourceId != 0) { final String[] data = mResources.getStringArray(resourceId); params.mTouchPositionCorrection.load(data); } } finally { keyAttr.recycle(); keyboardAttr.recycle(); } }