Skip to content

Commit 5363970

Browse files
feat: implemented logic to hide and show number keys row.
1 parent 14e94ea commit 5363970

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class MyKeyboard {
9797

9898
var parent: MyKeyboard
9999

100+
var isNumRow: Boolean = false
101+
100102
constructor(parent: MyKeyboard) {
101103
this.parent = parent
102104
}
@@ -107,6 +109,7 @@ class MyKeyboard {
107109
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
108110
defaultHeight = (res.getDimension(R.dimen.key_height) * this.parent.mKeyboardHeightMultiplier).roundToInt()
109111
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
112+
isNumRow = a.getBoolean(R.styleable.MyKeyboard_isNumRow, false)
110113
a.recycle()
111114
}
112115
}
@@ -342,12 +345,19 @@ class MyKeyboard {
342345
if (event == XmlResourceParser.START_TAG) {
343346
when (parser.name) {
344347
TAG_ROW -> {
348+
currentRow = createRowFromXml(res, parser)
349+
if (currentRow.isNumRow && !context.config.showNumbersRow) {
350+
continue
351+
}
345352
inRow = true
346353
x = 0
347-
currentRow = createRowFromXml(res, parser)
348354
mRows.add(currentRow)
349355
}
356+
350357
TAG_KEY -> {
358+
if (currentRow?.isNumRow == true && !context.config.showNumbersRow) {
359+
continue
360+
}
351361
inKey = true
352362
key = createKeyFromXml(res, currentRow!!, x, y, parser)
353363
mKeys!!.add(key)
@@ -362,6 +372,7 @@ class MyKeyboard {
362372
}
363373
currentRow.mKeys.add(key)
364374
}
375+
365376
TAG_KEYBOARD -> {
366377
parseKeyboardAttributes(res, parser)
367378
}

app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
263263
val repeat = Message.obtain(this, MSG_REPEAT)
264264
sendMessageDelayed(repeat, REPEAT_INTERVAL.toLong())
265265
}
266+
266267
MSG_LONGPRESS -> openPopupIfRequired(msg.obj as MotionEvent)
267268
}
268269
}
@@ -591,7 +592,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
591592
label, (key.width / 2).toFloat(), key.height / 2 + (paint.textSize - paint.descent()) / 2, paint
592593
)
593594

594-
if (key.topSmallNumber.isNotEmpty()) {
595+
if (key.topSmallNumber.isNotEmpty() && !context.config.showNumbersRow) {
595596
canvas.drawText(key.topSmallNumber, key.width - mTopSmallNumberMarginWidth, mTopSmallNumberMarginHeight, smallLetterPaint)
596597
}
597598

@@ -1204,6 +1205,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
12041205
}
12051206
}
12061207
}
1208+
12071209
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
12081210
mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply {
12091211
mOnKeyboardActionListener!!.onKey(code)
@@ -1262,6 +1264,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
12621264
invalidateKey(mCurrentKey)
12631265
return true
12641266
}
1267+
12651268
MotionEvent.ACTION_DOWN -> {
12661269
mAbortKey = false
12671270
mLastCodeX = touchX
@@ -1310,6 +1313,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
13101313
showPreview(keyIndex)
13111314
}
13121315
}
1316+
13131317
MotionEvent.ACTION_MOVE -> {
13141318
var continueLongPress = false
13151319
if (keyIndex != NOT_A_KEY) {
@@ -1363,6 +1367,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
13631367
mLastMoveTime = eventTime
13641368
}
13651369
}
1370+
13661371
MotionEvent.ACTION_UP -> {
13671372
mLastSpaceMoveX = 0
13681373
removeMessages()
@@ -1396,6 +1401,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
13961401
mOnKeyboardActionListener!!.onActionUp()
13971402
mIsLongPressingSpace = false
13981403
}
1404+
13991405
MotionEvent.ACTION_CANCEL -> {
14001406
mIsLongPressingSpace = false
14011407
mLastSpaceMoveX = 0
@@ -1515,12 +1521,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
15151521
mHandler!!.sendMessageDelayed(msg, REPEAT_START_DELAY.toLong())
15161522
true
15171523
}
1524+
15181525
MotionEvent.ACTION_UP -> {
15191526
mHandler!!.removeMessages(MSG_REPEAT)
15201527
mRepeatKeyIndex = NOT_A_KEY
15211528
isPressed = false
15221529
false
15231530
}
1531+
15241532
else -> false
15251533
}
15261534
}

0 commit comments

Comments
 (0)