Introduce autoXScale label option
Bug: 5267649 Change-Id: I7fdcb98c209b7ccf73075ef3a4e758782fe161e3main
parent
f5ef30dfc6
commit
4486d77270
|
@ -217,6 +217,7 @@
|
|||
<flag name="hasHintLabel" value="0x800" />
|
||||
<flag name="withIconLeft" value="0x1000" />
|
||||
<flag name="withIconRight" value="0x2000" />
|
||||
<flag name="autoXScale" value="0x4000" />
|
||||
</attr>
|
||||
<!-- The icon to display on the key instead of the label. -->
|
||||
<attr name="keyIcon" format="enum">
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<Key
|
||||
latin:code="44"
|
||||
latin:keyLabel="@string/label_pause_key"
|
||||
latin:keyLabelOption="followKeyHintLabelRatio|autoXScale"
|
||||
latin:keyWidth="9.25%p" />
|
||||
<Key
|
||||
latin:keyStyle="num1KeyStyle"
|
||||
|
@ -69,6 +70,7 @@
|
|||
<Key
|
||||
latin:code="59"
|
||||
latin:keyLabel="@string/label_wait_key"
|
||||
latin:keyLabelOption="followKeyHintLabelRatio|autoXScale"
|
||||
latin:keyWidth="9.25%p" />
|
||||
<Key
|
||||
latin:keyStyle="num4KeyStyle"
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<Key
|
||||
latin:code="44"
|
||||
latin:keyLabel="@string/label_pause_key"
|
||||
latin:keyLabelOption="followKeyHintLabelRatio|autoXScale"
|
||||
latin:keyWidth="8.047%p" />
|
||||
<Key
|
||||
latin:keyStyle="num1KeyStyle"
|
||||
|
@ -72,6 +73,7 @@
|
|||
<Key
|
||||
latin:code="59"
|
||||
latin:keyLabel="@string/label_wait_key"
|
||||
latin:keyLabelOption="followKeyHintLabelRatio|autoXScale"
|
||||
latin:keyWidth="8.047%p" />
|
||||
<Key
|
||||
latin:keyStyle="num4KeyStyle"
|
||||
|
|
|
@ -101,6 +101,7 @@
|
|||
latin:styleName="returnKeyStyle"
|
||||
latin:code="@integer/key_return"
|
||||
latin:keyLabel="@string/label_go_key"
|
||||
latin:keyLabelOption="autoXScale"
|
||||
latin:parentStyle="functionalKeyStyle" />
|
||||
</case>
|
||||
<case
|
||||
|
@ -110,6 +111,7 @@
|
|||
latin:styleName="returnKeyStyle"
|
||||
latin:code="@integer/key_return"
|
||||
latin:keyLabel="@string/label_next_key"
|
||||
latin:keyLabelOption="autoXScale"
|
||||
latin:parentStyle="functionalKeyStyle" />
|
||||
</case>
|
||||
<case
|
||||
|
@ -119,6 +121,7 @@
|
|||
latin:styleName="returnKeyStyle"
|
||||
latin:code="@integer/key_return"
|
||||
latin:keyLabel="@string/label_done_key"
|
||||
latin:keyLabelOption="autoXScale"
|
||||
latin:parentStyle="functionalKeyStyle" />
|
||||
</case>
|
||||
<case
|
||||
|
@ -128,6 +131,7 @@
|
|||
latin:styleName="returnKeyStyle"
|
||||
latin:code="@integer/key_return"
|
||||
latin:keyLabel="@string/label_send_key"
|
||||
latin:keyLabelOption="autoXScale"
|
||||
latin:parentStyle="functionalKeyStyle" />
|
||||
</case>
|
||||
<case
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<Key
|
||||
latin:code="44"
|
||||
latin:keyLabel="@string/label_pause_key"
|
||||
latin:keyLabelOption="followKeyHintLabelRatio" />
|
||||
latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" />
|
||||
<Key
|
||||
latin:keyLabel=","
|
||||
latin:keyStyle="numKeyStyle" />
|
||||
|
@ -65,7 +65,7 @@
|
|||
<Key
|
||||
latin:code="59"
|
||||
latin:keyLabel="@string/label_wait_key"
|
||||
latin:keyLabelOption="followKeyHintLabelRatio" />
|
||||
latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" />
|
||||
<Key
|
||||
latin:keyLabel="#"
|
||||
latin:keyStyle="numKeyStyle" />
|
||||
|
|
|
@ -64,6 +64,7 @@ public class Key {
|
|||
private static final int LABEL_OPTION_HAS_HINT_LABEL = 0x800;
|
||||
private static final int LABEL_OPTION_WITH_ICON_LEFT = 0x1000;
|
||||
private static final int LABEL_OPTION_WITH_ICON_RIGHT = 0x2000;
|
||||
private static final int LABEL_OPTION_AUTO_X_SCALE = 0x4000;
|
||||
|
||||
/** Icon to display instead of a label. Icon takes precedence over a label */
|
||||
private Drawable mIcon;
|
||||
|
@ -439,6 +440,10 @@ public class Key {
|
|||
return (mLabelOption & LABEL_OPTION_WITH_ICON_RIGHT) != 0;
|
||||
}
|
||||
|
||||
public boolean needsXScale() {
|
||||
return (mLabelOption & LABEL_OPTION_AUTO_X_SCALE) != 0;
|
||||
}
|
||||
|
||||
public Drawable getIcon() {
|
||||
return mIcon;
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||
// TODO: Use resource parameter for this value.
|
||||
private static final float LABEL_ICON_MARGIN = 0.05f;
|
||||
|
||||
// The maximum key label width in the proportion to the key width.
|
||||
private static final float MAX_LABEL_RATIO = 0.90f;
|
||||
|
||||
// Main keyboard
|
||||
private Keyboard mKeyboard;
|
||||
private final KeyDrawParams mKeyDrawParams;
|
||||
|
@ -572,18 +575,22 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||
paint.setTextAlign(Align.LEFT);
|
||||
} else if (key.hasLabelWithIconLeft() && icon != null) {
|
||||
labelWidth = getLabelWidth(label, paint) + icon.getIntrinsicWidth()
|
||||
+ (int)(LABEL_ICON_MARGIN * keyWidth);
|
||||
+ LABEL_ICON_MARGIN * keyWidth;
|
||||
positionX = centerX + labelWidth / 2;
|
||||
paint.setTextAlign(Align.RIGHT);
|
||||
} else if (key.hasLabelWithIconRight() && icon != null) {
|
||||
labelWidth = getLabelWidth(label, paint) + icon.getIntrinsicWidth()
|
||||
+ (int)(LABEL_ICON_MARGIN * keyWidth);
|
||||
+ LABEL_ICON_MARGIN * keyWidth;
|
||||
positionX = centerX - labelWidth / 2;
|
||||
paint.setTextAlign(Align.LEFT);
|
||||
} else {
|
||||
positionX = centerX;
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
}
|
||||
if (key.needsXScale()) {
|
||||
paint.setTextScaleX(
|
||||
Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint)));
|
||||
}
|
||||
|
||||
if (key.hasUppercaseLetter() && isManualTemporaryUpperCase) {
|
||||
paint.setColor(params.mKeyTextInactivatedColor);
|
||||
|
@ -598,8 +605,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||
paint.setColor(Color.TRANSPARENT);
|
||||
}
|
||||
canvas.drawText(label, 0, label.length(), positionX, baseline, paint);
|
||||
// Turn off drop shadow
|
||||
// Turn off drop shadow and reset x-scale.
|
||||
paint.setShadowLayer(0, 0, 0, 0);
|
||||
paint.setTextScaleX(1.0f);
|
||||
|
||||
if (icon != null) {
|
||||
final int iconWidth = icon.getIntrinsicWidth();
|
||||
|
|
Loading…
Reference in New Issue