aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorDavid Faden <dfaden@google.com>2014-09-03 14:15:44 -0700
committerTadashi G. Takaoka <takaoka@google.com>2014-09-18 09:40:02 +0000
commit5dda75b538ee53351fdfd800e0e5a9f329ad7c2e (patch)
treece950bec1e53ed45cb54ba944413612b50576077 /java/src
parenteddfe51b38755e0068e3c322868c5e209f212f6f (diff)
downloadlatinime-5dda75b538ee53351fdfd800e0e5a9f329ad7c2e.tar.gz
latinime-5dda75b538ee53351fdfd800e0e5a9f329ad7c2e.tar.xz
latinime-5dda75b538ee53351fdfd800e0e5a9f329ad7c2e.zip
Add methods to get a Key's horizontal and vertical gaps.
Record the horizontal and vertical gap for the key, adding corresponding accessors. This info is helpful in interpreting corresponding touch points data. Bug: 17400259 Change-Id: I825c537a48db35baab71580ff5c41cd911094a4b
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java47
1 files changed, 41 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 99a34bec7..863a8b7ad 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -98,6 +98,16 @@ public class Key implements Comparable<Key> {
private final int mWidth;
/** Height of the key, excluding the gap */
private final int mHeight;
+ /**
+ * The combined width in pixels of the horizontal gaps belonging to this key, both to the left
+ * and to the right. I.e., mWidth + mHorizontalGap = total width belonging to the key.
+ */
+ private final int mHorizontalGap;
+ /**
+ * The combined height in pixels of the vertical gaps belonging to this key, both above and
+ * below. I.e., mHeight + mVerticalGap = total height belonging to the key.
+ */
+ private final int mVerticalGap;
/** X coordinate of the top-left corner of the key in the keyboard layout, excluding the gap. */
private final int mX;
/** Y coordinate of the top-left corner of the key in the keyboard layout, excluding the gap. */
@@ -198,8 +208,10 @@ public class Key implements Comparable<Key> {
final String hintLabel, final int labelFlags, final int backgroundType, final int x,
final int y, final int width, final int height, final int horizontalGap,
final int verticalGap) {
- mHeight = height - verticalGap;
mWidth = width - horizontalGap;
+ mHeight = height - verticalGap;
+ mHorizontalGap = horizontalGap;
+ mVerticalGap = verticalGap;
mHintLabel = hintLabel;
mLabelFlags = labelFlags;
mBackgroundType = backgroundType;
@@ -214,7 +226,7 @@ public class Key implements Comparable<Key> {
mEnabled = (code != CODE_UNSPECIFIED);
mIconId = iconId;
// Horizontal gap is divided equally to both sides of the key.
- mX = x + horizontalGap / 2;
+ mX = x + mHorizontalGap / 2;
mY = y;
mHitBox.set(x, y, x + width + 1, y + height);
mKeyVisualAttributes = null;
@@ -235,18 +247,21 @@ public class Key implements Comparable<Key> {
*/
public Key(final String keySpec, final TypedArray keyAttr, final KeyStyle style,
final KeyboardParams params, final KeyboardRow row) {
- final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
+ mHorizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
+ mVerticalGap = params.mVerticalGap;
+
+ final float horizontalGapFloat = mHorizontalGap;
final int rowHeight = row.getRowHeight();
- mHeight = rowHeight - params.mVerticalGap;
+ mHeight = rowHeight - mVerticalGap;
final float keyXPos = row.getKeyX(keyAttr);
final float keyWidth = row.getKeyWidth(keyAttr, keyXPos);
final int keyYPos = row.getKeyY();
// Horizontal gap is divided equally to both sides of the key.
- mX = Math.round(keyXPos + horizontalGap / 2);
+ mX = Math.round(keyXPos + horizontalGapFloat / 2);
mY = keyYPos;
- mWidth = Math.round(keyWidth - horizontalGap);
+ mWidth = Math.round(keyWidth - horizontalGapFloat);
mHitBox.set(Math.round(keyXPos), keyYPos, Math.round(keyXPos + keyWidth) + 1,
keyYPos + rowHeight);
// Update row to have current x coordinate.
@@ -388,6 +403,8 @@ public class Key implements Comparable<Key> {
mIconId = key.mIconId;
mWidth = key.mWidth;
mHeight = key.mHeight;
+ mHorizontalGap = key.mHorizontalGap;
+ mVerticalGap = key.mVerticalGap;
mX = key.mX;
mY = key.mY;
mHitBox.set(key.mHitBox);
@@ -788,6 +805,24 @@ public class Key implements Comparable<Key> {
}
/**
+ * The combined width in pixels of the horizontal gaps belonging to this key, both above and
+ * below. I.e., getWidth() + getHorizontalGap() = total width belonging to the key.
+ * @return Horizontal gap belonging to this key.
+ */
+ public int getHorizontalGap() {
+ return mHorizontalGap;
+ }
+
+ /**
+ * The combined height in pixels of the vertical gaps belonging to this key, both above and
+ * below. I.e., getHeight() + getVerticalGap() = total height belonging to the key.
+ * @return Vertical gap belonging to this key.
+ */
+ public int getVerticalGap() {
+ return mVerticalGap;
+ }
+
+ /**
* Gets the x-coordinate of the top-left corner of the key in pixels, excluding the gap.
* @return The x-coordinate of the top-left corner of the key in pixels, excluding the gap.
*/