Skip to content

Commit

Permalink
Merge pull request #35 from angrezichatterbox/feature-Shadow-beneath-…
Browse files Browse the repository at this point in the history
…the-key

feat:Added a shadow beneath the key
  • Loading branch information
andrewtavis authored Jun 29, 2024
2 parents 9e9f393 + ea4cd14 commit 4b546f8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
51 changes: 41 additions & 10 deletions app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut

@SuppressLint("UseCompatLoadingForDrawables")
private fun onBufferDraw() {
val keyMargin = 8
val shadowOffset = 3
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
Expand Down Expand Up @@ -460,22 +467,28 @@ 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
for (i in 0 until keyCount) {
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)
Expand All @@ -489,11 +502,29 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
// resources.getDrawable(R.drawable.keyboard_key_background, context.theme)
// }


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.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
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 {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b546f8

Please sign in to comment.