Main.java

/**
 * Copyright (c) 2013 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.nnaclientexample;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;

import javax.microedition.lcdui.Displayable;
import com.nokia.notifications.installer.InstallListener;
import com.nokia.notifications.installer.InstallerFactory;
import com.nokia.notifications.installer.NotificationsEnablerInstaller;

/**
 * The application main class.
 */
public class Main extends MIDlet implements InstallListener
{
    private MainView mainView;
    Form installForm;
    Command exitCommand;

    /**
     * Constructor.
     */
    public Main() {
    }

    /**
     * @see javax.microedition.midlet.MIDlet#startApp()
     */
    public void startApp() {
        //mainView = new MainView(this);
        //Display.getDisplay(this).setCurrent(mainView);
       
        installForm = new Form("NNA Installer");
        installForm.append(new StringItem("Checking", null));
        exitCommand = new Command("Exit", Command.EXIT, 1);
        installForm.addCommand(exitCommand);
        installForm.setCommandListener(new CommandListener() {
                        public void commandAction(Command command, Displayable display) {
                            quit();
                        }
                    }
                );
        Display.getDisplay(this).setCurrent(installForm);
        // Check the availability of Notifications Enabler
        NotificationsEnablerInstaller installer = InstallerFactory.getInstaller();
        installer.checkAndUpdateNapiEnabler(this, installForm, this);
    }

    /**
     * @see javax.microedition.midlet.MIDlet#pauseApp() 
     */
    public void pauseApp() {
    }

    /**
     * @see javax.microedition.midlet.MIDlet#destroyApp(boolean) 
     */
    public void destroyApp(boolean unconditional) {
    }

    /**
     * Quits the application.
     */
    public void quit() {
        destroyApp(true);
        notifyDestroyed();
    }
    
    // Implements for InstallListener interface
    public void installResult(int result) {
        if (InstallListener.INSTALLATION_OK == result
                || InstallListener.ALREADY_EXISTS == result) {
            mainView = new MainView(this);
            Display.getDisplay(this).setCurrent(mainView);

            Display.getDisplay(this).setCurrent(new MainView(this));
        } else {
            installForm.append(new StringItem("Error",
                                              "Installation failed with code " + result));
        }
    }
}