mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Add keyLabelAlign attribute to Keyboard XML
Bug: 3216592 Change-Id: I88f8055199f2cd0525faf9374114fbebba53b951
This commit is contained in:
parent
45911256fd
commit
cd39f2adee
@ -106,6 +106,14 @@
|
|||||||
<attr name="keyOutputText" format="string" />
|
<attr name="keyOutputText" format="string" />
|
||||||
<!-- The label to display on the key. -->
|
<!-- The label to display on the key. -->
|
||||||
<attr name="keyLabel" format="string" />
|
<attr name="keyLabel" format="string" />
|
||||||
|
<!-- The key label option -->
|
||||||
|
<attr name="keyLabelOption">
|
||||||
|
<!-- This should be aligned with BaseKeyboardView.KEY_LABEL_OPTION_* -->
|
||||||
|
<flag name="alignLeft" value="1" />
|
||||||
|
<flag name="alignRight" value="2" />
|
||||||
|
<flag name="alignBottom" value="8" />
|
||||||
|
<flag name="fontItalic" value="16" />
|
||||||
|
</attr>
|
||||||
<!-- The unicode that this key generates in manual temporary upper case mode. -->
|
<!-- The unicode that this key generates in manual temporary upper case mode. -->
|
||||||
<attr name="manualTemporaryUpperCaseCode" format="integer" />
|
<attr name="manualTemporaryUpperCaseCode" format="integer" />
|
||||||
<!-- The icon to display on the key instead of the label. -->
|
<!-- The icon to display on the key instead of the label. -->
|
||||||
@ -132,14 +140,14 @@
|
|||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="BaseKeyboard_Case">
|
<declare-styleable name="BaseKeyboard_Case">
|
||||||
<!-- This should be matched with KeyboardSwitcher.MODE_* -->
|
<!-- This should be aligned with KeyboardSwitcher.MODE_* -->
|
||||||
<attr name="mode">
|
<attr name="mode">
|
||||||
<flag name="text" value="0" />
|
<enum name="text" value="0" />
|
||||||
<flag name="url" value="1" />
|
<enum name="url" value="1" />
|
||||||
<flag name="email" value="2" />
|
<enum name="email" value="2" />
|
||||||
<flag name="im" value="3" />
|
<enum name="im" value="3" />
|
||||||
<flag name="web" value="4" />
|
<enum name="web" value="4" />
|
||||||
<flag name="phone" value="5" />
|
<enum name="phone" value="5" />
|
||||||
</attr>
|
</attr>
|
||||||
<attr name="settingsKey" format="string" />
|
<attr name="settingsKey" format="string" />
|
||||||
<attr name="voiceKey" format="string" />
|
<attr name="voiceKey" format="string" />
|
||||||
|
@ -226,6 +226,12 @@
|
|||||||
<string name="label_alpha_key">ABC</string>
|
<string name="label_alpha_key">ABC</string>
|
||||||
<!-- Label for ALT modifier key. Must be short to fit on key! -->
|
<!-- Label for ALT modifier key. Must be short to fit on key! -->
|
||||||
<string name="label_alt_key">ALT</string>
|
<string name="label_alt_key">ALT</string>
|
||||||
|
<!-- Label for Backspace modifier key. Must be short to fit on key! -->
|
||||||
|
<string name="label_backspace_key">Backspace</string>
|
||||||
|
<!-- Label for Shift modifier key. Must be short to fit on key! -->
|
||||||
|
<string name="label_shift_key">Shift</string>
|
||||||
|
<!-- Label for Return key. Must be short to fit on key! -->
|
||||||
|
<string name="label_return_key">Return</string>
|
||||||
<!-- Label for Shift modifier key of symbol keyboard. Must be short to fit on key! -->
|
<!-- Label for Shift modifier key of symbol keyboard. Must be short to fit on key! -->
|
||||||
<string name="label_more_key">More</string>
|
<string name="label_more_key">More</string>
|
||||||
<!-- Label for "Tab" key. Must be short to fit on key! [CHAR LIMIT=4]-->
|
<!-- Label for "Tab" key. Must be short to fit on key! [CHAR LIMIT=4]-->
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_tab"
|
latin:codes="@integer/key_tab"
|
||||||
latin:keyLabel="@string/label_tab_key"
|
latin:keyLabel="@string/label_tab_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="12.1%p"
|
latin:keyWidth="12.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -61,8 +62,8 @@
|
|||||||
latin:horizontalGap="4.0%p" />
|
latin:horizontalGap="4.0%p" />
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_delete"
|
latin:codes="@integer/key_delete"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_delete"
|
latin:keyLabel="@string/label_backspace_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_delete"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="15.0%p"
|
latin:keyWidth="15.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isRepeatable="true"
|
latin:isRepeatable="true"
|
||||||
@ -72,6 +73,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_symbol"
|
latin:codes="@integer/key_symbol"
|
||||||
latin:keyLabel="@string/label_more_key"
|
latin:keyLabel="@string/label_more_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="12.1%p"
|
latin:keyWidth="12.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
@ -104,8 +106,8 @@
|
|||||||
latin:horizontalGap="4.0%p" />
|
latin:horizontalGap="4.0%p" />
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_return"
|
latin:codes="@integer/key_return"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_return"
|
latin:keyLabel="@string/label_return_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_return"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="15.0%p"
|
latin:keyWidth="15.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_tab"
|
latin:codes="@integer/key_tab"
|
||||||
latin:keyLabel="@string/label_tab_key"
|
latin:keyLabel="@string/label_tab_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="12.1%p"
|
latin:keyWidth="12.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -64,8 +65,8 @@
|
|||||||
latin:horizontalGap="4.0%p" />
|
latin:horizontalGap="4.0%p" />
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_delete"
|
latin:codes="@integer/key_delete"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_delete"
|
latin:keyLabel="@string/label_backspace_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_delete"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="15.0%p"
|
latin:keyWidth="15.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isRepeatable="true"
|
latin:isRepeatable="true"
|
||||||
@ -75,6 +76,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_symbol"
|
latin:codes="@integer/key_symbol"
|
||||||
latin:keyLabel="@string/label_more_key"
|
latin:keyLabel="@string/label_more_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="12.1%p"
|
latin:keyWidth="12.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
@ -110,8 +112,8 @@
|
|||||||
latin:horizontalGap="4.0%p" />
|
latin:horizontalGap="4.0%p" />
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_return"
|
latin:codes="@integer/key_return"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_return"
|
latin:keyLabel="@string/label_return_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_return"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="15.0%p"
|
latin:keyWidth="15.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_tab"
|
latin:codes="@integer/key_tab"
|
||||||
latin:keyLabel="Tab"
|
latin:keyLabel="@string/label_tab_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="7.0%p"
|
latin:keyWidth="7.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_symbol"
|
latin:codes="@integer/key_symbol"
|
||||||
latin:keyLabel="@string/label_symbol_key"
|
latin:keyLabel="@string/label_symbol_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="9.7%p"
|
latin:keyWidth="9.7%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -75,8 +76,8 @@
|
|||||||
</switch>
|
</switch>
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_return"
|
latin:codes="@integer/key_return"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_return"
|
latin:keyLabel="@string/label_return_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_return"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="8.3%p"
|
latin:keyWidth="8.3%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_shift"
|
latin:codes="@integer/key_shift"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_shift"
|
latin:keyLabel="@string/label_shift_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
|
||||||
latin:keyWidth="13.1%p"
|
latin:keyWidth="13.1%p"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -80,8 +80,8 @@
|
|||||||
</switch>
|
</switch>
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_shift"
|
latin:codes="@integer/key_shift"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_shift"
|
latin:keyLabel="@string/label_shift_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="13.1%p"
|
latin:keyWidth="13.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_tab"
|
latin:codes="@integer/key_tab"
|
||||||
latin:keyLabel="Tab"
|
latin:keyLabel="@string/label_tab_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="7.0%p"
|
latin:keyWidth="7.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -80,6 +81,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_symbol"
|
latin:codes="@integer/key_symbol"
|
||||||
latin:keyLabel="@string/label_alpha_key"
|
latin:keyLabel="@string/label_alpha_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="9.7%p"
|
latin:keyWidth="9.7%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -119,8 +121,8 @@
|
|||||||
latin:popupCharacters="]}>" />
|
latin:popupCharacters="]}>" />
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_return"
|
latin:codes="@integer/key_return"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_return"
|
latin:keyLabel="@string/label_return_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_return"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="8.3%p"
|
latin:keyWidth="8.3%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
@ -129,7 +131,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_shift"
|
latin:codes="@integer/key_shift"
|
||||||
latin:keyLabel="@string/label_more_key"
|
latin:keyLabel="@string/label_more_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="13.1%p"
|
latin:keyWidth="13.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
@ -162,6 +164,7 @@
|
|||||||
latin:codes="@integer/key_shift"
|
latin:codes="@integer/key_shift"
|
||||||
latin:keyLabel="@string/label_more_key"
|
latin:keyLabel="@string/label_more_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
||||||
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="13.1%p"
|
latin:keyWidth="13.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_tab"
|
latin:codes="@integer/key_tab"
|
||||||
latin:keyLabel="Tab"
|
latin:keyLabel="@string/label_tab_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="7.0%p"
|
latin:keyWidth="7.0%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -70,6 +71,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_symbol"
|
latin:codes="@integer/key_symbol"
|
||||||
latin:keyLabel="@string/label_alpha_key"
|
latin:keyLabel="@string/label_alpha_key"
|
||||||
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="9.7%p"
|
latin:keyWidth="9.7%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="left" />
|
latin:keyEdgeFlags="left" />
|
||||||
@ -99,8 +101,8 @@
|
|||||||
latin:keyLabel="]" />
|
latin:keyLabel="]" />
|
||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_return"
|
latin:codes="@integer/key_return"
|
||||||
latin:keyIcon="@drawable/sym_keyboard_return"
|
latin:keyLabel="@string/label_return_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_return"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="8.3%p"
|
latin:keyWidth="8.3%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:keyEdgeFlags="right" />
|
latin:keyEdgeFlags="right" />
|
||||||
@ -109,7 +111,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_shift"
|
latin:codes="@integer/key_shift"
|
||||||
latin:keyLabel="@string/label_more_key"
|
latin:keyLabel="@string/label_more_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
latin:keyLabelOption="fontItalic|alignLeft|alignBottom"
|
||||||
latin:keyWidth="13.1%p"
|
latin:keyWidth="13.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
@ -143,7 +145,7 @@
|
|||||||
<Key
|
<Key
|
||||||
latin:codes="@integer/key_shift"
|
latin:codes="@integer/key_shift"
|
||||||
latin:keyLabel="@string/label_more_key"
|
latin:keyLabel="@string/label_more_key"
|
||||||
latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
|
latin:keyLabelOption="fontItalic|alignRight|alignBottom"
|
||||||
latin:keyWidth="13.1%p"
|
latin:keyWidth="13.1%p"
|
||||||
latin:isModifier="true"
|
latin:isModifier="true"
|
||||||
latin:isSticky="true"
|
latin:isSticky="true"
|
||||||
|
@ -183,6 +183,8 @@ public class BaseKeyboard {
|
|||||||
|
|
||||||
/** Label to display */
|
/** Label to display */
|
||||||
public CharSequence label;
|
public CharSequence label;
|
||||||
|
/** Option of the label */
|
||||||
|
public int labelOption;
|
||||||
|
|
||||||
/** Icon to display instead of a label. Icon takes precedence over a label */
|
/** Icon to display instead of a label. Icon takes precedence over a label */
|
||||||
public Drawable icon;
|
public Drawable icon;
|
||||||
@ -331,6 +333,7 @@ public class BaseKeyboard {
|
|||||||
setDefaultBounds(manualTemporaryUpperCaseHintIcon);
|
setDefaultBounds(manualTemporaryUpperCaseHintIcon);
|
||||||
|
|
||||||
label = a.getText(R.styleable.BaseKeyboard_Key_keyLabel);
|
label = a.getText(R.styleable.BaseKeyboard_Key_keyLabel);
|
||||||
|
labelOption = a.getInt(R.styleable.BaseKeyboard_Key_keyLabelOption, 0);
|
||||||
manualTemporaryUpperCaseCode = a.getInt(
|
manualTemporaryUpperCaseCode = a.getInt(
|
||||||
R.styleable.BaseKeyboard_Key_manualTemporaryUpperCaseCode, 0);
|
R.styleable.BaseKeyboard_Key_manualTemporaryUpperCaseCode, 0);
|
||||||
text = a.getText(R.styleable.BaseKeyboard_Key_keyOutputText);
|
text = a.getText(R.styleable.BaseKeyboard_Key_keyOutputText);
|
||||||
|
@ -249,9 +249,20 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
|
|||||||
private final Rect mClipRegion = new Rect(0, 0, 0, 0);
|
private final Rect mClipRegion = new Rect(0, 0, 0, 0);
|
||||||
// This map caches key label text height in pixel as value and key label text size as map key.
|
// This map caches key label text height in pixel as value and key label text size as map key.
|
||||||
private final HashMap<Integer, Integer> mTextHeightCache = new HashMap<Integer, Integer>();
|
private final HashMap<Integer, Integer> mTextHeightCache = new HashMap<Integer, Integer>();
|
||||||
// Distance from horizontal center of the key, proportional to key label text height.
|
// This map caches key label text width in pixel as value and key label text size as map key.
|
||||||
private final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR = 0.55f;
|
private final HashMap<Integer, Integer> mTextWidthCache = new HashMap<Integer, Integer>();
|
||||||
private final String KEY_LABEL_HEIGHT_REFERENCE_CHAR = "H";
|
// Distance from horizontal center of the key, proportional to key label text height and width.
|
||||||
|
private final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER = 0.55f;
|
||||||
|
private final float KEY_LABEL_VERTICAL_PADDING_FACTOR = 1.60f;
|
||||||
|
private final float KEY_LABEL_HORIZONTAL_PADDING_FACTOR = 0.80f;
|
||||||
|
private final String KEY_LABEL_REFERENCE_CHAR = "H";
|
||||||
|
private final int KEY_LABEL_OPTION_ALIGN_LEFT = 1;
|
||||||
|
private final int KEY_LABEL_OPTION_ALIGN_RIGHT = 2;
|
||||||
|
private final int KEY_LABEL_OPTION_ALIGN_BOTTOM = 8;
|
||||||
|
private final int KEY_LABEL_OPTION_FONT_ITALIC = 16;
|
||||||
|
// TODO: Currently we don't have san-serif italic type face. This is actually san-serif
|
||||||
|
// non-italic type face.
|
||||||
|
private final Typeface TYPEFACE_ITALIC = Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC);
|
||||||
|
|
||||||
private final UIHandler mHandler = new UIHandler();
|
private final UIHandler mHandler = new UIHandler();
|
||||||
|
|
||||||
@ -808,12 +819,17 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
|
|||||||
keyBackground.draw(canvas);
|
keyBackground.draw(canvas);
|
||||||
|
|
||||||
boolean drawHintIcon = true;
|
boolean drawHintIcon = true;
|
||||||
|
// Draw key label
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
// For characters, use large font. For labels like "Done", use small font.
|
// For characters, use large font. For labels like "Done", use small font.
|
||||||
final int labelSize;
|
final int labelSize;
|
||||||
if (label.length() > 1 && key.codes.length < 2) {
|
if (label.length() > 1 && key.codes.length < 2) {
|
||||||
labelSize = mLabelTextSize;
|
labelSize = mLabelTextSize;
|
||||||
paint.setTypeface(Typeface.DEFAULT_BOLD);
|
if ((key.labelOption & KEY_LABEL_OPTION_FONT_ITALIC) != 0) {
|
||||||
|
paint.setTypeface(TYPEFACE_ITALIC);
|
||||||
|
} else {
|
||||||
|
paint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
labelSize = mKeyTextSize;
|
labelSize = mKeyTextSize;
|
||||||
paint.setTypeface(mKeyTextStyle);
|
paint.setTypeface(mKeyTextStyle);
|
||||||
@ -821,26 +837,51 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
|
|||||||
paint.setTextSize(labelSize);
|
paint.setTextSize(labelSize);
|
||||||
|
|
||||||
Integer labelHeightValue = mTextHeightCache.get(labelSize);
|
Integer labelHeightValue = mTextHeightCache.get(labelSize);
|
||||||
final int labelHeight;
|
final int labelCharHeight;
|
||||||
|
final int labelCharWidth;
|
||||||
if (labelHeightValue != null) {
|
if (labelHeightValue != null) {
|
||||||
labelHeight = labelHeightValue;
|
labelCharHeight = labelHeightValue;
|
||||||
|
labelCharWidth = mTextWidthCache.get(labelSize);
|
||||||
} else {
|
} else {
|
||||||
Rect textBounds = new Rect();
|
Rect textBounds = new Rect();
|
||||||
paint.getTextBounds(KEY_LABEL_HEIGHT_REFERENCE_CHAR, 0, 1, textBounds);
|
paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, textBounds);
|
||||||
labelHeight = textBounds.height();
|
labelCharHeight = textBounds.height();
|
||||||
mTextHeightCache.put(labelSize, labelHeight);
|
labelCharWidth = textBounds.width();
|
||||||
|
mTextHeightCache.put(labelSize, labelCharHeight);
|
||||||
|
mTextWidthCache.put(labelSize, labelCharWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a drop shadow for the text
|
// Vertical label text alignment.
|
||||||
|
final float baseline;
|
||||||
|
if ((key.labelOption & KEY_LABEL_OPTION_ALIGN_BOTTOM) != 0) {
|
||||||
|
baseline = key.height -
|
||||||
|
+ labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR;
|
||||||
|
} else { // Align center
|
||||||
|
final float centerY = (key.height + padding.top - padding.bottom) / 2;
|
||||||
|
baseline = centerY
|
||||||
|
+ labelCharHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER;
|
||||||
|
}
|
||||||
|
// Horizontal label text alignment
|
||||||
|
final int positionX;
|
||||||
|
if ((key.labelOption & KEY_LABEL_OPTION_ALIGN_LEFT) != 0) {
|
||||||
|
positionX = (int)(
|
||||||
|
labelCharWidth * KEY_LABEL_HORIZONTAL_PADDING_FACTOR + padding.left);
|
||||||
|
paint.setTextAlign(Align.LEFT);
|
||||||
|
} else if ((key.labelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
|
||||||
|
positionX = (int)(key.width
|
||||||
|
- labelCharWidth * KEY_LABEL_HORIZONTAL_PADDING_FACTOR - padding.right);
|
||||||
|
paint.setTextAlign(Align.RIGHT);
|
||||||
|
} else {
|
||||||
|
positionX = (key.width + padding.left - padding.right) / 2;
|
||||||
|
paint.setTextAlign(Align.CENTER);
|
||||||
|
}
|
||||||
|
// Set a drop shadow for the text
|
||||||
paint.setShadowLayer(mShadowRadius, 0, 0, mShadowColor);
|
paint.setShadowLayer(mShadowRadius, 0, 0, mShadowColor);
|
||||||
final int centerX = (key.width + padding.left - padding.right) / 2;
|
canvas.drawText(label, positionX, baseline, paint);
|
||||||
final int centerY = (key.height + padding.top - padding.bottom) / 2;
|
|
||||||
final float baseline = centerY
|
|
||||||
+ labelHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR;
|
|
||||||
canvas.drawText(label, centerX, baseline, paint);
|
|
||||||
// Turn off drop shadow
|
// Turn off drop shadow
|
||||||
paint.setShadowLayer(0, 0, 0, 0);
|
paint.setShadowLayer(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
// Draw key icon
|
||||||
if (key.label == null && key.icon != null) {
|
if (key.label == null && key.icon != null) {
|
||||||
int drawableWidth = key.icon.getIntrinsicWidth();
|
int drawableWidth = key.icon.getIntrinsicWidth();
|
||||||
int drawableHeight = key.icon.getIntrinsicHeight();
|
int drawableHeight = key.icon.getIntrinsicHeight();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user