From 1115a34a19411aeca6ba4faa8a775fb0faa07f21 Mon Sep 17 00:00:00 2001 From: juloo Date: Sun, 2 Aug 2015 19:56:23 +0200 Subject: [PATCH] Fix mini crash + Can disable on keys --- srcs/juloo.keyboard2/Keyboard2.java | 2 ++ srcs/juloo.keyboard2/Keyboard2View.java | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index bfcccdd..03f71bf 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -31,6 +31,8 @@ public class Keyboard2 extends InputMethodService { int eventCode = key.getEventCode(); + if (getCurrentInputConnection() == null) + return ; // TODO wait a little before give up switch (eventCode) { case KeyValue.EVENT_NONE: diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 0cea2c8..b44ee16 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -102,14 +102,14 @@ public class Keyboard2View extends View return (null); } - private boolean isKeyDown(KeyboardData.Key key) + private KeyDown getKeyDown(KeyboardData.Key key) { for (KeyDown k : _downKeys) { if (k.key == key) - return (true); + return (k); } - return (false); + return (null); } private void onTouchMove(float moveX, float moveY, int pointerId) @@ -138,7 +138,14 @@ public class Keyboard2View extends View keyW = _keyWidth * key.width; if (touchX >= x && touchX < (x + keyW)) { - _downKeys.add(new KeyDown(pointerId, key, touchX, touchY)); + KeyDown down = getKeyDown(key); + if (down != null) + { + if (down.pointerId == -1) + down.pointerId = pointerId; + } + else + _downKeys.add(new KeyDown(pointerId, key, touchX, touchY)); updateFlags(); invalidate(); return ; @@ -211,7 +218,7 @@ public class Keyboard2View extends View for (KeyboardData.Key k : row) { float keyW = _keyWidth * k.width; - if (isKeyDown(k)) + if (getKeyDown(k) != null) canvas.drawRect(x + _keyBgPadding, y + _keyBgPadding, x + keyW - _keyBgPadding, y + _keyHeight - _keyBgPadding, _keyDownBgPaint); else @@ -259,7 +266,7 @@ public class Keyboard2View extends View this.key = key; downX = x; downY = y; - flags = value.getFlags(); + flags = (value == null) ? 0 : value.getFlags(); } public boolean updateDown(float x, float y)