Fix correct rendering and positioning of icons
- Switched from png to svg resources - Icons use vector padding to gain the centered effect on the button - Implement caps lock feature - Code cleanup in CustomKey.kt
@ -17,10 +17,10 @@ class CustomKey : androidx.appcompat.widget.AppCompatButton, View.OnTouchListene
|
||||
|
||||
private var isKeyPressed: Boolean = false
|
||||
set(v) {
|
||||
super.setBackgroundTintList(ColorStateList.valueOf(getColorFromAttr(when {
|
||||
setBackgroundTintColor(when {
|
||||
v -> R.attr.key_bgColorPressed
|
||||
else -> R.attr.key_bgColor
|
||||
})))
|
||||
})
|
||||
field = v
|
||||
}
|
||||
private val osHandler = Handler()
|
||||
@ -52,29 +52,85 @@ class CustomKey : androidx.appcompat.widget.AppCompatButton, View.OnTouchListene
|
||||
super.setOnTouchListener(this)
|
||||
}
|
||||
|
||||
private fun getColorFromAttr(
|
||||
attrColor: Int,
|
||||
typedValue: TypedValue = TypedValue(),
|
||||
resolveRefs: Boolean = true
|
||||
): Int {
|
||||
context.theme.resolveAttribute(attrColor, typedValue, resolveRefs)
|
||||
return typedValue.data
|
||||
}
|
||||
|
||||
private fun setBackgroundTintColor(colorId: Int) {
|
||||
super.setBackgroundTintList(
|
||||
ColorStateList.valueOf(
|
||||
getColorFromAttr(colorId)
|
||||
)
|
||||
)
|
||||
}
|
||||
private fun setDrawableTintColor(colorId: Int) {
|
||||
super.setCompoundDrawableTintList(
|
||||
ColorStateList.valueOf(
|
||||
getColorFromAttr(colorId)
|
||||
)
|
||||
)
|
||||
}
|
||||
private fun setTextTintColor(colorId: Int) {
|
||||
super.setForegroundTintList(
|
||||
ColorStateList.valueOf(
|
||||
getColorFromAttr(colorId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun updateUI() {
|
||||
super.setText(createLabelText())
|
||||
var drawable: Drawable? = null
|
||||
when (cmd) {
|
||||
KeyCodes.DELETE -> (layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
KeyCodes.ENTER -> (layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
KeyCodes.SHIFT -> (layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
KeyCodes.SPACE -> (layoutParams as FlexboxLayout.LayoutParams).flexGrow = 5.0f
|
||||
KeyCodes.ENTER -> {
|
||||
(layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
drawable = getDrawable(context, R.drawable.ic_arrow_forward)
|
||||
}
|
||||
KeyCodes.DELETE -> {
|
||||
(layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
drawable = getDrawable(context, R.drawable.key_ic_backspace)
|
||||
}
|
||||
KeyCodes.LANGUAGE_SWITCH -> {
|
||||
drawable = getDrawable(context, R.drawable.key_ic_language)
|
||||
}
|
||||
KeyCodes.SHIFT -> {
|
||||
(layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
drawable = getDrawable(context, when {
|
||||
(keyboard?.caps ?: false) && (keyboard?.capsLock ?: false) -> {
|
||||
setDrawableTintColor(R.attr.app_colorAccentDark)
|
||||
R.drawable.key_ic_capslock
|
||||
}
|
||||
(keyboard?.caps ?: false) && !(keyboard?.capsLock ?: false) -> {
|
||||
setDrawableTintColor(R.attr.key_fgColor)
|
||||
R.drawable.key_ic_capslock
|
||||
}
|
||||
else -> {
|
||||
setDrawableTintColor(R.attr.key_fgColor)
|
||||
R.drawable.key_ic_caps
|
||||
}
|
||||
})
|
||||
}
|
||||
KeyCodes.SPACE -> {
|
||||
(layoutParams as FlexboxLayout.LayoutParams).flexGrow = 5.0f
|
||||
}
|
||||
KeyCodes.VIEW_SYMOBLS -> {
|
||||
(layoutParams as FlexboxLayout.LayoutParams).flexGrow = 1.0f
|
||||
super.setText("?123")
|
||||
}
|
||||
}
|
||||
val drawable: Drawable? = when (cmd) {
|
||||
KeyCodes.ENTER -> getDrawable(context, R.drawable.ic_arrow_forward)
|
||||
KeyCodes.DELETE -> getDrawable(context, R.drawable.ic_backspace)
|
||||
KeyCodes.LANGUAGE_SWITCH -> getDrawable(context, R.drawable.ic_language)
|
||||
KeyCodes.SHIFT -> getDrawable(context, R.drawable.ic_capslock)
|
||||
else -> null
|
||||
}
|
||||
drawable?.setBounds(0, 0, resources.getDimension(R.dimen.key_width).toInt(), resources.getDimension(R.dimen.key_width).toInt())
|
||||
if (drawable != null) {
|
||||
overlay.clear()
|
||||
overlay.add(drawable)
|
||||
if (measuredWidth > measuredHeight) {
|
||||
drawable.setBounds(0, 0, measuredHeight, measuredHeight)
|
||||
super.setCompoundDrawables(null, drawable, null, null)
|
||||
} else {
|
||||
drawable.setBounds(0, 0, measuredWidth, measuredWidth)
|
||||
super.setCompoundDrawables(drawable, null, null, null)
|
||||
}
|
||||
}
|
||||
requestLayout()
|
||||
invalidate()
|
||||
@ -91,15 +147,6 @@ class CustomKey : androidx.appcompat.widget.AppCompatButton, View.OnTouchListene
|
||||
}
|
||||
}
|
||||
|
||||
private fun getColorFromAttr(
|
||||
attrColor: Int,
|
||||
typedValue: TypedValue = TypedValue(),
|
||||
resolveRefs: Boolean = true
|
||||
): Int {
|
||||
context.theme.resolveAttribute(attrColor, typedValue, resolveRefs)
|
||||
return typedValue.data
|
||||
}
|
||||
|
||||
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
||||
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||
isKeyPressed = true
|
||||
|
@ -2,15 +2,19 @@ package dev.patrickgold.florisboard
|
||||
|
||||
import android.content.Context
|
||||
import android.inputmethodservice.InputMethodService
|
||||
import android.os.Handler
|
||||
import android.util.AttributeSet
|
||||
import android.view.KeyEvent
|
||||
import android.widget.LinearLayout
|
||||
|
||||
class CustomKeyboard : LinearLayout {
|
||||
|
||||
private var hasCapsRecentlyChanged: Boolean = false
|
||||
private val osHandler = Handler()
|
||||
private val showLanguageButton: Boolean
|
||||
|
||||
var caps: Boolean = false
|
||||
var capsLock: Boolean = false
|
||||
var layoutName: String?
|
||||
var inputMethodService: InputMethodService? = null
|
||||
val popupManager = KeyPopupManager(this)
|
||||
@ -40,7 +44,19 @@ class CustomKeyboard : LinearLayout {
|
||||
)
|
||||
KeyCodes.LANGUAGE_SWITCH -> {}
|
||||
KeyCodes.SHIFT -> {
|
||||
caps = !caps
|
||||
if (hasCapsRecentlyChanged) {
|
||||
osHandler.removeCallbacksAndMessages(null)
|
||||
caps = true
|
||||
capsLock = true
|
||||
hasCapsRecentlyChanged = false
|
||||
} else {
|
||||
caps = !caps
|
||||
capsLock = false
|
||||
hasCapsRecentlyChanged = true
|
||||
osHandler.postDelayed({
|
||||
hasCapsRecentlyChanged = false
|
||||
}, 300)
|
||||
}
|
||||
}
|
||||
KeyCodes.VIEW_SYMOBLS -> {}
|
||||
else -> {
|
||||
@ -49,6 +65,9 @@ class CustomKeyboard : LinearLayout {
|
||||
text = Character.toUpperCase(text)
|
||||
}
|
||||
ic.commitText(text.toString(), 1)
|
||||
if (!capsLock) {
|
||||
caps = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#000000"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M22,3L7,3c-0.69,0 -1.23,0.35 -1.59,0.88L0,12l5.41,8.11c0.36,0.53 0.9,0.89 1.59,0.89h15c1.1,0 2,-0.9 2,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM19,15.59L17.59,17 14,13.41 10.41,17 9,15.59 12.59,12 9,8.41 10.41,7 14,10.59 17.59,7 19,8.41 15.41,12 19,15.59z"/>
|
||||
</vector>
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#000000"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,8.41L16.59,13 18,11.59l-6,-6 -6,6L7.41,13 12,8.41zM6,18h12v-2H6v2z"/>
|
||||
</vector>
|
@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#000000"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/>
|
||||
</vector>
|
Before Width: | Height: | Size: 303 B |
Before Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 435 B |
Before Width: | Height: | Size: 218 B |
Before Width: | Height: | Size: 140 B |
Before Width: | Height: | Size: 295 B |
Before Width: | Height: | Size: 357 B |
Before Width: | Height: | Size: 195 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 521 B |
Before Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 894 B |
6
app/src/main/res/drawable/ic_backspace.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24"
|
||||
android:autoMirrored="true">
|
||||
<path android:fillColor="@android:color/black" android:pathData="M22,3L7,3c-0.69,0 -1.23,0.35 -1.59,0.88L0,12l5.41,8.11c0.36,0.53 0.9,0.89 1.59,0.89h15c1.1,0 2,-0.9 2,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM22,19L7.07,19L2.4,12l4.66,-7L22,5v14zM10.41,17L14,13.41 17.59,17 19,15.59 15.41,12 19,8.41 17.59,7 14,10.59 10.41,7 9,8.41 12.59,12 9,15.59z"/>
|
||||
</vector>
|
6
app/src/main/res/drawable/ic_keyboard_arrow_up.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24"
|
||||
android:autoMirrored="true">
|
||||
<path android:fillColor="@android:color/black" android:pathData="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/>
|
||||
</vector>
|
6
app/src/main/res/drawable/ic_keyboard_capslock.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24"
|
||||
android:autoMirrored="true">
|
||||
<path android:fillColor="@android:color/black" android:pathData="M12 8.41L16.59 13 18 11.59l-6-6-6 6L7.41 13 12 8.41zM6 18h12v-2H6v2z"/>
|
||||
</vector>
|
6
app/src/main/res/drawable/ic_language.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24"
|
||||
android:autoMirrored="true">
|
||||
<path android:fillColor="@android:color/black" android:pathData="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"/>
|
||||
</vector>
|
8
app/src/main/res/drawable/key_ic_backspace.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="@dimen/key_ic_padding"
|
||||
android:left="@dimen/key_ic_padding"
|
||||
android:right="@dimen/key_ic_padding"
|
||||
android:bottom="@dimen/key_ic_padding"
|
||||
android:drawable="@drawable/ic_backspace"/>
|
||||
</layer-list>
|
8
app/src/main/res/drawable/key_ic_caps.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="@dimen/key_ic_padding"
|
||||
android:left="@dimen/key_ic_padding"
|
||||
android:right="@dimen/key_ic_padding"
|
||||
android:bottom="@dimen/key_ic_padding"
|
||||
android:drawable="@drawable/ic_keyboard_arrow_up"/>
|
||||
</layer-list>
|
8
app/src/main/res/drawable/key_ic_capslock.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="@dimen/key_ic_padding"
|
||||
android:left="@dimen/key_ic_padding"
|
||||
android:right="@dimen/key_ic_padding"
|
||||
android:bottom="@dimen/key_ic_padding"
|
||||
android:drawable="@drawable/ic_keyboard_capslock"/>
|
||||
</layer-list>
|
8
app/src/main/res/drawable/key_ic_language.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="@dimen/key_ic_padding"
|
||||
android:left="@dimen/key_ic_padding"
|
||||
android:right="@dimen/key_ic_padding"
|
||||
android:bottom="@dimen/key_ic_padding"
|
||||
android:drawable="@drawable/ic_language"/>
|
||||
</layer-list>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/white" />
|
||||
<solid android:color="@android:color/black" />
|
||||
<corners android:radius="@dimen/key_borderRadius" />
|
||||
</shape>
|
||||
|
@ -5,8 +5,7 @@
|
||||
android:layout_height="@dimen/key_popup_height"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/key_popup_bgshape"
|
||||
android:backgroundTint="?attr/key_popup_bgColor"
|
||||
android:backgroundTintMode="multiply">
|
||||
android:backgroundTint="?attr/key_popup_bgColor">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/key_popup_text"
|
||||
|
@ -28,6 +28,10 @@
|
||||
<attr name="customKeyboardStyle" format="reference" />
|
||||
<attr name="customKeyboardRowStyle" format="reference" />
|
||||
|
||||
<attr name="app_colorPrimary" format="color" />
|
||||
<attr name="app_colorPrimaryDark" format="color" />
|
||||
<attr name="app_colorAccent" format="color" />
|
||||
<attr name="app_colorAccentDark" format="color" />
|
||||
<attr name="app_textColor" format="color" />
|
||||
|
||||
<attr name="key_bgColor" format="color" />
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#6200EE</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorAccent">#03DAC5</color>
|
||||
<color name="colorPrimary">#4caf50</color>
|
||||
<color name="colorPrimaryDark">#388e3c</color>
|
||||
<color name="colorAccent">#ff9800</color>
|
||||
<color name="colorAccentDark">#f57c00</color>
|
||||
|
||||
<color name="keyboardBackground_light">#D6D6D6</color>
|
||||
<color name="keyBackground_light">#E6F0F0F0</color>
|
||||
|
@ -6,6 +6,8 @@
|
||||
<dimen name="key_borderRadius">6dp</dimen>
|
||||
<dimen name="key_textSize">18sp</dimen>
|
||||
|
||||
<dimen name="key_ic_padding">7dp</dimen>
|
||||
|
||||
<dimen name="key_popup_width">35dp</dimen>
|
||||
<dimen name="key_popup_height">76dp</dimen>
|
||||
<dimen name="key_popup_textSize">28sp</dimen>
|
||||
|
@ -6,9 +6,11 @@
|
||||
<item name="android:layout_marginEnd">4dp</item>
|
||||
<item name="android:minHeight">0dp</item>
|
||||
<item name="android:minWidth">0dp</item>
|
||||
<item name="android:textAllCaps">false</item>
|
||||
<item name="android:background">@drawable/shape_rect_rounded</item>
|
||||
<item name="android:backgroundTint">?attr/key_bgColor</item>
|
||||
<item name="android:drawableTint">?attr/key_fgColor</item>
|
||||
<item name="android:textAllCaps">false</item>
|
||||
<item name="android:textColor">?attr/key_fgColor</item>
|
||||
<item name="android:textSize">@dimen/key_textSize</item>
|
||||
</style>
|
||||
|
||||
|
@ -7,7 +7,11 @@
|
||||
<item name="customKeyboardRowStyle">@style/CustomKeyboardStyleRow</item>
|
||||
</style>
|
||||
|
||||
<style name="KeyboardTheme.MaterialLight">
|
||||
<style name="KeyboardTheme.MaterialLight">>
|
||||
<item name="app_colorPrimary">@color/colorPrimary</item>
|
||||
<item name="app_colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="app_colorAccent">@color/colorAccent</item>
|
||||
<item name="app_colorAccentDark">@color/colorAccentDark</item>
|
||||
<item name="app_textColor">#000</item>
|
||||
<item name="android:textColor">?attr/app_textColor</item>
|
||||
|
||||
|