feat: implemented logic to hide and show number keys row.

This commit is contained in:
ismailnurudeen 2023-04-18 16:15:25 +01:00
parent 14e94ea8cd
commit 5363970799
2 changed files with 21 additions and 2 deletions

View File

@ -97,6 +97,8 @@ class MyKeyboard {
var parent: MyKeyboard var parent: MyKeyboard
var isNumRow: Boolean = false
constructor(parent: MyKeyboard) { constructor(parent: MyKeyboard) {
this.parent = parent this.parent = parent
} }
@ -107,6 +109,7 @@ class MyKeyboard {
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth) defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
defaultHeight = (res.getDimension(R.dimen.key_height) * this.parent.mKeyboardHeightMultiplier).roundToInt() defaultHeight = (res.getDimension(R.dimen.key_height) * this.parent.mKeyboardHeightMultiplier).roundToInt()
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap) defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
isNumRow = a.getBoolean(R.styleable.MyKeyboard_isNumRow, false)
a.recycle() a.recycle()
} }
} }
@ -342,12 +345,19 @@ class MyKeyboard {
if (event == XmlResourceParser.START_TAG) { if (event == XmlResourceParser.START_TAG) {
when (parser.name) { when (parser.name) {
TAG_ROW -> { TAG_ROW -> {
currentRow = createRowFromXml(res, parser)
if (currentRow.isNumRow && !context.config.showNumbersRow) {
continue
}
inRow = true inRow = true
x = 0 x = 0
currentRow = createRowFromXml(res, parser)
mRows.add(currentRow) mRows.add(currentRow)
} }
TAG_KEY -> { TAG_KEY -> {
if (currentRow?.isNumRow == true && !context.config.showNumbersRow) {
continue
}
inKey = true inKey = true
key = createKeyFromXml(res, currentRow!!, x, y, parser) key = createKeyFromXml(res, currentRow!!, x, y, parser)
mKeys!!.add(key) mKeys!!.add(key)
@ -362,6 +372,7 @@ class MyKeyboard {
} }
currentRow.mKeys.add(key) currentRow.mKeys.add(key)
} }
TAG_KEYBOARD -> { TAG_KEYBOARD -> {
parseKeyboardAttributes(res, parser) parseKeyboardAttributes(res, parser)
} }

View File

@ -263,6 +263,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val repeat = Message.obtain(this, MSG_REPEAT) val repeat = Message.obtain(this, MSG_REPEAT)
sendMessageDelayed(repeat, REPEAT_INTERVAL.toLong()) sendMessageDelayed(repeat, REPEAT_INTERVAL.toLong())
} }
MSG_LONGPRESS -> openPopupIfRequired(msg.obj as MotionEvent) 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 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) 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 -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply { mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply {
mOnKeyboardActionListener!!.onKey(code) mOnKeyboardActionListener!!.onKey(code)
@ -1262,6 +1264,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
invalidateKey(mCurrentKey) invalidateKey(mCurrentKey)
return true return true
} }
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
mAbortKey = false mAbortKey = false
mLastCodeX = touchX mLastCodeX = touchX
@ -1310,6 +1313,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
showPreview(keyIndex) showPreview(keyIndex)
} }
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
var continueLongPress = false var continueLongPress = false
if (keyIndex != NOT_A_KEY) { if (keyIndex != NOT_A_KEY) {
@ -1363,6 +1367,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mLastMoveTime = eventTime mLastMoveTime = eventTime
} }
} }
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {
mLastSpaceMoveX = 0 mLastSpaceMoveX = 0
removeMessages() removeMessages()
@ -1396,6 +1401,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mOnKeyboardActionListener!!.onActionUp() mOnKeyboardActionListener!!.onActionUp()
mIsLongPressingSpace = false mIsLongPressingSpace = false
} }
MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_CANCEL -> {
mIsLongPressingSpace = false mIsLongPressingSpace = false
mLastSpaceMoveX = 0 mLastSpaceMoveX = 0
@ -1515,12 +1521,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mHandler!!.sendMessageDelayed(msg, REPEAT_START_DELAY.toLong()) mHandler!!.sendMessageDelayed(msg, REPEAT_START_DELAY.toLong())
true true
} }
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {
mHandler!!.removeMessages(MSG_REPEAT) mHandler!!.removeMessages(MSG_REPEAT)
mRepeatKeyIndex = NOT_A_KEY mRepeatKeyIndex = NOT_A_KEY
isPressed = false isPressed = false
false false
} }
else -> false else -> false
} }
} }