Main.java

/*
 * Copyright © 2012 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.weatherapp;

import com.nokia.example.weatherapp.resources.Settings;
import com.nokia.example.weatherapp.views.ViewMaster;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;

public class Main
        extends MIDlet {

    private static Main self;
    private Display display;
    private ViewMaster viewMaster;

    public static Main getInstance() {
        return self;
    }

    public void startApp() {
        if (display == null) {
            self = this;
            display = Display.getDisplay(this);
            // Load persistent settings
            Settings.load();

            // Initiate view master and let it handle the views
            viewMaster = ViewMaster.getInstance();
            viewMaster.setDisplay(display);
            viewMaster.openView(ViewMaster.VIEW_WEATHER);

            // Perform location retrieval
            viewMaster.startLocationFinder();
        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        // Save persistent settings
        Settings.save();
    }

    public void exit() {
        destroyApp(true);
        notifyDestroyed();
    }

    // Checks whether TestMode has been set on in JAD or Manifest
    public boolean isInTestMode() {
        return "on".equalsIgnoreCase(getAppProperty("TestMode"));
    }
}