Add keyLabelHintVerticalAdjustment attribute

Bug: 11546184
Change-Id: I1fbdbbdcf4d6a74888c48f2e4f0b7afce7913653
This commit is contained in:
Tadashi G. Takaoka 2013-11-07 18:11:19 +09:00
parent 4d49908682
commit 541fa7858d
3 changed files with 12 additions and 1 deletions

View File

@ -276,6 +276,8 @@
<attr name="keyLabel" format="string" />
<!-- The hint label to display on the key in conjunction with the label. -->
<attr name="keyHintLabel" format="string" />
<!-- The vertical adjustment of key hint label in proportion to its height. -->
<attr name="keyHintLabelVerticalAdjustment" format="fraction" />
<!-- The key label flags. -->
<attr name="keyLabelFlags" format="integer">
<!-- This should be aligned with Key.LABEL_FLAGS__* -->

View File

@ -454,6 +454,9 @@ public class KeyboardView extends View {
blendAlpha(paint, params.mAnimAlpha);
final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
final KeyVisualAttributes visualAttr = key.getVisualAttributes();
final float adjustmentY = (visualAttr == null) ? 0.0f
: visualAttr.mHintLabelVerticalAdjustment * labelCharHeight;
final float hintX, hintY;
if (key.hasHintLabel()) {
// The hint label is placed just right of the key label. Used mainly on
@ -477,7 +480,7 @@ public class KeyboardView extends View {
hintY = -paint.ascent();
paint.setTextAlign(Align.CENTER);
}
canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY, paint);
canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY + adjustmentY, paint);
if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint();

View File

@ -47,6 +47,8 @@ public final class KeyVisualAttributes {
public final int mShiftedLetterHintActivatedColor;
public final int mPreviewTextColor;
public final float mHintLabelVerticalAdjustment;
private static final int[] VISUAL_ATTRIBUTE_IDS = {
R.styleable.Keyboard_Key_keyTypeface,
R.styleable.Keyboard_Key_keyLetterSize,
@ -65,6 +67,7 @@ public final class KeyVisualAttributes {
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor,
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor,
R.styleable.Keyboard_Key_keyPreviewTextColor,
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment,
};
private static final SparseIntArray sVisualAttributeIds = new SparseIntArray();
private static final int ATTR_DEFINED = 1;
@ -127,5 +130,8 @@ public final class KeyVisualAttributes {
mShiftedLetterHintActivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
}
}