I'm making a custom view that can be annotated with typical paint tools like draw, shape dropping, or writing text. I've implemented all of the tools that would fall under the "Drawing" category, but text entry is giving me a lot of trouble. I would very much prefer to avoid creating EditTexts on top of this view as an approach. There seem to be a lot of conflicting answers to questions about this topic out there.
What I want to do:
- Tap anywhere in the custom view and open keyboard / indicate that text can be entered
- Get keyboard input - preferably any kind of keyboard. How to listen to keypress in the soft keyboard seems to have some contention about what works for hard or soft keyboards.
- Take the keyboard input, and draw it on my canvas after the user enters any character.
- Allow the user to edit that text
- Allow the user to move the text
I've tried overriding onKeyUp() and intercepting each keypress. The android docs suggest that editable text should be entered using DynamicLayout, so I've been attempting to use dynamicLayout.draw(canvas). I can open the soft keyboard, but even after setting my view to focusable and requesting focus, the onKeyUp() does not fire. I've seen several answers to questions that warn against using anything but an EditText for text entry due to complexity and issues with custom keyboards. Surely someone knows how to do this?
What would be a huge help to me, is a basic overview of what goes into displaying user entered text on a canvas as it is entered. A high level step by step of what to do would be fine. Even just details on where to look to figure out the first three steps above would be greatly appreciated.