Add visualInsetsLeft and Right as Key attribute
Bug: 4269094 Change-Id: Ic38d326a8e9ef802453c909f3a81d556863acc9bmain
parent
a8c163f262
commit
56abeabced
|
@ -142,6 +142,9 @@
|
||||||
<attr name="shiftedIcon" format="reference" />
|
<attr name="shiftedIcon" format="reference" />
|
||||||
<!-- The key is enabled and responds on press. -->
|
<!-- The key is enabled and responds on press. -->
|
||||||
<attr name="enabled" format="boolean" />
|
<attr name="enabled" format="boolean" />
|
||||||
|
<!-- Visual insets -->
|
||||||
|
<attr name="visualInsetsLeft" format="dimension|fraction" />
|
||||||
|
<attr name="visualInsetsRight" format="dimension|fraction" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="Keyboard_Row">
|
<declare-styleable name="Keyboard_Row">
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="shiftKeyStyle"
|
latin:keyStyle="shiftKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsRight="2%p"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="w"
|
latin:keyLabel="w"
|
||||||
|
@ -131,6 +132,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="deleteKeyStyle"
|
latin:keyStyle="deleteKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsLeft="2%p"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
</Row>
|
</Row>
|
||||||
<include
|
<include
|
||||||
|
|
|
@ -48,11 +48,10 @@
|
||||||
latin:keyLabel="ם" />
|
latin:keyLabel="ם" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="פ" />
|
latin:keyLabel="פ" />
|
||||||
<Spacer
|
|
||||||
latin:horizontalGap="1.25%p" />
|
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="deleteKeyStyle"
|
latin:keyStyle="deleteKeyStyle"
|
||||||
latin:keyWidth="13.75%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsLeft="2%p"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
>
|
>
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="shiftKeyStyle"
|
latin:keyStyle="shiftKeyStyle"
|
||||||
latin:keyWidth="13%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsRight="2%p"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
<Spacer
|
|
||||||
latin:horizontalGap="2%p" />
|
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="z"
|
latin:keyLabel="z"
|
||||||
latin:popupCharacters="@string/alternates_for_z" />
|
latin:popupCharacters="@string/alternates_for_z" />
|
||||||
|
@ -48,11 +47,10 @@
|
||||||
latin:popupCharacters="@string/alternates_for_n" />
|
latin:popupCharacters="@string/alternates_for_n" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="m" />
|
latin:keyLabel="m" />
|
||||||
<Spacer
|
|
||||||
latin:horizontalGap="2%p" />
|
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="deleteKeyStyle"
|
latin:keyStyle="deleteKeyStyle"
|
||||||
latin:keyWidth="13%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsLeft="2%p"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
</Row>
|
</Row>
|
||||||
</merge>
|
</merge>
|
||||||
|
|
|
@ -78,6 +78,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="shiftKeyStyle"
|
latin:keyStyle="shiftKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsRight="2%p"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="y"
|
latin:keyLabel="y"
|
||||||
|
@ -100,6 +101,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="deleteKeyStyle"
|
latin:keyStyle="deleteKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsLeft="2%p"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
</Row>
|
</Row>
|
||||||
<include
|
<include
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="altKeyStyle"
|
latin:keyStyle="altKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsRight="2%p"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="!"
|
latin:keyLabel="!"
|
||||||
|
@ -122,6 +123,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="deleteKeyStyle"
|
latin:keyStyle="deleteKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsLeft="2%p"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
</Row>
|
</Row>
|
||||||
<include latin:keyboardLayout="@xml/kbd_symbols_row4" />
|
<include latin:keyboardLayout="@xml/kbd_symbols_row4" />
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="shiftKeyStyle"
|
latin:keyStyle="shiftKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsRight="2%p"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyLabel="™" />
|
latin:keyLabel="™" />
|
||||||
|
@ -110,6 +111,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="deleteKeyStyle"
|
latin:keyStyle="deleteKeyStyle"
|
||||||
latin:keyWidth="15%p"
|
latin:keyWidth="15%p"
|
||||||
|
latin:visualInsetsLeft="2%p"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
</Row>
|
</Row>
|
||||||
<include latin:keyboardLayout="@xml/kbd_symbols_shift_row4" />
|
<include latin:keyboardLayout="@xml/kbd_symbols_shift_row4" />
|
||||||
|
|
|
@ -61,8 +61,11 @@ public class Key {
|
||||||
public final int mWidth;
|
public final int mWidth;
|
||||||
/** Height of the key, not including the gap */
|
/** Height of the key, not including the gap */
|
||||||
public final int mHeight;
|
public final int mHeight;
|
||||||
/** The horizontal gap before this key */
|
/** The horizontal gap around this key */
|
||||||
public final int mGap;
|
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 */
|
/** Whether this key is sticky, i.e., a toggle key */
|
||||||
public final boolean mSticky;
|
public final boolean mSticky;
|
||||||
/** X coordinate of the key in the keyboard layout */
|
/** X coordinate of the key in the keyboard layout */
|
||||||
|
@ -144,6 +147,7 @@ public class Key {
|
||||||
mKeyboard = keyboard;
|
mKeyboard = keyboard;
|
||||||
mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap();
|
mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap();
|
||||||
mGap = keyboard.getHorizontalGap();
|
mGap = keyboard.getHorizontalGap();
|
||||||
|
mVisualInsetsLeft = mVisualInsetsRight = 0;
|
||||||
mWidth = width - mGap;
|
mWidth = width - mGap;
|
||||||
mEdgeFlags = edgeFlags;
|
mEdgeFlags = edgeFlags;
|
||||||
mHintIcon = null;
|
mHintIcon = null;
|
||||||
|
@ -230,6 +234,10 @@ public class Key {
|
||||||
mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0)
|
mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0)
|
||||||
| row.mRowEdgeFlags;
|
| 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);
|
mPreviewIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview);
|
||||||
Keyboard.setDefaultBounds(mPreviewIcon);
|
Keyboard.setDefaultBounds(mPreviewIcon);
|
||||||
mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon);
|
mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon);
|
||||||
|
|
|
@ -677,11 +677,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
// Switch the character to uppercase if shift is pressed
|
// Switch the character to uppercase if shift is pressed
|
||||||
String label = key.mLabel == null? null : adjustCase(key.mLabel).toString();
|
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();
|
final Rect bounds = keyBackground.getBounds();
|
||||||
if (key.mWidth != bounds.right || key.mHeight != bounds.bottom) {
|
if (keyDrawWidth != bounds.right || key.mHeight != bounds.bottom) {
|
||||||
keyBackground.setBounds(0, 0, key.mWidth, key.mHeight);
|
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);
|
keyBackground.draw(canvas);
|
||||||
|
|
||||||
final int rowHeight = padding.top + key.mHeight;
|
final int rowHeight = padding.top + key.mHeight;
|
||||||
|
@ -697,14 +699,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
baseline = key.mHeight -
|
baseline = key.mHeight -
|
||||||
+ labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR;
|
+ labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR;
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawHorizontalLine(canvas, (int)baseline, key.mWidth, 0xc0008000,
|
drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000,
|
||||||
new Paint());
|
new Paint());
|
||||||
} else { // Align center
|
} else { // Align center
|
||||||
final float centerY = (key.mHeight + padding.top - padding.bottom) / 2;
|
final float centerY = (key.mHeight + padding.top - padding.bottom) / 2;
|
||||||
baseline = centerY
|
baseline = centerY
|
||||||
+ labelCharHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER;
|
+ labelCharHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER;
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawHorizontalLine(canvas, (int)baseline, key.mWidth, 0xc0008000,
|
drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000,
|
||||||
new Paint());
|
new Paint());
|
||||||
}
|
}
|
||||||
// Horizontal label text alignment
|
// Horizontal label text alignment
|
||||||
|
@ -715,12 +717,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawVerticalLine(canvas, positionX, rowHeight, 0xc0800080, new Paint());
|
drawVerticalLine(canvas, positionX, rowHeight, 0xc0800080, new Paint());
|
||||||
} else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
|
} 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);
|
paint.setTextAlign(Align.RIGHT);
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawVerticalLine(canvas, positionX, rowHeight, 0xc0808000, new Paint());
|
drawVerticalLine(canvas, positionX, rowHeight, 0xc0808000, new Paint());
|
||||||
} else {
|
} else {
|
||||||
positionX = (key.mWidth + padding.left - padding.right) / 2;
|
positionX = (keyDrawWidth + padding.left - padding.right) / 2;
|
||||||
paint.setTextAlign(Align.CENTER);
|
paint.setTextAlign(Align.CENTER);
|
||||||
if (DEBUG_SHOW_ALIGN) {
|
if (DEBUG_SHOW_ALIGN) {
|
||||||
if (label.length() > 1)
|
if (label.length() > 1)
|
||||||
|
@ -756,13 +758,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawVerticalLine(canvas, drawableX, rowHeight, 0xc0800080, new Paint());
|
drawVerticalLine(canvas, drawableX, rowHeight, 0xc0800080, new Paint());
|
||||||
} else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
|
} else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
|
||||||
drawableX = key.mWidth - padding.right - mKeyLabelHorizontalPadding
|
drawableX = keyDrawWidth - padding.right - mKeyLabelHorizontalPadding
|
||||||
- drawableWidth;
|
- drawableWidth;
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawVerticalLine(canvas, drawableX + drawableWidth, rowHeight,
|
drawVerticalLine(canvas, drawableX + drawableWidth, rowHeight,
|
||||||
0xc0808000, new Paint());
|
0xc0808000, new Paint());
|
||||||
} else { // Align center
|
} else { // Align center
|
||||||
drawableX = (key.mWidth + padding.left - padding.right - drawableWidth) / 2;
|
drawableX = (keyDrawWidth + padding.left - padding.right - drawableWidth) / 2;
|
||||||
if (DEBUG_SHOW_ALIGN)
|
if (DEBUG_SHOW_ALIGN)
|
||||||
drawVerticalLine(canvas, drawableX + drawableWidth / 2, rowHeight,
|
drawVerticalLine(canvas, drawableX + drawableWidth / 2, rowHeight,
|
||||||
0xc0008080, new Paint());
|
0xc0008080, new Paint());
|
||||||
|
@ -773,7 +775,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
0x80c00000, new Paint());
|
0x80c00000, new Paint());
|
||||||
}
|
}
|
||||||
if (key.mHintIcon != null) {
|
if (key.mHintIcon != null) {
|
||||||
final int drawableWidth = key.mWidth;
|
final int drawableWidth = keyDrawWidth;
|
||||||
final int drawableHeight = key.mHeight;
|
final int drawableHeight = key.mHeight;
|
||||||
final int drawableX = 0;
|
final int drawableX = 0;
|
||||||
final int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL;
|
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,
|
drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight,
|
||||||
0x80c0c000, new Paint());
|
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
|
// 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.
|
// WindowManager.BadTokenException.
|
||||||
if (key == null || !mInForeground)
|
if (key == null || !mInForeground)
|
||||||
return;
|
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().
|
// What we show as preview should match what we show on key top in onBufferDraw().
|
||||||
if (key.mLabel != null) {
|
if (key.mLabel != null) {
|
||||||
// TODO Should take care of temporaryShiftLabel here.
|
// 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),
|
mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
||||||
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());
|
+ mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
|
||||||
final int popupHeight = mPreviewHeight;
|
final int popupHeight = mPreviewHeight;
|
||||||
LayoutParams lp = mPreviewText.getLayoutParams();
|
LayoutParams lp = mPreviewText.getLayoutParams();
|
||||||
|
@ -950,7 +954,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
lp.height = popupHeight;
|
lp.height = popupHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int popupPreviewX = key.mX - (popupWidth - key.mWidth) / 2;
|
int popupPreviewX = keyDrawX - (popupWidth - keyDrawWidth) / 2;
|
||||||
int popupPreviewY = key.mY - popupHeight + mPreviewOffset;
|
int popupPreviewY = key.mY - popupHeight + mPreviewOffset;
|
||||||
|
|
||||||
mHandler.cancelDismissPreview();
|
mHandler.cancelDismissPreview();
|
||||||
|
@ -973,10 +977,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
if (popupPreviewY + mWindowY < 0) {
|
if (popupPreviewY + mWindowY < 0) {
|
||||||
// If the key you're pressing is on the left side of the keyboard, show the popup on
|
// 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.
|
// the right, offset by enough to see at least one key to the left/right.
|
||||||
if (key.mX + key.mWidth <= getWidth() / 2) {
|
if (keyDrawX + keyDrawWidth <= getWidth() / 2) {
|
||||||
popupPreviewX += (int) (key.mWidth * 2.5);
|
popupPreviewX += (int) (keyDrawWidth * 2.5);
|
||||||
} else {
|
} else {
|
||||||
popupPreviewX -= (int) (key.mWidth * 2.5);
|
popupPreviewX -= (int) (keyDrawWidth * 2.5);
|
||||||
}
|
}
|
||||||
popupPreviewY += popupHeight;
|
popupPreviewY += popupHeight;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue