Created
June 21, 2012 08:42
-
-
Save amrishodiq/2964618 to your computer and use it in GitHub Desktop.
Splash screen implementation for Blackberry Java application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is how to use ScreenSplash.java | |
*/ | |
package com.durianapp.brandapp; | |
import com.durianapp.brandapp.ui.ScreenSplash; | |
public class BrandApp extends UiApplication { | |
public BrandApp() { | |
// ScreenMenu.get() is just another singleton getter for the next screen | |
// 1600 is the delay before the next screen, in milisecond | |
ScreenSplash.show(ScreenMenu.get(), 1600); | |
} | |
public static void main(String[] args){ | |
new BrandApp().enterEventDispatcher(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.durianapp.brandapp.ui; | |
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.Screen; | |
import net.rim.device.api.ui.UiApplication; | |
import net.rim.device.api.ui.component.BitmapField; | |
import net.rim.device.api.ui.container.MainScreen; | |
import net.rim.device.api.ui.container.VerticalFieldManager; | |
import net.rim.device.api.ui.decor.Background; | |
import net.rim.device.api.ui.decor.BackgroundFactory; | |
public class ScreenSplash extends MainScreen { | |
private static ScreenSplash screen; | |
public static ScreenSplash get(Screen nextScreen, int delay){ | |
if (screen == null) { | |
screen = new ScreenSplash(nextScreen, delay); | |
} | |
return screen; | |
} | |
public static void show(final Screen nextScreen, final int delay) { | |
if (!get(nextScreen, delay).isDisplayed()) { | |
UiApplication.getUiApplication().invokeLater(new Runnable() { | |
public void run() { | |
UiApplication.getUiApplication().pushScreen(get(nextScreen, delay)); | |
} | |
}); | |
} else { | |
UiApplication.getUiApplication().invokeLater(new Runnable() { | |
public void run() { | |
UiApplication.getUiApplication().popScreen(get(nextScreen, delay)); | |
UiApplication.getUiApplication().pushScreen(get(nextScreen, delay)); | |
} | |
}); | |
} | |
} | |
private BitmapField logoField; | |
private VerticalFieldManager bgManager; | |
public ScreenSplash(final Screen nextScreen, final int delay) { | |
super(NO_VERTICAL_SCROLL); | |
bgManager = new VerticalFieldManager(NO_VERTICAL_SCROLL | | |
USE_ALL_WIDTH | USE_ALL_HEIGHT); | |
// Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("gen/bg.jpg")); | |
bgManager.setBackground(Resources.getBackground()); | |
add(bgManager); | |
logoField = new BitmapField(Resources.getLogo()) { | |
public void layout(int w, int h) { | |
setExtent(Display.getWidth(), Display.getHeight()); | |
} | |
public void paint(Graphics g) { | |
int left = (getWidth() - getBitmapWidth())/2; | |
int top = (getHeight() - getBitmapHeight())/2; | |
g.drawBitmap(left, top, getBitmapWidth(), getBitmapHeight(), getBitmap(), 0, 0); | |
} | |
}; | |
bgManager.add(logoField); | |
new Thread(new Runnable() { | |
public void run() { | |
try { | |
Thread.sleep(delay); | |
} catch (InterruptedException e) { | |
} | |
UiApplication.getUiApplication().invokeLater(new Runnable() { | |
public void run() { | |
UiApplication.getUiApplication().pushScreen(nextScreen); | |
UiApplication.getUiApplication().popScreen(getScreen()); | |
} | |
}); | |
} | |
}).start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment