Implementing the MIDlet main class

The MIDlet main class implements the required utilities and displays the main view of the MIDlet.

The MIDlet main class creates the following UI:

Figure: SystemProperties opening view (Series 40)

To implement the MIDlet main class:

  1. Create the SystemProperties.java class file.

  2. Import the required classes.

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
  3. Set SystemProperties to extend MIDlet and implement CommandListener. MIDlets use the CommandListener interface to receive high-level UI events from the platform.

    public class SystemProperties extends MIDlet implements CommandListener {
  4. Create an array for each system property you want to include in the MIDlet. The properties are expressed as strings.

        protected static final String[] SYSPROPLISTS = {
            "CLDC&MIDP", "Optional packages", "MMAPI (JSR-135)", "Bluetooth API (JSR-82)", "FileConnection API (JSR-75)",
            "WMA (JSR-120/205)", "SATSA API (JSR-177)", "Web Services API (JSR-172)", "AMMS API (JSR-234)",
            "Scalable 2D Vector Graphics API (JSR-226)", "Mobile 3D Graphics API (JSR-184)",
            "Nokia-specific (network)", "Nokia-specific (system)", "Nokia-specific (UI)",
            "Nokia-specific (Canvas UI)", "Nokia-specific (protected)", "Nokia-specific (dual-SIM)", "S40 full touch APIs"
        };
        protected static final String[] CLDC_MIDPPROPS = {
            "microedition.profiles", "microedition.configuration", "microedition.locale", "microedition.platform",
            "microedition.encoding", "microedition.commports", "microedition.hostname", "microedition.jtwi.version",
            "microedition.msa.version"
        };
        protected static final String[] OPT_SYSPROPS = {
            "microedition.media.version", "microedition.pim.version", "microedition.m3g.version", "microedition.location.version",
            "bluetooth.api.version", "microedition.io.file.FileConnection.version", "microedition.global.version",
            "microedition.chapi.version", "microedition.sip.version", "wireless.messaging.version", "microedition.amms.version",
            "microedition.m2g.version", "microedition.payment.version", "microedition.contactless.version", "microedition.sensor.version",
            "obex.api.version", "microedition.broadcast.version", "com.nokia.mid.ui.version"
        };
        protected static final String[] MMAPI_SYSPROPS = {
            "supports.mixing", "supports.audio.capture", "supports.video.capture", "supports.recording", "audio.encodings",
            "video.encodings", "video.snapshot.encodings", "streamable.contents"
        };
        protected static final String[] BT_SYSPROPS = {
            "bluetooth.l2cap.receiveMTU.max", "bluetooth.connected.devices.max", "bluetooth.connected.inquiry",
            "bluetooth.connected.page", "bluetooth.connected.inquiry.scan", "bluetooth.connected.page.scan",
            "bluetooth.master.switch", "bluetooth.sd.trans.max", "bluetooth.sd.attr.retrievable.max"
        };
        protected static final String[] FILE_API_SYSPROPS = {
            "fileconn.dir.photos", "fileconn.dir.photos.name", "fileconn.dir.videos", "fileconn.dir.videos.name", "fileconn.dir.graphics",
            "fileconn.dir.graphics.name", "fileconn.dir.tones", "fileconn.dir.tones.name","fileconn.dir.music", "fileconn.dir.music.name",
            "fileconn.dir.recordings", "fileconn.dir.recordings.name", "fileconn.dir.landmarks", "fileconn.dir.landmarks.name",
            "fileconn.dir.memorycard", "fileconn.dir.memorycard.name", "fileconn.dir.private", "fileconn.dir.private.name",
            "fileconn.dir.themes", "fileconn.dir.themes.name", "fileconn.dir.received", "fileconn.dir.received.name",
            "fileconn.dir.roots.names", "file.separator", "fileconn.dir.cache", "fileconn.dir.bookmarks", "fileconn.dir.applications.bookmarks",
            "fileconn.dir.games.bookmarks"
        };
        protected static final String[] WMA_SYSPROPS = {
            "wireless.messaging.sms.smsc", "wireless.messaging.mms.mmsc"
        };
        protected static final String[] SATSA_SYSPROPS = {
            "microedition.satsa.crypto.version", "microedition.satsa.apdu.version", "microedition.satsa.pki.version",
            "microedition.smartcardslots"
        };
        protected static final String[] WEB_SERVICES_SYSPROPS = {
            "xml.jaxp.subset.version", "xml.rpc.subset.version"
        };
        protected static final String[] AMMS_SYSPROPS = {
            "tuner.modulations", "audio.samplerates", "audio3d.simultaneouslocations", "camera.orientations",
            "camera.resolutions", "supports.mediacapabilities"
        };
        protected static final String[] M2G_SYSPROPS = {
            "microedition.m2g.svg.baseProfile", "microedition.m2g.svg.version"
        };
        protected static final String[] M3G_SYSPROPS = {
            "supportAntialiasing", "supportTrueColor", "supportDithering", "supportMipmapping",
            "supportPerspectiveCorrection", "supportLocalCameraLighting", "maxLights",
            "maxViewportWidth", "maxViewportHeight", "maxViewportDimension", "maxTextureDimension",
            "m3gRelease", "maxSpriteCropDimension", "numTextureUnits", "maxTransformsPerVertex"
        };
        protected static final String[] NOKIA_NETWORK = {
            "com.nokia.mid.networkid", "com.nokia.mid.networksignal", "com.nokia.mid.networkavailability",
            "com.nokia.mid.networkstatus", "com.nokia.network.access", "com.nokia.midp.impl.isa.network.databearer"
        };
        protected static final String[] NOKIA_SYSTEM = {
            "com.nokia.mid.batterylevel", "com.nokia.mid.countrycode", "com.nokia.mid.calendars", "com.nokia.memoryramfree",
            "com.nokia.mid.dateformat", "com.nokia.mid.timeformat", "com.nokia.gpu.memory.total",
            "com.nokia.gpu.memory.used", "com.nokia.gpu.memory.shared", "com.nokia.gpu.memory.private", "com.nokia.mid.cmdline",
            "com.nokia.mid.cmdline.instance", "param1"
        };
        protected static final String[] NOKIA_UI = {
            "com.nokia.mid.impl.nativeDigitSupport", "com.nokia.mid.ui.layout", "com.nokia.mid.ui.joystick_event",
            "com.nokia.mid.ui.softnotification", "com.nokia.keyboard.type", "com.nokia.key.scancode", "com.nokia.key.modifier",
            "com.nokia.mid.settings.ombActive", "com.nokia.mid.ui.customfontsize", "com.nokia.mid.ui.screensaverprevention",
            "com.nokia.mid.ui.tactilefeedback", "com.nokia.mid.ui.frameanimator.fps", "com.nokia.mid.ui.frameanimator.pps"
        };
        protected static final String[] NOKIA_CANVAS_UI = {
            "com.nokia.canvas.net.indicator.location", "com.nokia.softkey1.label.location",
            "com.nokia.softkey2.label.location", "com.nokia.softkey3.label.location", "com.nokia.softkey1.label.anchor",
            "com.nokia.softkey2.label.anchor", "com.nokia.softkey3.label.anchor"
        };
        protected static final String[] NOKIA_PROTECTED = {
            "com.nokia.mid.imei", "Cell-ID", "com.nokia.mid.imsi", "com.nokia.mid.spn", "com.nokia.mid.mnc", "com.nokia.mid.ons",
            "com.nokia.mid.networkID", "com.nokia.mid.cellid", "com.nokia.mid.lac", "com.nokia.mid.gid1", "com.nokia.mid.gid2",
            "com.nokia.mid.msisdn", "com.nokia.mid.productcode"
        };
        protected static final String[] NOKIA_DUAL_SIM = {
            "com.nokia.multisim.cellid.sim1", "com.nokia.multisim.cellid.sim2", "com.nokia.multisim.lac.sim1", "com.nokia.multisim.lac.sim2",
            "com.nokia.multisim.mnc.sim1", "com.nokia.multisim.mnc.sim2", "com.nokia.multisim.networkavailability.sim1",
            "com.nokia.multisim.networkavailability.sim2", "com.nokia.multisim.networkid.sim1", "com.nokia.multisim.networkid.sim2",
            "com.nokia.multisim.networksignal.sim1", "com.nokia.multisim.networksignal.sim2", "com.nokia.multisim.networkstatus.sim1",
            "com.nokia.multisim.networkstatus.sim2"
        };
        protected static final String[] S40_FT_SYSPROPS = {
            "com.nokia.mid.ui.screensaverprevention", "com.nokia.mid.ui.tactilefeedback",
            "com.nokia.mid.ui.multipointtouch.version", "com.nokia.mid.ui.gestures.version", "com.nokia.mid.ui.theme.version",
            "com.nokia.mid.ui.orientation.version", "com.nokia.mid.ui.locale.version"
        };
  5. Create the required variables and the SystemProperties class constructor.

        private List list;
        private SysPropForm form;
        private Command exitCommand;
        private Command memCommand;
        protected int index;
        protected boolean bt = false;
        protected boolean m3g = false;
    
        public SystemProperties() {
            list = new List("System properties", List.IMPLICIT, SYSPROPLISTS, null);
            form = new SysPropForm(SYSPROPLISTS[0], this, CLDC_MIDPPROPS);
            memCommand = new Command("Memory status", Command.SCREEN, 2);
            exitCommand = new Command("Exit", Command.EXIT, 1);
            list.addCommand(memCommand);
            list.addCommand(exitCommand);
            list.setCommandListener(this);
            Display.getDisplay(this).setCurrent(list);
        }
  6. Define the mandatory lifecycle methods for starting, pausing, and destroying the MIDlet.

        protected void startApp() {
        }
    
        protected void pauseApp() {
        }
    
        protected void destroyApp(boolean p1) {
        }
  7. Use the commandAction method to move to the correct screen when the user chooses to view the details of a system property.

        public void commandAction(Command c, Displayable d) {
            if (c == List.SELECT_COMMAND) {
                index = list.getSelectedIndex();
                if (index == 0) {
                    form.update(SYSPROPLISTS[0], CLDC_MIDPPROPS);
                }
                if (index == 1) {
                    form.update(SYSPROPLISTS[1], OPT_SYSPROPS);
                }
                if (index == 2) {
                    form.update(SYSPROPLISTS[2], MMAPI_SYSPROPS);
                }
                if (index == 3) {
                    bt = true;
                    form.update(SYSPROPLISTS[3], BT_SYSPROPS);
                }
                if (index == 4) {
                    form.update(SYSPROPLISTS[4], FILE_API_SYSPROPS);
                }
                if (index == 5) {
                    form.update(SYSPROPLISTS[5], WMA_SYSPROPS);
                }
                if (index == 6) {
                    form.update(SYSPROPLISTS[6], SATSA_SYSPROPS);
                }
                if (index == 7) {
                    form.update(SYSPROPLISTS[7], WEB_SERVICES_SYSPROPS);
                }
                if (index == 8) {
                    form.update(SYSPROPLISTS[8], AMMS_SYSPROPS);
                }
                if (index == 9) {
                    form.update(SYSPROPLISTS[9], M2G_SYSPROPS);
                }
                if (index == 10) {
                    m3g = true;
                    form.update(SYSPROPLISTS[10], M3G_SYSPROPS);
                }
                if (index == 11) {
                    form.update(SYSPROPLISTS[11], NOKIA_NETWORK);
                }
                if (index == 12) {
                    form.update(SYSPROPLISTS[12], NOKIA_SYSTEM);
                }
                if (index == 13) {
                    form.update(SYSPROPLISTS[13], NOKIA_UI);
                }
                if (index == 14) {
                    SysPropFullCanvas canvas = new SysPropFullCanvas(this);
                    Display.getDisplay(this).setCurrent(canvas);
                    return;
                }
                else if (index == 15) {
                    form.update(SYSPROPLISTS[15], NOKIA_PROTECTED);
                }
                else if (index == 16) {
                    form.update(SYSPROPLISTS[16], NOKIA_DUAL_SIM);
                }
                else if (index == 17) {
                    form.update(SYSPROPLISTS[16], S40_FT_SYSPROPS);
                }
                Display.getDisplay(this).setCurrent(form);
            }
            if (c == memCommand) {
                showMemory();
            }
            if (c == exitCommand) {
                this.notifyDestroyed();
            }
        }
  8. Create a method for displaying the opening view of the MIDlet.

        protected void showList() {
            Display.getDisplay(this).setCurrent(list);
        }
  9. Create a method for displaying an alert window with the amount of used and available memory.

        private void showMemory() {
            Alert alert = new Alert("Memory status");
            String freemem = "" + Runtime.getRuntime().freeMemory();
            String totalmem = "" + Runtime.getRuntime().totalMemory();
            alert.setString("Free memory/Total memory: " + freemem + "/" + totalmem);
            alert.setType(AlertType.INFO);
            alert.setTimeout(Alert.FOREVER);
            Display.getDisplay(this).setCurrent(alert, list);
        }
    
    }

Now that you have implemented the MIDlet main class, implement the full screen display of property details.