2011-02-16 241 views
0

下面的飛濺屏幕顯示不正確。當我只推動splashscreen時,它的工作正常,但當我推動splashscreen,然後再推另一個屏幕時,它沒有問題。歡迎屏幕是閃屏。飛濺屏幕不能正常工作

所以此工程 -

pushScreen(new WelcomeScreen()); 

而不是現在這樣 -

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

在顯示menuscreen馬上而不是濺射屏幕的第二個場景。

這是閃屏代碼 - 兩個類。

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 = this; 
    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; 
     } 
    } 
} 

謝謝

回答

1

它看起來像問題是,MenuScreen是WelcomeScreen後推。在推送菜單屏幕之前,您需要放入某種機制來等待WelcomeScreen「完成」。

也許創建一個傳入WelcomeScreen的Listener對象。然後,當歡迎屏幕「完成」時,它會調用監聽程序(例如myListener.splashScreenFinished())。然後,監聽器的實現將創建並推送MenuScreen。

這可能是這個樣子:

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

你可以添加僞代碼來實現這一PLZ? – 2011-02-16 21:55:53