在黑莓上的进度指示器的启动画面

时间:2011-04-13 06:15:53

标签: blackberry screen splash

我正在设计一个带有活动指示器的启动画面。 我成功创建了一个启动画面,但我的指标没有添加到它, 在设置布局时,它隐藏在图像下方。

我该如何解决这个问题?

这是我的代码:

package mypackage;
import java.util.Timer;
import java.util.TimerTask;

import net.rim.device.api.system.Application;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorController;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorModel;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorView;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

import net.rim.device.api.ui.container.MainScreen;
//import net.rim.device.api.ui.extension.container.EyelidFieldManager;


public final class SplashScreen extends SplashScreenPage
{


    public SplashScreen()
    {        
     super(Bitmap.getBitmapResource("splash-blackberry.png"),2);
    }
}
class SplashScreenPage extends MainScreen

{   

    VerticalFieldManager vfm= new VerticalFieldManager(Field.FIELD_VCENTER);


HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_VCENTER)
    {
        protected void sublayout( int maxWidth, int maxHeight )
     {
        super.sublayout(360,60);
        setExtent(360, 60);

       Field field = getField(0);
       layoutChild(field,140, 60);
       setPositionChild(field, 100,200);
 }



    public void paint(Graphics graphics)
     {
         //Draw the background image and then call paint.

     // super.paint(graphics);
      //graphics.clear();

         // graphics.setBackgroundColor(0x000000);
          //graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0);

             // super.paint(graphics);
             // graphics.clear();       
         // graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0);


    }               

    };





    ActivityIndicatorView view = new ActivityIndicatorView(Field.USE_ALL_WIDTH);
    ActivityIndicatorModel model = new ActivityIndicatorModel();
    ActivityIndicatorController controller = new ActivityIndicatorController();






    boolean notlogged = false;
    Bitmap popup;
    SplashScreenPage screen1 = 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;
    //SplashScreen page is here
    public SplashScreenPage(Bitmap popup, final int seconds) 
    {

        view.setController(controller);
        view.setModel(model);
        view.setLabel("Loading");
        controller.setModel(model);
        controller.setView(view);

        model.setController(controller);        

        Bitmap bitmap = Bitmap.getBitmapResource("images.jpeg");
        view.createActivityImageField(bitmap, 5, Field.FIELD_BOTTOM);

      //  add(view);

   add(hfm);
    hfm.add(view);
  // add(vfm);
   // vfm.add(Bitmap.getBitmapResource("splash-blackberry.png"));






          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 * 15) {
                        showSplash = false;
                        splashDisplayed = true;
                        splashTimer.cancel();
                        invalidate();


                        synchronized (Application.getEventLock()){

                             UiApplication.getUiApplication().pushScreen(new secondscreen());
                              notlogged = true;
                             }

                       }
                }
            }
        };

       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);
           // super.paint(graphics);
           // graphics.clear();
        }
    }

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


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

    public void onExposed() {
           if( notlogged)
           UiApplication.getUiApplication().popScreen(this);
        }
}

1 个答案:

答案 0 :(得分:0)

在要添加视图的Horizo​​ntalFieldManager中,您需要确保调用super.paint(),因为它调用了subpaint(),它将告诉其子字段(在本例中为视图)自己绘制。我看到你已经注释掉了,所以你可能已经搞砸了。此外,请确保在调用super.paint()之前进行背景绘制,这样就不会用自己的绘画掩盖ActivityIndi​​catorView。

您是否可以通过清理代码(删除不重要的注释掉的代码)到您期望它工作的地方,这样可以更轻松地区分“尝试”任何你可以“编码和”工作“代码。