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); row.setXPos(keyXPos + keyWidth);
mBackgroundType = style.getInt(keyAttr, 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, mVisualInsetsLeft = Math.round(Keyboard.Builder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0)); R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0));

View File

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