Skip to content

Instantly share code, notes, and snippets.

@suzp1984
Last active December 14, 2019 00:04
Show Gist options
  • Save suzp1984/f0b98767d5d2627def10c4ab60e5e636 to your computer and use it in GitHub Desktop.
Save suzp1984/f0b98767d5d2627def10c4ab60e5e636 to your computer and use it in GitHub Desktop.
custom keyboard simulator View that performs like a keyboard.
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