abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2022-02-27 01:50:24 +0100
committerJules Aguillon2022-02-27 01:50:24 +0100
commit23685ddb3c7a4a9a0c757a12330b4cf45aa0707e (patch)
tree86769c1c7d7428021726a11596d51a217d25a40a /srcs
parentce5cee42a101f699493aea8311c087020672dc59 (diff)
downloadunexpected-keyboard-23685ddb3c7a4a9a0c757a12330b4cf45aa0707e.tar.gz
unexpected-keyboard-23685ddb3c7a4a9a0c757a12330b4cf45aa0707e.zip
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
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/Config.java10
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java11
-rw-r--r--srcs/juloo.keyboard2/Theme.java6
3 files changed, 12 insertions, 15 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index ebd7b70..cfd4fb7 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -15,6 +15,9 @@ final class Config
public final float marginTop;
public final float keyPadding;
+ public final float labelTextSize;
+ public final float sublabelTextSize;
+
// From preferences
public int layout; // Or '-1' for the system defaults
private float swipe_dist_dp;
@@ -48,6 +51,8 @@ final class Config
// static values
marginTop = res.getDimension(R.dimen.margin_top);
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
layout = -1;
vibrateEnabled = true;
@@ -85,16 +90,13 @@ final class Config
// is not the actual size of the keyboard, which will be bigger if the
// layout has a fifth row.
int keyboardHeightPercent;
- float extra_horizontal_margin;
if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) // Landscape mode
{
keyboardHeightPercent = 55;
- extra_horizontal_margin = res.getDimension(R.dimen.landscape_extra_horizontal_margin);
}
else
{
keyboardHeightPercent = prefs.getInt("keyboard_height", 35);
- extra_horizontal_margin = 0.f;
}
layout = layoutId_of_string(prefs.getString("layout", "system"));
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
// during rendered.
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);
characterSize = prefs.getFloat("character_size", characterSize);
accents = Integer.valueOf(prefs.getString("accents", "1"));
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 8584981..1975524 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -237,7 +237,7 @@ public class Keyboard2View extends View
canvas.drawRoundRect(_tmpRect, _theme.keyBorderRadius, _theme.keyBorderRadius,
isKeyDown ? _theme.keyDownBgPaint : _theme.keyBgPaint);
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;
if (k.edgekeys)
{
@@ -294,7 +294,7 @@ public class Keyboard2View extends View
k = KeyModifier.handleFlags(k, _flags);
Paint p = _theme.labelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0));
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);
}
@@ -303,7 +303,7 @@ public class Keyboard2View extends View
k = KeyModifier.handleFlags(k, _flags);
Paint p = _theme.subLabelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0), a);
p.setColor(labelColor(k, isKeyDown, _theme.subLabelColor));
- p.setTextSize(_theme.sublabelTextSize * scaleTextSize(k));
+ p.setTextSize(scaleTextSize(k, _config.sublabelTextSize));
if (v == Vertical.CENTER)
y -= (p.ascent() + p.descent()) / 2f;
else
@@ -311,8 +311,9 @@ public class Keyboard2View extends View
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;
}
}
diff --git a/srcs/juloo.keyboard2/Theme.java b/srcs/juloo.keyboard2/Theme.java
index 52147d9..3d57fe7 100644
--- a/srcs/juloo.keyboard2/Theme.java
+++ b/srcs/juloo.keyboard2/Theme.java
@@ -16,9 +16,6 @@ public class Theme
public final int labelColor;
public final int subLabelColor;
- public final float labelTextSize;
- public final float sublabelTextSize;
-
public final float keyBorderRadius;
private final Paint _keyLabelPaint;
@@ -38,9 +35,6 @@ public class Theme
subLabelColor = s.getColor(R.styleable.keyboard_colorSubLabel, 0);
keyBorderRadius = s.getDimension(R.styleable.keyboard_keyBorderRadius, 0);
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);
_keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null);
Typeface specialKeyFont = getSpecialKeyFont(context);