Merge "Support keyXPos/keyWidth override in <include>"
This commit is contained in:
commit
ed50cf005b
1 changed files with 38 additions and 5 deletions
|
@ -21,6 +21,7 @@ import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
@ -571,7 +572,7 @@ public class Keyboard {
|
||||||
|
|
||||||
private final Params mParams;
|
private final Params mParams;
|
||||||
/** Default width of a key in this row. */
|
/** Default width of a key in this row. */
|
||||||
public final float mDefaultKeyWidth;
|
private float mDefaultKeyWidth;
|
||||||
/** Default height of a key in this row. */
|
/** Default height of a key in this row. */
|
||||||
public final int mRowHeight;
|
public final int mRowHeight;
|
||||||
|
|
||||||
|
@ -598,6 +599,14 @@ public class Keyboard {
|
||||||
mCurrentX = 0.0f;
|
mCurrentX = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getDefaultKeyWidth() {
|
||||||
|
return mDefaultKeyWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultKeyWidth(float defaultKeyWidth) {
|
||||||
|
mDefaultKeyWidth = defaultKeyWidth;
|
||||||
|
}
|
||||||
|
|
||||||
public void setXPos(float keyXPos) {
|
public void setXPos(float keyXPos) {
|
||||||
mCurrentX = keyXPos;
|
mCurrentX = keyXPos;
|
||||||
}
|
}
|
||||||
|
@ -638,6 +647,10 @@ public class Keyboard {
|
||||||
return mCurrentX;
|
return mCurrentX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getKeyWidth(TypedArray keyAttr) {
|
||||||
|
return getKeyWidth(keyAttr, mCurrentX);
|
||||||
|
}
|
||||||
|
|
||||||
public float getKeyWidth(TypedArray keyAttr, float keyXPos) {
|
public float getKeyWidth(TypedArray keyAttr, float keyXPos) {
|
||||||
final int widthType = Builder.getEnumValue(keyAttr,
|
final int widthType = Builder.getEnumValue(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
|
R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
|
||||||
|
@ -937,17 +950,33 @@ public class Keyboard {
|
||||||
if (skip) {
|
if (skip) {
|
||||||
XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
|
XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
|
||||||
} else {
|
} else {
|
||||||
final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
final AttributeSet attr = Xml.asAttributeSet(parser);
|
||||||
|
final TypedArray keyboardAttr = mResources.obtainAttributes(attr,
|
||||||
R.styleable.Keyboard_Include);
|
R.styleable.Keyboard_Include);
|
||||||
|
final TypedArray keyAttr = mResources.obtainAttributes(attr,
|
||||||
|
R.styleable.Keyboard_Key);
|
||||||
int keyboardLayout = 0;
|
int keyboardLayout = 0;
|
||||||
|
float savedDefaultKeyWidth = 0;
|
||||||
try {
|
try {
|
||||||
XmlParseUtils.checkAttributeExists(a,
|
XmlParseUtils.checkAttributeExists(keyboardAttr,
|
||||||
R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
|
R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
|
||||||
TAG_INCLUDE, parser);
|
TAG_INCLUDE, parser);
|
||||||
keyboardLayout = a.getResourceId(
|
keyboardLayout = keyboardAttr.getResourceId(
|
||||||
R.styleable.Keyboard_Include_keyboardLayout, 0);
|
R.styleable.Keyboard_Include_keyboardLayout, 0);
|
||||||
|
if (row != null) {
|
||||||
|
savedDefaultKeyWidth = row.getDefaultKeyWidth();
|
||||||
|
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
|
||||||
|
// Override current x coordinate.
|
||||||
|
row.setXPos(row.getKeyX(keyAttr));
|
||||||
|
}
|
||||||
|
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyWidth)) {
|
||||||
|
// Override default key width.
|
||||||
|
row.setDefaultKeyWidth(row.getKeyWidth(keyAttr));
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle();
|
keyboardAttr.recycle();
|
||||||
|
keyAttr.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
|
XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
|
||||||
|
@ -957,6 +986,10 @@ public class Keyboard {
|
||||||
try {
|
try {
|
||||||
parseMerge(parserForInclude, row, skip);
|
parseMerge(parserForInclude, row, skip);
|
||||||
} finally {
|
} finally {
|
||||||
|
if (row != null) {
|
||||||
|
// Restore default key width.
|
||||||
|
row.setDefaultKeyWidth(savedDefaultKeyWidth);
|
||||||
|
}
|
||||||
parserForInclude.close();
|
parserForInclude.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue