public Row(Context askContext, Resources res, Keyboard parent, XmlResourceParser parser) { this.parent = parent; // some defaults defaultWidth = parent.mDefaultWidth; defaultHeightCode = parent.mDefaultHeightCode; defaultHorizontalGap = parent.mDefaultHorizontalGap; verticalGap = parent.getVerticalGap(); // now reading from the XML SparseIntArray attributeIdMap = parent.attributeIdMap; int[] remoteKeyboardLayoutStyleable = parent.remoteKeyboardLayoutStyleable; TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.keyWidth: defaultWidth = getDimensionOrFraction( a, remoteIndex, parent.mDisplayWidth, parent.mDefaultWidth); break; case android.R.attr.keyHeight: defaultHeightCode = getKeyHeightCode(a, remoteIndex, parent.mDefaultHeightCode); break; case android.R.attr.horizontalGap: defaultHorizontalGap = getDimensionOrFraction( a, remoteIndex, parent.mDisplayWidth, parent.mDefaultHorizontalGap); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); int[] remoteKeyboardRowLayoutStyleable = parent.remoteKeyboardRowLayoutStyleable; a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardRowLayoutStyleable); n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardRowLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.rowEdgeFlags: rowEdgeFlags = a.getInt(remoteIndex, 0); break; case android.R.attr.keyboardMode: mode = a.getResourceId(remoteIndex, 0); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); }
public Drawable getIcon() { try { if (mIconResId != INVALID_RES_ID) { return getPackageContext().getResources().getDrawable(mIconResId); } else { return null; } } catch (Resources.NotFoundException n) { Log.w(TAG, "Failed to load pack ICON! ResId: " + mIconResId); return null; } }
@NonNull public static int[] getKeyCodesFromTypedArray(TypedArray typedArray, int index) { TypedValue codesValue = new TypedValue(); typedArray.getValue(index, codesValue); if (codesValue.type == TypedValue.TYPE_INT_DEC || codesValue.type == TypedValue.TYPE_INT_HEX) { return new int[] {codesValue.data}; } else if (codesValue.type == TypedValue.TYPE_STRING) { return parseCSV(codesValue.string.toString()); } else { Log.w(TAG, "Unknown codes values!"); return new int[0]; } }
@Nullable public Drawable getScreenshot() { try { if (mThemeScreenshotResId != INVALID_RES_ID) { Context packageContext = getPackageContext(); if (packageContext == null) return null; return packageContext.getResources().getDrawable(mThemeScreenshotResId); } else { return null; } } catch (Resources.NotFoundException n) { Log.w(TAG, "Failed to load pack Screenshot! ResId:" + mThemeScreenshotResId); return null; } }
protected static int getKeyHeightCode(TypedArray a, int remoteIndex, int defaultHeightCode) { TypedValue value = a.peekValue(remoteIndex); if (value == null) { // means that it was not provided. So I take my parent's return defaultHeightCode; } else if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT && value.data <= 0 && value.data >= -3) { return value.data; } else { Log.w(TAG, "Key height attribute is incorrectly set! Defaulting to regular height."); return -1; } }
private void collectGarbage() { int poolSize = mStringPool.size(); int garbageSize = mSuggestions.size(); while (poolSize < mPrefMaxSuggestions && garbageSize > 0) { CharSequence garbage = mSuggestions.get(garbageSize - 1); if (garbage != null && garbage instanceof StringBuilder) { mStringPool.add(garbage); poolSize++; } garbageSize--; } if (poolSize == mPrefMaxSuggestions + 1) { Log.w(TAG, "String pool got too big: " + poolSize); } mSuggestions.clear(); }
public void popTextOutOfKey(CharSequence text) { if (TextUtils.isEmpty(text)) { Log.w(TAG, "Call for popTextOutOfKey with missing text argument!"); return; } if (!AnyApplication.getConfig().workaround_alwaysUseDrawText()) return; // not doing it with StaticLayout // performing "toString" so we'll have a separate copy of the CharSequence, // and not the original object which I fear is a reference copy (hence may be changed). mPopOutText = text.toString(); mPopOutTime = SystemClock.elapsedRealtime(); mPopOutStartPoint.x = mFirstTouchPoint.x; mPopOutStartPoint.y = mFirstTouchPoint.y; // it is ok to wait for the next loop. postInvalidate(); }
private void parseKeyboardAttributes( Context askContext, Resources res, XmlResourceParser parser) { TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable); Resources askRes = askContext.getResources(); // some defaults mDefaultWidth = mDisplayWidth / 10; mDefaultHeightCode = -1; mDefaultHorizontalGap = 0; mDefaultVerticalGap = askRes.getDimensionPixelOffset(R.dimen.default_key_vertical_gap); // now reading from XML int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.keyWidth: mDefaultWidth = getDimensionOrFraction(a, remoteIndex, mDisplayWidth, mDisplayWidth / 10); break; case android.R.attr.keyHeight: mDefaultHeightCode = getKeyHeightCode(a, remoteIndex, -1); break; case android.R.attr.horizontalGap: mDefaultHorizontalGap = getDimensionOrFraction(a, remoteIndex, mDisplayWidth, 0); break; case android.R.attr.verticalGap: mDefaultVerticalGap = getDimensionOrFraction(a, remoteIndex, mDisplayWidth, mDefaultVerticalGap); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE); // Square it for comparison mProximityThreshold = mProximityThreshold * mProximityThreshold; }
private void setDataFromTypedArray( Row parent, KeyboardDimens keyboardDimens, Resources askResources, TypedArray a, int remoteIndex, int localAttrId) { try { switch (localAttrId) { case android.R.attr.keyWidth: width = getDimensionOrFraction(a, remoteIndex, keyboard.mDisplayWidth, parent.defaultWidth); width = Math.min(keyboardDimens.getKeyMaxWidth(), width); break; case android.R.attr.keyHeight: int heightCode = getKeyHeightCode(a, remoteIndex, parent.defaultHeightCode); height = KeyboardSupport.getKeyHeightFromHeightCode( keyboardDimens, heightCode, askResources.getConfiguration().orientation); break; case android.R.attr.horizontalGap: gap = getDimensionOrFraction( a, remoteIndex, keyboard.mDisplayWidth, parent.defaultHorizontalGap); break; case android.R.attr.codes: codes = KeyboardSupport.getKeyCodesFromTypedArray(a, remoteIndex); break; case android.R.attr.iconPreview: iconPreview = a.getDrawable(remoteIndex); KeyboardSupport.updateDrawableBounds(iconPreview); break; case android.R.attr.popupCharacters: popupCharacters = a.getText(remoteIndex); break; case android.R.attr.popupKeyboard: popupResId = a.getResourceId(remoteIndex, 0); break; case android.R.attr.isRepeatable: repeatable = a.getBoolean(remoteIndex, false); break; case R.attr.showPreview: showPreview = a.getBoolean(remoteIndex, true); break; case R.attr.keyDynamicEmblem: dynamicEmblem = a.getInt(remoteIndex, KEY_EMBLEM_NONE); break; case android.R.attr.isModifier: modifier = a.getBoolean(remoteIndex, false); break; case android.R.attr.isSticky: sticky = a.getBoolean(remoteIndex, false); break; case android.R.attr.keyEdgeFlags: edgeFlags = a.getInt(remoteIndex, 0); edgeFlags |= parent.rowEdgeFlags; break; case android.R.attr.keyIcon: icon = a.getDrawable(remoteIndex); KeyboardSupport.updateDrawableBounds(icon); break; case android.R.attr.keyLabel: label = a.getText(remoteIndex); break; case android.R.attr.keyOutputText: text = a.getText(remoteIndex); break; } } catch (Exception e) { Log.w(TAG, "Failed to load keyboard layout! ", e); } }