From 42f2ec10ccaa6405493e4296a87e965ea7974554 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Mon, 3 Jun 2024 18:22:59 +0530 Subject: [PATCH 1/3] feat:Added a shadow beneath the key --- .../kotlin/org/scribe/views/MyKeyboardView.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt b/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt index b1fc8fb1..4efd7b15 100644 --- a/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt @@ -415,6 +415,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut @SuppressLint("UseCompatLoadingForDrawables") private fun onBufferDraw() { + val keyMargin = 8 + val shadowOffset = 5 + val shadowPaint = Paint().apply { + style = Paint.Style.STROKE + strokeWidth = 2f + color = Color.BLACK + } if (mBuffer == null || mKeyboardChanged) { if (mBuffer == null || mKeyboardChanged && (mBuffer!!.width != width || mBuffer!!.height != height)) { // Make sure our bitmap is at least 1x1 @@ -444,6 +451,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut typeface = Typeface.DEFAULT } + val borderPaint = Paint().apply { + style = Paint.Style.STROKE + strokeWidth = 0.5f + color = Color.BLACK + } + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR) val keyCount = keys.size @@ -473,11 +486,19 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut // resources.getDrawable(R.drawable.keyboard_key_background, context.theme) // } + + val shadowRect = RectF( + (key.x + keyMargin - shadowOffset).toFloat(), + (key.y + keyMargin - shadowOffset).toFloat(), + (key.x + key.width - keyMargin + shadowOffset).toFloat(), + (key.y + key.height - keyMargin + shadowOffset).toFloat() + ) + canvas.drawRect(shadowRect, shadowPaint) // Switch the character to uppercase if shift is pressed val label = adjustCase(key.label)?.toString() val bounds = keyBackground!!.bounds if (key.width != bounds.right || key.height != bounds.bottom) { - keyBackground.setBounds(0, 0, key.width, key.height) + keyBackground.setBounds(keyMargin, keyMargin, key.width - keyMargin, key.height - keyMargin) } keyBackground.state = when { @@ -494,6 +515,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut canvas.translate(key.x.toFloat(), key.y.toFloat()) keyBackground.draw(canvas) + val borderRect = RectF(keyMargin.toFloat(), keyMargin.toFloat(), (key.width - keyMargin).toFloat(), (key.height - keyMargin).toFloat()) + + canvas.drawRect(borderRect, borderPaint) if (label?.isNotEmpty() == true) { // For characters, use large font. For labels like "Done", use small font. if (label.length > 1) { From 1ecfd7088e2e6fe162a40591d104cc2d714aaec0 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Sat, 29 Jun 2024 13:04:29 +0530 Subject: [PATCH 2/3] feat:Made the keys rounded and fixed the spacebar padding error --- .../kotlin/org/scribe/views/MyKeyboardView.kt | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt b/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt index 4efd7b15..e758e447 100644 --- a/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt @@ -416,7 +416,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut @SuppressLint("UseCompatLoadingForDrawables") private fun onBufferDraw() { val keyMargin = 8 - val shadowOffset = 5 + val shadowOffset = 3 val shadowPaint = Paint().apply { style = Paint.Style.STROKE strokeWidth = 2f @@ -464,15 +464,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val key = keys[i] val code = key.code var keyBackground = mKeyBackground - if (code == KEYCODE_ENTER) { - keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme) - } else if (code == KEYCODE_SPACE) { - keyBackground = if (context.config.isUsingSystemTheme) { - resources.getDrawable(R.drawable.keyboard_space_background_material, context.theme) - } else { - resources.getDrawable(R.drawable.keyboard_space_background, context.theme) - } - } +// if (code == KEYCODE_ENTER) { +// keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme) +// } else if (code == KEYCODE_SPACE) { +// keyBackground = if (context.config.isUsingSystemTheme) { +// resources.getDrawable(R.drawable.keyboard_space_background_material, context.theme) +// } else { +// resources.getDrawable(R.drawable.keyboard_space_background, context.theme) +// } +// } // keyBackground = if (code == KEYCODE_ENTER) { // resources.getDrawable(R.drawable.keyboard_enter_background, context.theme) @@ -487,13 +487,23 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut // } - val shadowRect = RectF( - (key.x + keyMargin - shadowOffset).toFloat(), - (key.y + keyMargin - shadowOffset).toFloat(), - (key.x + key.width - keyMargin + shadowOffset).toFloat(), - (key.y + key.height - keyMargin + shadowOffset).toFloat() + val padding = 5 + + val rectRadius = 25f + + val keyRect = RectF( + (key.x + keyMargin - shadowOffset + padding).toFloat(), + (key.y + keyMargin - shadowOffset + padding).toFloat(), + (key.x + key.width - keyMargin + shadowOffset - padding).toFloat(), + (key.y + key.height - keyMargin + shadowOffset - padding).toFloat() ) - canvas.drawRect(shadowRect, shadowPaint) + canvas.drawRoundRect(keyRect, rectRadius, rectRadius, shadowPaint) + + keyBackground!!.setBounds( + keyMargin, keyMargin, + key.width - keyMargin, key.height - keyMargin + ) + // Switch the character to uppercase if shift is pressed val label = adjustCase(key.label)?.toString() val bounds = keyBackground!!.bounds @@ -515,9 +525,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut canvas.translate(key.x.toFloat(), key.y.toFloat()) keyBackground.draw(canvas) - val borderRect = RectF(keyMargin.toFloat(), keyMargin.toFloat(), (key.width - keyMargin).toFloat(), (key.height - keyMargin).toFloat()) - - canvas.drawRect(borderRect, borderPaint) if (label?.isNotEmpty() == true) { // For characters, use large font. For labels like "Done", use small font. if (label.length > 1) { From ea4cd1434c33789e835e1cc8c2efec2f875a2f6b Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Sat, 29 Jun 2024 23:16:28 +0200 Subject: [PATCH 3/3] Update Gradle build files given suggestions --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 7f3aa0e9..3dc33924 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index af52bcd0..54094446 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Jan 04 09:48:27 CET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME