Merge pull request #144 from ismailnurudeen/feat/key_seconday_icon
Feat/added secondary icon to key
This commit is contained in:
commit
e9568d9e86
|
@ -138,6 +138,9 @@ class MyKeyboard {
|
||||||
/** Icon to display instead of a label. Icon takes precedence over a label */
|
/** Icon to display instead of a label. Icon takes precedence over a label */
|
||||||
var icon: Drawable? = null
|
var icon: Drawable? = null
|
||||||
|
|
||||||
|
/** Icon to display top left of an icon.*/
|
||||||
|
var secondaryIcon: Drawable? = null
|
||||||
|
|
||||||
/** Width of the key, not including the gap */
|
/** Width of the key, not including the gap */
|
||||||
var width: Int
|
var width: Int
|
||||||
|
|
||||||
|
@ -204,6 +207,9 @@ class MyKeyboard {
|
||||||
icon = a.getDrawable(R.styleable.MyKeyboard_Key_keyIcon)
|
icon = a.getDrawable(R.styleable.MyKeyboard_Key_keyIcon)
|
||||||
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
|
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
|
||||||
|
|
||||||
|
secondaryIcon = a.getDrawable(R.styleable.MyKeyboard_Key_secondaryKeyIcon)
|
||||||
|
secondaryIcon?.setBounds(0, 0, secondaryIcon!!.intrinsicWidth, secondaryIcon!!.intrinsicHeight)
|
||||||
|
|
||||||
label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
|
label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
|
||||||
topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: ""
|
topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: ""
|
||||||
|
|
||||||
|
@ -230,10 +236,12 @@ class MyKeyboard {
|
||||||
fun isInside(x: Int, y: Int): Boolean {
|
fun isInside(x: Int, y: Int): Boolean {
|
||||||
val leftEdge = edgeFlags and EDGE_LEFT > 0
|
val leftEdge = edgeFlags and EDGE_LEFT > 0
|
||||||
val rightEdge = edgeFlags and EDGE_RIGHT > 0
|
val rightEdge = edgeFlags and EDGE_RIGHT > 0
|
||||||
return ((x >= this.x || leftEdge && x <= this.x + width)
|
return (
|
||||||
&& (x < this.x + width || rightEdge && x >= this.x)
|
(x >= this.x || leftEdge && x <= this.x + width) &&
|
||||||
&& (y >= this.y && y <= this.y + height)
|
(x < this.x + width || rightEdge && x >= this.x) &&
|
||||||
&& (y < this.y + height && y >= this.y))
|
(y >= this.y && y <= this.y + height) &&
|
||||||
|
(y < this.y + height && y >= this.y)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +257,7 @@ class MyKeyboard {
|
||||||
mDefaultHorizontalGap = 0
|
mDefaultHorizontalGap = 0
|
||||||
mDefaultWidth = mDisplayWidth / 10
|
mDefaultWidth = mDisplayWidth / 10
|
||||||
mDefaultHeight = mDefaultWidth
|
mDefaultHeight = mDefaultWidth
|
||||||
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier);
|
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier)
|
||||||
mKeys = ArrayList()
|
mKeys = ArrayList()
|
||||||
mEnterKeyType = enterKeyType
|
mEnterKeyType = enterKeyType
|
||||||
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
|
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
|
||||||
|
@ -273,7 +281,7 @@ class MyKeyboard {
|
||||||
row.defaultHeight = mDefaultHeight
|
row.defaultHeight = mDefaultHeight
|
||||||
row.defaultWidth = keyWidth
|
row.defaultWidth = keyWidth
|
||||||
row.defaultHorizontalGap = mDefaultHorizontalGap
|
row.defaultHorizontalGap = mDefaultHorizontalGap
|
||||||
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier);
|
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier)
|
||||||
|
|
||||||
characters.forEachIndexed { index, character ->
|
characters.forEachIndexed { index, character ->
|
||||||
val key = Key(row)
|
val key = Key(row)
|
||||||
|
@ -386,7 +394,7 @@ class MyKeyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getKeyboardHeightMultiplier(multiplierType: Int): Float {
|
private fun getKeyboardHeightMultiplier(multiplierType: Int): Float {
|
||||||
return when(multiplierType) {
|
return when (multiplierType) {
|
||||||
KEYBOARD_HEIGHT_MULTIPLIER_SMALL -> 1.0F
|
KEYBOARD_HEIGHT_MULTIPLIER_SMALL -> 1.0F
|
||||||
KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM -> 1.2F
|
KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM -> 1.2F
|
||||||
KEYBOARD_HEIGHT_MULTIPLIER_LARGE -> 1.4F
|
KEYBOARD_HEIGHT_MULTIPLIER_LARGE -> 1.4F
|
||||||
|
|
|
@ -609,16 +609,53 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
|
|
||||||
if (code == KEYCODE_ENTER) {
|
if (code == KEYCODE_ENTER) {
|
||||||
key.icon!!.applyColorFilter(mPrimaryColor.getContrastColor())
|
key.icon!!.applyColorFilter(mPrimaryColor.getContrastColor())
|
||||||
|
key.secondaryIcon?.applyColorFilter(mPrimaryColor.getContrastColor())
|
||||||
} else if (code == KEYCODE_DELETE || code == KEYCODE_SHIFT || code == KEYCODE_EMOJI) {
|
} else if (code == KEYCODE_DELETE || code == KEYCODE_SHIFT || code == KEYCODE_EMOJI) {
|
||||||
key.icon!!.applyColorFilter(mTextColor)
|
key.icon!!.applyColorFilter(mTextColor)
|
||||||
|
key.secondaryIcon?.applyColorFilter(mTextColor)
|
||||||
}
|
}
|
||||||
|
val keyIcon = key.icon!!
|
||||||
|
val secondaryIcon = key.secondaryIcon
|
||||||
|
|
||||||
val drawableX = (key.width - key.icon!!.intrinsicWidth) / 2
|
if (secondaryIcon != null) {
|
||||||
val drawableY = (key.height - key.icon!!.intrinsicHeight) / 2
|
val keyIconWidth = (keyIcon.intrinsicWidth * 0.9f).toInt()
|
||||||
canvas.translate(drawableX.toFloat(), drawableY.toFloat())
|
val keyIconHeight = (keyIcon.intrinsicHeight * 0.9f).toInt()
|
||||||
key.icon!!.setBounds(0, 0, key.icon!!.intrinsicWidth, key.icon!!.intrinsicHeight)
|
val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6f).toInt()
|
||||||
key.icon!!.draw(canvas)
|
val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6f).toInt()
|
||||||
canvas.translate(-drawableX.toFloat(), -drawableY.toFloat())
|
|
||||||
|
val centerX = key.width / 2
|
||||||
|
val centerY = key.height / 2
|
||||||
|
|
||||||
|
val keyIconLeft = centerX - keyIconWidth / 2
|
||||||
|
val keyIconTop = centerY - keyIconHeight / 2
|
||||||
|
|
||||||
|
keyIcon.setBounds(keyIconLeft, keyIconTop, keyIconLeft + keyIconWidth, keyIconTop + keyIconHeight)
|
||||||
|
keyIcon.draw(canvas)
|
||||||
|
|
||||||
|
val secondaryIconPaddingRight = 10
|
||||||
|
val secondaryIconLeft = key.width - secondaryIconPaddingRight - secondaryIconWidth
|
||||||
|
val secondaryIconRight = secondaryIconLeft + secondaryIconWidth
|
||||||
|
|
||||||
|
val secondaryIconTop = 14 // This will act as a topPadding
|
||||||
|
val secondaryIconBottom = secondaryIconTop + secondaryIconHeight
|
||||||
|
|
||||||
|
secondaryIcon.setBounds(
|
||||||
|
secondaryIconLeft,
|
||||||
|
secondaryIconTop,
|
||||||
|
secondaryIconRight,
|
||||||
|
secondaryIconBottom
|
||||||
|
)
|
||||||
|
secondaryIcon.draw(canvas)
|
||||||
|
|
||||||
|
secondaryIcon.draw(canvas)
|
||||||
|
} else {
|
||||||
|
val drawableX = (key.width - keyIcon.intrinsicWidth) / 2
|
||||||
|
val drawableY = (key.height - keyIcon.intrinsicHeight) / 2
|
||||||
|
canvas.translate(drawableX.toFloat(), drawableY.toFloat())
|
||||||
|
keyIcon.setBounds(0, 0, keyIcon.intrinsicWidth, keyIcon.intrinsicHeight)
|
||||||
|
keyIcon.draw(canvas)
|
||||||
|
canvas.translate(-drawableX.toFloat(), -drawableY.toFloat())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
canvas.translate(-key.x.toFloat(), -key.y.toFloat())
|
canvas.translate(-key.x.toFloat(), -key.y.toFloat())
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<vector android:height="24dp" android:tint="#ffffff"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="@android:color/white" 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,2s0.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,-2s0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2s-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,-2s-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>
|
|
@ -33,6 +33,8 @@
|
||||||
<attr name="keyLabel" format="string" />
|
<attr name="keyLabel" format="string" />
|
||||||
<!-- The icon to display on the key instead of the label. -->
|
<!-- The icon to display on the key instead of the label. -->
|
||||||
<attr name="keyIcon" format="reference" />
|
<attr name="keyIcon" format="reference" />
|
||||||
|
<!-- The icon to display on the top left of a key with icon. -->
|
||||||
|
<attr name="secondaryKeyIcon" format="reference" />
|
||||||
<!-- Top small number shown above letters of the first row. -->
|
<!-- Top small number shown above letters of the first row. -->
|
||||||
<attr name="topSmallNumber" format="string" />
|
<attr name="topSmallNumber" format="string" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
|
@ -162,6 +162,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -123,6 +123,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -126,6 +126,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -137,6 +137,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -159,6 +159,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -112,6 +112,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -123,6 +123,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
|
@ -133,6 +133,7 @@
|
||||||
app:code="-6"
|
app:code="-6"
|
||||||
app:keyEdgeFlags="left"
|
app:keyEdgeFlags="left"
|
||||||
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
app:keyIcon="@drawable/ic_emoji_emotions_outline_vector"
|
||||||
|
app:secondaryKeyIcon="@drawable/ic_language_outlined"
|
||||||
app:keyWidth="10%p" />
|
app:keyWidth="10%p" />
|
||||||
<Key
|
<Key
|
||||||
app:code="32"
|
app:code="32"
|
||||||
|
|
Loading…
Reference in New Issue