diff options
author | 2011-07-18 17:14:50 -0700 | |
---|---|---|
committer | 2011-07-20 16:56:21 -0700 | |
commit | 426723a9cfb18d742602cb5098092808d592ea6d (patch) | |
tree | 6c0d5f973467a1b5553b131355ddbf26d2da0805 /java/src | |
parent | 856b582cfb1eb8f6e683c7520d9cdb85ef9f2186 (diff) | |
download | latinime-426723a9cfb18d742602cb5098092808d592ea6d.tar.gz latinime-426723a9cfb18d742602cb5098092808d592ea6d.tar.xz latinime-426723a9cfb18d742602cb5098092808d592ea6d.zip |
Remove Key edge flags from XML
The first key and the last of the row are automatically marked as left
and right edge key respectively. The existence of Spacer will prevent
those automatic marking.
Bug: 5038844
Change-Id: Ie34169ceaf76e24923b8d8125eda6ecb95cf1fee
Diffstat (limited to 'java/src')
3 files changed, 28 insertions, 16 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 45bf68cdf..33ab511a5 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -95,7 +95,7 @@ public class Key { * {@link Keyboard#EDGE_LEFT}, {@link Keyboard#EDGE_RIGHT}, * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}. */ - public final int mEdgeFlags; + private int mEdgeFlags; /** Whether this is a functional key which has different key top than normal key */ public final boolean mFunctional; /** Whether this key repeats itself when held down */ @@ -273,8 +273,7 @@ public class Key { 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 = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0) - | row.mRowEdgeFlags; + mEdgeFlags = 0; final KeyboardIconsSet iconsSet = mKeyboard.mIconsSet; mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr, @@ -316,6 +315,10 @@ public class Key { } } + public void addEdgeFlags(int flags) { + mEdgeFlags |= flags; + } + public CharSequence getCaseAdjustedLabel() { return mKeyboard.adjustLabelCase(mLabel); } @@ -441,15 +444,18 @@ public class Key { * assume that all points between the key and the edge are considered to be on the key. */ public boolean isOnKey(int x, int y) { + final int left = mX - mGap / 2; + final int right = left + mWidth + mGap; + final int top = mY; + final int bottom = top + mHeight + mKeyboard.getVerticalGap(); final int flags = mEdgeFlags; + if (flags == 0) { + return x >= left && x <= right && y >= top && y <= bottom; + } final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0; final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0; final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0; final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0; - final int left = mX - mGap / 2; - final int right = left + mWidth + mGap; - final int top = mY; - final int bottom = top + mHeight + mKeyboard.getVerticalGap(); // In order to mitigate rounding errors, we use (left <= x <= right) here. return (x >= left || leftEdge) && (x <= right || rightEdge) && (y >= top || topEdge) && (y <= bottom || bottomEdge); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java index e35db8955..fcda91990 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -135,6 +135,8 @@ public class KeyboardParser { private int mMaxRowWidth = 0; private int mTotalHeight = 0; private Row mCurrentRow = null; + private boolean mLeftEdge; + private Key mRightEdgeKey = null; private final KeyStyles mKeyStyles = new KeyStyles(); public KeyboardParser(Keyboard keyboard, Context context) { @@ -623,6 +625,8 @@ public class KeyboardParser { mCurrentX = 0; setSpacer(mCurrentX, mHorizontalEdgesPadding); mCurrentRow = row; + mLeftEdge = true; + mRightEdgeKey = null; } private void endRow() { @@ -633,10 +637,19 @@ public class KeyboardParser { mMaxRowWidth = mCurrentX; mCurrentY += mCurrentRow.mDefaultHeight; mCurrentRow = null; + if (mRightEdgeKey != null) { + mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT); + mRightEdgeKey = null; + } } private void endKey(Key key) { mCurrentX = key.mX - key.mGap / 2 + key.mWidth + key.mGap; + if (mLeftEdge) { + key.addEdgeFlags(Keyboard.EDGE_LEFT); + mLeftEdge = false; + } + mRightEdgeKey = key; } private void endKeyboard(int defaultVerticalGap) { @@ -646,6 +659,8 @@ public class KeyboardParser { private void setSpacer(int keyXPos, int width) { mCurrentX = keyXPos + width; + mLeftEdge = false; + mRightEdgeKey = null; } public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/Row.java b/java/src/com/android/inputmethod/keyboard/internal/Row.java index 06aadcc05..b34d6d06f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/Row.java +++ b/java/src/com/android/inputmethod/keyboard/internal/Row.java @@ -38,11 +38,6 @@ public class Row { public final int mDefaultHorizontalGap; /** Vertical gap following this row. */ public final int mVerticalGap; - /** - * Edge flags for this row of keys. Possible values that can be assigned are - * {@link Keyboard#EDGE_TOP EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM EDGE_BOTTOM} - */ - public final int mRowEdgeFlags; private final Keyboard mKeyboard; @@ -61,10 +56,6 @@ public class Row { mVerticalGap = KeyboardParser.getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, keyboardHeight, keyboard.getVerticalGap()); a.recycle(); - a = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Row); - mRowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0); - a.recycle(); } public Keyboard getKeyboard() { |