am 775f27c8: am cc6ddb05: Merge "Revert "Move resource related methods to ResourceUtils"" into jb-mr1-dev
* commit '775f27c88180bd9bf875c0c76b32cfe2cab9da59': Revert "Move resource related methods to ResourceUtils"main
commit
acde9cc7fc
|
@ -36,7 +36,6 @@ import com.android.inputmethod.keyboard.internal.KeySpecParser.MoreKeySpec;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
|
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.ResourceUtils;
|
|
||||||
import com.android.inputmethod.latin.StringUtils;
|
import com.android.inputmethod.latin.StringUtils;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -230,9 +229,9 @@ public class Key {
|
||||||
mBackgroundType = style.getInt(keyAttr,
|
mBackgroundType = style.getInt(keyAttr,
|
||||||
R.styleable.Keyboard_Key_backgroundType, row.getDefaultBackgroundType());
|
R.styleable.Keyboard_Key_backgroundType, row.getDefaultBackgroundType());
|
||||||
|
|
||||||
mVisualInsetsLeft = Math.round(ResourceUtils.getDimensionOrFraction(keyAttr,
|
mVisualInsetsLeft = Math.round(Keyboard.Builder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0));
|
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0));
|
||||||
mVisualInsetsRight = Math.round(ResourceUtils.getDimensionOrFraction(keyAttr,
|
mVisualInsetsRight = Math.round(Keyboard.Builder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0));
|
R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0));
|
||||||
mIconId = KeySpecParser.getIconId(style.getString(keyAttr,
|
mIconId = KeySpecParser.getIconId(style.getString(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyIcon));
|
R.styleable.Keyboard_Key_keyIcon));
|
||||||
|
|
|
@ -39,7 +39,6 @@ import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
|
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.ResourceUtils;
|
import com.android.inputmethod.latin.ResourceUtils;
|
||||||
import com.android.inputmethod.latin.StringUtils;
|
|
||||||
import com.android.inputmethod.latin.SubtypeLocale;
|
import com.android.inputmethod.latin.SubtypeLocale;
|
||||||
import com.android.inputmethod.latin.XmlParseUtils;
|
import com.android.inputmethod.latin.XmlParseUtils;
|
||||||
|
|
||||||
|
@ -566,13 +565,13 @@ public class Keyboard {
|
||||||
mParams = params;
|
mParams = params;
|
||||||
TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard);
|
R.styleable.Keyboard);
|
||||||
mRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
mRowHeight = (int)Builder.getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_rowHeight,
|
R.styleable.Keyboard_rowHeight,
|
||||||
params.mBaseHeight, params.mDefaultRowHeight);
|
params.mBaseHeight, params.mDefaultRowHeight);
|
||||||
keyboardAttr.recycle();
|
keyboardAttr.recycle();
|
||||||
TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
mDefaultKeyWidth = ResourceUtils.getDimensionOrFraction(keyAttr,
|
mDefaultKeyWidth = Builder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyWidth,
|
R.styleable.Keyboard_Key_keyWidth,
|
||||||
params.mBaseWidth, params.mDefaultKeyWidth);
|
params.mBaseWidth, params.mDefaultKeyWidth);
|
||||||
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
|
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
|
||||||
|
@ -625,7 +624,7 @@ public class Keyboard {
|
||||||
final int keyboardRightEdge = mParams.mOccupiedWidth
|
final int keyboardRightEdge = mParams.mOccupiedWidth
|
||||||
- mParams.mHorizontalEdgesPadding;
|
- mParams.mHorizontalEdgesPadding;
|
||||||
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
|
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
|
||||||
final float keyXPos = ResourceUtils.getDimensionOrFraction(keyAttr,
|
final float keyXPos = Builder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyXPos, mParams.mBaseWidth, 0);
|
R.styleable.Keyboard_Key_keyXPos, mParams.mBaseWidth, 0);
|
||||||
if (keyXPos < 0) {
|
if (keyXPos < 0) {
|
||||||
// If keyXPos is negative, the actual x-coordinate will be
|
// If keyXPos is negative, the actual x-coordinate will be
|
||||||
|
@ -646,7 +645,7 @@ public class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getKeyWidth(TypedArray keyAttr, float keyXPos) {
|
public float getKeyWidth(TypedArray keyAttr, float keyXPos) {
|
||||||
final int widthType = ResourceUtils.getEnumValue(keyAttr,
|
final int widthType = Builder.getEnumValue(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
|
R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
|
||||||
switch (widthType) {
|
switch (widthType) {
|
||||||
case KEYWIDTH_FILL_RIGHT:
|
case KEYWIDTH_FILL_RIGHT:
|
||||||
|
@ -656,7 +655,7 @@ public class Keyboard {
|
||||||
// out the area up to the right edge of the keyboard.
|
// out the area up to the right edge of the keyboard.
|
||||||
return keyboardRightEdge - keyXPos;
|
return keyboardRightEdge - keyXPos;
|
||||||
default: // KEYWIDTH_NOT_ENUM
|
default: // KEYWIDTH_NOT_ENUM
|
||||||
return ResourceUtils.getDimensionOrFraction(keyAttr,
|
return Builder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyWidth,
|
R.styleable.Keyboard_Key_keyWidth,
|
||||||
mParams.mBaseWidth, mDefaultKeyWidth);
|
mParams.mBaseWidth, mDefaultKeyWidth);
|
||||||
}
|
}
|
||||||
|
@ -769,14 +768,14 @@ public class Keyboard {
|
||||||
keyboardHeight = keyboardAttr.getDimension(
|
keyboardHeight = keyboardAttr.getDimension(
|
||||||
R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
|
R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
|
||||||
}
|
}
|
||||||
final float maxKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
final float maxKeyboardHeight = getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);
|
R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);
|
||||||
float minKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
float minKeyboardHeight = getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_minKeyboardHeight, displayHeight, displayHeight / 2);
|
R.styleable.Keyboard_minKeyboardHeight, displayHeight, displayHeight / 2);
|
||||||
if (minKeyboardHeight < 0) {
|
if (minKeyboardHeight < 0) {
|
||||||
// Specified fraction was negative, so it should be calculated against display
|
// Specified fraction was negative, so it should be calculated against display
|
||||||
// width.
|
// width.
|
||||||
minKeyboardHeight = -ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
minKeyboardHeight = -getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2);
|
R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2);
|
||||||
}
|
}
|
||||||
final Params params = mParams;
|
final Params params = mParams;
|
||||||
|
@ -785,27 +784,26 @@ public class Keyboard {
|
||||||
params.mOccupiedHeight = (int)Math.max(
|
params.mOccupiedHeight = (int)Math.max(
|
||||||
Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
|
Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
|
||||||
params.mOccupiedWidth = params.mId.mWidth;
|
params.mOccupiedWidth = params.mId.mWidth;
|
||||||
params.mTopPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mTopPadding = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0);
|
R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0);
|
||||||
params.mBottomPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mBottomPadding = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_keyboardBottomPadding, params.mOccupiedHeight, 0);
|
R.styleable.Keyboard_keyboardBottomPadding, params.mOccupiedHeight, 0);
|
||||||
params.mHorizontalEdgesPadding = (int)ResourceUtils.getDimensionOrFraction(
|
params.mHorizontalEdgesPadding = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
keyboardAttr,
|
|
||||||
R.styleable.Keyboard_keyboardHorizontalEdgesPadding,
|
R.styleable.Keyboard_keyboardHorizontalEdgesPadding,
|
||||||
mParams.mOccupiedWidth, 0);
|
mParams.mOccupiedWidth, 0);
|
||||||
|
|
||||||
params.mBaseWidth = params.mOccupiedWidth - params.mHorizontalEdgesPadding * 2
|
params.mBaseWidth = params.mOccupiedWidth - params.mHorizontalEdgesPadding * 2
|
||||||
- params.mHorizontalCenterPadding;
|
- params.mHorizontalCenterPadding;
|
||||||
params.mDefaultKeyWidth = (int)ResourceUtils.getDimensionOrFraction(keyAttr,
|
params.mDefaultKeyWidth = (int)getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyWidth, params.mBaseWidth,
|
R.styleable.Keyboard_Key_keyWidth, params.mBaseWidth,
|
||||||
params.mBaseWidth / DEFAULT_KEYBOARD_COLUMNS);
|
params.mBaseWidth / DEFAULT_KEYBOARD_COLUMNS);
|
||||||
params.mHorizontalGap = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mHorizontalGap = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_horizontalGap, params.mBaseWidth, 0);
|
R.styleable.Keyboard_horizontalGap, params.mBaseWidth, 0);
|
||||||
params.mVerticalGap = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mVerticalGap = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_verticalGap, params.mOccupiedHeight, 0);
|
R.styleable.Keyboard_verticalGap, params.mOccupiedHeight, 0);
|
||||||
params.mBaseHeight = params.mOccupiedHeight - params.mTopPadding
|
params.mBaseHeight = params.mOccupiedHeight - params.mTopPadding
|
||||||
- params.mBottomPadding + params.mVerticalGap;
|
- params.mBottomPadding + params.mVerticalGap;
|
||||||
params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mDefaultRowHeight = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_rowHeight, params.mBaseHeight,
|
R.styleable.Keyboard_rowHeight, params.mBaseHeight,
|
||||||
params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
|
params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
|
||||||
|
|
||||||
|
@ -1223,7 +1221,7 @@ public class Keyboard {
|
||||||
// If <case> does not have "index" attribute, that means this <case> is wild-card for
|
// If <case> does not have "index" attribute, that means this <case> is wild-card for
|
||||||
// the attribute.
|
// the attribute.
|
||||||
return !a.hasValue(index)
|
return !a.hasValue(index)
|
||||||
|| StringUtils.containsInArray(value, a.getString(index).split("\\|"));
|
|| stringArrayContains(a.getString(index).split("\\|"), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean matchTypedValue(TypedArray a, int index, int intValue,
|
private static boolean matchTypedValue(TypedArray a, int index, int intValue,
|
||||||
|
@ -1234,10 +1232,19 @@ public class Keyboard {
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (ResourceUtils.isIntegerValue(v)) {
|
if (isIntegerValue(v)) {
|
||||||
return intValue == a.getInt(index, 0);
|
return intValue == a.getInt(index, 0);
|
||||||
} else if (ResourceUtils.isStringValue(v)) {
|
} else if (isStringValue(v)) {
|
||||||
return StringUtils.containsInArray(strValue, a.getString(index).split("\\|"));
|
return stringArrayContains(a.getString(index).split("\\|"), strValue);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean stringArrayContains(String[] array, String value) {
|
||||||
|
for (final String elem : array) {
|
||||||
|
if (elem.equals(value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1327,6 +1334,47 @@ public class Keyboard {
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float getDimensionOrFraction(TypedArray a, int index, int base,
|
||||||
|
float defValue) {
|
||||||
|
final TypedValue value = a.peekValue(index);
|
||||||
|
if (value == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
if (isFractionValue(value)) {
|
||||||
|
return a.getFraction(index, base, base, defValue);
|
||||||
|
} else if (isDimensionValue(value)) {
|
||||||
|
return a.getDimension(index, defValue);
|
||||||
|
}
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getEnumValue(TypedArray a, int index, int defValue) {
|
||||||
|
final TypedValue value = a.peekValue(index);
|
||||||
|
if (value == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
if (isIntegerValue(value)) {
|
||||||
|
return a.getInt(index, defValue);
|
||||||
|
}
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isFractionValue(TypedValue v) {
|
||||||
|
return v.type == TypedValue.TYPE_FRACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDimensionValue(TypedValue v) {
|
||||||
|
return v.type == TypedValue.TYPE_DIMENSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isIntegerValue(TypedValue v) {
|
||||||
|
return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isStringValue(TypedValue v) {
|
||||||
|
return v.type == TypedValue.TYPE_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
private static String textAttr(String value, String name) {
|
private static String textAttr(String value, String name) {
|
||||||
return value != null ? String.format(" %s=%s", name, value) : "";
|
return value != null ? String.format(" %s=%s", name, value) : "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ import com.android.inputmethod.latin.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.ResourceUtils;
|
|
||||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||||
import com.android.inputmethod.latin.StringUtils;
|
import com.android.inputmethod.latin.StringUtils;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||||
|
@ -85,6 +84,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
|
|
||||||
// Miscellaneous constants
|
// Miscellaneous constants
|
||||||
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
|
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
|
||||||
|
private static final float UNDEFINED_RATIO = -1.0f;
|
||||||
|
private static final int UNDEFINED_DIMENSION = -1;
|
||||||
|
|
||||||
// XML attributes
|
// XML attributes
|
||||||
protected final float mVerticalCorrection;
|
protected final float mVerticalCorrection;
|
||||||
protected final int mMoreKeysLayout;
|
protected final int mMoreKeysLayout;
|
||||||
|
@ -217,26 +219,20 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
|
|
||||||
public KeyDrawParams(final TypedArray a) {
|
public KeyDrawParams(final TypedArray a) {
|
||||||
mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
|
mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
|
||||||
if (!ResourceUtils.isValidFraction(mKeyLetterRatio = ResourceUtils.getFraction(a,
|
if (!isValidFraction(mKeyLetterRatio = getFraction(a,
|
||||||
R.styleable.KeyboardView_keyLetterSize))) {
|
R.styleable.KeyboardView_keyLetterSize))) {
|
||||||
mKeyLetterSize = ResourceUtils.getDimensionPixelSize(a,
|
mKeyLetterSize = getDimensionPixelSize(a, R.styleable.KeyboardView_keyLetterSize);
|
||||||
R.styleable.KeyboardView_keyLetterSize);
|
|
||||||
}
|
}
|
||||||
if (!ResourceUtils.isValidFraction(mKeyLabelRatio = ResourceUtils.getFraction(a,
|
if (!isValidFraction(mKeyLabelRatio = getFraction(a,
|
||||||
R.styleable.KeyboardView_keyLabelSize))) {
|
R.styleable.KeyboardView_keyLabelSize))) {
|
||||||
mKeyLabelSize = ResourceUtils.getDimensionPixelSize(a,
|
mKeyLabelSize = getDimensionPixelSize(a, R.styleable.KeyboardView_keyLabelSize);
|
||||||
R.styleable.KeyboardView_keyLabelSize);
|
|
||||||
}
|
}
|
||||||
mKeyLargeLabelRatio = ResourceUtils.getFraction(a,
|
mKeyLargeLabelRatio = getFraction(a, R.styleable.KeyboardView_keyLargeLabelRatio);
|
||||||
R.styleable.KeyboardView_keyLargeLabelRatio);
|
mKeyLargeLetterRatio = getFraction(a, R.styleable.KeyboardView_keyLargeLetterRatio);
|
||||||
mKeyLargeLetterRatio = ResourceUtils.getFraction(a,
|
mKeyHintLetterRatio = getFraction(a, R.styleable.KeyboardView_keyHintLetterRatio);
|
||||||
R.styleable.KeyboardView_keyLargeLetterRatio);
|
mKeyShiftedLetterHintRatio = getFraction(a,
|
||||||
mKeyHintLetterRatio = ResourceUtils.getFraction(a,
|
|
||||||
R.styleable.KeyboardView_keyHintLetterRatio);
|
|
||||||
mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(a,
|
|
||||||
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
|
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
|
||||||
mKeyHintLabelRatio = ResourceUtils.getFraction(a,
|
mKeyHintLabelRatio = getFraction(a, R.styleable.KeyboardView_keyHintLabelRatio);
|
||||||
R.styleable.KeyboardView_keyHintLabelRatio);
|
|
||||||
mKeyLabelHorizontalPadding = a.getDimension(
|
mKeyLabelHorizontalPadding = a.getDimension(
|
||||||
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
|
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
|
||||||
mKeyHintLetterPadding = a.getDimension(
|
mKeyHintLetterPadding = a.getDimension(
|
||||||
|
@ -267,10 +263,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
mKeyTypeface = (keyboard.mKeyTypeface != null)
|
mKeyTypeface = (keyboard.mKeyTypeface != null)
|
||||||
? keyboard.mKeyTypeface : mKeyTypefaceFromKeyboardView;
|
? keyboard.mKeyTypeface : mKeyTypefaceFromKeyboardView;
|
||||||
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
||||||
if (ResourceUtils.isValidFraction(mKeyLetterRatio)) {
|
if (isValidFraction(mKeyLetterRatio)) {
|
||||||
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
||||||
}
|
}
|
||||||
if (ResourceUtils.isValidFraction(mKeyLabelRatio)) {
|
if (isValidFraction(mKeyLabelRatio)) {
|
||||||
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
||||||
}
|
}
|
||||||
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
||||||
|
@ -345,15 +341,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
R.styleable.KeyboardView_keyPreviewOffset, 0);
|
R.styleable.KeyboardView_keyPreviewOffset, 0);
|
||||||
mPreviewHeight = a.getDimensionPixelSize(
|
mPreviewHeight = a.getDimensionPixelSize(
|
||||||
R.styleable.KeyboardView_keyPreviewHeight, 80);
|
R.styleable.KeyboardView_keyPreviewHeight, 80);
|
||||||
mPreviewTextRatio = ResourceUtils.getFraction(a,
|
mPreviewTextRatio = getFraction(a, R.styleable.KeyboardView_keyPreviewTextRatio);
|
||||||
R.styleable.KeyboardView_keyPreviewTextRatio);
|
|
||||||
mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
|
mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
|
||||||
mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
|
mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateParams(final Keyboard keyboard, final KeyDrawParams keyDrawParams) {
|
public void updateParams(final Keyboard keyboard, final KeyDrawParams keyDrawParams) {
|
||||||
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
||||||
if (ResourceUtils.isValidFraction(mPreviewTextRatio)) {
|
if (isValidFraction(mPreviewTextRatio)) {
|
||||||
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
|
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
|
||||||
}
|
}
|
||||||
mKeyLetterSize = keyDrawParams.mKeyLetterSize;
|
mKeyLetterSize = keyDrawParams.mKeyLetterSize;
|
||||||
|
@ -392,6 +387,26 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isValidFraction(final float fraction) {
|
||||||
|
return fraction >= 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float getFraction(final TypedArray a, final int index) {
|
||||||
|
final TypedValue value = a.peekValue(index);
|
||||||
|
if (value == null || value.type != TypedValue.TYPE_FRACTION) {
|
||||||
|
return UNDEFINED_RATIO;
|
||||||
|
}
|
||||||
|
return a.getFraction(index, 1, 1, UNDEFINED_RATIO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getDimensionPixelSize(final TypedArray a, final int index) {
|
||||||
|
final TypedValue value = a.peekValue(index);
|
||||||
|
if (value == null || value.type != TypedValue.TYPE_DIMENSION) {
|
||||||
|
return UNDEFINED_DIMENSION;
|
||||||
|
}
|
||||||
|
return a.getDimensionPixelSize(index, UNDEFINED_DIMENSION);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
|
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
|
||||||
* view will re-layout itself to accommodate the keyboard.
|
* view will re-layout itself to accommodate the keyboard.
|
||||||
|
|
|
@ -17,16 +17,11 @@
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.TypedValue;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public final class ResourceUtils {
|
public final class ResourceUtils {
|
||||||
public static final float UNDEFINED_RATIO = -1.0f;
|
|
||||||
public static final int UNDEFINED_DIMENSION = -1;
|
|
||||||
|
|
||||||
private ResourceUtils() {
|
private ResourceUtils() {
|
||||||
// This utility class is not publicly instantiable.
|
// This utility class is not publicly instantiable.
|
||||||
}
|
}
|
||||||
|
@ -50,69 +45,4 @@ public final class ResourceUtils {
|
||||||
}
|
}
|
||||||
return sDeviceOverrideValueMap.get(key);
|
return sDeviceOverrideValueMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidFraction(final float fraction) {
|
|
||||||
return fraction >= 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getFraction(final TypedArray a, final int index, final float defValue) {
|
|
||||||
final TypedValue value = a.peekValue(index);
|
|
||||||
if (value == null || !isFractionValue(value)) {
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
return a.getFraction(index, 1, 1, defValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getFraction(final TypedArray a, final int index) {
|
|
||||||
return getFraction(a, index, UNDEFINED_RATIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getDimensionPixelSize(final TypedArray a, final int index) {
|
|
||||||
final TypedValue value = a.peekValue(index);
|
|
||||||
if (value == null || !isDimensionValue(value)) {
|
|
||||||
return ResourceUtils.UNDEFINED_DIMENSION;
|
|
||||||
}
|
|
||||||
return a.getDimensionPixelSize(index, ResourceUtils.UNDEFINED_DIMENSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getDimensionOrFraction(TypedArray a, int index, int base,
|
|
||||||
float defValue) {
|
|
||||||
final TypedValue value = a.peekValue(index);
|
|
||||||
if (value == null) {
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
if (isFractionValue(value)) {
|
|
||||||
return a.getFraction(index, base, base, defValue);
|
|
||||||
} else if (isDimensionValue(value)) {
|
|
||||||
return a.getDimension(index, defValue);
|
|
||||||
}
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getEnumValue(TypedArray a, int index, int defValue) {
|
|
||||||
final TypedValue value = a.peekValue(index);
|
|
||||||
if (value == null) {
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
if (isIntegerValue(value)) {
|
|
||||||
return a.getInt(index, defValue);
|
|
||||||
}
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFractionValue(TypedValue v) {
|
|
||||||
return v.type == TypedValue.TYPE_FRACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isDimensionValue(TypedValue v) {
|
|
||||||
return v.type == TypedValue.TYPE_DIMENSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIntegerValue(TypedValue v) {
|
|
||||||
return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStringValue(TypedValue v) {
|
|
||||||
return v.type == TypedValue.TYPE_STRING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ import com.android.inputmethod.latin.AutoCorrection;
|
||||||
import com.android.inputmethod.latin.CollectionUtils;
|
import com.android.inputmethod.latin.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.ResourceUtils;
|
|
||||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||||
import com.android.inputmethod.latin.SuggestedWords;
|
import com.android.inputmethod.latin.SuggestedWords;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
@ -197,15 +196,15 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripViewStyle);
|
R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripViewStyle);
|
||||||
mSuggestionStripOption = a.getInt(
|
mSuggestionStripOption = a.getInt(
|
||||||
R.styleable.SuggestionStripView_suggestionStripOption, 0);
|
R.styleable.SuggestionStripView_suggestionStripOption, 0);
|
||||||
final float alphaValidTypedWord = ResourceUtils.getFraction(a,
|
final float alphaValidTypedWord = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaValidTypedWord, 1.0f);
|
R.styleable.SuggestionStripView_alphaValidTypedWord, 1.0f);
|
||||||
final float alphaTypedWord = ResourceUtils.getFraction(a,
|
final float alphaTypedWord = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaTypedWord, 1.0f);
|
R.styleable.SuggestionStripView_alphaTypedWord, 1.0f);
|
||||||
final float alphaAutoCorrect = ResourceUtils.getFraction(a,
|
final float alphaAutoCorrect = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaAutoCorrect, 1.0f);
|
R.styleable.SuggestionStripView_alphaAutoCorrect, 1.0f);
|
||||||
final float alphaSuggested = ResourceUtils.getFraction(a,
|
final float alphaSuggested = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaSuggested, 1.0f);
|
R.styleable.SuggestionStripView_alphaSuggested, 1.0f);
|
||||||
mAlphaObsoleted = ResourceUtils.getFraction(a,
|
mAlphaObsoleted = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaSuggested, 1.0f);
|
R.styleable.SuggestionStripView_alphaSuggested, 1.0f);
|
||||||
mColorValidTypedWord = applyAlpha(a.getColor(
|
mColorValidTypedWord = applyAlpha(a.getColor(
|
||||||
R.styleable.SuggestionStripView_colorValidTypedWord, 0), alphaValidTypedWord);
|
R.styleable.SuggestionStripView_colorValidTypedWord, 0), alphaValidTypedWord);
|
||||||
|
@ -218,13 +217,13 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
mSuggestionsCountInStrip = a.getInt(
|
mSuggestionsCountInStrip = a.getInt(
|
||||||
R.styleable.SuggestionStripView_suggestionsCountInStrip,
|
R.styleable.SuggestionStripView_suggestionsCountInStrip,
|
||||||
DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
|
DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
|
||||||
mCenterSuggestionWeight = ResourceUtils.getFraction(a,
|
mCenterSuggestionWeight = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_centerSuggestionPercentile,
|
R.styleable.SuggestionStripView_centerSuggestionPercentile,
|
||||||
DEFAULT_CENTER_SUGGESTION_PERCENTILE);
|
DEFAULT_CENTER_SUGGESTION_PERCENTILE);
|
||||||
mMaxMoreSuggestionsRow = a.getInt(
|
mMaxMoreSuggestionsRow = a.getInt(
|
||||||
R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
|
R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
|
||||||
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
|
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
|
||||||
mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
|
mMinMoreSuggestionsWidth = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
|
R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
|
@ -279,6 +278,10 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
return new BitmapDrawable(res, buffer);
|
return new BitmapDrawable(res, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float getFraction(final TypedArray a, final int index, final float defValue) {
|
||||||
|
return a.getFraction(index, 1, 1, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
private CharSequence getStyledSuggestionWord(SuggestedWords suggestedWords, int pos) {
|
private CharSequence getStyledSuggestionWord(SuggestedWords suggestedWords, int pos) {
|
||||||
final CharSequence word = suggestedWords.getWord(pos);
|
final CharSequence word = suggestedWords.getWord(pos);
|
||||||
final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect();
|
final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect();
|
||||||
|
|
Loading…
Reference in New Issue