feat: implemented logic to hide and show number keys row.
This commit is contained in:
parent
14e94ea8cd
commit
5363970799
2 changed files with 21 additions and 2 deletions
|
@ -97,6 +97,8 @@ class MyKeyboard {
|
|||
|
||||
var parent: MyKeyboard
|
||||
|
||||
var isNumRow: Boolean = false
|
||||
|
||||
constructor(parent: MyKeyboard) {
|
||||
this.parent = parent
|
||||
}
|
||||
|
@ -107,6 +109,7 @@ class MyKeyboard {
|
|||
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
|
||||
defaultHeight = (res.getDimension(R.dimen.key_height) * this.parent.mKeyboardHeightMultiplier).roundToInt()
|
||||
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
|
||||
isNumRow = a.getBoolean(R.styleable.MyKeyboard_isNumRow, false)
|
||||
a.recycle()
|
||||
}
|
||||
}
|
||||
|
@ -342,12 +345,19 @@ class MyKeyboard {
|
|||
if (event == XmlResourceParser.START_TAG) {
|
||||
when (parser.name) {
|
||||
TAG_ROW -> {
|
||||
currentRow = createRowFromXml(res, parser)
|
||||
if (currentRow.isNumRow && !context.config.showNumbersRow) {
|
||||
continue
|
||||
}
|
||||
inRow = true
|
||||
x = 0
|
||||
currentRow = createRowFromXml(res, parser)
|
||||
mRows.add(currentRow)
|
||||
}
|
||||
|
||||
TAG_KEY -> {
|
||||
if (currentRow?.isNumRow == true && !context.config.showNumbersRow) {
|
||||
continue
|
||||
}
|
||||
inKey = true
|
||||
key = createKeyFromXml(res, currentRow!!, x, y, parser)
|
||||
mKeys!!.add(key)
|
||||
|
@ -362,6 +372,7 @@ class MyKeyboard {
|
|||
}
|
||||
currentRow.mKeys.add(key)
|
||||
}
|
||||
|
||||
TAG_KEYBOARD -> {
|
||||
parseKeyboardAttributes(res, parser)
|
||||
}
|
||||
|
|
|
@ -263,6 +263,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
val repeat = Message.obtain(this, MSG_REPEAT)
|
||||
sendMessageDelayed(repeat, REPEAT_INTERVAL.toLong())
|
||||
}
|
||||
|
||||
MSG_LONGPRESS -> openPopupIfRequired(msg.obj as MotionEvent)
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +592,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
label, (key.width / 2).toFloat(), key.height / 2 + (paint.textSize - paint.descent()) / 2, paint
|
||||
)
|
||||
|
||||
if (key.topSmallNumber.isNotEmpty()) {
|
||||
if (key.topSmallNumber.isNotEmpty() && !context.config.showNumbersRow) {
|
||||
canvas.drawText(key.topSmallNumber, key.width - mTopSmallNumberMarginWidth, mTopSmallNumberMarginHeight, smallLetterPaint)
|
||||
}
|
||||
|
||||
|
@ -1204,6 +1205,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply {
|
||||
mOnKeyboardActionListener!!.onKey(code)
|
||||
|
@ -1262,6 +1264,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
invalidateKey(mCurrentKey)
|
||||
return true
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
mAbortKey = false
|
||||
mLastCodeX = touchX
|
||||
|
@ -1310,6 +1313,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
showPreview(keyIndex)
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
var continueLongPress = false
|
||||
if (keyIndex != NOT_A_KEY) {
|
||||
|
@ -1363,6 +1367,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
mLastMoveTime = eventTime
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP -> {
|
||||
mLastSpaceMoveX = 0
|
||||
removeMessages()
|
||||
|
@ -1396,6 +1401,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
mOnKeyboardActionListener!!.onActionUp()
|
||||
mIsLongPressingSpace = false
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_CANCEL -> {
|
||||
mIsLongPressingSpace = false
|
||||
mLastSpaceMoveX = 0
|
||||
|
@ -1515,12 +1521,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
mHandler!!.sendMessageDelayed(msg, REPEAT_START_DELAY.toLong())
|
||||
true
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP -> {
|
||||
mHandler!!.removeMessages(MSG_REPEAT)
|
||||
mRepeatKeyIndex = NOT_A_KEY
|
||||
isPressed = false
|
||||
false
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue