2

I'm making a custom view that can be annotated with typical paint tools like draw, shape dropping, or writing text, and I'm stuck on how to enable text input without resorting to creating new views on touch. I'd like to be able to handle all of the annotation in this one custom view class.

My idea is to extend EditText, since it seems to have all of the functionality I need for creating editable text onscreen. Currently, I override onTouchEvent(MotionEvent event) to annotate whatever drawable has been loaded into my custom EditText called AnnotationView. I can call super.onTouchEvent(event) when the text tool is selected, and the soft keyboard displays. Entered text is displayed on screen, and I can edit it. However, at the moment I can only enter text in one place, seeing as how this currently is just an EditText with added drawing capabilities. Any other overridden methods (onSizeChanged, onDraw, performClick) start with a call to their super implementation.

Has anyone here attempted something like this before? I need to allow the user to start editing text at their touch coordinates, but I have no idea what methods I'd need to override or create to do that. It seems like this would be a good way to avoid requiring more views be created from the Activity using AnnotationView, but I'm not sure how feasible this approach really is.

Issue can be seen here: Image of AnnotationView being used in a sample app


To explain why I'm trying to avoid creating new views to write text in - I'd like to release this as a library, so I'm trying to require the least amount of hassle for someone using this view. Ideally, a developer could just place this view and then choose whatever tools I've implemented via their own UI. If I need to create views on top of this, I'll need to require users to roll their own text editing implementation via some kind of listener... maybe? If I'm missing a simpler way of doing this, please let me know! I've seen similar questions asked here, but it seems like a definitive good practice for capturing user input and displaying it on canvas would be useful for a lot of beginners such as myself.

neekolawz
  • 99
  • 8
  • You better be drawing on Canvas, you will have to look how to listen for SoftKeyboard input, this will also make it easy to you to drag text on screen and other things – Marcos Vasconcelos Aug 15 '18 at 20:13
  • @Marcos Vasconcelos - Yes, this is all drawn on a canvas. Know any good resources on how to listen for input for a canvas? I went with having AnnotationView extend EditText because I'd love to have all of the built-in functionality that EditTexts have without needing to roll my own text input system. – neekolawz Aug 15 '18 at 20:20
  • Just search "How to bind SoftInputMethod android", the touch coordinates you have then just draw uppon it the listened text – Marcos Vasconcelos Aug 15 '18 at 20:22
  • @MarcosVasconcelos - Maybe I'm searching for this incorrectly, but I'm struggling to find any straight forward help on how to do this. Would it be possible for you to go into more detail? – neekolawz Aug 15 '18 at 22:52
  • https://stackoverflow.com/questions/10616567/how-to-listen-the-keypress-in-the-soft-keyboard – Marcos Vasconcelos Aug 15 '18 at 23:10

0 Answers0