Calculate x coordinate with floating point
This change also fixes some keyboard layouts a bit. Bug: 5245837 Change-Id: I5929e656763b150e71afe89238386904da214e21main
parent
3e0511e304
commit
b58925ea0d
|
@ -29,8 +29,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="й"
|
latin:keyLabel="й"
|
||||||
latin:keyHintLabel="1"
|
latin:keyHintLabel="1"
|
||||||
latin:moreKeys="1"
|
latin:moreKeys="1" />
|
||||||
latin:keyWidth="8.75%p" />
|
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="ц"
|
latin:keyLabel="ц"
|
||||||
latin:keyHintLabel="2"
|
latin:keyHintLabel="2"
|
||||||
|
|
|
@ -24,13 +24,12 @@
|
||||||
<include
|
<include
|
||||||
latin:keyboardLayout="@xml/kbd_key_styles" />
|
latin:keyboardLayout="@xml/kbd_key_styles" />
|
||||||
<Row
|
<Row
|
||||||
latin:keyWidth="9.09%p"
|
latin:keyWidth="9.091%p"
|
||||||
>
|
>
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="q"
|
latin:keyLabel="q"
|
||||||
latin:keyHintLabel="1"
|
latin:keyHintLabel="1"
|
||||||
latin:moreKeys="@string/more_keys_for_q"
|
latin:moreKeys="@string/more_keys_for_q" />
|
||||||
latin:keyWidth="8.75%p" />
|
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="w"
|
latin:keyLabel="w"
|
||||||
latin:keyHintLabel="2"
|
latin:keyHintLabel="2"
|
||||||
|
@ -72,7 +71,7 @@
|
||||||
latin:keyWidth="fillRight" />
|
latin:keyWidth="fillRight" />
|
||||||
</Row>
|
</Row>
|
||||||
<Row
|
<Row
|
||||||
latin:keyWidth="9.09%p"
|
latin:keyWidth="9.091%p"
|
||||||
>
|
>
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="a"
|
latin:keyLabel="a"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<include
|
<include
|
||||||
latin:keyboardLayout="@xml/kbd_key_styles" />
|
latin:keyboardLayout="@xml/kbd_key_styles" />
|
||||||
<Row
|
<Row
|
||||||
latin:keyWidth="9.09%p"
|
latin:keyWidth="9.091%p"
|
||||||
>
|
>
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="љ"
|
latin:keyLabel="љ"
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
latin:keyWidth="fillRight" />
|
latin:keyWidth="fillRight" />
|
||||||
</Row>
|
</Row>
|
||||||
<Row
|
<Row
|
||||||
latin:keyWidth="9.09%p"
|
latin:keyWidth="9.091%p"
|
||||||
>
|
>
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="а" />
|
latin:keyLabel="а" />
|
||||||
|
@ -98,10 +98,11 @@
|
||||||
latin:keyWidth="fillRight" />
|
latin:keyWidth="fillRight" />
|
||||||
</Row>
|
</Row>
|
||||||
<Row
|
<Row
|
||||||
latin:keyWidth="8.90%p"
|
latin:keyWidth="8.5%p"
|
||||||
>
|
>
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="shiftKeyStyle" />
|
latin:keyStyle="shiftKeyStyle"
|
||||||
|
latin:keyWidth="11.75%p" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="ѕ" />
|
latin:keyLabel="ѕ" />
|
||||||
<Key
|
<Key
|
||||||
|
|
|
@ -253,126 +253,115 @@ public class Key {
|
||||||
|
|
||||||
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard);
|
R.styleable.Keyboard);
|
||||||
int keyWidth;
|
mHeight = (int)KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
||||||
try {
|
R.styleable.Keyboard_rowHeight, params.mHeight, row.mRowHeight)
|
||||||
mHeight = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
- params.mVerticalGap;
|
||||||
R.styleable.Keyboard_rowHeight,
|
final float horizontalGap = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
||||||
params.mHeight, row.mRowHeight) - params.mVerticalGap;
|
R.styleable.Keyboard_horizontalGap, params.mWidth, params.mHorizontalGap);
|
||||||
mHorizontalGap = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
mVerticalGap = params.mVerticalGap;
|
||||||
R.styleable.Keyboard_horizontalGap,
|
float keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
||||||
params.mWidth, params.mHorizontalGap);
|
R.styleable.Keyboard_keyWidth, params.mWidth, row.mDefaultKeyWidth);
|
||||||
mVerticalGap = params.mVerticalGap;
|
keyboardAttr.recycle();
|
||||||
keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
|
||||||
R.styleable.Keyboard_keyWidth,
|
|
||||||
params.mWidth, row.mDefaultKeyWidth);
|
|
||||||
} finally {
|
|
||||||
keyboardAttr.recycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
try {
|
|
||||||
final KeyStyle style;
|
|
||||||
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) {
|
|
||||||
String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle);
|
|
||||||
style = keyStyles.getKeyStyle(styleName);
|
|
||||||
if (style == null)
|
|
||||||
throw new ParseException("Unknown key style: " + styleName, parser);
|
|
||||||
} else {
|
|
||||||
style = keyStyles.getEmptyKeyStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
final int keyboardWidth = params.mOccupiedWidth;
|
final KeyStyle style;
|
||||||
final int x = row.mCurrentX;
|
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) {
|
||||||
int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle);
|
||||||
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
|
style = keyStyles.getKeyStyle(styleName);
|
||||||
if (keyXPos < 0) {
|
if (style == null)
|
||||||
// If keyXPos is negative, the actual x-coordinate will be k + keyXPos.
|
throw new ParseException("Unknown key style: " + styleName, parser);
|
||||||
keyXPos += keyboardWidth;
|
} else {
|
||||||
if (keyXPos < x) {
|
style = keyStyles.getEmptyKeyStyle();
|
||||||
// keyXPos shouldn't be less than x because drawable area for this key starts
|
|
||||||
// at x. Or, this key will overlaps the adjacent key on its left hand side.
|
|
||||||
keyXPos = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (keyWidth == KEYWIDTH_FILL_RIGHT) {
|
|
||||||
// If keyWidth is zero, the actual key width will be determined to fill out the
|
|
||||||
// area up to the right edge of the keyboard.
|
|
||||||
keyWidth = keyboardWidth - keyXPos;
|
|
||||||
} else if (keyWidth <= KEYWIDTH_FILL_BOTH) {
|
|
||||||
// If keyWidth is negative, the actual key width will be determined to fill out the
|
|
||||||
// area between the nearest key on the left hand side and the right edge of the
|
|
||||||
// keyboard.
|
|
||||||
keyXPos = x;
|
|
||||||
keyWidth = keyboardWidth - keyXPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Horizontal gap is divided equally to both sides of the key.
|
|
||||||
mX = keyXPos + mHorizontalGap / 2;
|
|
||||||
mY = row.mCurrentY;
|
|
||||||
mWidth = keyWidth - mHorizontalGap;
|
|
||||||
|
|
||||||
// Update row to have x-coordinate of the right edge of this key.
|
|
||||||
row.mCurrentX = keyXPos + keyWidth;
|
|
||||||
|
|
||||||
final CharSequence[] moreKeys = style.getTextArray(
|
|
||||||
keyAttr, R.styleable.Keyboard_Key_moreKeys);
|
|
||||||
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
|
|
||||||
// config_digit_more_keys_enabled.
|
|
||||||
if (params.mId.isAlphabetKeyboard() && !res.getBoolean(
|
|
||||||
R.bool.config_digit_more_keys_enabled)) {
|
|
||||||
mMoreKeys = MoreKeySpecParser.filterOut(
|
|
||||||
res, moreKeys, MoreKeySpecParser.DIGIT_FILTER);
|
|
||||||
} else {
|
|
||||||
mMoreKeys = moreKeys;
|
|
||||||
}
|
|
||||||
mMaxMoreKeysColumn = style.getInt(keyboardAttr,
|
|
||||||
R.styleable.Keyboard_Key_maxMoreKeysColumn,
|
|
||||||
params.mMaxMiniKeyboardColumn);
|
|
||||||
|
|
||||||
mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
|
|
||||||
mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false);
|
|
||||||
mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false);
|
|
||||||
mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
|
|
||||||
mEdgeFlags = 0;
|
|
||||||
|
|
||||||
final KeyboardIconsSet iconsSet = params.mIconsSet;
|
|
||||||
mVisualInsetsLeft = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_visualInsetsLeft, keyboardWidth, 0);
|
|
||||||
mVisualInsetsRight = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_visualInsetsRight, keyboardWidth, 0);
|
|
||||||
mPreviewIcon = iconsSet.getIcon(style.getInt(
|
|
||||||
keyAttr, R.styleable.Keyboard_Key_keyIconPreview,
|
|
||||||
KeyboardIconsSet.ICON_UNDEFINED));
|
|
||||||
mIcon = iconsSet.getIcon(style.getInt(
|
|
||||||
keyAttr, R.styleable.Keyboard_Key_keyIcon,
|
|
||||||
KeyboardIconsSet.ICON_UNDEFINED));
|
|
||||||
final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
|
|
||||||
KeyboardIconsSet.ICON_UNDEFINED);
|
|
||||||
if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
|
|
||||||
final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
|
|
||||||
params.addShiftedIcon(this, shiftedIcon);
|
|
||||||
}
|
|
||||||
mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
|
|
||||||
|
|
||||||
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
|
|
||||||
mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0);
|
|
||||||
mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
|
|
||||||
// Choose the first letter of the label as primary code if not
|
|
||||||
// specified.
|
|
||||||
final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,
|
|
||||||
Keyboard.CODE_UNSPECIFIED);
|
|
||||||
if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) {
|
|
||||||
final int firstChar = mLabel.charAt(0);
|
|
||||||
mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard);
|
|
||||||
} else if (code != Keyboard.CODE_UNSPECIFIED) {
|
|
||||||
mCode = code;
|
|
||||||
} else {
|
|
||||||
mCode = Keyboard.CODE_DUMMY;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
keyAttr.recycle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int keyboardWidth = params.mOccupiedWidth;
|
||||||
|
final float x = row.mCurrentX;
|
||||||
|
float keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
|
||||||
|
if (keyXPos < 0) {
|
||||||
|
// If keyXPos is negative, the actual x-coordinate will be keyboardWidth + keyXPos.
|
||||||
|
keyXPos += keyboardWidth;
|
||||||
|
if (keyXPos < x) {
|
||||||
|
// keyXPos shouldn't be less than x because drawable area for this key starts
|
||||||
|
// at x. Or, this key will overlaps the adjacent key on its left hand side.
|
||||||
|
keyXPos = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keyWidth == KEYWIDTH_FILL_RIGHT) {
|
||||||
|
// If keyWidth is zero, the actual key width will be determined to fill out the
|
||||||
|
// area up to the right edge of the keyboard.
|
||||||
|
keyWidth = keyboardWidth - keyXPos;
|
||||||
|
} else if (keyWidth <= KEYWIDTH_FILL_BOTH) {
|
||||||
|
// If keyWidth is negative, the actual key width will be determined to fill out the
|
||||||
|
// area between the nearest key on the left hand side and the right edge of the
|
||||||
|
// keyboard.
|
||||||
|
keyXPos = x;
|
||||||
|
keyWidth = keyboardWidth - keyXPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Horizontal gap is divided equally to both sides of the key.
|
||||||
|
mX = (int) (keyXPos + horizontalGap / 2);
|
||||||
|
mY = row.mCurrentY;
|
||||||
|
mWidth = (int) (keyWidth - horizontalGap);
|
||||||
|
mHorizontalGap = (int) horizontalGap;
|
||||||
|
// Update row to have current x coordinate.
|
||||||
|
row.mCurrentX = keyXPos + keyWidth;
|
||||||
|
|
||||||
|
final CharSequence[] moreKeys = style.getTextArray(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_moreKeys);
|
||||||
|
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
|
||||||
|
// config_digit_more_keys_enabled.
|
||||||
|
if (params.mId.isAlphabetKeyboard()
|
||||||
|
&& !res.getBoolean(R.bool.config_digit_more_keys_enabled)) {
|
||||||
|
mMoreKeys = MoreKeySpecParser.filterOut(res, moreKeys, MoreKeySpecParser.DIGIT_FILTER);
|
||||||
|
} else {
|
||||||
|
mMoreKeys = moreKeys;
|
||||||
|
}
|
||||||
|
mMaxMoreKeysColumn = style.getInt(keyboardAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn,
|
||||||
|
params.mMaxMiniKeyboardColumn);
|
||||||
|
|
||||||
|
mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
|
||||||
|
mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false);
|
||||||
|
mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false);
|
||||||
|
mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
|
||||||
|
mEdgeFlags = 0;
|
||||||
|
|
||||||
|
final KeyboardIconsSet iconsSet = params.mIconsSet;
|
||||||
|
mVisualInsetsLeft = (int) KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_visualInsetsLeft, keyboardWidth, 0);
|
||||||
|
mVisualInsetsRight = (int) KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_visualInsetsRight, keyboardWidth, 0);
|
||||||
|
mPreviewIcon = iconsSet.getIcon(style.getInt(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED));
|
||||||
|
mIcon = iconsSet.getIcon(style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIcon,
|
||||||
|
KeyboardIconsSet.ICON_UNDEFINED));
|
||||||
|
final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
|
||||||
|
KeyboardIconsSet.ICON_UNDEFINED);
|
||||||
|
if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
|
||||||
|
final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
|
||||||
|
params.addShiftedIcon(this, shiftedIcon);
|
||||||
|
}
|
||||||
|
mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
|
||||||
|
|
||||||
|
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
|
||||||
|
mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0);
|
||||||
|
mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
|
||||||
|
// Choose the first letter of the label as primary code if not
|
||||||
|
// specified.
|
||||||
|
final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,
|
||||||
|
Keyboard.CODE_UNSPECIFIED);
|
||||||
|
if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) {
|
||||||
|
final int firstChar = mLabel.charAt(0);
|
||||||
|
mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard);
|
||||||
|
} else if (code != Keyboard.CODE_UNSPECIFIED) {
|
||||||
|
mCode = code;
|
||||||
|
} else {
|
||||||
|
mCode = Keyboard.CODE_DUMMY;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyAttr.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEdgeFlags(int flags) {
|
public void addEdgeFlags(int flags) {
|
||||||
|
|
|
@ -218,14 +218,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
final int displayHeight = mDisplayMetrics.heightPixels;
|
final int displayHeight = mDisplayMetrics.heightPixels;
|
||||||
final int keyboardHeight = (int)keyboardAttr.getDimension(
|
final int keyboardHeight = (int)keyboardAttr.getDimension(
|
||||||
R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
|
R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
|
||||||
final int maxKeyboardHeight = getDimensionOrFraction(keyboardAttr,
|
final int maxKeyboardHeight = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);
|
R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);
|
||||||
int minKeyboardHeight = getDimensionOrFraction(keyboardAttr,
|
int minKeyboardHeight = (int)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 = -getDimensionOrFraction(keyboardAttr,
|
minKeyboardHeight = -(int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2);
|
R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2);
|
||||||
}
|
}
|
||||||
// Keyboard height will not exceed maxKeyboardHeight and will not be less than
|
// Keyboard height will not exceed maxKeyboardHeight and will not be less than
|
||||||
|
@ -233,9 +233,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
mParams.mOccupiedHeight = Math.max(
|
mParams.mOccupiedHeight = Math.max(
|
||||||
Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
|
Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
|
||||||
mParams.mOccupiedWidth = mParams.mId.mWidth;
|
mParams.mOccupiedWidth = mParams.mId.mWidth;
|
||||||
mParams.mTopPadding = getDimensionOrFraction(keyboardAttr,
|
mParams.mTopPadding = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_keyboardTopPadding, mParams.mOccupiedHeight, 0);
|
R.styleable.Keyboard_keyboardTopPadding, mParams.mOccupiedHeight, 0);
|
||||||
mParams.mBottomPadding = getDimensionOrFraction(keyboardAttr,
|
mParams.mBottomPadding = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_keyboardBottomPadding, mParams.mOccupiedHeight, 0);
|
R.styleable.Keyboard_keyboardBottomPadding, mParams.mOccupiedHeight, 0);
|
||||||
|
|
||||||
final int height = mParams.mOccupiedHeight;
|
final int height = mParams.mOccupiedHeight;
|
||||||
|
@ -243,13 +243,13 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
- mParams.mHorizontalCenterPadding;
|
- mParams.mHorizontalCenterPadding;
|
||||||
mParams.mHeight = height;
|
mParams.mHeight = height;
|
||||||
mParams.mWidth = width;
|
mParams.mWidth = width;
|
||||||
mParams.mDefaultKeyWidth = getDimensionOrFraction(keyboardAttr,
|
mParams.mDefaultKeyWidth = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_keyWidth, width, width / 10);
|
R.styleable.Keyboard_keyWidth, width, width / 10);
|
||||||
mParams.mDefaultRowHeight = getDimensionOrFraction(keyboardAttr,
|
mParams.mDefaultRowHeight = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_rowHeight, height, height / 4);
|
R.styleable.Keyboard_rowHeight, height, height / 4);
|
||||||
mParams.mHorizontalGap = getDimensionOrFraction(keyboardAttr,
|
mParams.mHorizontalGap = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_horizontalGap, width, 0);
|
R.styleable.Keyboard_horizontalGap, width, 0);
|
||||||
mParams.mVerticalGap = getDimensionOrFraction(keyboardAttr,
|
mParams.mVerticalGap = (int)getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_verticalGap, height, 0);
|
R.styleable.Keyboard_verticalGap, height, 0);
|
||||||
|
|
||||||
mParams.mIsRtlKeyboard = keyboardAttr.getBoolean(
|
mParams.mIsRtlKeyboard = keyboardAttr.getBoolean(
|
||||||
|
@ -384,13 +384,13 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap))
|
if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap))
|
||||||
throw new IllegalAttribute(parser, "horizontalGap");
|
throw new IllegalAttribute(parser, "horizontalGap");
|
||||||
final int keyboardWidth = mParams.mWidth;
|
final int keyboardWidth = mParams.mWidth;
|
||||||
final int keyWidth = getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth,
|
final float keyWidth = getDimensionOrFraction(keyboardAttr,
|
||||||
keyboardWidth, row.mDefaultKeyWidth);
|
R.styleable.Keyboard_keyWidth, keyboardWidth, row.mDefaultKeyWidth);
|
||||||
keyboardAttr.recycle();
|
keyboardAttr.recycle();
|
||||||
|
|
||||||
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
float keyXPos = getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, row.mCurrentX);
|
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, row.mCurrentX);
|
||||||
if (keyXPos < 0) {
|
if (keyXPos < 0) {
|
||||||
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
|
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
|
||||||
|
@ -688,24 +688,23 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
private void endKeyboard() {
|
private void endKeyboard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSpacer(int keyXPos, int width, Row row) {
|
private void setSpacer(float keyXPos, float width, Row row) {
|
||||||
row.mCurrentX = keyXPos + width;
|
row.mCurrentX = keyXPos + width;
|
||||||
mLeftEdge = false;
|
mLeftEdge = false;
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
|
public static float getDimensionOrFraction(TypedArray a, int index, int base, float defValue) {
|
||||||
final TypedValue value = a.peekValue(index);
|
final TypedValue value = a.peekValue(index);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return defValue;
|
return defValue;
|
||||||
if (isFractionValue(value)) {
|
if (isFractionValue(value)) {
|
||||||
// Round it to avoid values like 47.9999 from getting truncated
|
return a.getFraction(index, base, base, defValue);
|
||||||
return Math.round(a.getFraction(index, base, base, defValue));
|
|
||||||
} else if (isDimensionValue(value)) {
|
} else if (isDimensionValue(value)) {
|
||||||
return a.getDimensionPixelOffset(index, defValue);
|
return a.getDimension(index, defValue);
|
||||||
} else if (isIntegerValue(value)) {
|
} else if (isIntegerValue(value)) {
|
||||||
// For enum value.
|
// For enum value.
|
||||||
return a.getInt(index, defValue);
|
return a.getInt(index, 0);
|
||||||
}
|
}
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,13 @@ import com.android.inputmethod.latin.R;
|
||||||
*/
|
*/
|
||||||
public class Row {
|
public class Row {
|
||||||
/** Default width of a key in this row. */
|
/** Default width of a key in this row. */
|
||||||
public final int mDefaultKeyWidth;
|
public final float mDefaultKeyWidth;
|
||||||
/** Default height of a key in this row. */
|
/** Default height of a key in this row. */
|
||||||
public final int mRowHeight;
|
public final int mRowHeight;
|
||||||
|
|
||||||
public final int mCurrentY;
|
public final int mCurrentY;
|
||||||
// Will be updated by {@link Key}'s constructor.
|
// Will be updated by {@link Key}'s constructor.
|
||||||
public int mCurrentX;
|
public float mCurrentX;
|
||||||
|
|
||||||
public Row(Resources res, KeyboardParams params, XmlResourceParser parser, int y) {
|
public Row(Resources res, KeyboardParams params, XmlResourceParser parser, int y) {
|
||||||
final int keyboardWidth = params.mWidth;
|
final int keyboardWidth = params.mWidth;
|
||||||
|
@ -46,11 +46,11 @@ public class Row {
|
||||||
R.styleable.Keyboard);
|
R.styleable.Keyboard);
|
||||||
mDefaultKeyWidth = KeyboardBuilder.getDimensionOrFraction(a,
|
mDefaultKeyWidth = KeyboardBuilder.getDimensionOrFraction(a,
|
||||||
R.styleable.Keyboard_keyWidth, keyboardWidth, params.mDefaultKeyWidth);
|
R.styleable.Keyboard_keyWidth, keyboardWidth, params.mDefaultKeyWidth);
|
||||||
mRowHeight = KeyboardBuilder.getDimensionOrFraction(a,
|
mRowHeight = (int)KeyboardBuilder.getDimensionOrFraction(a,
|
||||||
R.styleable.Keyboard_rowHeight, keyboardHeight, params.mDefaultRowHeight);
|
R.styleable.Keyboard_rowHeight, keyboardHeight, params.mDefaultRowHeight);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
mCurrentY = y;
|
mCurrentY = y;
|
||||||
mCurrentX = 0;
|
mCurrentX = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue