|
Tuesday March 07, 2006 |
|
Simple example of WaitScreen component
|
TIP
|
There is WaitScreen component ( ) in the Palette of the Mobility Pack when you are working in a Visual Midlet. This component is available only for MIDP2.0 and Visual Midlet in MIDP 2.0. It is designed for run of longer tasks that can block UI in background. The task will run and you will see the WaitScreen with a text or image. When the task finishs then it continues on next screen. There is SimpleCancellableTask non-visual component for definition of the task for the WaitScreen. You can find the SimpleCancellableTask in Resources in Palette. Drag and drop it into your Visual Design MIDlet.
Open Properties of the new SimpleCancellableTask and you can define Executable Method Body. The Executable Method Body is the code that will run on the background when the WaitScreen appears on the screen of the device. Note that the WaitScreen can end either with Failure or with Success. When the SimpleCancellableTask ends without an exception then it will continue to the Success screen otherwise it will go to the Failure screen.
I created a simple example that connect to internet and shows a price of a stock. I reused some codes from QuotesMIDlet.java
The main problem that found when I was creating the example was that the simpleShockPriceTextBox component is created and used in setNextDisplayable method of the WaitScreen before the data are downloaded from network. I had to add call of setString(...) of the showShockPriceTextBox at the end of the Executable Method Body of the SimpleCancellableTask. It updated the value correctly. I tried a different approach before. I set showShockPriceTextBox=null and hoped that it will re-create the component again with the right values but it didn't worked in that way
UPDATE:
|
|
( Mar 07 2006, 07:51:50 PM CET )
Permalink
|
|
Trackback URL: http://blogs.sun.com/lukas/entry/simple_example_of_waitscreen_component
|
Posted by Daniel on November 28, 2006 at 04:20 PM CET #
I'm open to write about any other issues? Any idea what would interest you ? (of course, something what is not described somewhere else).
Posted by Lukas on November 28, 2006 at 09:46 PM CET #
Posted by Pablo A Castillo on December 29, 2006 at 04:04 PM CET #
I can write more tips - the question is "about what", what are you interested in? Ideas are welcome..
Posted by Lukas on December 29, 2006 at 05:21 PM CET #
It would not be a big deal, as one could easily implemente MyCancellableTask with cancel() trivially implemented by setting a flag (stopped) to true.
However, given the way the autogenerated code works in NB Mobile pack, this is not easily achieved and leaves quite a lot of hand-coding to do.
I also noticed that in your sample code you are using now deprecated methods, so maybe worth updating it ;-)
Am I missing something here?
Comments warmly welcome!
Posted by Marco Massenzio on March 19, 2007 at 07:33 PM CET #
You can implement it in you way.
About the updating of the source code. You are right. They changed the approach. (see http://blogs.sun.com/roller/page/lukas?entry=change_in_waitscreen_component)
I'll update thi post a little bit.
Posted by Lukas on March 20, 2007 at 10:41 AM CET #
thanks man!
Posted by Eko on January 16, 2008 at 02:11 AM CET #
Lukas
In a waitscreen how can i control which point (success or failure) the program may take depending the return value of the called task...
Posted by max simon on July 13, 2008 at 06:57 PM CEST #
The SUCCESS is when your code doesn't end with exception. If an exception is thrown then it continue the FAILURE path. Therefore you have to either change your method to throw exception when it should fail or you have to check the value in the waitscreen execute body and then throw the exception to let the waitscreen know that the method failed
Posted by Lukas on July 17, 2008 at 11:51 AM CEST #
thanks lukas
I'm going to do some test
Posted by Max Simon on July 17, 2008 at 03:32 PM CEST #
Hi Lukas,
I was recently looking at the tutorial project on http://www.netbeans.org/kb/60/mobility/filebrowser.html .
I wanted to add a WaitScreen to the project for
loading a file so that when a *.txt file is selected
{ie. inputFile.getName().endsWith("txt")}
the txt file contents are displayed in a textbox as per the the supplied readfile() method. However, if a non-txt file is selected an Alert should pop-up indicating that the wrong file type was selected, and the filebrowser should be displayed once again.
I got as far as adding a Waitscreen and a "Wrong file type" Alert. Could you suggest how I can invoke the FAILURE_COMMAND in the WaitScreen so that the "Wrong file type" Alert can get display. Any additional suggestion to accomplish this file type checking would be welcomed.
Thanks, Daniel
Posted by Daniel H on July 24, 2008 at 06:14 PM CEST #
@Daniel H: what about:
public void execute() throws Exception {
// write task-execution user code here
if(getFileBrowser().getSelectedFile().getName().endsWith(".txt")) {
//process the file
} else {
throw new Exception("File isn't text file");
}
}
However you might think about better solution. IMO, you should move the if(.txt) condition into IF component of Flow designer. I'll try to attach a sample project later.
Posted by Lukas on July 28, 2008 at 09:18 AM CEST #