Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Added Shadow to the keys and reduced border radius #37

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions app/src/main/kotlin/org/scribe/views/MyKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
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 @@ -467,10 +462,18 @@ 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



val keyBackgroundPaint = Paint().apply {
color = Color.WHITE
style = Paint.Style.FILL
}

val shadowPaint = Paint().apply {
color = Color.GRAY
alpha = 100
style = Paint.Style.FILL
}

canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)
Expand Down Expand Up @@ -505,15 +508,26 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut

val padding = 5

val rectRadius = 25f
val rectRadius = 15f
val shadowOffsetY = 9f

val shadowRect = RectF(
(key.x + keyMargin + padding).toFloat(),
(key.y + keyMargin + padding + shadowOffsetY).toFloat(),
(key.x + key.width - keyMargin - padding).toFloat(),
(key.y + key.height - keyMargin - padding + shadowOffsetY).toFloat()
)

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)
canvas.drawRoundRect(shadowRect, rectRadius, rectRadius, shadowPaint)

canvas.drawRoundRect(keyRect, rectRadius, rectRadius, keyBackgroundPaint)


keyBackground!!.setBounds(
keyMargin, keyMargin,
Expand Down Expand Up @@ -860,7 +874,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}

override fun hasTextBeforeCursor(): Boolean {
return mOnKeyboardActionListener!!.hasTextBeforeCursor()
return mOnKeyboardActionListener!!.hasTextBeforeCursor()
}

override fun commitPeriodAfterSpace() {
Expand Down