* commit '0bed75a81844f35cce359c2a7dfac71a8b3d84b9': Add Key label off center attribute
This commit is contained in:
commit
72d0f08743
7 changed files with 53 additions and 16 deletions
|
@ -293,7 +293,7 @@
|
||||||
<attr name="keyLabelFlags" format="integer">
|
<attr name="keyLabelFlags" format="integer">
|
||||||
<!-- This should be aligned with Key.LABEL_FLAGS__* -->
|
<!-- This should be aligned with Key.LABEL_FLAGS__* -->
|
||||||
<flag name="alignIconToBottom" value="0x04" />
|
<flag name="alignIconToBottom" value="0x04" />
|
||||||
<flag name="alignLeftOfCenter" value="0x08" />
|
<flag name="alignLabelOffCenter" value="0x08" />
|
||||||
<flag name="fontNormal" value="0x10" />
|
<flag name="fontNormal" value="0x10" />
|
||||||
<flag name="fontMonoSpace" value="0x20" />
|
<flag name="fontMonoSpace" value="0x20" />
|
||||||
<flag name="fontDefault" value="0x30" />
|
<flag name="fontDefault" value="0x30" />
|
||||||
|
@ -368,6 +368,14 @@
|
||||||
<attr name="keyHintLabelRatio" format="fraction" />
|
<attr name="keyHintLabelRatio" format="fraction" />
|
||||||
<!-- Size of the text for shifted letter hint, in the proportion of key height. -->
|
<!-- Size of the text for shifted letter hint, in the proportion of key height. -->
|
||||||
<attr name="keyShiftedLetterHintRatio" format="fraction" />
|
<attr name="keyShiftedLetterHintRatio" format="fraction" />
|
||||||
|
<!-- The label's horizontal offset to the center of the key. Negative is to left and
|
||||||
|
positive is to right. The value is in proportion of the width of
|
||||||
|
TypefaceUtils.KEY_LABEL_REFERENCE_CHAR. -->
|
||||||
|
<attr name="keyLabelOffCenterRatio" format="fraction" />
|
||||||
|
<!-- The hint label's horizontal offset to the center of the key. Negative is to left and
|
||||||
|
positive is to right. The value is in proportion of the width of
|
||||||
|
TypefaceUtils.KEY_LABEL_REFERENCE_CHAR. -->
|
||||||
|
<attr name="keyHintLabelOffCenterRatio" format="fraction" />
|
||||||
<!-- Color to use for the label in a key. -->
|
<!-- Color to use for the label in a key. -->
|
||||||
<attr name="keyTextColor" format="color" />
|
<attr name="keyTextColor" format="color" />
|
||||||
<attr name="keyTextShadowColor" format="color" />
|
<attr name="keyTextShadowColor" format="color" />
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
<item name="keyHintLetterRatio">@fraction/config_key_hint_letter_ratio</item>
|
<item name="keyHintLetterRatio">@fraction/config_key_hint_letter_ratio</item>
|
||||||
<item name="keyHintLabelRatio">@fraction/config_key_hint_label_ratio</item>
|
<item name="keyHintLabelRatio">@fraction/config_key_hint_label_ratio</item>
|
||||||
<item name="keyShiftedLetterHintRatio">@fraction/config_key_shifted_letter_hint_ratio</item>
|
<item name="keyShiftedLetterHintRatio">@fraction/config_key_shifted_letter_hint_ratio</item>
|
||||||
|
<item name="keyLabelOffCenterRatio">-175%</item>
|
||||||
|
<item name="keyHintLabelOffCenterRatio">200%</item>
|
||||||
<item name="keyTypeface">normal</item>
|
<item name="keyTypeface">normal</item>
|
||||||
<!-- A negative value to disable key text shadow layer. -->
|
<!-- A negative value to disable key text shadow layer. -->
|
||||||
<item name="keyTextShadowRadius">-1.0</item>
|
<item name="keyTextShadowRadius">-1.0</item>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
latin:parentStyle="numKeyBaseStyle" />
|
latin:parentStyle="numKeyBaseStyle" />
|
||||||
<key-style
|
<key-style
|
||||||
latin:styleName="numberKeyStyle"
|
latin:styleName="numberKeyStyle"
|
||||||
latin:keyLabelFlags="alignLeftOfCenter|hasHintLabel"
|
latin:keyLabelFlags="alignLabelOffCenter|hasHintLabel"
|
||||||
latin:parentStyle="numKeyStyle" />
|
latin:parentStyle="numKeyStyle" />
|
||||||
<key-style
|
<key-style
|
||||||
latin:styleName="num0KeyStyle"
|
latin:styleName="num0KeyStyle"
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class Key implements Comparable<Key> {
|
||||||
/** Flags of the label */
|
/** Flags of the label */
|
||||||
private final int mLabelFlags;
|
private final int mLabelFlags;
|
||||||
private static final int LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM = 0x04;
|
private static final int LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM = 0x04;
|
||||||
private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08;
|
private static final int LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER = 0x08;
|
||||||
// Font typeface specification.
|
// Font typeface specification.
|
||||||
private static final int LABEL_FLAGS_FONT_MASK = 0x30;
|
private static final int LABEL_FLAGS_FONT_MASK = 0x30;
|
||||||
private static final int LABEL_FLAGS_FONT_NORMAL = 0x10;
|
private static final int LABEL_FLAGS_FONT_NORMAL = 0x10;
|
||||||
|
@ -648,8 +648,8 @@ public class Key implements Comparable<Key> {
|
||||||
return (mLabelFlags & LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM) != 0;
|
return (mLabelFlags & LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isAlignLeftOfCenter() {
|
public final boolean isAlignLabelOffCenter() {
|
||||||
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0;
|
return (mLabelFlags & LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean hasPopupHint() {
|
public final boolean hasPopupHint() {
|
||||||
|
|
|
@ -369,9 +369,9 @@ public class KeyboardView extends View {
|
||||||
final float baseline = centerY + labelCharHeight / 2.0f;
|
final float baseline = centerY + labelCharHeight / 2.0f;
|
||||||
|
|
||||||
// Horizontal label text alignment
|
// Horizontal label text alignment
|
||||||
if (key.isAlignLeftOfCenter()) {
|
if (key.isAlignLabelOffCenter()) {
|
||||||
// TODO: Parameterise this?
|
// The label is placed off center of the key. Used mainly on "phone number" layout.
|
||||||
positionX = centerX - labelCharWidth * 7.0f / 4.0f;
|
positionX = centerX + params.mLabelOffCenterRatio * labelCharWidth;
|
||||||
paint.setTextAlign(Align.LEFT);
|
paint.setTextAlign(Align.LEFT);
|
||||||
} else {
|
} else {
|
||||||
positionX = centerX;
|
positionX = centerX;
|
||||||
|
@ -418,15 +418,12 @@ public class KeyboardView extends View {
|
||||||
blendAlpha(paint, params.mAnimAlpha);
|
blendAlpha(paint, params.mAnimAlpha);
|
||||||
final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
|
final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
|
||||||
final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
|
final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
|
||||||
final KeyVisualAttributes visualAttr = key.getVisualAttributes();
|
final float adjustmentY = params.mHintLabelVerticalAdjustment * labelCharHeight;
|
||||||
final float adjustmentY = (visualAttr == null) ? 0.0f
|
|
||||||
: visualAttr.mHintLabelVerticalAdjustment * labelCharHeight;
|
|
||||||
final float hintX, hintY;
|
final float hintX, hintY;
|
||||||
if (key.hasHintLabel()) {
|
if (key.hasHintLabel()) {
|
||||||
// The hint label is placed just right of the key label. Used mainly on
|
// The hint label is placed just right of the key label. Used mainly on
|
||||||
// "phone number" layout.
|
// "phone number" layout.
|
||||||
// TODO: Generalize the following calculations.
|
hintX = positionX + params.mHintLabelOffCenterRatio * labelCharWidth;
|
||||||
hintX = positionX + labelCharWidth * 2.0f;
|
|
||||||
hintY = centerY + labelCharHeight / 2.0f;
|
hintY = centerY + labelCharHeight / 2.0f;
|
||||||
paint.setTextAlign(Align.LEFT);
|
paint.setTextAlign(Align.LEFT);
|
||||||
} else if (key.hasShiftedLetterHint()) {
|
} else if (key.hasShiftedLetterHint()) {
|
||||||
|
|
|
@ -42,6 +42,10 @@ public final class KeyDrawParams {
|
||||||
public int mShiftedLetterHintActivatedColor;
|
public int mShiftedLetterHintActivatedColor;
|
||||||
public int mPreviewTextColor;
|
public int mPreviewTextColor;
|
||||||
|
|
||||||
|
public float mHintLabelVerticalAdjustment;
|
||||||
|
public float mLabelOffCenterRatio;
|
||||||
|
public float mHintLabelOffCenterRatio;
|
||||||
|
|
||||||
public int mAnimAlpha;
|
public int mAnimAlpha;
|
||||||
|
|
||||||
public KeyDrawParams() {}
|
public KeyDrawParams() {}
|
||||||
|
@ -68,6 +72,10 @@ public final class KeyDrawParams {
|
||||||
mShiftedLetterHintActivatedColor = copyFrom.mShiftedLetterHintActivatedColor;
|
mShiftedLetterHintActivatedColor = copyFrom.mShiftedLetterHintActivatedColor;
|
||||||
mPreviewTextColor = copyFrom.mPreviewTextColor;
|
mPreviewTextColor = copyFrom.mPreviewTextColor;
|
||||||
|
|
||||||
|
mHintLabelVerticalAdjustment = copyFrom.mHintLabelVerticalAdjustment;
|
||||||
|
mLabelOffCenterRatio = copyFrom.mLabelOffCenterRatio;
|
||||||
|
mHintLabelOffCenterRatio = copyFrom.mHintLabelOffCenterRatio;
|
||||||
|
|
||||||
mAnimAlpha = copyFrom.mAnimAlpha;
|
mAnimAlpha = copyFrom.mAnimAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +111,13 @@ public final class KeyDrawParams {
|
||||||
mShiftedLetterHintActivatedColor = selectColor(
|
mShiftedLetterHintActivatedColor = selectColor(
|
||||||
attr.mShiftedLetterHintActivatedColor, mShiftedLetterHintActivatedColor);
|
attr.mShiftedLetterHintActivatedColor, mShiftedLetterHintActivatedColor);
|
||||||
mPreviewTextColor = selectColor(attr.mPreviewTextColor, mPreviewTextColor);
|
mPreviewTextColor = selectColor(attr.mPreviewTextColor, mPreviewTextColor);
|
||||||
|
|
||||||
|
mHintLabelVerticalAdjustment = selectFloatIfNonZero(
|
||||||
|
attr.mHintLabelVerticalAdjustment, mHintLabelVerticalAdjustment);
|
||||||
|
mLabelOffCenterRatio = selectFloatIfNonZero(
|
||||||
|
attr.mLabelOffCenterRatio, mLabelOffCenterRatio);
|
||||||
|
mHintLabelOffCenterRatio = selectFloatIfNonZero(
|
||||||
|
attr.mHintLabelOffCenterRatio, mHintLabelOffCenterRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyDrawParams mayCloneAndUpdateParams(final int keyHeight,
|
public KeyDrawParams mayCloneAndUpdateParams(final int keyHeight,
|
||||||
|
@ -115,7 +130,7 @@ public final class KeyDrawParams {
|
||||||
return newParams;
|
return newParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight,
|
private static int selectTextSizeFromDimensionOrRatio(final int keyHeight,
|
||||||
final int dimens, final float ratio, final int defaultDimens) {
|
final int dimens, final float ratio, final int defaultDimens) {
|
||||||
if (ResourceUtils.isValidDimensionPixelSize(dimens)) {
|
if (ResourceUtils.isValidDimensionPixelSize(dimens)) {
|
||||||
return dimens;
|
return dimens;
|
||||||
|
@ -126,7 +141,7 @@ public final class KeyDrawParams {
|
||||||
return defaultDimens;
|
return defaultDimens;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int selectTextSize(final int keyHeight, final float ratio,
|
private static int selectTextSize(final int keyHeight, final float ratio,
|
||||||
final int defaultSize) {
|
final int defaultSize) {
|
||||||
if (ResourceUtils.isValidFraction(ratio)) {
|
if (ResourceUtils.isValidFraction(ratio)) {
|
||||||
return (int)(keyHeight * ratio);
|
return (int)(keyHeight * ratio);
|
||||||
|
@ -134,10 +149,17 @@ public final class KeyDrawParams {
|
||||||
return defaultSize;
|
return defaultSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int selectColor(final int attrColor, final int defaultColor) {
|
private static int selectColor(final int attrColor, final int defaultColor) {
|
||||||
if (attrColor != 0) {
|
if (attrColor != 0) {
|
||||||
return attrColor;
|
return attrColor;
|
||||||
}
|
}
|
||||||
return defaultColor;
|
return defaultColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static float selectFloatIfNonZero(final float attrFloat, final float defaultFloat) {
|
||||||
|
if (attrFloat != 0) {
|
||||||
|
return attrFloat;
|
||||||
|
}
|
||||||
|
return defaultFloat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ public final class KeyVisualAttributes {
|
||||||
public final int mPreviewTextColor;
|
public final int mPreviewTextColor;
|
||||||
|
|
||||||
public final float mHintLabelVerticalAdjustment;
|
public final float mHintLabelVerticalAdjustment;
|
||||||
|
public final float mLabelOffCenterRatio;
|
||||||
|
public final float mHintLabelOffCenterRatio;
|
||||||
|
|
||||||
private static final int[] VISUAL_ATTRIBUTE_IDS = {
|
private static final int[] VISUAL_ATTRIBUTE_IDS = {
|
||||||
R.styleable.Keyboard_Key_keyTypeface,
|
R.styleable.Keyboard_Key_keyTypeface,
|
||||||
|
@ -69,6 +71,8 @@ public final class KeyVisualAttributes {
|
||||||
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor,
|
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor,
|
||||||
R.styleable.Keyboard_Key_keyPreviewTextColor,
|
R.styleable.Keyboard_Key_keyPreviewTextColor,
|
||||||
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment,
|
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment,
|
||||||
|
R.styleable.Keyboard_Key_keyLabelOffCenterRatio,
|
||||||
|
R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio
|
||||||
};
|
};
|
||||||
private static final SparseIntArray sVisualAttributeIds = new SparseIntArray();
|
private static final SparseIntArray sVisualAttributeIds = new SparseIntArray();
|
||||||
private static final int ATTR_DEFINED = 1;
|
private static final int ATTR_DEFINED = 1;
|
||||||
|
@ -135,5 +139,9 @@ public final class KeyVisualAttributes {
|
||||||
|
|
||||||
mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
|
mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
|
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
|
||||||
|
mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
|
||||||
|
mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
|
||||||
|
R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue