Auto text sizing using fraction of key height
Bug: 4411676 Change-Id: I8f289dcebe577d277fe2ad6a8331d59f735cbadamain
parent
13e6725a78
commit
d157834345
|
@ -29,6 +29,9 @@
|
|||
<dimen name="keyboard_top_padding">0.0in</dimen>
|
||||
<dimen name="keyboard_bottom_padding">0.0in</dimen>
|
||||
<dimen name="keyboard_horizontal_edges_padding">0.0in</dimen>
|
||||
<fraction name="key_letter_ratio">55%</fraction>
|
||||
<fraction name="key_label_text_ratio">35%</fraction>
|
||||
<fraction name="key_preview_text_ratio">90%</fraction>
|
||||
<dimen name="candidate_strip_height">38dip</dimen>
|
||||
<dimen name="candidate_strip_fading_edge_length">63dip</dimen>
|
||||
<dimen name="spacebar_vertical_correction">2dip</dimen>
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
<dimen name="keyboard_bottom_padding">0.0mm</dimen>
|
||||
<dimen name="keyboard_horizontal_edges_padding">0.0mm</dimen>
|
||||
|
||||
<dimen name="key_letter_size">28dip</dimen>
|
||||
<dimen name="key_label_text_size">20dip</dimen>
|
||||
<fraction name="key_letter_ratio">30.7%</fraction>
|
||||
<fraction name="key_label_text_ratio">21.9%</fraction>
|
||||
<!-- left or right padding of label alignment -->
|
||||
<dimen name="key_label_horizontal_alignment_padding">18dip</dimen>
|
||||
<dimen name="key_preview_height_holo">26.5mm</dimen>
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
<!-- popup_key_height x -1.0 -->
|
||||
<dimen name="mini_keyboard_vertical_correction">-13.0mm</dimen>
|
||||
|
||||
<dimen name="key_letter_size">26dip</dimen>
|
||||
<dimen name="key_label_text_size">16dip</dimen>
|
||||
<fraction name="key_letter_ratio">34.4%</fraction>
|
||||
<fraction name="key_label_text_ratio">21.2%</fraction>
|
||||
<!-- left or right padding of label alignment -->
|
||||
<dimen name="key_label_horizontal_alignment_padding">6dip</dimen>
|
||||
<dimen name="key_preview_text_size_large">24dip</dimen>
|
||||
<fraction name="key_preview_text_ratio">26.3%</fraction>
|
||||
<dimen name="key_preview_height_holo">23.0mm</dimen>
|
||||
<dimen name="key_preview_offset_holo">8.0mm</dimen>
|
||||
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
checkable+checked+pressed. -->
|
||||
<attr name="keyBackground" format="reference" />
|
||||
|
||||
<!-- Size of the text for one letter character keys. -->
|
||||
<attr name="keyLetterSize" format="dimension" />
|
||||
<!-- Size of the text for one letter character keys, in the proportion of key height.
|
||||
-->
|
||||
<attr name="keyLetterRatio" format="float" />
|
||||
|
||||
<!-- Size of the text for custom keys with some text and no icon. -->
|
||||
<attr name="labelTextSize" format="dimension" />
|
||||
<!-- Size of the text for custom keys with some text and no icon, in the proportion of key
|
||||
height. -->
|
||||
<attr name="labelTextRatio" format="float" />
|
||||
|
||||
<!-- Color to use for the label in a key. -->
|
||||
<attr name="keyTextColor" format="color" />
|
||||
|
|
|
@ -43,14 +43,13 @@
|
|||
to user's finger. -->
|
||||
<dimen name="keyboard_vertical_correction">-0.05in</dimen>
|
||||
|
||||
<!-- TODO: use fraction for key letter size and etc. -->
|
||||
<dimen name="key_letter_size">21dip</dimen>
|
||||
<dimen name="key_label_text_size">13dip</dimen>
|
||||
<fraction name="key_letter_ratio">45%</fraction>
|
||||
<fraction name="key_label_text_ratio">29%</fraction>
|
||||
<!-- left or right padding of label alignment -->
|
||||
<dimen name="key_label_horizontal_alignment_padding">21dip</dimen>
|
||||
<dimen name="key_preview_height">80sp</dimen>
|
||||
<dimen name="key_preview_offset">0.000in</dimen>
|
||||
<dimen name="key_preview_text_size_large">36sp</dimen>
|
||||
<fraction name="key_preview_text_ratio">82%</fraction>
|
||||
<dimen name="key_preview_height_holo">130sp</dimen>
|
||||
<dimen name="key_preview_offset_holo">0.193in</dimen>
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
<item name="android:background">@drawable/keyboard_background</item>
|
||||
|
||||
<item name="keyBackground">@drawable/btn_keyboard_key</item>
|
||||
<item name="keyLetterSize">@dimen/key_letter_size</item>
|
||||
<item name="keyLetterRatio">@fraction/key_letter_ratio</item>
|
||||
<item name="keyLetterStyle">normal</item>
|
||||
<item name="keyTextColor">#FFFFFFFF</item>
|
||||
<item name="keyTextColorDisabled">#FFFFFFFF</item>
|
||||
<item name="keyPreviewLayout">@layout/key_preview</item>
|
||||
<item name="keyPreviewOffset">@dimen/key_preview_offset</item>
|
||||
<item name="keyPreviewHeight">@dimen/key_preview_height</item>
|
||||
<item name="labelTextSize">@dimen/key_label_text_size</item>
|
||||
<item name="labelTextRatio">@fraction/key_label_text_ratio</item>
|
||||
<item name="popupLayout">@layout/keyboard_popup</item>
|
||||
<item name="keyHysteresisDistance">@dimen/key_hysteresis_distance</item>
|
||||
<item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
|
||||
|
|
|
@ -86,10 +86,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1;
|
||||
|
||||
// XML attribute
|
||||
private float mKeyLetterRatio;
|
||||
private int mKeyLetterSize;
|
||||
private int mKeyTextColor;
|
||||
private int mKeyTextColorDisabled;
|
||||
private Typeface mKeyLetterStyle = Typeface.DEFAULT;
|
||||
private float mLabelTextRatio;
|
||||
private int mLabelTextSize;
|
||||
private int mColorScheme = COLOR_SCHEME_WHITE;
|
||||
private int mShadowColor;
|
||||
|
@ -108,7 +110,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
// Key preview
|
||||
private boolean mInForeground;
|
||||
private TextView mPreviewText;
|
||||
private int mPreviewTextSizeLarge;
|
||||
private float mPreviewTextRatio;
|
||||
private int mPreviewTextSize;
|
||||
private boolean mShowKeyPreview = true;
|
||||
private int mKeyPreviewDisplayedY;
|
||||
private final int mDelayBeforePreview;
|
||||
|
@ -327,8 +330,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
case R.styleable.KeyboardView_keyPreviewHeight:
|
||||
mPreviewHeight = a.getDimensionPixelSize(attr, 80);
|
||||
break;
|
||||
case R.styleable.KeyboardView_keyLetterSize:
|
||||
mKeyLetterSize = a.getDimensionPixelSize(attr, 18);
|
||||
case R.styleable.KeyboardView_keyLetterRatio:
|
||||
mKeyLetterRatio = getRatio(a, attr);
|
||||
break;
|
||||
case R.styleable.KeyboardView_keyTextColor:
|
||||
mKeyTextColor = a.getColor(attr, 0xFF000000);
|
||||
|
@ -336,8 +339,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
case R.styleable.KeyboardView_keyTextColorDisabled:
|
||||
mKeyTextColorDisabled = a.getColor(attr, 0xFF000000);
|
||||
break;
|
||||
case R.styleable.KeyboardView_labelTextSize:
|
||||
mLabelTextSize = a.getDimensionPixelSize(attr, 14);
|
||||
case R.styleable.KeyboardView_labelTextRatio:
|
||||
mLabelTextRatio = getRatio(a, attr);
|
||||
break;
|
||||
case R.styleable.KeyboardView_popupLayout:
|
||||
mPopupLayout = a.getResourceId(attr, 0);
|
||||
|
@ -365,7 +368,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
|
||||
if (previewLayout != 0) {
|
||||
mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
|
||||
mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large);
|
||||
mPreviewTextRatio = getRatio(res, R.fraction.key_preview_text_ratio);
|
||||
} else {
|
||||
mShowKeyPreview = false;
|
||||
}
|
||||
|
@ -460,6 +463,16 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
|
||||
}
|
||||
|
||||
// Read fraction value in TypedArray as float.
|
||||
private static float getRatio(TypedArray a, int index) {
|
||||
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
|
||||
}
|
||||
|
||||
// Read fraction value in resource as float.
|
||||
private static float getRatio(Resources res, int id) {
|
||||
return res.getFraction(id, 1000, 1000) / 1000.0f;
|
||||
}
|
||||
|
||||
public void startIgnoringDoubleTap() {
|
||||
if (ENABLE_CAPSLOCK_BY_DOUBLETAP)
|
||||
mHandler.startIgnoringDoubleTap();
|
||||
|
@ -506,6 +519,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
invalidateAllKeys();
|
||||
mKeyDetector.setProximityThreshold(keyboard.getMostCommonKeyWidth());
|
||||
mPopupPanelCache.clear();
|
||||
final int keyHeight = keyboard.getRowHeight() - keyboard.getVerticalGap();
|
||||
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
||||
mLabelTextSize = (int)(keyHeight * mLabelTextRatio);
|
||||
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -938,7 +955,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyLetterSize);
|
||||
previewText.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
} else {
|
||||
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
|
||||
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSize);
|
||||
previewText.setTypeface(mKeyLetterStyle);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue