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.
Related
Going to make a pretty statistic part for my app and saw a pretty good looking UI (see below). What I'm asking is what's the approach? I have a few ideas, for example drawing multiple ImageButtons (one for every text field) and paint the background the same color as the ImageButtons.
This if i want each of the texts to be clickable, in the example picture for example pressing 18c fires one action and pressing Cambridge another action.
How would you approach this?
What components to use?
Want to do as much as possible in xml, but I'll take suggestions in code too. Whatever is better for you.
EDIT:
Found a good example about how to solve the listView part:
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
I can make control extending Composite or Canvas.
How to make it selectable? I.e. how to make it behave like Button? Button is disabled for extend. I see a lot of unportable code inside it.
So how to make Button-like control of myself?
Should I process mouse and keyboard events myself or there is some premade functionality to utilize?
You will have to handle the events yourself. I'll give you a couple of hints and references here:
First of all, make sure you read this: Creating Your Own Widgets using SWT
Have a look at SquareButton. It's a custom Button widget and should contain all the code you need.
Here is a very related SO question.
Hope this helps.
Canvas is for drawing from "inside". So, you have to create your own UI input. As here.
When specific action is performed, I want to replace button with text field. I know that I have to call button1.setVisible(false); but I don't know how to create text field on the exact same place. I am using NetBeans designer, if you can give me a hint, how to add 2 components at same place, and switch between then, something like switching between layers in photoshop, if something like that is possible, would be great. Thanks
For many components in one space, use a CardLayout as see in this short example.
I'm trying to add a ColorPicker to my app. I see a lot a of ColorPickers (the one frome the API'S Samples, the one from Cyanogen, the AmbilWarna library, the HoloColorPicker, and the ColorPickerPreference). I think that the best for my app is the last one, but I don't need to use it on a preference.
So, what I want is to use this library inside my project when I click a button, and then take the resulting code from the SharedPreferences(I think, I don't know it), and use that color as I want for my app.
I try to use only some of the classes (only ColorPickerDialog, ColorPickerView, ColorPickerPanelView and AlphaPatternDrawable) and then I think that I have to do:
ColorPickerDialog dialog = new ColorPickerDialog(Main.this, Color.BLACK);
dialog.show();
And now I don't know how can I have the selected color.
Also I added to my project the xml view.
Any idea?
To know what is the selected color you need to to:
color=dialog.getfinalColor();
So, I think that the problem was easy to solve it. But now the problem is find a listener to detect when the dialog is closed and then to save the variable "color".
The BlackBerryCanvas documentation says:
This class extends the functionality of the Canvas class to include full touch support and featured text input support.
I have extended BlackBerryCanvas, but am having trouble adding any text input.
It's not that I know what to do but cannot get it work -- I simply do not know how to add a text input box or field.
EDIT: Or have I misunderstood and this is not possible? From reading around, it seems as though it is, but I'm starting to wonder why it's so hard to find anything on it.
EDIT2: I'm think maybe it's something to do with the BlackBerryTextBox?
EDIT3:
Applications using this class can call the #setInputHelper method to get the text input support.
might also be something. It hasn't given me quite enough clues to be able to do it myself though I'm afraid.
Thanks.
If you don't particularly need to use the Canvas hierarchy, I suggest you use the more commonly used Field hierarchy.
That means you should create an application and start with a Screen. An easy concrete implementation of Screen is the FullScreen. To get the text input you are seeking, add an AutoTextEditField to the screen.