October 1, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Introducing a Lightweight UI Toolkit: Shake Your User Interface

  • September 25, 2008
  • By Ibon Urrutia
  • Send Email »
  • More Articles »

In your application, if the current city is not selected (first time users have to select the city to show weather forecast) you should warn users about it. I added the following code to WeatherDisplay:

...
// Current City has not been set
   if (currentCity.yahooCode == null) {
      Dialog.show("Set city to display info",
         "Go to set place and select " +
         "cities to show weather information for them", "Ok", null);
      return;
   }
...

And, the About dialog window on WeatherMidlet could be more pleasant than your first ugly Form. it is better; the code is smaller than on your first approach:

...
case ABOUT_COMMAND:
   Dialog.show("About", getAboutText(), Dialog.TYPE_INFO, null,
               "Ok", null);
   break;
...

The LWUIT API offers some static methods to create a Dialog, as you see in those examples. If you don't add a "Cancel" text, only a OK command will be added to the dialog. There are some methods that allow developers to add different Commands to dialog window; these can be useful if the Dialog is going to affect execution flow.

Figure 7: About Dialog Window

Progress Bar

As every JavaME developer knows, most of the time it is not sufficient to test your application in emulators; you have to go to real devices, not only to test possible implementation bugs, but also to test on real execution conditions. In your case, network latencies may greatly affect your application's usability: At every moment, you have to inform your users about what your application is doing, so you are going to add some progress bars when your application is connecting to the Internet to download information.

LWUIT doesn't offer a generic progress bar widget, but creating one is very easy. In your application, downloading is done at the beginning of the forms, when you need all information to be showed to your users, so while you are downloading all information, you can show a progress indicator to inform users that you are doing "something" and that they have to wait.

Because you don't know how long your download is going to last, you need is an infinite progress indicator (as some Ajax applications use). So, what you could do is create a simple Label and animate it.

How animation is done in LWUIT

LWUIT has a single main thread where all events and paints are dispatched. It is called EDT (inspired by the Event Dispatch Thread in Swing and AWT). LWUIT offers an interface, Animation interface, that all components (Forms, Containers, Buttons...) implement with two methods:

  • void paint(Graphics g): Paints screen, and that is the common paint method of every component (remember lcdui Canvas?).
  • boolean animate(): Called once every frame, and tells EDT whether or not you are are going to repaint your element.

To use animation, you have to register your component as animated in your Form by using the registerAnimated method. Animation frames are set on the Display class, the class that controls the EDT, in setFramerate(int fps). So, if you use the default 10 FPS, in one second EDT will call animate() of every registered component of the current form 10 times.

Basically, this is the same common technique some people use when using a Timer class that is called every X milliseconds and repaints your screen, but in a more organized, easier, and standardized way.


Tags: mobility



Page 5 of 7



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel