diff options
Diffstat (limited to 'srcs')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2View.java | 38 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyboardData.java | 70 |
2 files changed, 57 insertions, 51 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 16cb85f..508c787 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -196,13 +196,13 @@ public class Keyboard2View extends View private void onTouchDown(float touchX, float touchY, int pointerId) { float y = _config.marginTop - _config.keyHeight; - for (KeyboardData.Row row : _keyboard.getRows()) + for (KeyboardData.Row row : _keyboard.rows) { y += _config.keyHeight; if (touchY < y || touchY >= (y + _config.keyHeight)) continue ; float x = _config.horizontalMargin; - for (KeyboardData.Key key : row.getKeys()) + for (KeyboardData.Key key : row.keys) { x += key.shift * _keyWidth; float keyW = _keyWidth * key.width; @@ -350,51 +350,49 @@ public class Keyboard2View extends View @Override public void onMeasure(int wSpec, int hSpec) { - DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); - int height; - - if (_keyboard.getRows() == null) - height = 0; - else - height = (int)((_config.keyHeight + _config.keyVerticalInterval) - * ((float)_keyboard.getRows().size()) - + _config.marginTop + _config.marginBottom); - setMeasuredDimension(dm.widthPixels, height); - _keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.getKeysWidth(); + DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); + int height; + height = (int)(_config.keyHeight * _keyboard.keysHeight + + _keyboard.rows.size() * _config.keyVerticalInterval + + _config.marginTop + _config.marginBottom); + setMeasuredDimension(dm.widthPixels, height); + _keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.keysWidth; } @Override protected void onDraw(Canvas canvas) { 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; - for (KeyboardData.Key k : row.getKeys()) + float keyH = row.height * _config.keyHeight; + for (KeyboardData.Key k : row.keys) { x += k.shift * _keyWidth + _config.keyHorizontalInterval; float keyW = _keyWidth * k.width - _config.keyHorizontalInterval; KeyDown keyDown = getKeyDown(k); - _tmpRect.set(x, y, x + keyW, y + _config.keyHeight); + _tmpRect.set(x, y, x + keyW, y + keyH); if (keyDown != null) canvas.drawRect(_tmpRect, _keyDownBgPaint); else canvas.drawRoundRect(_tmpRect, _config.keyRound, _config.keyRound, _keyBgPaint); 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)); float subPadding = _config.keyPadding; if (k.key1 != null) drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding - _keySubLabelPaint.ascent(), false); 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) drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding - _keySubLabelPaint.ascent(), true); 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; } - y += _config.keyHeight + _config.keyVerticalInterval; + y += keyH + _config.keyVerticalInterval; } } diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 2356954..ea226ee 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -6,15 +6,24 @@ import java.util.List; class KeyboardData { - private final List<Row> _rows; - private final float _keysWidth; + public final List<Row> rows; + /* 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; - for (Row r : rows) kpr = Math.max(kpr, r.keysWidth()); - _rows = rows; - _keysWidth = kpr; + float kw = 0.f; + float kh = 0.f; + for (Row r : rows_) + { + kw = Math.max(kw, r.keysWidth); + kh += r.height + r.shift; + } + rows = rows_; + keysWidth = kw; + keysHeight = kh; } public static KeyboardData parse(XmlResourceParser parser) @@ -40,7 +49,6 @@ class KeyboardData throw new Exception("Unknow keyboard tag: " + tag); } } - return new KeyboardData(rows); } catch (Exception e) { @@ -49,36 +57,40 @@ class KeyboardData return new KeyboardData(rows); } - public List<Row> getRows() { return _rows; } - - public float getKeysWidth() { return _keysWidth; } - public KeyboardData removeKeys(MapKeys f) { - ArrayList<Row> rows = new ArrayList<Row>(); - for (Row r : _rows) - rows.add(r.removeKeys(f)); - return new KeyboardData(rows); + ArrayList<Row> rows_ = new ArrayList<Row>(); + for (Row r : rows) + rows_.add(r.removeKeys(f)); + return new KeyboardData(rows_); } 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. */ - 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; - for (Key k : keys) kw += k.width + k.shift; - _keys = keys; - _keysWidth = kw; + for (Key k : keys_) kw += k.width + k.shift; + keys = keys_; + height = h; + shift = s; + keysWidth = kw; } public static Row parse(XmlResourceParser parser) throws Exception { ArrayList<Key> keys = new ArrayList<Key>(); int status; + float h = parser.getAttributeFloatValue(null, "height", 1f); + float shift = parser.getAttributeFloatValue(null, "shift", 0f); while ((status = parser.next()) != XmlResourceParser.END_TAG) { if (status == XmlResourceParser.START_TAG) @@ -90,19 +102,15 @@ class KeyboardData 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) { - ArrayList<Key> keys = new ArrayList<Key>(); - for (Key k : _keys) - keys.add(k.removeKeys(f)); - return new Row(keys); + ArrayList<Key> keys_ = new ArrayList<Key>(); + for (Key k : keys) + keys_.add(k.removeKeys(f)); + return new Row(keys_, height, shift); } } |
