Create the TouristMIDlet
class
file.
Import the required classes.
package com.nokia.example.location.tourist; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; import com.nokia.example.location.tourist.model.ConfigurationProvider; import com.nokia.example.location.tourist.model.ProviderStatusListener; import com.nokia.example.location.tourist.model.TouristData; import com.nokia.example.location.tourist.ui.MessageUI; import com.nokia.example.location.tourist.ui.TouristUI;
Set TouristMIDlet
to
extend MIDlet. Make and implement ProviderStatusListener
.
Create the constructor.
/** * Tourist Route MIDlet class. */ public class TouristMIDlet extends MIDlet implements ProviderStatusListener { /** A static reference to Display object. */ private static Display display = null; /** A Reference to TouristData. */ private TouristData data = null; /** Lock object */ private Object mutex = new Object(); public TouristMIDlet() { super(); }
Define the three required MIDlet methods for this application.
protected void startApp() throws MIDletStateChangeException { display = Display.getDisplay(this); if (ConfigurationProvider.isLocationApiSupported()) { ConfigurationProvider.getInstance().autoSearch(this); } else { MessageUI.showApiNotSupported(); } } protected void pauseApp() { } protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { }
Create a method for getting a reference to the Display object.
/** * Getter method for Display reference. * * @return reference to Display object. */ public static Display getDisplay() { return display; }
Create a method for indicating the selection of the location provider.
/** * Event indicating location provider is selected. MIDlet use may therefore * begin. * * @see com.nokia.example.location.tourist.model.ProviderSelectedListener#providerSelectedEvent() */ public void providerSelectedEvent() { // Attempt to acquire the mutex synchronized (mutex) { // Start scanning location updates. Also set the TouristData // reference data. MessageUI.showLocationProviderState(); // Inform the user that MIDlet is looking for location data. data = new TouristData((ProviderStatusListener) this); } }
Create a method for indicating that the first location update has occurred.
/** * Event indication about the first location update. This method sets * Tourist UI visible. By using mutex object, we ensure TouristaData (data) * is created on providerSelectedEvent. * * @see com.nokia.example.location.tourist.model.ProviderStatusListener#firstLocationUpdateEvent() */ public void firstLocationUpdateEvent() { // Attempt to acquire the mutex synchronized (mutex) { TouristUI ui = new TouristUI(data); data.setTouristUI(ui); display.setCurrent(ui); } } }