am 0a4f4b2b: Add autoScale Key attribute
* commit '0a4f4b2bbdac07fc88d41911e57c55ac0c1fd587': Add autoScale Key attributemain
commit
8d68a68258
|
@ -295,14 +295,16 @@
|
||||||
<flag name="withIconLeft" value="0x1000" />
|
<flag name="withIconLeft" value="0x1000" />
|
||||||
<flag name="withIconRight" value="0x2000" />
|
<flag name="withIconRight" value="0x2000" />
|
||||||
<flag name="autoXScale" value="0x4000" />
|
<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,
|
<!-- If true, character case of code, altCode, moreKeys, keyOutputText, keyLabel,
|
||||||
or keyHintLabel will never be subject to change. -->
|
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
|
<!-- If true, use keyShiftedLetterHintActivatedColor for the shifted letter hint and
|
||||||
keyTextInactivatedColor for the primary key top label. -->
|
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. -->
|
<!-- If true, use EditorInfo.actionLabel for the key label. -->
|
||||||
<flag name="fromCustomActionLabel" value="0x20000" />
|
<flag name="fromCustomActionLabel" value="0x40000" />
|
||||||
<!-- If true, disable keyHintLabel. -->
|
<!-- If true, disable keyHintLabel. -->
|
||||||
<flag name="disableKeyHintLabel" value="0x40000000" />
|
<flag name="disableKeyHintLabel" value="0x40000000" />
|
||||||
<!-- If true, disable additionalMoreKeys. -->
|
<!-- If true, disable additionalMoreKeys. -->
|
||||||
|
|
|
@ -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_HAS_HINT_LABEL = 0x800;
|
||||||
private static final int LABEL_FLAGS_WITH_ICON_LEFT = 0x1000;
|
private static final int LABEL_FLAGS_WITH_ICON_LEFT = 0x1000;
|
||||||
private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000;
|
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_AUTO_X_SCALE = 0x4000;
|
||||||
private static final int LABEL_FLAGS_PRESERVE_CASE = 0x8000;
|
private static final int LABEL_FLAGS_AUTO_Y_SCALE = 0x8000;
|
||||||
private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x10000;
|
private static final int LABEL_FLAGS_AUTO_SCALE = LABEL_FLAGS_AUTO_X_SCALE
|
||||||
private static final int LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL = 0x20000;
|
| 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_HINT_LABEL = 0x40000000;
|
||||||
private static final int LABEL_FLAGS_DISABLE_ADDITIONAL_MORE_KEYS = 0x80000000;
|
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;
|
return (mLabelFlags & LABEL_FLAGS_WITH_ICON_RIGHT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean needsXScale() {
|
public final boolean needsAutoXScale() {
|
||||||
return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0;
|
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() {
|
public final boolean isShiftedLetterActivated() {
|
||||||
return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0;
|
return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,9 +404,15 @@ public class KeyboardView extends View {
|
||||||
positionX = centerX;
|
positionX = centerX;
|
||||||
paint.setTextAlign(Align.CENTER);
|
paint.setTextAlign(Align.CENTER);
|
||||||
}
|
}
|
||||||
if (key.needsXScale()) {
|
if (key.needsAutoXScale()) {
|
||||||
paint.setTextScaleX(Math.min(1.0f,
|
final float ratio = Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) /
|
||||||
(keyWidth * MAX_LABEL_RATIO) / TypefaceUtils.getLabelWidth(label, paint)));
|
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));
|
paint.setColor(key.selectTextColor(params));
|
||||||
|
|
Loading…
Reference in New Issue