am e19c520b
: Align space key icon to bottom of a key
* commit 'e19c520b419faaf96180984528ae32b514a1bc77': Align space key icon to bottom of a key
This commit is contained in:
commit
bfcb3323d2
4 changed files with 14 additions and 3 deletions
|
@ -292,6 +292,7 @@
|
||||||
<!-- The key label flags. -->
|
<!-- The key label flags. -->
|
||||||
<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="alignLeftOfCenter" value="0x08" />
|
<flag name="alignLeftOfCenter" value="0x08" />
|
||||||
<flag name="fontNormal" value="0x10" />
|
<flag name="fontNormal" value="0x10" />
|
||||||
<flag name="fontMonoSpace" value="0x20" />
|
<flag name="fontMonoSpace" value="0x20" />
|
||||||
|
|
|
@ -120,6 +120,7 @@
|
||||||
<key-style
|
<key-style
|
||||||
latin:styleName="numSpaceKeyStyle"
|
latin:styleName="numSpaceKeyStyle"
|
||||||
latin:keySpec="!icon/space_key_for_number_layout|!code/key_space"
|
latin:keySpec="!icon/space_key_for_number_layout|!code/key_space"
|
||||||
|
latin:keyLabelFlags="alignIconToBottom"
|
||||||
latin:keyActionFlags="enableLongPress"
|
latin:keyActionFlags="enableLongPress"
|
||||||
latin:parentStyle="numKeyBaseStyle" />
|
latin:parentStyle="numKeyBaseStyle" />
|
||||||
</merge>
|
</merge>
|
||||||
|
|
|
@ -58,6 +58,7 @@ public class Key implements Comparable<Key> {
|
||||||
private final String mHintLabel;
|
private final String mHintLabel;
|
||||||
/** 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_LEFT_OF_CENTER = 0x08;
|
private static final int LABEL_FLAGS_ALIGN_LEFT_OF_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;
|
||||||
|
@ -643,6 +644,10 @@ public class Key implements Comparable<Key> {
|
||||||
return Typeface.DEFAULT_BOLD;
|
return Typeface.DEFAULT_BOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean isAlignIconToBottom() {
|
||||||
|
return (mLabelFlags & LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean isAlignLeftOfCenter() {
|
public final boolean isAlignLeftOfCenter() {
|
||||||
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0;
|
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -456,9 +456,13 @@ public class KeyboardView extends View {
|
||||||
iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth);
|
iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth);
|
||||||
}
|
}
|
||||||
final int iconHeight = icon.getIntrinsicHeight();
|
final int iconHeight = icon.getIntrinsicHeight();
|
||||||
// Align center.
|
final int iconY;
|
||||||
final int iconY = (keyHeight - iconHeight) / 2;
|
if (key.isAlignIconToBottom()) {
|
||||||
final int iconX = (keyWidth - iconWidth) / 2;
|
iconY = keyHeight - iconHeight;
|
||||||
|
} else {
|
||||||
|
iconY = (keyHeight - iconHeight) / 2; // Align vertically center.
|
||||||
|
}
|
||||||
|
final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center.
|
||||||
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue