Autocomplete edit field for blackberry jde 4.6 - blackberry

How do I create an auto-complete edit field for blackberry that works on the 4.6 jde?
I know it has to do with a fieldchangelistener and painting a floating rect on the screen, but I haven't succeeded so far.

Sorry for saying such a demotivating thing, however I would even not try to do that. You should realize that simply painting a "floating rect on the screen" is not enough - that "floating rect" shoud be a focusable field that appears over another fields on the screen, however this is impossible with 4.6 APIs.

Say you want to make autocomplete field for Contacts.
Make an object which stores all contact info
Make a CustomAutoCompleteFld class with extends Field.
When this field is clicked its fieldchanged() will get invoked.
Now display a popupScreen with custom width n ht wrt to the records to be shown. This popupScreen is your 'Floating rect'.
The records to be added should themselves be for eg: clickable LabelFields
The records to be displayed depend on your 'Search algo' performed on the obj storing your Contacts info. U'll have to implement your own Search algo.
Now on clicking the record i.e., the labelfld, invoke the fieldChanged of the LabelFld and do further processing

Related

Using barcode scanner with Delphi

I'm developing a POS (pet project) and I'm thinking of adding a bar code scanner to capture the sales faster. I do not have a scanner at the moment with me, and would like to ask some questions, as I'm stuck a bit.
On the sales screen my initial idea was to have an TEdit component and when a person scans the product it would fill the TEdit with the string. Now the problem I'm encountering is that I want to make the TEdit invisible so that the person does not see it. But once you make the TEdit invisible, you cannot set focus on it, so that plan cannot work.
So can anyone suggest what I can use to "capture" the scanned string? How would I make the component to listen and wait for the scanner? I assume that the scanner would be like a normal keyboard event, like button down or up.
There's KeyPreview property on TForm. Set it to true, so all key presses are processed by form first before controls.
Article about keyboard processing in Delphi: http://delphi.about.com/od/objectpascalide/a/keyboard_events.htm
Related SO question: How does Delphi's KeyPreview work?
What I have done is use the KeyPreview to monitor for a function key like F9 which the bar code scanner is set to prefix scans with. When this is received, I pop up a dialog with a single edit box and OK button. This then receives the rest of the barcode information, and the scanner ends the entry with the Enter key. I can then determine the purpose of the scanned data (in my case, one type starts with a prefix) and then put the data into the appropriate field on my main form.
I chose F9 because it seems inert in most applications, so you can use the scanner in other ways, but I support other keys too for flexibility. My application also has a scanner test mode where it shows the keys sent.
You can use a TEdit with a height and width of 0 so it won't appears and make sure it get focused when you scan your barcode.
You can also place the TEdit outside of the visible window, setting the component's Top and Left properties to something like -50. You can then set focus to it just like a regular visible TEdit box, but it will be invisible to the user.

What is the equivalent of Android Toast in RIM?

In android, there is a function call Toast and it show instantly without involve in time. I tried to use Status in RIM but it must run in the invokeLater and cannot set the time less than 1 second. So it cannot display instantly.
Any other built in that same with Toast or Status?
No there is not afaik. Toast was "invented" in a way by Android.
Previous OS's have used popup boxes with confirmation buttons. A Toast is almost like a popup box with a timer attached to it.
Of course, #Signare gives the common replacement correctly for what you would "normally" do on BlackBerry. Dialog.alert(String)
If you want something more "Androidy", this is something we want to implement at Cobi, but have not gotten around to yet due to time constraints working on client work.
There are 2 unique aspects to a Toast compared to the "old" way of doing things:
the popup only shows for a short time
the popup does not block the user from interacting with the background screen at all
To create the popup screen, look at the PopupScreen class - and you pass in a layout manager of your own that will be displayed.
You could start a timer when the screen is shown (we have not implemented this yet) and that could close the screen for you.
As far as not blocking the user - this is the major difference - and I do not know if it can be done if you use the PopupScreen class. Perhaps if your PopupScreen passes all keypresses through to the underlying screen, this may be possible.
In some of our apps, we have a custom field, defined in our base MainScreen subclass, that can be positioned over the rest of the fields on the screen. This allows the user to continue interacting with the screen while the field is displayed. I cannot share that code at the moment here.

Blackberry input field that mimics the input field of Android

I'm trying to make a login screen for Blackberry with input fields for username and password that look like the the editText field of android. Basically, there should be a well defined background and default prompt text in a different color when no text has been input. Unfortunately, I couldn't find a default field provided by blackberry. I'm currently using an EditField and a PasswordEditField with BorderFactory to provide the demarcation. Is anyone aware of such libraries or some other open source efforts by someone to do so? Please point me to any tutorial, etc too.
Thanks!
You will need to write your own custom field which extends EditField.
http://docs.blackberry.com/en/developers/deliverables/11958/Create_a_custom_field_508117_11.jsp
My suggestions are:
Override the Field.paint() method to place the label inside the text box (rather than to the left of it which is the default behaviour). This is where your instruction to the user can go, ie the 'Username' or 'Password' text.
Override the Field.onFocus() method to remove the instruction from the text box. Conversely override the Field.onUnfocus() method to add it back in if the user moves to another text box without entering any text.

Blackberry Event Handling and Focus Issues

I am having an issue with a small blackberry application where touch events are being processed by 1 of 2 certain fields that has focus.
In my case, I have 2 images, one at the top (first element on the screen) and at the bottom (last element added to the screen. Both are subclasses of the BitmapField. Their purpose is to display a web site when the user taps (clicks with the trackpad/ball).
The issue is when either of these has focus, no matter where the user taps on the screen (i.e. in an EditField, another custom button, or just a part of the background), the BitmapField that has focus consumes the event calls the web browser. This obviously only an issue on the BB Torch simulator, and I building for BB OS 5.0.
I have the BitmapField consuming both navigation clicks and touch events.
Also, any direction on where to get a good (as in not written by RIM) event handling guide for the Blackberry API would be helpful.
UPDATE:
I have tried:
public boolean isFocusable() {
return false;
}
But, ideally I would like this to work on devices such as the Curve and Bold.
UPDATE 2:
There a couple of LabelFields inside layout managers that can receive focus, but they do not cause this issue, it only happens when the BitmapFields have focus.
I'd suggest to create a custom image button field by subclassing from Field. Override paint(Graphics graphics) to draw image and focused border (or background). Then just override navigationClick(int status, int time). The BB UI framework will call that method when user clicks your field on a touch screen. As well it'll work for a non-touch screen devices. As a great benefit - you will not need to bother yourself with TouchEvents at all.
Make sure that on the touchEvent() you are checking the location of the touch. If it is outside of your BitmapField's extent, you should be returning super.touchEvent(message). Regardless of where the touch is, when a field has focus it is sent to it first to determine if it should be handling it at all.

How can I show the numeric virtual keyboard on the Blackberry Storm?

I'm having some difficulty showing the virtual keyboard I want for the Blackberry Storm. I have an option to toggle the keyboard's visibility on a certain screen. Whenever the user types a number, it's handled by the screen, rather than any particular field (there are no textfields on this screen). This much works fine. I can show and hide the keyboard when the user chooses to.
My question is this: How do I make the keyboard that shows up the same as what would appear had the focus been on a BasicEditField with a numeric filter applied, without using a BasicEditField for the input?
I don't think BlackBerry has exposed any APIs to allow for programmatic control over the type of virtual keyboard that is shown. I seem to remember reading about it in the BB forums (although unfortunately I can't find it now).
One thing you could try doing is using a BasicEditField with a numeric field, but place it offscreen so that it isn't visible. When you want to capture numeric input from the user, put focus on that element. I haven't tried this, it's just a thought.

Resources