From a1e370ee4fd033fae0f783d9120f6ab75d1ce711 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 27 Jan 2012 21:20:57 +0900 Subject: [PATCH] Support keyXPos/keyWidth override in Change-Id: I03576a6fb7916f2f66f2035a04872fe89b573cdc --- .../inputmethod/keyboard/Keyboard.java | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index abe5b62ee..dd882098d 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -21,6 +21,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.text.TextUtils; +import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; @@ -571,7 +572,7 @@ public class Keyboard { private final Params mParams; /** Default width of a key in this row. */ - public final float mDefaultKeyWidth; + private float mDefaultKeyWidth; /** Default height of a key in this row. */ public final int mRowHeight; @@ -598,6 +599,14 @@ public class Keyboard { mCurrentX = 0.0f; } + public float getDefaultKeyWidth() { + return mDefaultKeyWidth; + } + + public void setDefaultKeyWidth(float defaultKeyWidth) { + mDefaultKeyWidth = defaultKeyWidth; + } + public void setXPos(float keyXPos) { mCurrentX = keyXPos; } @@ -638,6 +647,10 @@ public class Keyboard { return mCurrentX; } + public float getKeyWidth(TypedArray keyAttr) { + return getKeyWidth(keyAttr, mCurrentX); + } + public float getKeyWidth(TypedArray keyAttr, float keyXPos) { final int widthType = Builder.getEnumValue(keyAttr, R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM); @@ -937,17 +950,33 @@ public class Keyboard { if (skip) { XmlParseUtils.checkEndTag(TAG_INCLUDE, parser); } 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); + final TypedArray keyAttr = mResources.obtainAttributes(attr, + R.styleable.Keyboard_Key); int keyboardLayout = 0; + float savedDefaultKeyWidth = 0; try { - XmlParseUtils.checkAttributeExists(a, + XmlParseUtils.checkAttributeExists(keyboardAttr, R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout", TAG_INCLUDE, parser); - keyboardLayout = a.getResourceId( + keyboardLayout = keyboardAttr.getResourceId( 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 { - a.recycle(); + keyboardAttr.recycle(); + keyAttr.recycle(); } XmlParseUtils.checkEndTag(TAG_INCLUDE, parser); @@ -957,6 +986,10 @@ public class Keyboard { try { parseMerge(parserForInclude, row, skip); } finally { + if (row != null) { + // Restore default key width. + row.setDefaultKeyWidth(savedDefaultKeyWidth); + } parserForInclude.close(); } }