am 59dae7e1: am 907ba593: Can specify Key.backgroundType in <Row> and <include> attribute

* commit '59dae7e141b6d6a8bea287f6699e34137390c5f9':
  Can specify Key.backgroundType in <Row> and <include> attribute
main
Tadashi G. Takaoka 2012-06-06 10:42:38 -07:00 committed by Android Git Automerger
commit 562239bf51
2 changed files with 29 additions and 10 deletions

View File

@ -227,7 +227,7 @@ public class Key {
row.setXPos(keyXPos + keyWidth);
mBackgroundType = style.getInt(keyAttr,
R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL);
R.styleable.Keyboard_Key_backgroundType, row.getDefaultBackgroundType());
mVisualInsetsLeft = Math.round(Keyboard.Builder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0));

View File

@ -533,6 +533,8 @@ public class Keyboard {
public final int mRowHeight;
/** Default keyLabelFlags in this row. */
private int mDefaultKeyLabelFlags;
/** Default backgroundType for this row */
private int mDefaultBackgroundType;
private final int mCurrentY;
// Will be updated by {@link Key}'s constructor.
@ -551,8 +553,11 @@ public class Keyboard {
mDefaultKeyWidth = Builder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyWidth,
params.mBaseWidth, params.mDefaultKeyWidth);
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
Key.BACKGROUND_TYPE_NORMAL);
keyAttr.recycle();
// TODO: Initialize this with <Row> attribute as backgroundType is done.
mDefaultKeyLabelFlags = 0;
mCurrentY = y;
mCurrentX = 0.0f;
@ -574,6 +579,14 @@ public class Keyboard {
mDefaultKeyLabelFlags = keyLabelFlags;
}
public int getDefaultBackgroundType() {
return mDefaultBackgroundType;
}
public void setDefaultBackgroundType(int backgroundType) {
mDefaultBackgroundType = backgroundType;
}
public void setXPos(float keyXPos) {
mCurrentX = keyXPos;
}
@ -952,6 +965,7 @@ public class Keyboard {
int keyboardLayout = 0;
float savedDefaultKeyWidth = 0;
int savedDefaultKeyLabelFlags = 0;
int savedDefaultBackgroundType = Key.BACKGROUND_TYPE_NORMAL;
try {
XmlParseUtils.checkAttributeExists(keyboardAttr,
R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
@ -959,22 +973,26 @@ public class Keyboard {
keyboardLayout = keyboardAttr.getResourceId(
R.styleable.Keyboard_Include_keyboardLayout, 0);
if (row != null) {
savedDefaultKeyWidth = row.getDefaultKeyWidth();
savedDefaultKeyLabelFlags = row.getDefaultKeyLabelFlags();
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
// Override current x coordinate.
row.setXPos(row.getKeyX(keyAttr));
}
// TODO: Remove this if-clause and do the same as backgroundType below.
savedDefaultKeyWidth = row.getDefaultKeyWidth();
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyWidth)) {
// Override default key width.
row.setDefaultKeyWidth(row.getKeyWidth(keyAttr));
}
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyLabelFlags)) {
// Override default key label flags.
row.setDefaultKeyLabelFlags(
keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0)
| savedDefaultKeyLabelFlags);
}
savedDefaultKeyLabelFlags = row.getDefaultKeyLabelFlags();
// Bitwise-or default keyLabelFlag if exists.
row.setDefaultKeyLabelFlags(keyAttr.getInt(
R.styleable.Keyboard_Key_keyLabelFlags, 0)
| savedDefaultKeyLabelFlags);
savedDefaultBackgroundType = row.getDefaultBackgroundType();
// Override default backgroundType if exists.
row.setDefaultBackgroundType(keyAttr.getInt(
R.styleable.Keyboard_Key_backgroundType,
savedDefaultBackgroundType));
}
} finally {
keyboardAttr.recycle();
@ -991,9 +1009,10 @@ public class Keyboard {
parseMerge(parserForInclude, row, skip);
} finally {
if (row != null) {
// Restore default key width and key label flags.
// Restore default keyWidth, keyLabelFlags, and backgroundType.
row.setDefaultKeyWidth(savedDefaultKeyWidth);
row.setDefaultKeyLabelFlags(savedDefaultKeyLabelFlags);
row.setDefaultBackgroundType(savedDefaultBackgroundType);
}
parserForInclude.close();
}