mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-01-23 05:48:54 +01:00
Remove fixed keyboard width
Remove the constant of keys per rows. Add the 'shift' attribute to declare eventual alignment/blanks in layouts.
This commit is contained in:
parent
ca07bff133
commit
1421bccc7b
@ -13,7 +13,7 @@
|
|||||||
<key key0="p" key1="insert" key2="0" />
|
<key key0="p" key1="insert" key2="0" />
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<key key0="a" key1="tab" key2="`" />
|
<key shift="0.5" key0="a" key1="tab" key2="`" />
|
||||||
<key key0="s" key1="accent1" key2="accent2" key4="accent6" />
|
<key key0="s" key1="accent1" key2="accent2" key4="accent6" />
|
||||||
<key key0="d" key1="accent3" key2="accent4" key3="accent5" />
|
<key key0="d" key1="accent3" key2="accent4" key3="accent5" />
|
||||||
<key key0="f" />
|
<key key0="f" />
|
||||||
|
@ -18,8 +18,6 @@ import java.util.ArrayList;
|
|||||||
public class Keyboard2View extends View
|
public class Keyboard2View extends View
|
||||||
implements View.OnTouchListener, Handler.Callback
|
implements View.OnTouchListener, Handler.Callback
|
||||||
{
|
{
|
||||||
private static final float KEY_PER_ROW = 10;
|
|
||||||
|
|
||||||
private static final long VIBRATE_MIN_INTERVAL = 100;
|
private static final long VIBRATE_MIN_INTERVAL = 100;
|
||||||
|
|
||||||
private KeyboardData _keyboard;
|
private KeyboardData _keyboard;
|
||||||
@ -187,20 +185,17 @@ public class Keyboard2View extends View
|
|||||||
|
|
||||||
private void onTouchDown(float touchX, float touchY, int pointerId)
|
private void onTouchDown(float touchX, float touchY, int pointerId)
|
||||||
{
|
{
|
||||||
float x;
|
float y = _config.marginTop - _config.keyHeight;
|
||||||
float y;
|
|
||||||
float keyW;
|
|
||||||
|
|
||||||
y = _config.marginTop - _config.keyHeight;
|
|
||||||
for (KeyboardData.Row row : _keyboard.getRows())
|
for (KeyboardData.Row row : _keyboard.getRows())
|
||||||
{
|
{
|
||||||
y += _config.keyHeight;
|
y += _config.keyHeight;
|
||||||
if (touchY < y || touchY >= (y + _config.keyHeight))
|
if (touchY < y || touchY >= (y + _config.keyHeight))
|
||||||
continue ;
|
continue ;
|
||||||
x = (KEY_PER_ROW * _keyWidth - row.getWidth(_keyWidth)) / 2 + _config.horizontalMargin;
|
float x = _config.horizontalMargin;
|
||||||
for (KeyboardData.Key key : row.getKeys())
|
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))
|
if (touchX >= x && touchX < (x + keyW))
|
||||||
{
|
{
|
||||||
KeyDown down = getKeyDown(key);
|
KeyDown down = getKeyDown(key);
|
||||||
@ -333,21 +328,19 @@ public class Keyboard2View extends View
|
|||||||
height = (int)(_config.keyHeight * ((float)_keyboard.getRows().size())
|
height = (int)(_config.keyHeight * ((float)_keyboard.getRows().size())
|
||||||
+ _config.marginTop + _config.marginBottom);
|
+ _config.marginTop + _config.marginBottom);
|
||||||
setMeasuredDimension(dm.widthPixels, height);
|
setMeasuredDimension(dm.widthPixels, height);
|
||||||
_keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / KEY_PER_ROW;
|
_keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.getKeysWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas)
|
protected void onDraw(Canvas canvas)
|
||||||
{
|
{
|
||||||
float x;
|
float y = _config.marginTop;
|
||||||
float y;
|
|
||||||
|
|
||||||
y = _config.marginTop;
|
|
||||||
for (KeyboardData.Row row : _keyboard.getRows())
|
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())
|
for (KeyboardData.Key k : row.getKeys())
|
||||||
{
|
{
|
||||||
|
x += k.shift * _keyWidth;
|
||||||
float keyW = _keyWidth * k.width;
|
float keyW = _keyWidth * k.width;
|
||||||
KeyDown keyDown = getKeyDown(k);
|
KeyDown keyDown = getKeyDown(k);
|
||||||
_tmpRect.set(x + _config.keyBgPadding, y + _config.keyBgPadding,
|
_tmpRect.set(x + _config.keyBgPadding, y + _config.keyBgPadding,
|
||||||
|
@ -7,10 +7,14 @@ import java.util.List;
|
|||||||
class KeyboardData
|
class KeyboardData
|
||||||
{
|
{
|
||||||
private final List<Row> _rows;
|
private final List<Row> _rows;
|
||||||
|
private final float _keysWidth;
|
||||||
|
|
||||||
public KeyboardData(ArrayList<Row> rows)
|
public KeyboardData(List<Row> rows)
|
||||||
{
|
{
|
||||||
|
float kpr = 0.f;
|
||||||
|
for (Row r : rows) kpr = Math.max(kpr, r.keysWidth());
|
||||||
_rows = rows;
|
_rows = rows;
|
||||||
|
_keysWidth = kpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyboardData parse(XmlResourceParser parser)
|
public static KeyboardData parse(XmlResourceParser parser)
|
||||||
@ -45,10 +49,9 @@ class KeyboardData
|
|||||||
return new KeyboardData(rows);
|
return new KeyboardData(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Row> getRows()
|
public List<Row> getRows() { return _rows; }
|
||||||
{
|
|
||||||
return (_rows);
|
public float getKeysWidth() { return _keysWidth; }
|
||||||
}
|
|
||||||
|
|
||||||
public KeyboardData removeKeys(MapKeys f)
|
public KeyboardData removeKeys(MapKeys f)
|
||||||
{
|
{
|
||||||
@ -61,12 +64,13 @@ class KeyboardData
|
|||||||
public static class Row
|
public static class Row
|
||||||
{
|
{
|
||||||
private final List<Key> _keys;
|
private final List<Key> _keys;
|
||||||
|
/* 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 kw = 0.f;
|
float kw = 0.f;
|
||||||
for (Key k : keys) kw += k.width;
|
for (Key k : keys) kw += k.width + k.shift;
|
||||||
_keys = keys;
|
_keys = keys;
|
||||||
_keysWidth = kw;
|
_keysWidth = kw;
|
||||||
}
|
}
|
||||||
@ -91,10 +95,7 @@ class KeyboardData
|
|||||||
|
|
||||||
public List<Key> getKeys() { return _keys; }
|
public List<Key> getKeys() { return _keys; }
|
||||||
|
|
||||||
public float getWidth(float keyWidth)
|
public float keysWidth() { return _keysWidth; }
|
||||||
{
|
|
||||||
return (keyWidth * _keysWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Row removeKeys(MapKeys f)
|
public Row removeKeys(MapKeys f)
|
||||||
{
|
{
|
||||||
@ -118,9 +119,12 @@ class KeyboardData
|
|||||||
public final KeyValue key3;
|
public final KeyValue key3;
|
||||||
public final KeyValue key4;
|
public final KeyValue key4;
|
||||||
|
|
||||||
|
/* Key width in relative unit. */
|
||||||
public final float width;
|
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;
|
key0 = k0;
|
||||||
key1 = k1;
|
key1 = k1;
|
||||||
@ -128,6 +132,7 @@ class KeyboardData
|
|||||||
key3 = k3;
|
key3 = k3;
|
||||||
key4 = k4;
|
key4 = k4;
|
||||||
width = w;
|
width = w;
|
||||||
|
shift = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Key parse(XmlResourceParser parser) throws Exception
|
public static Key parse(XmlResourceParser parser) throws Exception
|
||||||
@ -137,23 +142,16 @@ class KeyboardData
|
|||||||
KeyValue k2 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key2"));
|
KeyValue k2 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key2"));
|
||||||
KeyValue k3 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key3"));
|
KeyValue k3 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key3"));
|
||||||
KeyValue k4 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key4"));
|
KeyValue k4 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key4"));
|
||||||
float width;
|
float width = parser.getAttributeFloatValue(null, "width", 1f);
|
||||||
try
|
float shift = parser.getAttributeFloatValue(null, "shift", 0.f);
|
||||||
{
|
|
||||||
width = parser.getAttributeFloatValue(null, "width", 1f);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
width = 1f;
|
|
||||||
}
|
|
||||||
while (parser.next() != XmlResourceParser.END_TAG)
|
while (parser.next() != XmlResourceParser.END_TAG)
|
||||||
continue ;
|
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)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user