diff --git a/res/values/themes.xml b/res/values/themes.xml index b23beda..671912e 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -14,8 +14,14 @@ - + + + + + + + @@ -30,6 +36,8 @@ ?attr/colorKeyboard ?attr/android:isLightTheme 5dp + 0dp + 0dp ?attr/emoji_button_bg ?attr/colorLabel @@ -38,6 +46,9 @@ #1b1b1b #333333 #1b1b1b + 1.2dp + 0dp + #404040 #ffffff #3399ff #33cc33 @@ -51,6 +62,12 @@ #e3e3e3 #cccccc #e3e3e3 + 0.6dp + 0dp + #cccccc + #eeeeee + #cccccc + #aaaaaa #000000 #0066cc #33cc33 @@ -64,6 +81,12 @@ #000000 #000000 #333333 + 1dp + 1dp + #2a2a2a + #2a2a2a + #2a2a2a + #2a2a2a #eeeeee #009dff #00ff26 @@ -77,7 +100,13 @@ true #ffffff #ffffff - #cccccc + 1dp + 1dp + #f0f0f0 + #f0f0f0 + #eeeeee + #eeeeee + #ffffff #000000 #0066cc #33cc33 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);