Can specify Key.backgroundType in <Row> and <include> attribute
Bug: 6568834 Change-Id: I138464b5445e13eaf062ce84a1ba332dfd1afafa
This commit is contained in:
parent
be2fef4d5e
commit
907ba59397
2 changed files with 29 additions and 10 deletions
|
@ -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));
|
||||
|
|
|
@ -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 = 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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue