Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 179
Registered: ‎07-19-2012
My Device: Z10 Limited Edition and Dev Alpha C
My Carrier: Movistar-Venezuela

webicon with splashscreen [Error]

believes that this webicon with SplashScreen ejcutar when my BlackBerry is not responding.

 

/*
 * SplashScreen.java
 *
 * © <marcossit.blogspot.com>, 2011-2012
 * By @Marcossit
 */


package TecnoBBerry;
 
import java.util.Timer;
import java.util.TimerTask;
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 * 2000){
                        showSplash = true;
                        splashDisplayed = true;
                        splashTimer.cancel();
                        invalidate();
                    }
                }
            }
        };
 
        splashTimer.scheduleAtFixedRate(splashTask, 1000, 1000);
 
    }
 
    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 = true;
            splashDisplayed = true;
            invalidate();
            return true;
        }else{
            return true;
        }
    }
}

 

/*
 * WelcomeScreen.java
 *
 * © <marcossit.blogspot.com>, 2011-2012
 * By @Marcossit
 */

package TecnoBBerry;
 
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("por.jpg"), 1000);
        //normal mainscreen items:
        setTitle("Conectando al BBM 6.0+ by Marcossit");
    }
}

 

/*
 * TecnoBBerry.java
 *
 * © <your company here>, <year>
 * Confidential and proprietary.
 */

package TecnoBBerry;

import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.device.api.ui.UiApplication;

class TecnoBBerry extends UiApplication{
    public static void main(String[] args){
        TecnoBBerry instance = new TecnoBBerry();
        instance.enterEventDispatcher();
    }
    
    public TecnoBBerry() {
        pushScreen(new WelcomeScreen());
        BrowserSession site = Browser.getDefaultSession();
        site.displayPage("http://tecnobberry.com");
        site.showBrowser();
        System.exit(0);
    }
}

 can someone tell me where can be my mistake? to not run properly? or some example of WebiCon with SplashScreen?

 


Follow me in Twitter:

@Marcossit

BBM Channel:

MarcossitDev: C0002C366  

DeviceSuite For BlackBerry 10:

Link to Download DeviceSuite:

Support was successful? Accept as Solution and click on:


Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: webicon with splashscreen [Error]

From your description, I am not sure what your problem is, but I think with a couple of changes we should be able to get this working.

 

The first thing is that your actual screen calls System.exit() perhaps not giving the Browser time to get going, and as a result, the system stops the Browser invocation.   The code I am talking about is this:

 

        site.showBrowser();
        System.exit(0);

 

Now I would actually not want to close the application down until the Browser has started.  You could detect this in a number of ways.  But possibly the easiest is to override your Screens .'onObscured()' method. So in your Welcome screen, override the method and in there, calls System.exit(0);  So you know the Browser has started because it is replacing your screen on the Display.

 

The second thing I am not sure about, is that the constructor actually does not give up control when you think it does.  So the actual execution of statements is pretty much (missing out some irrelevant stuff:

 

TecnoBBerry instance = new TecnoBBerry();

pushScreen(new WelcomeScreen());

super(Bitmap.getBitmapResource("por.jpg"), 1000);

splashTask = new TimerTask()....

splashTimer.scheduleAtFixedRate(splashTask, 1000, 1000);

BrowserSession site = Browser.getDefaultSession();

site.showBrowser();

System.exit(0);

instance.enterEventDispatcher();

 

Well that is what it would be.  But I doubt you even get to

instance.enterEventDispatcher();

since you have exited...

 

So you need to break the sequence with something that will wait for the user.  So I would resequence your processing so that it goes loosely

1) main creates splash screen

2) splash screen starts browser when dismissed

3) splash screen exits application in onObscured.

 

But as noted, I am not 100% sure that I understand what your problem is nor exactly what you are trying to do, so perhaps this does not match what you want.  But hopefully it will help.

 

Can I suggest that when stuff like this happens, you step through the lines of the code to make sure that things are being executed as you want them to.  I suspect if you had stepped through these lines you would have been able to progress this a little further. 

 

Good luck

 

 

: