SplashView.java

/*
 * Copyright © 2011 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.wordpress.views;

import com.nokia.example.wordpress.helpers.ImageLoader;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 * Splash view. Displays the logo for a few seconds and then activates the
 * login view.
 */
public class SplashView extends BaseView {

    private Image loaderScreen;

    SplashView(Graphics g, int x, int y, int width, int height) {
        super(g, ViewMaster.VIEW_SPLASH, x, y, width, height);
        try {
            loaderScreen = ImageLoader.getInstance().loadImage("/loader_screen.png");
        } catch (IOException e) {
        }
    }

    public void activate() {
        System.out.println("splash activate");
        super.activate();

        Timer timer = new Timer();
        TimerTask task = new TimerTask() {

            public void run() {
                viewMaster.setView(ViewMaster.VIEW_LOGIN);
            }
        };
        timer.schedule(task, 3000); // how long to show the splash

    }

    public void draw(int x, int y, int width, int height) {
        System.out.println("splash render");
        drawLogoScreen("Nokia C3 blog admin demo");
    }

    public void drawLogoScreen(String text) {
        // Check whether the wide lower part of the graphic fits into the
        // screen width. If not, clip it out.
        int gfxHeight = loaderScreen.getHeight();
        if (width <= 270) {
            // Only draw this much from the top of the graphic.
            gfxHeight = 165;
        }
        g.drawRegion(loaderScreen, 0, 0, loaderScreen.getWidth(), gfxHeight,
                Sprite.TRANS_NONE, width / 2, 0, g.TOP | g.HCENTER);
        g.setColor(Visual.BACKGROUND_COLOR);
        final int textY = height - Visual.SMALL_FONT.getHeight() - 8;
        g.fillRect(0, textY, width, Visual.SMALL_FONT.getHeight());
        g.setColor(Visual.LOGO_TEXT_COLOR);
        g.setFont(Visual.SMALL_FONT);
        g.drawString(text, width / 2, height - 8, g.BOTTOM | g.HCENTER);
    }
}