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.racer;
import com.nokia.example.racer.gestures.GestureProvider;
import com.nokia.example.racer.views.*;
import com.nokia.mid.ui.DeviceControl;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
public class Main
extends MIDlet
implements ExitListener {
public static boolean sensorsSupported; // indicates if the device supports acceleration sensors
public static boolean gesturesSupported; // indicates if the device supports gestures
public static boolean landscape; // indicates if the device supports landscape mode
private static Main self;
private Display display;
/*
* views for the actual racing, menu, and settings
*/
private GameView gameView;
private MenuView menuView;
private SettingsView settingsView;
public static Main getInstance() {
return self;
}
/**
* Starts the app by showing splash screen and initializes views
*/
public void startApp() {
if (display == null) {
display = Display.getDisplay(this);
self = this;
DeviceControl.setLights(0, 100); // prevent screen saving
/*
* first show a splash screen
*/
SplashView splashView = new SplashView();
display.setCurrent(splashView);
/*
* load other views in the background
*/
new Thread() {
public void run() {
gameView = new GameView();
// enable gestures needed in GameView
gesturesSupported = GestureProvider.enableGestures();
menuView = new MenuView();
settingsView = new SettingsView();
try {
sleep(1000);
}
catch (InterruptedException e) {
}
showMenu(); // when ready, show menu
try {
join();
}
catch (InterruptedException e) {
}
}
}.start();
splashView = null;
}
}
public void showGameView() {
display.setCurrent(gameView);
}
public void showMenu() {
display.setCurrent(menuView);
}
public void showSettings() {
display.setCurrent(settingsView);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void exit() {
destroyApp(false);
notifyDestroyed();
}
public Display getDisplay() {
return display;
}
public GameView getGameView() {
return gameView;
}
}