diff --git a/res/xml/qwerty.xml b/res/xml/qwerty.xml
index 20bc45e..ecef724 100644
--- a/res/xml/qwerty.xml
+++ b/res/xml/qwerty.xml
@@ -13,7 +13,7 @@
-
+
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 84159b2..ccbbb7e 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -18,8 +18,6 @@ import java.util.ArrayList;
public class Keyboard2View extends View
implements View.OnTouchListener, Handler.Callback
{
- private static final float KEY_PER_ROW = 10;
-
private static final long VIBRATE_MIN_INTERVAL = 100;
private KeyboardData _keyboard;
@@ -187,20 +185,17 @@ public class Keyboard2View extends View
private void onTouchDown(float touchX, float touchY, int pointerId)
{
- float x;
- float y;
- float keyW;
-
- y = _config.marginTop - _config.keyHeight;
+ float y = _config.marginTop - _config.keyHeight;
for (KeyboardData.Row row : _keyboard.getRows())
{
y += _config.keyHeight;
if (touchY < y || touchY >= (y + _config.keyHeight))
continue ;
- x = (KEY_PER_ROW * _keyWidth - row.getWidth(_keyWidth)) / 2 + _config.horizontalMargin;
+ float x = _config.horizontalMargin;
for (KeyboardData.Key key : row.getKeys())
{
- keyW = _keyWidth * key.width;
+ x += key.shift * _keyWidth;
+ float keyW = _keyWidth * key.width;
if (touchX >= x && touchX < (x + keyW))
{
KeyDown down = getKeyDown(key);
@@ -333,21 +328,19 @@ public class Keyboard2View extends View
height = (int)(_config.keyHeight * ((float)_keyboard.getRows().size())
+ _config.marginTop + _config.marginBottom);
setMeasuredDimension(dm.widthPixels, height);
- _keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / KEY_PER_ROW;
+ _keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.getKeysWidth();
}
@Override
protected void onDraw(Canvas canvas)
{
- float x;
- float y;
-
- y = _config.marginTop;
+ float y = _config.marginTop;
for (KeyboardData.Row row : _keyboard.getRows())
{
- x = (KEY_PER_ROW * _keyWidth - row.getWidth(_keyWidth)) / 2f + _config.horizontalMargin;
+ float x = _config.horizontalMargin;
for (KeyboardData.Key k : row.getKeys())
{
+ x += k.shift * _keyWidth;
float keyW = _keyWidth * k.width;
KeyDown keyDown = getKeyDown(k);
_tmpRect.set(x + _config.keyBgPadding, y + _config.keyBgPadding,
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 4bf4ec0..000c7e0 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -7,10 +7,14 @@ import java.util.List;
class KeyboardData
{
private final List _rows;
+ private final float _keysWidth;
- public KeyboardData(ArrayList rows)
+ public KeyboardData(List rows)
{
+ float kpr = 0.f;
+ for (Row r : rows) kpr = Math.max(kpr, r.keysWidth());
_rows = rows;
+ _keysWidth = kpr;
}
public static KeyboardData parse(XmlResourceParser parser)
@@ -45,10 +49,9 @@ class KeyboardData
return new KeyboardData(rows);
}
- public List getRows()
- {
- return (_rows);
- }
+ public List getRows() { return _rows; }
+
+ public float getKeysWidth() { return _keysWidth; }
public KeyboardData removeKeys(MapKeys f)
{
@@ -61,12 +64,13 @@ class KeyboardData
public static class Row
{
private final List _keys;
+ /* Total width of very keys. Unit is abstract. */
private final float _keysWidth;
public Row(List keys)
{
float kw = 0.f;
- for (Key k : keys) kw += k.width;
+ for (Key k : keys) kw += k.width + k.shift;
_keys = keys;
_keysWidth = kw;
}
@@ -91,10 +95,7 @@ class KeyboardData
public List getKeys() { return _keys; }
- public float getWidth(float keyWidth)
- {
- return (keyWidth * _keysWidth);
- }
+ public float keysWidth() { return _keysWidth; }
public Row removeKeys(MapKeys f)
{
@@ -118,9 +119,12 @@ class KeyboardData
public final KeyValue key3;
public final KeyValue key4;
+ /* Key width in relative unit. */
public final float width;
+ /* Extra empty space on the left of the key. */
+ public final float shift;
- public Key(KeyValue k0, KeyValue k1, KeyValue k2, KeyValue k3, KeyValue k4, float w)
+ public Key(KeyValue k0, KeyValue k1, KeyValue k2, KeyValue k3, KeyValue k4, float w, float s)
{
key0 = k0;
key1 = k1;
@@ -128,6 +132,7 @@ class KeyboardData
key3 = k3;
key4 = k4;
width = w;
+ shift = s;
}
public static Key parse(XmlResourceParser parser) throws Exception
@@ -137,23 +142,16 @@ class KeyboardData
KeyValue k2 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key2"));
KeyValue k3 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key3"));
KeyValue k4 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key4"));
- float width;
- try
- {
- width = parser.getAttributeFloatValue(null, "width", 1f);
- }
- catch (Exception e)
- {
- width = 1f;
- }
+ float width = parser.getAttributeFloatValue(null, "width", 1f);
+ float shift = parser.getAttributeFloatValue(null, "shift", 0.f);
while (parser.next() != XmlResourceParser.END_TAG)
continue ;
- return new Key(k0, k1, k2, k3, k4, width);
+ return new Key(k0, k1, k2, k3, k4, width, shift);
}
public Key removeKeys(MapKeys f)
{
- return new Key(f.map(key0), f.map(key1), f.map(key2), f.map(key3), f.map(key4), width);
+ return new Key(f.map(key0), f.map(key1), f.map(key2), f.map(key3), f.map(key4), width, shift);
}
}