aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java10
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java36
2 files changed, 29 insertions, 17 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 59c132e91..1b7e8ef21 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -61,8 +61,11 @@ public class Key {
public final int mWidth;
/** Height of the key, not including the gap */
public final int mHeight;
- /** The horizontal gap before this key */
+ /** The horizontal gap around this key */
public final int mGap;
+ /** The visual insets */
+ public final int mVisualInsetsLeft;
+ public final int mVisualInsetsRight;
/** Whether this key is sticky, i.e., a toggle key */
public final boolean mSticky;
/** X coordinate of the key in the keyboard layout */
@@ -144,6 +147,7 @@ public class Key {
mKeyboard = keyboard;
mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap();
mGap = keyboard.getHorizontalGap();
+ mVisualInsetsLeft = mVisualInsetsRight = 0;
mWidth = width - mGap;
mEdgeFlags = edgeFlags;
mHintIcon = null;
@@ -230,6 +234,10 @@ public class Key {
mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0)
| row.mRowEdgeFlags;
+ mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_visualInsetsLeft, mKeyboard.getDisplayHeight(), 0);
+ mVisualInsetsRight = KeyboardParser.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_visualInsetsRight, mKeyboard.getDisplayHeight(), 0);
mPreviewIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview);
Keyboard.setDefaultBounds(mPreviewIcon);
mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index e82796bf4..7b570d7ed 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -677,11 +677,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Switch the character to uppercase if shift is pressed
String label = key.mLabel == null? null : adjustCase(key.mLabel).toString();
+ final int keyDrawX = key.mX + key.mVisualInsetsLeft;
+ final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
final Rect bounds = keyBackground.getBounds();
- if (key.mWidth != bounds.right || key.mHeight != bounds.bottom) {
- keyBackground.setBounds(0, 0, key.mWidth, key.mHeight);
+ if (keyDrawWidth != bounds.right || key.mHeight != bounds.bottom) {
+ keyBackground.setBounds(0, 0, keyDrawWidth, key.mHeight);
}
- canvas.translate(key.mX + kbdPaddingLeft, key.mY + kbdPaddingTop);
+ canvas.translate(keyDrawX + kbdPaddingLeft, key.mY + kbdPaddingTop);
keyBackground.draw(canvas);
final int rowHeight = padding.top + key.mHeight;
@@ -697,14 +699,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
baseline = key.mHeight -
+ labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR;
if (DEBUG_SHOW_ALIGN)
- drawHorizontalLine(canvas, (int)baseline, key.mWidth, 0xc0008000,
+ drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000,
new Paint());
} else { // Align center
final float centerY = (key.mHeight + padding.top - padding.bottom) / 2;
baseline = centerY
+ labelCharHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER;
if (DEBUG_SHOW_ALIGN)
- drawHorizontalLine(canvas, (int)baseline, key.mWidth, 0xc0008000,
+ drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000,
new Paint());
}
// Horizontal label text alignment
@@ -715,12 +717,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
if (DEBUG_SHOW_ALIGN)
drawVerticalLine(canvas, positionX, rowHeight, 0xc0800080, new Paint());
} else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
- positionX = key.mWidth - mKeyLabelHorizontalPadding - padding.right;
+ positionX = keyDrawWidth - mKeyLabelHorizontalPadding - padding.right;
paint.setTextAlign(Align.RIGHT);
if (DEBUG_SHOW_ALIGN)
drawVerticalLine(canvas, positionX, rowHeight, 0xc0808000, new Paint());
} else {
- positionX = (key.mWidth + padding.left - padding.right) / 2;
+ positionX = (keyDrawWidth + padding.left - padding.right) / 2;
paint.setTextAlign(Align.CENTER);
if (DEBUG_SHOW_ALIGN) {
if (label.length() > 1)
@@ -756,13 +758,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
if (DEBUG_SHOW_ALIGN)
drawVerticalLine(canvas, drawableX, rowHeight, 0xc0800080, new Paint());
} else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
- drawableX = key.mWidth - padding.right - mKeyLabelHorizontalPadding
+ drawableX = keyDrawWidth - padding.right - mKeyLabelHorizontalPadding
- drawableWidth;
if (DEBUG_SHOW_ALIGN)
drawVerticalLine(canvas, drawableX + drawableWidth, rowHeight,
0xc0808000, new Paint());
} else { // Align center
- drawableX = (key.mWidth + padding.left - padding.right - drawableWidth) / 2;
+ drawableX = (keyDrawWidth + padding.left - padding.right - drawableWidth) / 2;
if (DEBUG_SHOW_ALIGN)
drawVerticalLine(canvas, drawableX + drawableWidth / 2, rowHeight,
0xc0008080, new Paint());
@@ -773,7 +775,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
0x80c00000, new Paint());
}
if (key.mHintIcon != null) {
- final int drawableWidth = key.mWidth;
+ final int drawableWidth = keyDrawWidth;
final int drawableHeight = key.mHeight;
final int drawableX = 0;
final int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL;
@@ -785,7 +787,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight,
0x80c0c000, new Paint());
}
- canvas.translate(-key.mX - kbdPaddingLeft, -key.mY - kbdPaddingTop);
+ canvas.translate(-keyDrawX - kbdPaddingLeft, -key.mY - kbdPaddingTop);
}
// TODO: Move this function to ProximityInfo for getting rid of public declarations for
@@ -921,6 +923,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// WindowManager.BadTokenException.
if (key == null || !mInForeground)
return;
+ final int keyDrawX = key.mX + key.mVisualInsetsLeft;
+ final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
// What we show as preview should match what we show on key top in onBufferDraw().
if (key.mLabel != null) {
// TODO Should take care of temporaryShiftLabel here.
@@ -941,7 +945,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
- int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.mWidth
+ int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), keyDrawWidth
+ mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
final int popupHeight = mPreviewHeight;
LayoutParams lp = mPreviewText.getLayoutParams();
@@ -950,7 +954,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
lp.height = popupHeight;
}
- int popupPreviewX = key.mX - (popupWidth - key.mWidth) / 2;
+ int popupPreviewX = keyDrawX - (popupWidth - keyDrawWidth) / 2;
int popupPreviewY = key.mY - popupHeight + mPreviewOffset;
mHandler.cancelDismissPreview();
@@ -973,10 +977,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
if (popupPreviewY + mWindowY < 0) {
// If the key you're pressing is on the left side of the keyboard, show the popup on
// the right, offset by enough to see at least one key to the left/right.
- if (key.mX + key.mWidth <= getWidth() / 2) {
- popupPreviewX += (int) (key.mWidth * 2.5);
+ if (keyDrawX + keyDrawWidth <= getWidth() / 2) {
+ popupPreviewX += (int) (keyDrawWidth * 2.5);
} else {
- popupPreviewX -= (int) (key.mWidth * 2.5);
+ popupPreviewX -= (int) (keyDrawWidth * 2.5);
}
popupPreviewY += popupHeight;
}