Slightly reduce the size of the bottom row

This commit is contained in:
Jules Aguillon 2021-04-29 00:59:19 +02:00
parent b976f4a791
commit ec5cda0ce6
5 changed files with 60 additions and 54 deletions

View File

@ -34,7 +34,7 @@
<key key0="n" key1="accent4" key2="§" key4="!" /> <key key0="n" key1="accent4" key2="§" key4="!" />
<key width="2.0" key0="backspace" key2="delete" /> <key width="2.0" key0="backspace" key2="delete" />
</row> </row>
<row> <row height="0.95">
<key width="1.8" key0="ctrl" key3="switch_numeric" /> <key width="1.8" key0="ctrl" key3="switch_numeric" />
<key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" /> <key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" />
<key width="4.0" key0="space" /> <key width="4.0" key0="space" />

View File

@ -25,7 +25,7 @@
<key key0="3" key4="page_down" /> <key key0="3" key4="page_down" />
<key width="1.15" key0="backspace" key2="delete" /> <key width="1.15" key0="backspace" key2="delete" />
</row> </row>
<row> <row height="0.95">
<key width="1.5" key0="ctrl" key3="switch_text" /> <key width="1.5" key0="ctrl" key3="switch_text" />
<key width="1.5" key0="0" /> <key width="1.5" key0="0" />
<key width="0.75" key0="." key2="," /> <key width="0.75" key0="." key2="," />

View File

@ -34,7 +34,7 @@
<key key0="m" key2="&quot;" key3="'" /> <key key0="m" key2="&quot;" key3="'" />
<key width="1.5" key0="backspace" key2="delete" /> <key width="1.5" key0="backspace" key2="delete" />
</row> </row>
<row> <row height="0.95">
<key width="1.8" key0="ctrl" key3="switch_numeric" /> <key width="1.8" key0="ctrl" key3="switch_numeric" />
<key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" /> <key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" />
<key width="4.0" key0="space" /> <key width="4.0" key0="space" />

View File

@ -196,13 +196,13 @@ public class Keyboard2View extends View
private void onTouchDown(float touchX, float touchY, int pointerId) private void onTouchDown(float touchX, float touchY, int pointerId)
{ {
float y = _config.marginTop - _config.keyHeight; float y = _config.marginTop - _config.keyHeight;
for (KeyboardData.Row row : _keyboard.getRows()) for (KeyboardData.Row row : _keyboard.rows)
{ {
y += _config.keyHeight; y += _config.keyHeight;
if (touchY < y || touchY >= (y + _config.keyHeight)) if (touchY < y || touchY >= (y + _config.keyHeight))
continue ; continue ;
float x = _config.horizontalMargin; float x = _config.horizontalMargin;
for (KeyboardData.Key key : row.getKeys()) for (KeyboardData.Key key : row.keys)
{ {
x += key.shift * _keyWidth; x += key.shift * _keyWidth;
float keyW = _keyWidth * key.width; float keyW = _keyWidth * key.width;
@ -350,51 +350,49 @@ public class Keyboard2View extends View
@Override @Override
public void onMeasure(int wSpec, int hSpec) public void onMeasure(int wSpec, int hSpec)
{ {
DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
int height; int height;
height = (int)(_config.keyHeight * _keyboard.keysHeight
if (_keyboard.getRows() == null) + _keyboard.rows.size() * _config.keyVerticalInterval
height = 0; + _config.marginTop + _config.marginBottom);
else setMeasuredDimension(dm.widthPixels, height);
height = (int)((_config.keyHeight + _config.keyVerticalInterval) _keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.keysWidth;
* ((float)_keyboard.getRows().size())
+ _config.marginTop + _config.marginBottom);
setMeasuredDimension(dm.widthPixels, height);
_keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.getKeysWidth();
} }
@Override @Override
protected void onDraw(Canvas canvas) protected void onDraw(Canvas canvas)
{ {
float y = _config.marginTop; float y = _config.marginTop;
for (KeyboardData.Row row : _keyboard.getRows()) for (KeyboardData.Row row : _keyboard.rows)
{ {
y += row.shift * _config.keyHeight;
float x = _config.horizontalMargin; float x = _config.horizontalMargin;
for (KeyboardData.Key k : row.getKeys()) float keyH = row.height * _config.keyHeight;
for (KeyboardData.Key k : row.keys)
{ {
x += k.shift * _keyWidth + _config.keyHorizontalInterval; x += k.shift * _keyWidth + _config.keyHorizontalInterval;
float keyW = _keyWidth * k.width - _config.keyHorizontalInterval; float keyW = _keyWidth * k.width - _config.keyHorizontalInterval;
KeyDown keyDown = getKeyDown(k); KeyDown keyDown = getKeyDown(k);
_tmpRect.set(x, y, x + keyW, y + _config.keyHeight); _tmpRect.set(x, y, x + keyW, y + keyH);
if (keyDown != null) if (keyDown != null)
canvas.drawRect(_tmpRect, _keyDownBgPaint); canvas.drawRect(_tmpRect, _keyDownBgPaint);
else else
canvas.drawRoundRect(_tmpRect, _config.keyRound, _config.keyRound, _keyBgPaint); canvas.drawRoundRect(_tmpRect, _config.keyRound, _config.keyRound, _keyBgPaint);
if (k.key0 != null) if (k.key0 != null)
drawLabel(canvas, k.key0, keyW / 2f + x, (_config.keyHeight + _labelTextSize) / 2f + y, drawLabel(canvas, k.key0, keyW / 2f + x, (keyH + _labelTextSize) / 2f + y,
(keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0)); (keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0));
float subPadding = _config.keyPadding; float subPadding = _config.keyPadding;
if (k.key1 != null) if (k.key1 != null)
drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding - _keySubLabelPaint.ascent(), false); drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding - _keySubLabelPaint.ascent(), false);
if (k.key3 != null) if (k.key3 != null)
drawSubLabel(canvas, k.key3, x + subPadding, y + _config.keyHeight - subPadding - _keySubLabelPaint.descent(), false); drawSubLabel(canvas, k.key3, x + subPadding, y + keyH - subPadding - _keySubLabelPaint.descent(), false);
if (k.key2 != null) if (k.key2 != null)
drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding - _keySubLabelPaint.ascent(), true); drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding - _keySubLabelPaint.ascent(), true);
if (k.key4 != null) if (k.key4 != null)
drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + _config.keyHeight - subPadding - _keySubLabelPaint.descent(), true); drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + keyH - subPadding - _keySubLabelPaint.descent(), true);
x += keyW; x += keyW;
} }
y += _config.keyHeight + _config.keyVerticalInterval; y += keyH + _config.keyVerticalInterval;
} }
} }

View File

@ -6,15 +6,24 @@ import java.util.List;
class KeyboardData class KeyboardData
{ {
private final List<Row> _rows; public final List<Row> rows;
private final float _keysWidth; /* Total width of the keyboard. Unit is abstract. */
public final float keysWidth;
/* Total height of the keyboard. Unit is abstract. */
public final float keysHeight;
public KeyboardData(List<Row> rows) public KeyboardData(List<Row> rows_)
{ {
float kpr = 0.f; float kw = 0.f;
for (Row r : rows) kpr = Math.max(kpr, r.keysWidth()); float kh = 0.f;
_rows = rows; for (Row r : rows_)
_keysWidth = kpr; {
kw = Math.max(kw, r.keysWidth);
kh += r.height + r.shift;
}
rows = rows_;
keysWidth = kw;
keysHeight = kh;
} }
public static KeyboardData parse(XmlResourceParser parser) public static KeyboardData parse(XmlResourceParser parser)
@ -40,7 +49,6 @@ class KeyboardData
throw new Exception("Unknow keyboard tag: " + tag); throw new Exception("Unknow keyboard tag: " + tag);
} }
} }
return new KeyboardData(rows);
} }
catch (Exception e) catch (Exception e)
{ {
@ -49,36 +57,40 @@ class KeyboardData
return new KeyboardData(rows); return new KeyboardData(rows);
} }
public List<Row> getRows() { return _rows; }
public float getKeysWidth() { return _keysWidth; }
public KeyboardData removeKeys(MapKeys f) public KeyboardData removeKeys(MapKeys f)
{ {
ArrayList<Row> rows = new ArrayList<Row>(); ArrayList<Row> rows_ = new ArrayList<Row>();
for (Row r : _rows) for (Row r : rows)
rows.add(r.removeKeys(f)); rows_.add(r.removeKeys(f));
return new KeyboardData(rows); return new KeyboardData(rows_);
} }
public static class Row public static class Row
{ {
private final List<Key> _keys; public final List<Key> keys;
/* Height of the row. Unit is abstract. */
public final float height;
/* Extra empty space on the top. */
public final float shift;
/* Total width of very keys. Unit is abstract. */ /* Total width of very keys. Unit is abstract. */
private final float _keysWidth; private final float keysWidth;
public Row(List<Key> keys) public Row(List<Key> keys_, float h, float s)
{ {
float kw = 0.f; float kw = 0.f;
for (Key k : keys) kw += k.width + k.shift; for (Key k : keys_) kw += k.width + k.shift;
_keys = keys; keys = keys_;
_keysWidth = kw; height = h;
shift = s;
keysWidth = kw;
} }
public static Row parse(XmlResourceParser parser) throws Exception public static Row parse(XmlResourceParser parser) throws Exception
{ {
ArrayList<Key> keys = new ArrayList<Key>(); ArrayList<Key> keys = new ArrayList<Key>();
int status; int status;
float h = parser.getAttributeFloatValue(null, "height", 1f);
float shift = parser.getAttributeFloatValue(null, "shift", 0f);
while ((status = parser.next()) != XmlResourceParser.END_TAG) while ((status = parser.next()) != XmlResourceParser.END_TAG)
{ {
if (status == XmlResourceParser.START_TAG) if (status == XmlResourceParser.START_TAG)
@ -90,19 +102,15 @@ class KeyboardData
throw new Exception("Unknow row tag: " + tag); throw new Exception("Unknow row tag: " + tag);
} }
} }
return new Row(keys); return new Row(keys, h, shift);
} }
public List<Key> getKeys() { return _keys; }
public float keysWidth() { return _keysWidth; }
public Row removeKeys(MapKeys f) public Row removeKeys(MapKeys f)
{ {
ArrayList<Key> keys = new ArrayList<Key>(); ArrayList<Key> keys_ = new ArrayList<Key>();
for (Key k : _keys) for (Key k : keys)
keys.add(k.removeKeys(f)); keys_.add(k.removeKeys(f));
return new Row(keys); return new Row(keys_, height, shift);
} }
} }