copying some Dialpad related things from Contacts to this app

This commit is contained in:
tibbi
2020-05-09 22:46:52 +02:00
parent 3a564542fc
commit e5f0d3c6f1
23 changed files with 951 additions and 42 deletions

View File

@ -0,0 +1,26 @@
package com.simplemobiletools.dialer.extensions
import android.view.KeyEvent
import android.widget.EditText
fun EditText.addCharacter(char: Char) {
dispatchKeyEvent(getKeyEvent(getCharKeyCode(char)))
}
fun EditText.getKeyEvent(keyCode: Int) = KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0)
private fun getCharKeyCode(char: Char) = when (char) {
'0' -> KeyEvent.KEYCODE_0
'1' -> KeyEvent.KEYCODE_1
'2' -> KeyEvent.KEYCODE_2
'3' -> KeyEvent.KEYCODE_3
'4' -> KeyEvent.KEYCODE_4
'5' -> KeyEvent.KEYCODE_5
'6' -> KeyEvent.KEYCODE_6
'7' -> KeyEvent.KEYCODE_7
'8' -> KeyEvent.KEYCODE_8
'9' -> KeyEvent.KEYCODE_9
'*' -> KeyEvent.KEYCODE_STAR
'+' -> KeyEvent.KEYCODE_PLUS
else -> KeyEvent.KEYCODE_POUND
}