abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/Keyboard2View.java
diff options
context:
space:
mode:
authorJules Aguillon2022-11-13 20:53:06 +0100
committerJules Aguillon2022-11-13 20:53:06 +0100
commit64c7c8ce20e2e49b2bf3ee13da9a3def5a57a7d7 (patch)
tree7f3a7d12d22c3092fd3bad3dd5abb6b156489c66 /srcs/juloo.keyboard2/Keyboard2View.java
parentc1751578ef2c30a78561511d1eb37500c945ecae (diff)
downloadunexpected-keyboard-64c7c8ce20e2e49b2bf3ee13da9a3def5a57a7d7.tar.gz
unexpected-keyboard-64c7c8ce20e2e49b2bf3ee13da9a3def5a57a7d7.zip
Draw borders and update themes
Themes can define the color of each borders independently. Every borders must have the same width for now. It's possible to set a different width when the key is activated, thought this is only used to remove borders. The 4 themes are updated to take advantage of borders.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2View.java')
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java40
1 files changed, 37 insertions, 3 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 05cb765..631b363 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -3,6 +3,7 @@ package juloo.keyboard2;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -265,9 +266,7 @@ public class Keyboard2View extends View
x += k.shift * _keyWidth;
float keyW = _keyWidth * k.width - _config.keyHorizontalInterval;
boolean isKeyDown = _pointers.isKeyDown(k);
- _tmpRect.set(x, y, x + keyW, y + keyH);
- canvas.drawRoundRect(_tmpRect, _theme.keyBorderRadius, _theme.keyBorderRadius,
- isKeyDown ? _theme.keyDownBgPaint : _theme.keyBgPaint);
+ drawKeyFrame(canvas, x, y, keyW, keyH, isKeyDown);
drawLabel(canvas, k.key0, keyW / 2f + x, y, keyH, isKeyDown);
if (k.edgekeys)
{
@@ -299,6 +298,41 @@ public class Keyboard2View extends View
super.onDetachedFromWindow();
}
+ /** Draw borders and background of the key. */
+ void drawKeyFrame(Canvas canvas, float x, float y, float keyW, float keyH,
+ boolean isKeyDown)
+ {
+ float r = _theme.keyBorderRadius;
+ float w = isKeyDown ? _theme.keyBorderWidthActivated : _theme.keyBorderWidth;
+ float w2 = _theme.keyBorderWidth / 2.f;
+ _tmpRect.set(x + w2, y + w2, x + keyW - w2, y + keyH - w2);
+ canvas.drawRoundRect(_tmpRect, r, r,
+ isKeyDown ? _theme.keyDownBgPaint : _theme.keyBgPaint);
+ if (w > 0.f)
+ {
+ _theme.keyBorderPaint.setStrokeWidth(w);
+ float overlap = r - r * 0.85f + w; // sin(45°)
+ drawBorder(canvas, x, y, x + overlap, y + keyH, _theme.keyBorderColorLeft);
+ drawBorder(canvas, x, y, x + keyW, y + overlap, _theme.keyBorderColorTop);
+ drawBorder(canvas, x + keyW - overlap, y, x + keyW, y + keyH, _theme.keyBorderColorRight);
+ drawBorder(canvas, x, y + keyH - overlap, x + keyW, y + keyH, _theme.keyBorderColorBottom);
+ }
+ }
+
+ /** Clip to draw a border at a time. This allows to call [drawRoundRect]
+ several time with the same parameters but a different Paint. */
+ void drawBorder(Canvas canvas, float clipl, float clipt, float clipr,
+ float clipb, int color)
+ {
+ Paint p = _theme.keyBorderPaint;
+ float r = _theme.keyBorderRadius;
+ canvas.save();
+ canvas.clipRect(clipl, clipt, clipr, clipb);
+ p.setColor(color);
+ canvas.drawRoundRect(_tmpRect, r, r, p);
+ canvas.restore();
+ }
+
private int labelColor(KeyValue k, boolean isKeyDown, boolean sublabel)
{
if (isKeyDown)