am 48409b9a: Merge "Remove "dimension|fraction" format from Key and Keyboard attributes"

# Via Android (Google) Code Review (1) and Tadashi G. Takaoka (1)
* commit '48409b9ac60fb64eb80d1d8da3452f9ab40f5002':
  Remove "dimension|fraction" format from Key and Keyboard attributes
main
Tadashi G. Takaoka 2013-01-29 20:10:04 -08:00 committed by Android Git Automerger
commit 809e4efa81
6 changed files with 79 additions and 75 deletions

View File

@ -173,18 +173,18 @@
<attr name="themeId" format="integer" />
<!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" />
<!-- Keyboard top, bottom, both horizontal edges paddings. -->
<attr name="keyboardTopPadding" format="dimension|fraction" />
<attr name="keyboardBottomPadding" format="dimension|fraction" />
<attr name="keyboardHorizontalEdgesPadding" format="dimension|fraction" />
<!-- Default height of a row (key height + vertical gap), in pixels or percentage of
<!-- Keyboard top, bottom edges paddings, in propotion of keyboard height. -->
<attr name="keyboardTopPadding" format="fraction" />
<attr name="keyboardBottomPadding" format="fraction" />
<!-- Keyboard both horizontal edges paddings, in propotion of keyboard width. -->
<attr name="keyboardHorizontalEdgesPadding" format="fraction" />
<!-- Default height of a row (key height + vertical gap), in pixels or in the proportion of
keyboard height. -->
<attr name="rowHeight" format="dimension|fraction" />
<!-- Default horizontal gap between keys, in pixels or percentage of keyboard width. -->
<attr name="horizontalGap" format="dimension|fraction" />
<!-- Default vertical gap between rows of keys, in pixels or percentage of keyboard
height. -->
<attr name="verticalGap" format="dimension|fraction" />
<!-- Default horizontal gap between keys, in the proportion of keyboard width. -->
<attr name="horizontalGap" format="fraction" />
<!-- Default vertical gap between rows of keys, in the proportion of keyboard height. -->
<attr name="verticalGap" format="fraction" />
<!-- More keys keyboard layout template -->
<attr name="moreKeysTemplate" format="reference" />
<!-- Icon set for key top and key preview.
@ -288,19 +288,20 @@
<attr name="keyIconPreview" format="string" />
<!-- The key style to specify a set of key attributes defined by <key_style/> -->
<attr name="keyStyle" format="string" />
<!-- Visual insets -->
<attr name="visualInsetsLeft" format="dimension|fraction" />
<attr name="visualInsetsRight" format="dimension|fraction" />
<!-- Width of the key, in pixels or percentage of display width.
If the value is fillRight, the actual key width will be determined to fill out the area
up to the right edge of the keyboard. -->
<!-- Visual insets, in the proportion of keyboard width. -->
<attr name="visualInsetsLeft" format="fraction" />
<attr name="visualInsetsRight" format="fraction" />
<!-- 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 up to the right edge of the keyboard. -->
<!-- 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" />
</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. -->
<attr name="keyXPos" format="dimension|fraction" />
<attr name="keyXPos" format="fraction" />
<!-- Key top visual attributes -->
<attr name="keyTypeface" format="enum">

View File

@ -119,9 +119,9 @@
name="MoreKeysKeyboard"
parent="Keyboard"
>
<item name="keyboardTopPadding">0dp</item>
<item name="keyboardBottomPadding">0dp</item>
<item name="horizontalGap">0dp</item>
<item name="keyboardTopPadding">0%p</item>
<item name="keyboardBottomPadding">0%p</item>
<item name="horizontalGap">0%p</item>
<item name="touchPositionCorrectionData">@null</item>
</style>
<style
@ -224,9 +224,9 @@
name="MoreKeysKeyboard.Stone"
parent="Keyboard.Stone"
>
<item name="keyboardTopPadding">0dp</item>
<item name="keyboardBottomPadding">0dp</item>
<item name="horizontalGap">0dp</item>
<item name="keyboardTopPadding">0%p</item>
<item name="keyboardBottomPadding">0%p</item>
<item name="horizontalGap">0%p</item>
<item name="touchPositionCorrectionData">@null</item>
</style>
<style
@ -294,9 +294,9 @@
name="MoreKeysKeyboard.Gingerbread"
parent="Keyboard.Gingerbread"
>
<item name="keyboardTopPadding">0dp</item>
<item name="keyboardBottomPadding">0dp</item>
<item name="horizontalGap">0dp</item>
<item name="keyboardTopPadding">0%p</item>
<item name="keyboardBottomPadding">0%p</item>
<item name="horizontalGap">0%p</item>
<item name="touchPositionCorrectionData">@null</item>
</style>
<style
@ -353,9 +353,9 @@
name="MoreKeysKeyboard.IceCreamSandwich"
parent="Keyboard.IceCreamSandwich"
>
<item name="keyboardTopPadding">0dp</item>
<item name="keyboardBottomPadding">0dp</item>
<item name="horizontalGap">0dp</item>
<item name="keyboardTopPadding">0%p</item>
<item name="keyboardBottomPadding">0%p</item>
<item name="horizontalGap">0%p</item>
<item name="touchPositionCorrectionData">@null</item>
</style>
<style

View File

@ -41,7 +41,6 @@ import com.android.inputmethod.keyboard.internal.KeyboardRow;
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResourceUtils;
import com.android.inputmethod.latin.StringUtils;
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,
final XmlPullParser parser) throws XmlPullParserException {
final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
final int keyHeight = row.mRowHeight;
mHeight = keyHeight - params.mVerticalGap;
final int rowHeight = row.mRowHeight;
mHeight = rowHeight - params.mVerticalGap;
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
@ -241,17 +240,18 @@ public class Key implements Comparable<Key> {
mY = keyYPos;
mWidth = Math.round(keyWidth - horizontalGap);
mHitBox.set(Math.round(keyXPos), keyYPos, Math.round(keyXPos + keyWidth) + 1,
keyYPos + keyHeight);
keyYPos + rowHeight);
// Update row to have current x coordinate.
row.setXPos(keyXPos + keyWidth);
mBackgroundType = style.getInt(keyAttr,
R.styleable.Keyboard_Key_backgroundType, row.getDefaultBackgroundType());
final int visualInsetsLeft = Math.round(ResourceUtils.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0));
final int visualInsetsRight = Math.round(ResourceUtils.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0));
final int baseWidth = params.mBaseWidth;
final int visualInsetsLeft = Math.round(keyAttr.getFraction(
R.styleable.Keyboard_Key_visualInsetsLeft, baseWidth, baseWidth, 0));
final int visualInsetsRight = Math.round(keyAttr.getFraction(
R.styleable.Keyboard_Key_visualInsetsRight, baseWidth, baseWidth, 0));
mIconId = KeySpecParser.getIconId(style.getString(keyAttr,
R.styleable.Keyboard_Key_keyIcon));
final int disabledIconId = KeySpecParser.getIconId(style.getString(keyAttr,

View File

@ -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>
* <pre>
* &lt;Keyboard
* latin:keyWidth="%10p"
* latin:keyHeight="50px"
* latin:horizontalGap="2px"
* latin:verticalGap="2px" &gt;
* &lt;Row latin:keyWidth="32px" &gt;
* latin:keyWidth="10%p"
* latin:rowHeight="50px"
* latin:horizontalGap="2%p"
* latin:verticalGap="2%p" &gt;
* &lt;Row latin:keyWidth="10%p" &gt;
* &lt;Key latin:keyLabel="A" /&gt;
* ...
* &lt;/Row&gt;

View File

@ -235,31 +235,36 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
R.styleable.Keyboard_Key);
try {
final KeyboardParams params = mParams;
params.mOccupiedHeight = params.mId.mHeight;
params.mOccupiedWidth = params.mId.mWidth;
params.mTopPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0);
params.mBottomPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyboardBottomPadding, params.mOccupiedHeight, 0);
params.mHorizontalEdgesPadding = (int)ResourceUtils.getDimensionOrFraction(
keyboardAttr,
R.styleable.Keyboard_keyboardHorizontalEdgesPadding,
mParams.mOccupiedWidth, 0);
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);
// TODO: Split keyboardHorizontalEdgesPadding into two, keyboardLeftPaddings and
// 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.mDefaultKeyWidth = (int)ResourceUtils.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyWidth, params.mBaseWidth,
params.mBaseWidth / DEFAULT_KEYBOARD_COLUMNS);
params.mHorizontalGap = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_horizontalGap, params.mBaseWidth, 0);
params.mVerticalGap = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_verticalGap, params.mOccupiedHeight, 0);
params.mBaseHeight = params.mOccupiedHeight - params.mTopPadding
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, params.mBaseHeight,
params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS);
params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);

View File

@ -54,17 +54,16 @@ public final class KeyboardRow {
public KeyboardRow(final Resources res, final KeyboardParams params, final XmlPullParser parser,
final int y) {
mParams = params;
TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
mRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight,
params.mBaseHeight, params.mDefaultRowHeight);
keyboardAttr.recycle();
TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
mDefaultKeyWidth = ResourceUtils.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyWidth,
params.mBaseWidth, params.mDefaultKeyWidth);
mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
params.mBaseWidth, params.mBaseWidth, params.mDefaultKeyWidth);
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
Key.BACKGROUND_TYPE_NORMAL);
keyAttr.recycle();
@ -115,8 +114,8 @@ public final class KeyboardRow {
final int keyboardRightEdge = mParams.mOccupiedWidth
- mParams.mHorizontalEdgesPadding;
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
final float keyXPos = ResourceUtils.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyXPos, mParams.mBaseWidth, 0);
final float keyXPos = keyAttr.getFraction(R.styleable.Keyboard_Key_keyXPos,
mParams.mBaseWidth, mParams.mBaseWidth, 0);
if (keyXPos < 0) {
// If keyXPos is negative, the actual x-coordinate will be
// keyboardWidth + keyXPos.
@ -146,9 +145,8 @@ public final class KeyboardRow {
// out the area up to the right edge of the keyboard.
return keyboardRightEdge - keyXPos;
default: // KEYWIDTH_NOT_ENUM
return ResourceUtils.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyWidth,
mParams.mBaseWidth, mDefaultKeyWidth);
return keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
mParams.mBaseWidth, mParams.mBaseWidth, mDefaultKeyWidth);
}
}
}