mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-12-25 07:29:03 +01:00
Compute text size relative to key height
Instead of a fixed size that don't work at all for bigger screens. Other tweaks: - Use the value-land dimens to vary 'extra_horizontal_margin' - Move label size to Config, because it can change at runtime (rotation) - Slightly decrease the size of "long" symbols
This commit is contained in:
parent
ce5cee42a1
commit
23685ddb3c
@ -4,7 +4,8 @@
|
|||||||
<dimen name="margin_bottom">3dp</dimen>
|
<dimen name="margin_bottom">3dp</dimen>
|
||||||
<dimen name="key_padding">3dp</dimen>
|
<dimen name="key_padding">3dp</dimen>
|
||||||
<dimen name="key_height">36dp</dimen>
|
<dimen name="key_height">36dp</dimen>
|
||||||
<dimen name="label_text_size">18dp</dimen>
|
<item name="label_text_size" type="integer" format="float">0.4</item>
|
||||||
<dimen name="sublabel_text_size">11dp</dimen>
|
<item name="sublabel_text_size" type="integer" format="float">0.3</item>
|
||||||
<dimen name="emoji_type_button_height">48dp</dimen>
|
<dimen name="emoji_type_button_height">48dp</dimen>
|
||||||
|
<dimen name="extra_horizontal_margin">20dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
<dimen name="key_vertical_interval">2dp</dimen>
|
<dimen name="key_vertical_interval">2dp</dimen>
|
||||||
<dimen name="key_horizontal_interval">2dp</dimen>
|
<dimen name="key_horizontal_interval">2dp</dimen>
|
||||||
<dimen name="key_height">51dp</dimen>
|
<dimen name="key_height">51dp</dimen>
|
||||||
<dimen name="label_text_size">18dp</dimen>
|
<item name="label_text_size" type="integer" format="float">0.33</item>
|
||||||
<dimen name="sublabel_text_size">12dp</dimen>
|
<item name="sublabel_text_size" type="integer" format="float">0.22</item>
|
||||||
<dimen name="emoji_type_button_height">56dp</dimen>
|
<dimen name="emoji_type_button_height">56dp</dimen>
|
||||||
<dimen name="emoji_grid_height">250dp</dimen>
|
<dimen name="emoji_grid_height">250dp</dimen>
|
||||||
<dimen name="emoji_text_size">28dp</dimen>
|
<dimen name="emoji_text_size">28dp</dimen>
|
||||||
<dimen name="landscape_extra_horizontal_margin">20dp</dimen>
|
<dimen name="extra_horizontal_margin">0dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
<style name="emojiTypeButton">
|
<style name="emojiTypeButton">
|
||||||
<item name="android:padding">1px</item>
|
<item name="android:padding">1px</item>
|
||||||
<item name="android:gravity">center</item>
|
<item name="android:gravity">center</item>
|
||||||
<item name="android:minHeight">@dimen/label_text_size</item>
|
<item name="android:minHeight">18dp</item>
|
||||||
<item name="android:background">?attr/emoji_button_bg</item>
|
<item name="android:background">?attr/emoji_button_bg</item>
|
||||||
<item name="android:textColor">?attr/emoji_key_text</item>
|
<item name="android:textColor">?attr/emoji_key_text</item>
|
||||||
<item name="android:textSize">@dimen/label_text_size</item>
|
<item name="android:textSize">18dp</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="emojiKeyButton">
|
<style name="emojiKeyButton">
|
||||||
<item name="android:layout_width">0px</item>
|
<item name="android:layout_width">0px</item>
|
||||||
@ -15,7 +15,7 @@
|
|||||||
<item name="android:padding">0px</item>
|
<item name="android:padding">0px</item>
|
||||||
<item name="android:background">?attr/emoji_key_bg</item>
|
<item name="android:background">?attr/emoji_key_bg</item>
|
||||||
<item name="android:textColor">?attr/emoji_key_text</item>
|
<item name="android:textColor">?attr/emoji_key_text</item>
|
||||||
<item name="android:textSize">@dimen/label_text_size</item>
|
<item name="android:textSize">18dp</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- Passed to TextView.setTextAppearance -->
|
<!-- Passed to TextView.setTextAppearance -->
|
||||||
<style name="emojiGridButton">
|
<style name="emojiGridButton">
|
||||||
|
@ -15,6 +15,9 @@ final class Config
|
|||||||
public final float marginTop;
|
public final float marginTop;
|
||||||
public final float keyPadding;
|
public final float keyPadding;
|
||||||
|
|
||||||
|
public final float labelTextSize;
|
||||||
|
public final float sublabelTextSize;
|
||||||
|
|
||||||
// From preferences
|
// From preferences
|
||||||
public int layout; // Or '-1' for the system defaults
|
public int layout; // Or '-1' for the system defaults
|
||||||
private float swipe_dist_dp;
|
private float swipe_dist_dp;
|
||||||
@ -48,6 +51,8 @@ final class Config
|
|||||||
// static values
|
// static values
|
||||||
marginTop = res.getDimension(R.dimen.margin_top);
|
marginTop = res.getDimension(R.dimen.margin_top);
|
||||||
keyPadding = res.getDimension(R.dimen.key_padding);
|
keyPadding = res.getDimension(R.dimen.key_padding);
|
||||||
|
labelTextSize = res.getFloat(R.integer.label_text_size);
|
||||||
|
sublabelTextSize = res.getFloat(R.integer.sublabel_text_size);
|
||||||
// default values
|
// default values
|
||||||
layout = -1;
|
layout = -1;
|
||||||
vibrateEnabled = true;
|
vibrateEnabled = true;
|
||||||
@ -85,16 +90,13 @@ final class Config
|
|||||||
// is not the actual size of the keyboard, which will be bigger if the
|
// is not the actual size of the keyboard, which will be bigger if the
|
||||||
// layout has a fifth row.
|
// layout has a fifth row.
|
||||||
int keyboardHeightPercent;
|
int keyboardHeightPercent;
|
||||||
float extra_horizontal_margin;
|
|
||||||
if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) // Landscape mode
|
if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) // Landscape mode
|
||||||
{
|
{
|
||||||
keyboardHeightPercent = 55;
|
keyboardHeightPercent = 55;
|
||||||
extra_horizontal_margin = res.getDimension(R.dimen.landscape_extra_horizontal_margin);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyboardHeightPercent = prefs.getInt("keyboard_height", 35);
|
keyboardHeightPercent = prefs.getInt("keyboard_height", 35);
|
||||||
extra_horizontal_margin = 0.f;
|
|
||||||
}
|
}
|
||||||
layout = layoutId_of_string(prefs.getString("layout", "system"));
|
layout = layoutId_of_string(prefs.getString("layout", "system"));
|
||||||
swipe_dist_dp = Float.valueOf(prefs.getString("swipe_dist", "15"));
|
swipe_dist_dp = Float.valueOf(prefs.getString("swipe_dist", "15"));
|
||||||
@ -109,7 +111,7 @@ final class Config
|
|||||||
// Do not substract keyVerticalInterval from keyHeight because this is done
|
// Do not substract keyVerticalInterval from keyHeight because this is done
|
||||||
// during rendered.
|
// during rendered.
|
||||||
keyHeight = dm.heightPixels * keyboardHeightPercent / 100 / 4;
|
keyHeight = dm.heightPixels * keyboardHeightPercent / 100 / 4;
|
||||||
horizontalMargin = getDipPref(dm, prefs, "horizontal_margin", horizontalMargin) + extra_horizontal_margin;
|
horizontalMargin = getDipPref(dm, prefs, "horizontal_margin", horizontalMargin) + res.getDimension(R.dimen.extra_horizontal_margin);
|
||||||
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
|
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
|
||||||
characterSize = prefs.getFloat("character_size", characterSize);
|
characterSize = prefs.getFloat("character_size", characterSize);
|
||||||
accents = Integer.valueOf(prefs.getString("accents", "1"));
|
accents = Integer.valueOf(prefs.getString("accents", "1"));
|
||||||
|
@ -237,7 +237,7 @@ public class Keyboard2View extends View
|
|||||||
canvas.drawRoundRect(_tmpRect, _theme.keyBorderRadius, _theme.keyBorderRadius,
|
canvas.drawRoundRect(_tmpRect, _theme.keyBorderRadius, _theme.keyBorderRadius,
|
||||||
isKeyDown ? _theme.keyDownBgPaint : _theme.keyBgPaint);
|
isKeyDown ? _theme.keyDownBgPaint : _theme.keyBgPaint);
|
||||||
if (k.key0 != null)
|
if (k.key0 != null)
|
||||||
drawLabel(canvas, k.key0, keyW / 2f + x, (keyH + _theme.labelTextSize) / 2f + y, isKeyDown);
|
drawLabel(canvas, k.key0, keyW / 2f + x, (keyH + scaleTextSize(k.key0, _config.labelTextSize)) / 2f + y, isKeyDown);
|
||||||
float subPadding = _config.keyPadding;
|
float subPadding = _config.keyPadding;
|
||||||
if (k.edgekeys)
|
if (k.edgekeys)
|
||||||
{
|
{
|
||||||
@ -294,7 +294,7 @@ public class Keyboard2View extends View
|
|||||||
k = KeyModifier.handleFlags(k, _flags);
|
k = KeyModifier.handleFlags(k, _flags);
|
||||||
Paint p = _theme.labelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0));
|
Paint p = _theme.labelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0));
|
||||||
p.setColor(labelColor(k, isKeyDown, _theme.labelColor));
|
p.setColor(labelColor(k, isKeyDown, _theme.labelColor));
|
||||||
p.setTextSize(_theme.labelTextSize * scaleTextSize(k));
|
p.setTextSize(scaleTextSize(k, _config.labelTextSize));
|
||||||
canvas.drawText(k.symbol, x, y, p);
|
canvas.drawText(k.symbol, x, y, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ public class Keyboard2View extends View
|
|||||||
k = KeyModifier.handleFlags(k, _flags);
|
k = KeyModifier.handleFlags(k, _flags);
|
||||||
Paint p = _theme.subLabelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0), a);
|
Paint p = _theme.subLabelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0), a);
|
||||||
p.setColor(labelColor(k, isKeyDown, _theme.subLabelColor));
|
p.setColor(labelColor(k, isKeyDown, _theme.subLabelColor));
|
||||||
p.setTextSize(_theme.sublabelTextSize * scaleTextSize(k));
|
p.setTextSize(scaleTextSize(k, _config.sublabelTextSize));
|
||||||
if (v == Vertical.CENTER)
|
if (v == Vertical.CENTER)
|
||||||
y -= (p.ascent() + p.descent()) / 2f;
|
y -= (p.ascent() + p.descent()) / 2f;
|
||||||
else
|
else
|
||||||
@ -311,8 +311,9 @@ public class Keyboard2View extends View
|
|||||||
canvas.drawText(k.symbol, x, y, p);
|
canvas.drawText(k.symbol, x, y, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float scaleTextSize(KeyValue k)
|
private float scaleTextSize(KeyValue k, float rel_size)
|
||||||
{
|
{
|
||||||
return ((k.symbol.length() < 2) ? 1.f : 0.8f) * _config.characterSize;
|
float smaller_if_long = (k.symbol.length() < 2) ? 1.f : 0.75f;
|
||||||
|
return _config.keyHeight * rel_size * smaller_if_long * _config.characterSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,6 @@ public class Theme
|
|||||||
public final int labelColor;
|
public final int labelColor;
|
||||||
public final int subLabelColor;
|
public final int subLabelColor;
|
||||||
|
|
||||||
public final float labelTextSize;
|
|
||||||
public final float sublabelTextSize;
|
|
||||||
|
|
||||||
public final float keyBorderRadius;
|
public final float keyBorderRadius;
|
||||||
|
|
||||||
private final Paint _keyLabelPaint;
|
private final Paint _keyLabelPaint;
|
||||||
@ -38,9 +35,6 @@ public class Theme
|
|||||||
subLabelColor = s.getColor(R.styleable.keyboard_colorSubLabel, 0);
|
subLabelColor = s.getColor(R.styleable.keyboard_colorSubLabel, 0);
|
||||||
keyBorderRadius = s.getDimension(R.styleable.keyboard_keyBorderRadius, 0);
|
keyBorderRadius = s.getDimension(R.styleable.keyboard_keyBorderRadius, 0);
|
||||||
s.recycle();
|
s.recycle();
|
||||||
Resources res = context.getResources();
|
|
||||||
labelTextSize = res.getDimension(R.dimen.label_text_size);
|
|
||||||
sublabelTextSize = res.getDimension(R.dimen.sublabel_text_size);
|
|
||||||
_keyLabelPaint = initLabelPaint(Paint.Align.CENTER, null);
|
_keyLabelPaint = initLabelPaint(Paint.Align.CENTER, null);
|
||||||
_keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null);
|
_keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null);
|
||||||
Typeface specialKeyFont = getSpecialKeyFont(context);
|
Typeface specialKeyFont = getSpecialKeyFont(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user