diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 0d11cca94..f4a7874fc 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -46,6 +46,7 @@ @string/pref_theme_e_cobalt @string/pref_theme_e_pine @string/pref_theme_e_epaperblack + @string/pref_theme_e_gradientpurplepink system @@ -65,6 +66,7 @@ cobalt pine epaperblack + gradientpurplepink @string/pref_swipe_dist_e_very_short diff --git a/res/values/strings.xml b/res/values/strings.xml index 6c416523e..e7d770fde 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -83,6 +83,7 @@ Cobalt Pine ePaper Black + Purple Pink Gradient Very short Short Normal diff --git a/res/values/themes.xml b/res/values/themes.xml index 170c86734..7e4b3a93b 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -3,6 +3,9 @@ + + + @@ -332,4 +335,29 @@ ?colorLabel 2dp + diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index fd19b49cc..e2d882101 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -278,6 +278,7 @@ private int getThemeId(Resources res, String theme_name) case "cobalt": return R.style.Cobalt; case "pine": return R.style.Pine; case "epaperblack": return R.style.ePaperBlack; + case "gradientpurplepink": return R.style.GradientPurplePink; default: case "system": if ((night_mode & Configuration.UI_MODE_NIGHT_NO) != 0) diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 5e854a0ff..52e527613 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -19,6 +19,8 @@ import android.view.WindowMetrics; import java.util.Arrays; import java.util.List; +import android.graphics.LinearGradient; +import android.graphics.Shader; public class Keyboard2View extends View implements View.OnTouchListener, Pointers.IPointerEventHandler @@ -53,6 +55,8 @@ public class Keyboard2View extends View private Theme _theme; private Theme.Computed _tc; + private final Paint _keyboardBackgroundPaint = new Paint(); + private static RectF _tmpRect = new RectF(); enum Vertical @@ -337,9 +341,42 @@ public WindowInsets onApplyWindowInsets(WindowInsets wi) Vertical.BOTTOM }; + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) + { + super.onSizeChanged(w, h, oldw, oldh); + + if (_theme.hasKeyboardGradient && h > 0) + { + LinearGradient gradient = new LinearGradient( + 0, + 0, + 0, + h, + _theme.keyboardGradientStart, + _theme.keyboardGradientEnd, + Shader.TileMode.CLAMP); + + _keyboardBackgroundPaint.setShader(gradient); + } + else + { + _keyboardBackgroundPaint.setShader(null); + } + } + @Override protected void onDraw(Canvas canvas) { + if (_theme.hasKeyboardGradient) + { + canvas.drawRect( + 0, + 0, + getWidth(), + getHeight(), + _keyboardBackgroundPaint); + } float y = _tc.margin_top; for (KeyboardData.Row row : _keyboard.rows) { diff --git a/srcs/juloo.keyboard2/Theme.java b/srcs/juloo.keyboard2/Theme.java index 8f4e8f65d..2d20a22c1 100644 --- a/srcs/juloo.keyboard2/Theme.java +++ b/srcs/juloo.keyboard2/Theme.java @@ -15,6 +15,11 @@ public class Theme public final int colorKeyAction; public final int colorKeySpaceBar; + // Optional keyboard background gradient + public final boolean hasKeyboardGradient; + public final int keyboardGradientStart; + public final int keyboardGradientEnd; + // Label colors public final int lockedColor; public final int activatedColor; @@ -42,6 +47,9 @@ public Theme(Context context, AttributeSet attrs) { getKeyFont(context); // _key_font will be accessed TypedArray s = context.getTheme().obtainStyledAttributes(attrs, R.styleable.keyboard, 0, 0); + hasKeyboardGradient = s.hasValue(R.styleable.keyboard_keyboardGradientStart) && s.hasValue(R.styleable.keyboard_keyboardGradientEnd); + keyboardGradientStart = s.getColor(R.styleable.keyboard_keyboardGradientStart, 0); + keyboardGradientEnd = s.getColor(R.styleable.keyboard_keyboardGradientEnd, 0); colorKey = s.getColor(R.styleable.keyboard_colorKey, 0); colorKeyActivated = s.getColor(R.styleable.keyboard_colorKeyActivated, 0); colorKeyAction = s.getColor(R.styleable.keyboard_colorKeyAction, colorKey);