开发者

Splashscreen not working

The below splashscreen is not displaying correctly. It works fine when I push just the splashscreen but not when I push the splashscreen and then another screen. Welcome screen is the splashscreen.

So this works -

pushScreen(new WelcomeScreen());

But not this -

pushScreen(new WelcomeScreen());
pushScreen(new MenuScreen());

In the second scenario the menuscreen is displayed straight away but not the splashscreen.

Here is the splash screen code - two classes.

package screens;

import com.src.driver.Driver;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.LabelField;

public class WelcomeScreen extends SplashScreen {

    public WelcomeScreen() {
        super(Bitmap.getBitmapResource("icon.png"), 5);
        //normal mainscreen items:
        //setTitle("SplashScreen Test");
        //add(new LabelField("HelloWorld!"));
    }
}

package screens;

import java.util.Timer;
import java.util.TimerTask;

import com.src.driver.Driver;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.MainScreen;

public class SplashScreen extends MainScreen {

    Bitmap popup;
    SplashScreen screen = thi开发者_如何转开发s;
    private Timer splashTimer = new Timer();
    private TimerTask splashTask;
    int count = 0;
    int screenWidth = Display.getWidth();
    int screenHeight = Display.getHeight();
    int yCoord;
    int xCoord;
    boolean showSplash = true;
    boolean splashDisplayed = false;

    public SplashScreen(Bitmap popup, final int seconds) {
        this.popup = popup;
        xCoord = (screenWidth - popup.getWidth()) / 2;
        yCoord = (screenHeight - popup.getHeight()) / 2;

        splashTask = new TimerTask() {

            public void run() {
                if (showSplash && !splashDisplayed) {
                    count++;
                    if (count == seconds * 10) {
                        showSplash = false;
                        splashDisplayed = true;
                        splashTimer.cancel();
                        invalidate();
                    }
                }
            }
        };

        splashTimer.scheduleAtFixedRate(splashTask, 100, 100);

    }

    protected void paint(Graphics graphics) {
        super.paint(graphics);
        if (showSplash && !splashDisplayed) {
            graphics.drawBitmap(xCoord, yCoord, popup.getWidth(), popup.getHeight(), popup, 0, 0);
            //draw border, delete if not needed:
            //graphics.setColor(0xcccccc);
            //graphics.drawRect(xCoord, yCoord, popup.getWidth(), popup.getHeight());
        }
    }

    protected void onUiEngineAttached(boolean attached) {
        showSplash = true;
        invalidate();
        super.onUiEngineAttached(attached);
    }

    //allow user to dismiss splash screen:
    protected boolean navigationMovement(int dx, int dy, int status, int time) {
        return DismissSplash();

    }

    protected boolean navigationClick(int status, int time) {
        return DismissSplash();
    }

    protected boolean keyChar(char c, int status, int time) {
        return DismissSplash();
    }

    private boolean DismissSplash() {
        if (showSplash) {
            showSplash = false;
            splashDisplayed = true;
            invalidate();
            return true;
        }else{
            return false;
        }
    }
}

Thank you


It looks like the problem is that MenuScreen is pushed immediately after WelcomeScreen. You will need to put in some kind of mechanism that waits for WelcomeScreen to "finish" before pushing the MenuScreen.

Maybe create a Listener object that is passed into WelcomeScreen. Then when WelcomeScreen "finishes" it would call the Listener (e.g. myListener.splashScreenFinished()). Then the implementation of the Listener would create and push the MenuScreen.

This might look something like this:

interface MyListener {
    public void splashScreenFinished();
}

 

class MyApp implements MyListener {
    ...
    public void splashScreenFinished() {
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                pushScreen(new MenuScreen());
            }
        });
    }

    public void startupApp() {
        pushScreen(new WelcomeScreen(this));
    }
    ...
}

 

class WelcomeScreen {
    private MyListener l;

    public WelcomeScreen(MyListener listener) {
        l = listener;
        ...
    }

    protected onSplashTimerDone() {
        if (l != null)
            l.splashScreenFinished();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜