Remove "dimension|fraction" format from Key and Keyboard attributes
Change-Id: Ieec8b7f5ccdf2a57bcc539dcb5313b6353f926d7
This commit is contained in:
parent
83f173cccd
commit
5ee2d79e41
6 changed files with 79 additions and 75 deletions
|
@ -173,18 +173,18 @@
|
||||||
<attr name="themeId" format="integer" />
|
<attr name="themeId" format="integer" />
|
||||||
<!-- Touch position correction -->
|
<!-- Touch position correction -->
|
||||||
<attr name="touchPositionCorrectionData" format="reference" />
|
<attr name="touchPositionCorrectionData" format="reference" />
|
||||||
<!-- Keyboard top, bottom, both horizontal edges paddings. -->
|
<!-- Keyboard top, bottom edges paddings, in propotion of keyboard height. -->
|
||||||
<attr name="keyboardTopPadding" format="dimension|fraction" />
|
<attr name="keyboardTopPadding" format="fraction" />
|
||||||
<attr name="keyboardBottomPadding" format="dimension|fraction" />
|
<attr name="keyboardBottomPadding" format="fraction" />
|
||||||
<attr name="keyboardHorizontalEdgesPadding" format="dimension|fraction" />
|
<!-- Keyboard both horizontal edges paddings, in propotion of keyboard width. -->
|
||||||
<!-- Default height of a row (key height + vertical gap), in pixels or percentage of
|
<attr name="keyboardHorizontalEdgesPadding" format="fraction" />
|
||||||
|
<!-- Default height of a row (key height + vertical gap), in pixels or in the proportion of
|
||||||
keyboard height. -->
|
keyboard height. -->
|
||||||
<attr name="rowHeight" format="dimension|fraction" />
|
<attr name="rowHeight" format="dimension|fraction" />
|
||||||
<!-- Default horizontal gap between keys, in pixels or percentage of keyboard width. -->
|
<!-- Default horizontal gap between keys, in the proportion of keyboard width. -->
|
||||||
<attr name="horizontalGap" format="dimension|fraction" />
|
<attr name="horizontalGap" format="fraction" />
|
||||||
<!-- Default vertical gap between rows of keys, in pixels or percentage of keyboard
|
<!-- Default vertical gap between rows of keys, in the proportion of keyboard height. -->
|
||||||
height. -->
|
<attr name="verticalGap" format="fraction" />
|
||||||
<attr name="verticalGap" format="dimension|fraction" />
|
|
||||||
<!-- More keys keyboard layout template -->
|
<!-- More keys keyboard layout template -->
|
||||||
<attr name="moreKeysTemplate" format="reference" />
|
<attr name="moreKeysTemplate" format="reference" />
|
||||||
<!-- Icon set for key top and key preview.
|
<!-- Icon set for key top and key preview.
|
||||||
|
@ -288,19 +288,20 @@
|
||||||
<attr name="keyIconPreview" format="string" />
|
<attr name="keyIconPreview" format="string" />
|
||||||
<!-- The key style to specify a set of key attributes defined by <key_style/> -->
|
<!-- The key style to specify a set of key attributes defined by <key_style/> -->
|
||||||
<attr name="keyStyle" format="string" />
|
<attr name="keyStyle" format="string" />
|
||||||
<!-- Visual insets -->
|
<!-- Visual insets, in the proportion of keyboard width. -->
|
||||||
<attr name="visualInsetsLeft" format="dimension|fraction" />
|
<attr name="visualInsetsLeft" format="fraction" />
|
||||||
<attr name="visualInsetsRight" format="dimension|fraction" />
|
<attr name="visualInsetsRight" format="fraction" />
|
||||||
<!-- Width of the key, in pixels or percentage of display width.
|
<!-- Width of the key, in the proportion of keyboard width.
|
||||||
If the value is fillRight, the actual key width will be determined to fill out the area
|
If the value is fillRight, the actual key width will be determined to fill out the
|
||||||
up to the right edge of the keyboard. -->
|
area up to the right edge of the keyboard. -->
|
||||||
<!-- This should be aligned with KeyboardBuilder.Row.KEYWIDTH_* -->
|
<!-- This should be aligned with KeyboardBuilder.Row.KEYWIDTH_* -->
|
||||||
<attr name="keyWidth" format="dimension|fraction|enum">
|
<attr name="keyWidth" format="fraction|enum">
|
||||||
<enum name="fillRight" value="-1" />
|
<enum name="fillRight" value="-1" />
|
||||||
</attr>
|
</attr>
|
||||||
<!-- The X-coordinate of upper right corner of this key including horizontal gap.
|
<!-- The X-coordinate of upper right corner of this key including horizontal gap, in the
|
||||||
|
proportion of keyboard width.
|
||||||
If the value is negative, the origin is the right edge of the keyboard. -->
|
If the value is negative, the origin is the right edge of the keyboard. -->
|
||||||
<attr name="keyXPos" format="dimension|fraction" />
|
<attr name="keyXPos" format="fraction" />
|
||||||
|
|
||||||
<!-- Key top visual attributes -->
|
<!-- Key top visual attributes -->
|
||||||
<attr name="keyTypeface" format="enum">
|
<attr name="keyTypeface" format="enum">
|
||||||
|
|
|
@ -119,9 +119,9 @@
|
||||||
name="MoreKeysKeyboard"
|
name="MoreKeysKeyboard"
|
||||||
parent="Keyboard"
|
parent="Keyboard"
|
||||||
>
|
>
|
||||||
<item name="keyboardTopPadding">0dp</item>
|
<item name="keyboardTopPadding">0%p</item>
|
||||||
<item name="keyboardBottomPadding">0dp</item>
|
<item name="keyboardBottomPadding">0%p</item>
|
||||||
<item name="horizontalGap">0dp</item>
|
<item name="horizontalGap">0%p</item>
|
||||||
<item name="touchPositionCorrectionData">@null</item>
|
<item name="touchPositionCorrectionData">@null</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
|
@ -224,9 +224,9 @@
|
||||||
name="MoreKeysKeyboard.Stone"
|
name="MoreKeysKeyboard.Stone"
|
||||||
parent="Keyboard.Stone"
|
parent="Keyboard.Stone"
|
||||||
>
|
>
|
||||||
<item name="keyboardTopPadding">0dp</item>
|
<item name="keyboardTopPadding">0%p</item>
|
||||||
<item name="keyboardBottomPadding">0dp</item>
|
<item name="keyboardBottomPadding">0%p</item>
|
||||||
<item name="horizontalGap">0dp</item>
|
<item name="horizontalGap">0%p</item>
|
||||||
<item name="touchPositionCorrectionData">@null</item>
|
<item name="touchPositionCorrectionData">@null</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
|
@ -294,9 +294,9 @@
|
||||||
name="MoreKeysKeyboard.Gingerbread"
|
name="MoreKeysKeyboard.Gingerbread"
|
||||||
parent="Keyboard.Gingerbread"
|
parent="Keyboard.Gingerbread"
|
||||||
>
|
>
|
||||||
<item name="keyboardTopPadding">0dp</item>
|
<item name="keyboardTopPadding">0%p</item>
|
||||||
<item name="keyboardBottomPadding">0dp</item>
|
<item name="keyboardBottomPadding">0%p</item>
|
||||||
<item name="horizontalGap">0dp</item>
|
<item name="horizontalGap">0%p</item>
|
||||||
<item name="touchPositionCorrectionData">@null</item>
|
<item name="touchPositionCorrectionData">@null</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
|
@ -353,9 +353,9 @@
|
||||||
name="MoreKeysKeyboard.IceCreamSandwich"
|
name="MoreKeysKeyboard.IceCreamSandwich"
|
||||||
parent="Keyboard.IceCreamSandwich"
|
parent="Keyboard.IceCreamSandwich"
|
||||||
>
|
>
|
||||||
<item name="keyboardTopPadding">0dp</item>
|
<item name="keyboardTopPadding">0%p</item>
|
||||||
<item name="keyboardBottomPadding">0dp</item>
|
<item name="keyboardBottomPadding">0%p</item>
|
||||||
<item name="horizontalGap">0dp</item>
|
<item name="horizontalGap">0%p</item>
|
||||||
<item name="touchPositionCorrectionData">@null</item>
|
<item name="touchPositionCorrectionData">@null</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
|
|
|
@ -41,7 +41,6 @@ import com.android.inputmethod.keyboard.internal.KeyboardRow;
|
||||||
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
|
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
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;
|
||||||
|
@ -225,8 +224,8 @@ public class Key implements Comparable<Key> {
|
||||||
public Key(final Resources res, final KeyboardParams params, final KeyboardRow row,
|
public Key(final Resources res, final KeyboardParams params, final KeyboardRow row,
|
||||||
final XmlPullParser parser) throws XmlPullParserException {
|
final XmlPullParser parser) throws XmlPullParserException {
|
||||||
final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
|
final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
|
||||||
final int keyHeight = row.mRowHeight;
|
final int rowHeight = row.mRowHeight;
|
||||||
mHeight = keyHeight - params.mVerticalGap;
|
mHeight = rowHeight - params.mVerticalGap;
|
||||||
|
|
||||||
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
|
@ -241,17 +240,18 @@ public class Key implements Comparable<Key> {
|
||||||
mY = keyYPos;
|
mY = keyYPos;
|
||||||
mWidth = Math.round(keyWidth - horizontalGap);
|
mWidth = Math.round(keyWidth - horizontalGap);
|
||||||
mHitBox.set(Math.round(keyXPos), keyYPos, Math.round(keyXPos + keyWidth) + 1,
|
mHitBox.set(Math.round(keyXPos), keyYPos, Math.round(keyXPos + keyWidth) + 1,
|
||||||
keyYPos + keyHeight);
|
keyYPos + rowHeight);
|
||||||
// Update row to have current x coordinate.
|
// Update row to have current x coordinate.
|
||||||
row.setXPos(keyXPos + keyWidth);
|
row.setXPos(keyXPos + keyWidth);
|
||||||
|
|
||||||
mBackgroundType = style.getInt(keyAttr,
|
mBackgroundType = style.getInt(keyAttr,
|
||||||
R.styleable.Keyboard_Key_backgroundType, row.getDefaultBackgroundType());
|
R.styleable.Keyboard_Key_backgroundType, row.getDefaultBackgroundType());
|
||||||
|
|
||||||
final int visualInsetsLeft = Math.round(ResourceUtils.getDimensionOrFraction(keyAttr,
|
final int baseWidth = params.mBaseWidth;
|
||||||
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0));
|
final int visualInsetsLeft = Math.round(keyAttr.getFraction(
|
||||||
final int visualInsetsRight = Math.round(ResourceUtils.getDimensionOrFraction(keyAttr,
|
R.styleable.Keyboard_Key_visualInsetsLeft, baseWidth, baseWidth, 0));
|
||||||
R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0));
|
final int visualInsetsRight = Math.round(keyAttr.getFraction(
|
||||||
|
R.styleable.Keyboard_Key_visualInsetsRight, baseWidth, baseWidth, 0));
|
||||||
mIconId = KeySpecParser.getIconId(style.getString(keyAttr,
|
mIconId = KeySpecParser.getIconId(style.getString(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyIcon));
|
R.styleable.Keyboard_Key_keyIcon));
|
||||||
final int disabledIconId = KeySpecParser.getIconId(style.getString(keyAttr,
|
final int disabledIconId = KeySpecParser.getIconId(style.getString(keyAttr,
|
||||||
|
|
|
@ -30,11 +30,11 @@ import com.android.inputmethod.latin.Constants;
|
||||||
* <p>The layout file for a keyboard contains XML that looks like the following snippet:</p>
|
* <p>The layout file for a keyboard contains XML that looks like the following snippet:</p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* <Keyboard
|
* <Keyboard
|
||||||
* latin:keyWidth="%10p"
|
* latin:keyWidth="10%p"
|
||||||
* latin:keyHeight="50px"
|
* latin:rowHeight="50px"
|
||||||
* latin:horizontalGap="2px"
|
* latin:horizontalGap="2%p"
|
||||||
* latin:verticalGap="2px" >
|
* latin:verticalGap="2%p" >
|
||||||
* <Row latin:keyWidth="32px" >
|
* <Row latin:keyWidth="10%p" >
|
||||||
* <Key latin:keyLabel="A" />
|
* <Key latin:keyLabel="A" />
|
||||||
* ...
|
* ...
|
||||||
* </Row>
|
* </Row>
|
||||||
|
|
|
@ -235,31 +235,36 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
try {
|
try {
|
||||||
final KeyboardParams params = mParams;
|
final KeyboardParams params = mParams;
|
||||||
params.mOccupiedHeight = params.mId.mHeight;
|
final int height = params.mId.mHeight;
|
||||||
params.mOccupiedWidth = params.mId.mWidth;
|
final int width = params.mId.mWidth;
|
||||||
params.mTopPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mOccupiedHeight = height;
|
||||||
R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0);
|
params.mOccupiedWidth = width;
|
||||||
params.mBottomPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mTopPadding = (int)keyboardAttr.getFraction(
|
||||||
R.styleable.Keyboard_keyboardBottomPadding, params.mOccupiedHeight, 0);
|
R.styleable.Keyboard_keyboardTopPadding, height, height, 0);
|
||||||
params.mHorizontalEdgesPadding = (int)ResourceUtils.getDimensionOrFraction(
|
params.mBottomPadding = (int)keyboardAttr.getFraction(
|
||||||
keyboardAttr,
|
R.styleable.Keyboard_keyboardBottomPadding, height, height, 0);
|
||||||
R.styleable.Keyboard_keyboardHorizontalEdgesPadding,
|
// TODO: Split keyboardHorizontalEdgesPadding into two, keyboardLeftPaddings and
|
||||||
mParams.mOccupiedWidth, 0);
|
// keyboardRightPaddings.
|
||||||
|
params.mHorizontalEdgesPadding = (int)keyboardAttr.getFraction(
|
||||||
|
R.styleable.Keyboard_keyboardHorizontalEdgesPadding, width, width, 0);
|
||||||
|
|
||||||
params.mBaseWidth = params.mOccupiedWidth - params.mHorizontalEdgesPadding * 2
|
final int baseWidth = params.mOccupiedWidth - params.mHorizontalEdgesPadding * 2
|
||||||
- params.mHorizontalCenterPadding;
|
- params.mHorizontalCenterPadding;
|
||||||
params.mDefaultKeyWidth = (int)ResourceUtils.getDimensionOrFraction(keyAttr,
|
params.mBaseWidth = baseWidth;
|
||||||
R.styleable.Keyboard_Key_keyWidth, params.mBaseWidth,
|
params.mDefaultKeyWidth = (int)keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
|
||||||
params.mBaseWidth / DEFAULT_KEYBOARD_COLUMNS);
|
baseWidth, baseWidth, baseWidth / DEFAULT_KEYBOARD_COLUMNS);
|
||||||
params.mHorizontalGap = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mHorizontalGap = (int)keyboardAttr.getFraction(
|
||||||
R.styleable.Keyboard_horizontalGap, params.mBaseWidth, 0);
|
R.styleable.Keyboard_horizontalGap, baseWidth, baseWidth, 0);
|
||||||
params.mVerticalGap = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
// TODO: Fix keyboard geometry calculation clearer. Historically vertical gap between
|
||||||
R.styleable.Keyboard_verticalGap, params.mOccupiedHeight, 0);
|
// rows are determined based on the entire keyboard height including top and bottom
|
||||||
params.mBaseHeight = params.mOccupiedHeight - params.mTopPadding
|
// 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.mBottomPadding + params.mVerticalGap;
|
||||||
|
params.mBaseHeight = baseHeight;
|
||||||
params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_rowHeight, params.mBaseHeight,
|
R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS);
|
||||||
params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
|
|
||||||
|
|
||||||
params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
|
params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
|
||||||
|
|
||||||
|
|
|
@ -54,17 +54,16 @@ public final class KeyboardRow {
|
||||||
public KeyboardRow(final Resources res, final KeyboardParams params, final XmlPullParser parser,
|
public KeyboardRow(final Resources res, final KeyboardParams params, final XmlPullParser parser,
|
||||||
final int y) {
|
final int y) {
|
||||||
mParams = params;
|
mParams = params;
|
||||||
TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard);
|
R.styleable.Keyboard);
|
||||||
mRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
|
mRowHeight = (int)ResourceUtils.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),
|
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
mDefaultKeyWidth = ResourceUtils.getDimensionOrFraction(keyAttr,
|
mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
|
||||||
R.styleable.Keyboard_Key_keyWidth,
|
params.mBaseWidth, params.mBaseWidth, params.mDefaultKeyWidth);
|
||||||
params.mBaseWidth, params.mDefaultKeyWidth);
|
|
||||||
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
|
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
|
||||||
Key.BACKGROUND_TYPE_NORMAL);
|
Key.BACKGROUND_TYPE_NORMAL);
|
||||||
keyAttr.recycle();
|
keyAttr.recycle();
|
||||||
|
@ -115,8 +114,8 @@ public final class KeyboardRow {
|
||||||
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 = keyAttr.getFraction(R.styleable.Keyboard_Key_keyXPos,
|
||||||
R.styleable.Keyboard_Key_keyXPos, mParams.mBaseWidth, 0);
|
mParams.mBaseWidth, 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
|
||||||
// keyboardWidth + keyXPos.
|
// keyboardWidth + keyXPos.
|
||||||
|
@ -146,9 +145,8 @@ public final class KeyboardRow {
|
||||||
// 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 keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
|
||||||
R.styleable.Keyboard_Key_keyWidth,
|
mParams.mBaseWidth, mParams.mBaseWidth, mDefaultKeyWidth);
|
||||||
mParams.mBaseWidth, mDefaultKeyWidth);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue