Add autoScale Key attribute

Bug: 11546184
Change-Id: I754e98dbc0689dbf14c52d4906141a150bde97a6
This commit is contained in:
Tadashi G. Takaoka 2013-11-07 12:48:10 +09:00
parent 42b3663c4b
commit 0a4f4b2bbd
3 changed files with 28 additions and 10 deletions

View file

@ -295,14 +295,16 @@
<flag name="withIconLeft" value="0x1000" />
<flag name="withIconRight" value="0x2000" />
<flag name="autoXScale" value="0x4000" />
<!-- The autoScale value implies autoXScale bit on to optimize scaling code path. -->
<flag name="autoScale" value="0xc000" />
<!-- If true, character case of code, altCode, moreKeys, keyOutputText, keyLabel,
or keyHintLabel will never be subject to change. -->
<flag name="preserveCase" value="0x8000" />
<flag name="preserveCase" value="0x10000" />
<!-- If true, use keyShiftedLetterHintActivatedColor for the shifted letter hint and
keyTextInactivatedColor for the primary key top label. -->
<flag name="shiftedLetterActivated" value="0x10000" />
<flag name="shiftedLetterActivated" value="0x20000" />
<!-- If true, use EditorInfo.actionLabel for the key label. -->
<flag name="fromCustomActionLabel" value="0x20000" />
<flag name="fromCustomActionLabel" value="0x40000" />
<!-- If true, disable keyHintLabel. -->
<flag name="disableKeyHintLabel" value="0x40000000" />
<!-- If true, disable additionalMoreKeys. -->

View file

@ -84,10 +84,16 @@ public class Key implements Comparable<Key> {
private static final int LABEL_FLAGS_HAS_HINT_LABEL = 0x800;
private static final int LABEL_FLAGS_WITH_ICON_LEFT = 0x1000;
private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000;
// The bit to calculate the ratio of key label width against key width. If autoXScale bit is on
// and autoYScale bit is off, the key label may be shrunk only for X-direction.
// If both autoXScale and autoYScale bits are on, the key label text size may be auto scaled.
private static final int LABEL_FLAGS_AUTO_X_SCALE = 0x4000;
private static final int LABEL_FLAGS_PRESERVE_CASE = 0x8000;
private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x10000;
private static final int LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL = 0x20000;
private static final int LABEL_FLAGS_AUTO_Y_SCALE = 0x8000;
private static final int LABEL_FLAGS_AUTO_SCALE = LABEL_FLAGS_AUTO_X_SCALE
| LABEL_FLAGS_AUTO_Y_SCALE;
private static final int LABEL_FLAGS_PRESERVE_CASE = 0x10000;
private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x20000;
private static final int LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL = 0x40000;
private static final int LABEL_FLAGS_DISABLE_HINT_LABEL = 0x40000000;
private static final int LABEL_FLAGS_DISABLE_ADDITIONAL_MORE_KEYS = 0x80000000;
@ -702,10 +708,14 @@ public class Key implements Comparable<Key> {
return (mLabelFlags & LABEL_FLAGS_WITH_ICON_RIGHT) != 0;
}
public final boolean needsXScale() {
public final boolean needsAutoXScale() {
return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0;
}
public final boolean needsAutoScale() {
return (mLabelFlags & LABEL_FLAGS_AUTO_SCALE) == LABEL_FLAGS_AUTO_SCALE;
}
public final boolean isShiftedLetterActivated() {
return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0;
}

View file

@ -404,9 +404,15 @@ public class KeyboardView extends View {
positionX = centerX;
paint.setTextAlign(Align.CENTER);
}
if (key.needsXScale()) {
paint.setTextScaleX(Math.min(1.0f,
(keyWidth * MAX_LABEL_RATIO) / TypefaceUtils.getLabelWidth(label, paint)));
if (key.needsAutoXScale()) {
final float ratio = Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) /
TypefaceUtils.getLabelWidth(label, paint));
if (key.needsAutoScale()) {
final float autoSize = paint.getTextSize() * ratio;
paint.setTextSize(autoSize);
} else {
paint.setTextScaleX(ratio);
}
}
paint.setColor(key.selectTextColor(params));