aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-09-02 01:13:34 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-02 01:13:34 -0700
commit08e64e187490881bdd85f4a5d5301ee1e1c21a10 (patch)
treee0d5667fd5946cded99185880d4070d0591ea056 /java/src
parentae835286b718ee4a2dac386a77c4cbaed768c68c (diff)
parentb58925ea0d358c1d966cb16ffd14459f637a450c (diff)
downloadlatinime-08e64e187490881bdd85f4a5d5301ee1e1c21a10.tar.gz
latinime-08e64e187490881bdd85f4a5d5301ee1e1c21a10.tar.xz
latinime-08e64e187490881bdd85f4a5d5301ee1e1c21a10.zip
Merge "Calculate x coordinate with floating point"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java213
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java35
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/Row.java8
3 files changed, 122 insertions, 134 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index c2f0a3db6..ced18f0f3 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -253,126 +253,115 @@ public class Key {
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
- int keyWidth;
- try {
- mHeight = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
- R.styleable.Keyboard_rowHeight,
- params.mHeight, row.mRowHeight) - params.mVerticalGap;
- mHorizontalGap = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
- R.styleable.Keyboard_horizontalGap,
- params.mWidth, params.mHorizontalGap);
- mVerticalGap = params.mVerticalGap;
- keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
- R.styleable.Keyboard_keyWidth,
- params.mWidth, row.mDefaultKeyWidth);
- } finally {
- keyboardAttr.recycle();
- }
+ mHeight = (int)KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
+ R.styleable.Keyboard_rowHeight, params.mHeight, row.mRowHeight)
+ - params.mVerticalGap;
+ final float horizontalGap = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
+ R.styleable.Keyboard_horizontalGap, params.mWidth, params.mHorizontalGap);
+ mVerticalGap = params.mVerticalGap;
+ float keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
+ R.styleable.Keyboard_keyWidth, params.mWidth, row.mDefaultKeyWidth);
+ keyboardAttr.recycle();
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
- try {
- final KeyStyle style;
- if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) {
- String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle);
- style = keyStyles.getKeyStyle(styleName);
- if (style == null)
- throw new ParseException("Unknown key style: " + styleName, parser);
- } else {
- style = keyStyles.getEmptyKeyStyle();
- }
- final int keyboardWidth = params.mOccupiedWidth;
- final int x = row.mCurrentX;
- int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
- R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
- if (keyXPos < 0) {
- // If keyXPos is negative, the actual x-coordinate will be k + keyXPos.
- keyXPos += keyboardWidth;
- if (keyXPos < x) {
- // keyXPos shouldn't be less than x because drawable area for this key starts
- // at x. Or, this key will overlaps the adjacent key on its left hand side.
- keyXPos = x;
- }
- }
- if (keyWidth == KEYWIDTH_FILL_RIGHT) {
- // If keyWidth is zero, the actual key width will be determined to fill out the
- // area up to the right edge of the keyboard.
- keyWidth = keyboardWidth - keyXPos;
- } else if (keyWidth <= KEYWIDTH_FILL_BOTH) {
- // If keyWidth is negative, the actual key width will be determined to fill out the
- // area between the nearest key on the left hand side and the right edge of the
- // keyboard.
+ final KeyStyle style;
+ if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) {
+ String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle);
+ style = keyStyles.getKeyStyle(styleName);
+ if (style == null)
+ throw new ParseException("Unknown key style: " + styleName, parser);
+ } else {
+ style = keyStyles.getEmptyKeyStyle();
+ }
+
+ final int keyboardWidth = params.mOccupiedWidth;
+ final float x = row.mCurrentX;
+ float keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
+ if (keyXPos < 0) {
+ // If keyXPos is negative, the actual x-coordinate will be keyboardWidth + keyXPos.
+ keyXPos += keyboardWidth;
+ if (keyXPos < x) {
+ // keyXPos shouldn't be less than x because drawable area for this key starts
+ // at x. Or, this key will overlaps the adjacent key on its left hand side.
keyXPos = x;
- keyWidth = keyboardWidth - keyXPos;
}
+ }
+ if (keyWidth == KEYWIDTH_FILL_RIGHT) {
+ // If keyWidth is zero, the actual key width will be determined to fill out the
+ // area up to the right edge of the keyboard.
+ keyWidth = keyboardWidth - keyXPos;
+ } else if (keyWidth <= KEYWIDTH_FILL_BOTH) {
+ // If keyWidth is negative, the actual key width will be determined to fill out the
+ // area between the nearest key on the left hand side and the right edge of the
+ // keyboard.
+ keyXPos = x;
+ keyWidth = keyboardWidth - keyXPos;
+ }
- // Horizontal gap is divided equally to both sides of the key.
- mX = keyXPos + mHorizontalGap / 2;
- mY = row.mCurrentY;
- mWidth = keyWidth - mHorizontalGap;
-
- // Update row to have x-coordinate of the right edge of this key.
- row.mCurrentX = keyXPos + keyWidth;
-
- final CharSequence[] moreKeys = style.getTextArray(
- keyAttr, R.styleable.Keyboard_Key_moreKeys);
- // In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
- // config_digit_more_keys_enabled.
- if (params.mId.isAlphabetKeyboard() && !res.getBoolean(
- R.bool.config_digit_more_keys_enabled)) {
- mMoreKeys = MoreKeySpecParser.filterOut(
- res, moreKeys, MoreKeySpecParser.DIGIT_FILTER);
- } else {
- mMoreKeys = moreKeys;
- }
- mMaxMoreKeysColumn = style.getInt(keyboardAttr,
- R.styleable.Keyboard_Key_maxMoreKeysColumn,
- params.mMaxMiniKeyboardColumn);
-
- mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
- mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false);
- mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false);
- mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
- mEdgeFlags = 0;
-
- final KeyboardIconsSet iconsSet = params.mIconsSet;
- mVisualInsetsLeft = KeyboardBuilder.getDimensionOrFraction(keyAttr,
- R.styleable.Keyboard_Key_visualInsetsLeft, keyboardWidth, 0);
- mVisualInsetsRight = KeyboardBuilder.getDimensionOrFraction(keyAttr,
- R.styleable.Keyboard_Key_visualInsetsRight, keyboardWidth, 0);
- mPreviewIcon = iconsSet.getIcon(style.getInt(
- keyAttr, R.styleable.Keyboard_Key_keyIconPreview,
- KeyboardIconsSet.ICON_UNDEFINED));
- mIcon = iconsSet.getIcon(style.getInt(
- keyAttr, R.styleable.Keyboard_Key_keyIcon,
- KeyboardIconsSet.ICON_UNDEFINED));
- final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
- KeyboardIconsSet.ICON_UNDEFINED);
- if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
- final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
- params.addShiftedIcon(this, shiftedIcon);
- }
- mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
-
- mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
- mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0);
- mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
- // Choose the first letter of the label as primary code if not
- // specified.
- final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,
- Keyboard.CODE_UNSPECIFIED);
- if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) {
- final int firstChar = mLabel.charAt(0);
- mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard);
- } else if (code != Keyboard.CODE_UNSPECIFIED) {
- mCode = code;
- } else {
- mCode = Keyboard.CODE_DUMMY;
- }
- } finally {
- keyAttr.recycle();
+ // Horizontal gap is divided equally to both sides of the key.
+ mX = (int) (keyXPos + horizontalGap / 2);
+ mY = row.mCurrentY;
+ mWidth = (int) (keyWidth - horizontalGap);
+ mHorizontalGap = (int) horizontalGap;
+ // Update row to have current x coordinate.
+ row.mCurrentX = keyXPos + keyWidth;
+
+ final CharSequence[] moreKeys = style.getTextArray(keyAttr,
+ R.styleable.Keyboard_Key_moreKeys);
+ // In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
+ // config_digit_more_keys_enabled.
+ if (params.mId.isAlphabetKeyboard()
+ && !res.getBoolean(R.bool.config_digit_more_keys_enabled)) {
+ mMoreKeys = MoreKeySpecParser.filterOut(res, moreKeys, MoreKeySpecParser.DIGIT_FILTER);
+ } else {
+ mMoreKeys = moreKeys;
+ }
+ mMaxMoreKeysColumn = style.getInt(keyboardAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn,
+ params.mMaxMiniKeyboardColumn);
+
+ mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
+ mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false);
+ mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false);
+ mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
+ mEdgeFlags = 0;
+
+ final KeyboardIconsSet iconsSet = params.mIconsSet;
+ mVisualInsetsLeft = (int) KeyboardBuilder.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_visualInsetsLeft, keyboardWidth, 0);
+ mVisualInsetsRight = (int) KeyboardBuilder.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_visualInsetsRight, keyboardWidth, 0);
+ mPreviewIcon = iconsSet.getIcon(style.getInt(keyAttr,
+ R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED));
+ mIcon = iconsSet.getIcon(style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIcon,
+ KeyboardIconsSet.ICON_UNDEFINED));
+ final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
+ KeyboardIconsSet.ICON_UNDEFINED);
+ if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
+ final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
+ params.addShiftedIcon(this, shiftedIcon);
}
+ mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
+
+ mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
+ mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0);
+ mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
+ // Choose the first letter of the label as primary code if not
+ // specified.
+ final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code,
+ Keyboard.CODE_UNSPECIFIED);
+ if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) {
+ final int firstChar = mLabel.charAt(0);
+ mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard);
+ } else if (code != Keyboard.CODE_UNSPECIFIED) {
+ mCode = code;
+ } else {
+ mCode = Keyboard.CODE_DUMMY;
+ }
+
+ keyAttr.recycle();
}
public void addEdgeFlags(int flags) {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index ff26b5977..5336ea909 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -218,14 +218,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final int displayHeight = mDisplayMetrics.heightPixels;
final int keyboardHeight = (int)keyboardAttr.getDimension(
R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
- final int maxKeyboardHeight = getDimensionOrFraction(keyboardAttr,
+ final int maxKeyboardHeight = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);
- int minKeyboardHeight = getDimensionOrFraction(keyboardAttr,
+ int minKeyboardHeight = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_minKeyboardHeight, displayHeight, displayHeight / 2);
if (minKeyboardHeight < 0) {
// Specified fraction was negative, so it should be calculated against display
// width.
- minKeyboardHeight = -getDimensionOrFraction(keyboardAttr,
+ minKeyboardHeight = -(int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2);
}
// Keyboard height will not exceed maxKeyboardHeight and will not be less than
@@ -233,9 +233,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
mParams.mOccupiedHeight = Math.max(
Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
mParams.mOccupiedWidth = mParams.mId.mWidth;
- mParams.mTopPadding = getDimensionOrFraction(keyboardAttr,
+ mParams.mTopPadding = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyboardTopPadding, mParams.mOccupiedHeight, 0);
- mParams.mBottomPadding = getDimensionOrFraction(keyboardAttr,
+ mParams.mBottomPadding = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyboardBottomPadding, mParams.mOccupiedHeight, 0);
final int height = mParams.mOccupiedHeight;
@@ -243,13 +243,13 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
- mParams.mHorizontalCenterPadding;
mParams.mHeight = height;
mParams.mWidth = width;
- mParams.mDefaultKeyWidth = getDimensionOrFraction(keyboardAttr,
+ mParams.mDefaultKeyWidth = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyWidth, width, width / 10);
- mParams.mDefaultRowHeight = getDimensionOrFraction(keyboardAttr,
+ mParams.mDefaultRowHeight = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight, height, height / 4);
- mParams.mHorizontalGap = getDimensionOrFraction(keyboardAttr,
+ mParams.mHorizontalGap = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_horizontalGap, width, 0);
- mParams.mVerticalGap = getDimensionOrFraction(keyboardAttr,
+ mParams.mVerticalGap = (int)getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_verticalGap, height, 0);
mParams.mIsRtlKeyboard = keyboardAttr.getBoolean(
@@ -384,13 +384,13 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap))
throw new IllegalAttribute(parser, "horizontalGap");
final int keyboardWidth = mParams.mWidth;
- final int keyWidth = getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth,
- keyboardWidth, row.mDefaultKeyWidth);
+ final float keyWidth = getDimensionOrFraction(keyboardAttr,
+ R.styleable.Keyboard_keyWidth, keyboardWidth, row.mDefaultKeyWidth);
keyboardAttr.recycle();
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
- int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
+ float keyXPos = getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, row.mCurrentX);
if (keyXPos < 0) {
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
@@ -688,24 +688,23 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
private void endKeyboard() {
}
- private void setSpacer(int keyXPos, int width, Row row) {
+ private void setSpacer(float keyXPos, float width, Row row) {
row.mCurrentX = keyXPos + width;
mLeftEdge = false;
mRightEdgeKey = null;
}
- public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
+ public static float getDimensionOrFraction(TypedArray a, int index, int base, float defValue) {
final TypedValue value = a.peekValue(index);
if (value == null)
return defValue;
if (isFractionValue(value)) {
- // Round it to avoid values like 47.9999 from getting truncated
- return Math.round(a.getFraction(index, base, base, defValue));
+ return a.getFraction(index, base, base, defValue);
} else if (isDimensionValue(value)) {
- return a.getDimensionPixelOffset(index, defValue);
+ return a.getDimension(index, defValue);
} else if (isIntegerValue(value)) {
// For enum value.
- return a.getInt(index, defValue);
+ return a.getInt(index, 0);
}
return defValue;
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/Row.java b/java/src/com/android/inputmethod/keyboard/internal/Row.java
index fdf1dec68..d81881d77 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/Row.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/Row.java
@@ -31,13 +31,13 @@ import com.android.inputmethod.latin.R;
*/
public class Row {
/** Default width of a key in this row. */
- public final int mDefaultKeyWidth;
+ public final float mDefaultKeyWidth;
/** Default height of a key in this row. */
public final int mRowHeight;
public final int mCurrentY;
// Will be updated by {@link Key}'s constructor.
- public int mCurrentX;
+ public float mCurrentX;
public Row(Resources res, KeyboardParams params, XmlResourceParser parser, int y) {
final int keyboardWidth = params.mWidth;
@@ -46,11 +46,11 @@ public class Row {
R.styleable.Keyboard);
mDefaultKeyWidth = KeyboardBuilder.getDimensionOrFraction(a,
R.styleable.Keyboard_keyWidth, keyboardWidth, params.mDefaultKeyWidth);
- mRowHeight = KeyboardBuilder.getDimensionOrFraction(a,
+ mRowHeight = (int)KeyboardBuilder.getDimensionOrFraction(a,
R.styleable.Keyboard_rowHeight, keyboardHeight, params.mDefaultRowHeight);
a.recycle();
mCurrentY = y;
- mCurrentX = 0;
+ mCurrentX = 0.0f;
}
}