abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java40
-rw-r--r--srcs/juloo.keyboard2/Theme.java17
2 files changed, 53 insertions, 4 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)
diff --git a/srcs/juloo.keyboard2/Theme.java b/srcs/juloo.keyboard2/Theme.java
index 21d21fd..b5e5b88 100644
--- a/srcs/juloo.keyboard2/Theme.java
+++ b/srcs/juloo.keyboard2/Theme.java
@@ -12,6 +12,7 @@ public class Theme
{
public final Paint keyBgPaint = new Paint();
public final Paint keyDownBgPaint = new Paint();
+ public final Paint keyBorderPaint = new Paint();
public final int lockedColor;
public final int activatedColor;
public final int labelColor;
@@ -19,6 +20,12 @@ public class Theme
public final int secondaryLabelColor;
public final float keyBorderRadius;
+ public final float keyBorderWidth;
+ public final float keyBorderWidthActivated;
+ public final int keyBorderColorLeft;
+ public final int keyBorderColorTop;
+ public final int keyBorderColorRight;
+ public final int keyBorderColorBottom;
public final int colorNavBar;
public final boolean isLightNavBar;
@@ -32,7 +39,8 @@ public class Theme
public Theme(Context context, AttributeSet attrs)
{
TypedArray s = context.getTheme().obtainStyledAttributes(attrs, R.styleable.keyboard, 0, 0);
- keyBgPaint.setColor(s.getColor(R.styleable.keyboard_colorKey, 0));
+ int colorKey = s.getColor(R.styleable.keyboard_colorKey, 0);
+ keyBgPaint.setColor(colorKey);
keyDownBgPaint.setColor(s.getColor(R.styleable.keyboard_colorKeyActivated, 0));
// colorKeyboard = s.getColor(R.styleable.keyboard_colorKeyboard, 0);
colorNavBar = s.getColor(R.styleable.keyboard_navigationBarColor, 0);
@@ -44,6 +52,13 @@ public class Theme
float secondaryLightOffset = s.getFloat(R.styleable.keyboard_secondaryLightOffset, 1.f);
secondaryLabelColor = adjustLight(labelColor, secondaryLightOffset);
keyBorderRadius = s.getDimension(R.styleable.keyboard_keyBorderRadius, 0);
+ keyBorderWidth = s.getDimension(R.styleable.keyboard_keyBorderWidth, 0);
+ keyBorderWidthActivated = s.getDimension(R.styleable.keyboard_keyBorderWidthActivated, 0);
+ keyBorderPaint.setStyle(Paint.Style.STROKE);
+ keyBorderColorLeft = s.getColor(R.styleable.keyboard_keyBorderColorLeft, colorKey);
+ keyBorderColorTop = s.getColor(R.styleable.keyboard_keyBorderColorTop, colorKey);
+ keyBorderColorRight = s.getColor(R.styleable.keyboard_keyBorderColorRight, colorKey);
+ keyBorderColorBottom = s.getColor(R.styleable.keyboard_keyBorderColorBottom, colorKey);
s.recycle();
_keyLabelPaint = initLabelPaint(Paint.Align.CENTER, null);
_keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null);