Last active
December 14, 2019 00:04
-
-
Save suzp1984/f0b98767d5d2627def10c4ab60e5e636 to your computer and use it in GitHub Desktop.
custom keyboard simulator View that performs like a keyboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomKeyboardView @JvmOverloads constructor(context: Context, | |
attrs: AttributeSet? = null, | |
defStyle: Int = 0, | |
defStyleRes: Int = 0) : | |
ViewGroup(context, attrs, defStyle, defStyleRes) { | |
var inputConnection: InputConnection? = null | |
private val childViews: Array<View> | |
private val viewClickListener = View.OnClickListener { | |
inputConnection?.commitText('a', 1) | |
// inputConnection?.deleteSurroundingText(1, 0) | |
// inputConnection?.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)) | |
// inputConnection?.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)) | |
// inputConnection?.performEditorAction(EditorInfo.IME_ACTION_DONE) | |
} | |
init { | |
// init child views | |
addView(childView) | |
// listen for child view click/touch events | |
childView.setOnClickListener(viewClickListener) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment