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
Contributor
cubyn9x
Posts: 21
Registered: ‎06-14-2012
My Device: 9900

Help me........Splash Screen

The algorithm is as follows:
The program will include two MainScreen. 1 and 1 MainScreen Splashscreen MainScreen do is the main program (Here is UiApp)

When the program starts, we display Splashscreen ago, in this Splashscreen through BitmapField we add an Image containing Splashscreen want to do. At the same time will give an animated Thread sleep for 5 seconds, after 5 seconds it wake up to the main MainScreen load up.

So when the program runs it will see an image, animated 5 seconds going into the main program.

When you exit the program it self turn out to be out Home Screen of BB.

 

Code UiApp

 

import net.rim.device.api.ui.UiApplication;

/**
* This class extends the UiApplication class, providing a
* graphical user interface.
*/
public class UiApp extends UiApplication
{
/**
* Entry point for application
* @param args Command line arguments (not used)
*/
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
UiApp theApp = new UiApp();
theApp.enterEventDispatcher();
}

/**
* Creates a new MyApp object
*/
public UiApp()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new SplashScreen(this));
}
}

 

Code Cubyn

 

import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.util.StringProvider;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.command.ReadOnlyCommandMetadata;
import net.rim.device.api.command.CommandHandler;
import net.rim.device.api.command.Command;


public final class Cubyn extends MainScreen
{

EditField username;

PasswordEditField password;

ObjectChoiceField domain;

ButtonField btnClear;

ButtonField btnLogin;

LoginCommandHandler loginHandler = new LoginCommandHandler();
ClearCommandHandler clearHandler = new ClearCommandHandler();

SplashScreen _mySplashScreen;
Cubyn(SplashScreen mySplashScreen)
{
_mySplashScreen = mySplashScree
}
public Cubyn()
{
Bitmap logo = Bitmap.getBitmapResource("iconvn.png");
BitmapField bmpField = new BitmapField(logo, Field.FIELD_HCENTER);
add(bmpField);

add(new SeparatorField());

username = new EditField("Tên đăng nhập: ", "");
password = new PasswordEditField("Mật khẩu: ", "");
add(username);
add(password);

domain = new ObjectChoiceField("Địa điểm: ",new String[]{"Nhà riêng","Văn phòng"} );
add(domain);

CheckboxField chkRemember = new CheckboxField("Ghi nhớ mật khẩu", true);
add(chkRemember);

add(new SeparatorField());

btnClear = new ButtonField("Xóa", ButtonField.CONSUME_CLICK);
btnLogin = new ButtonField("Đăng nhập", ButtonField.CONSUME_CLICK );

HorizontalFieldManager buttonManager = new HorizontalFieldManager(Field.FIELD_RIGHT);
add(buttonManager);
buttonManager.add(btnClear);
buttonManager.add(btnLogin);

btnClear.setCommand(new Command(clearHandler));
btnLogin.setCommand(new Command(loginHandler));

setTitle("Thông tin");

}

public void clearText() {
username.setText("");
password.setText("");
}

public void login() {
if (username.getTextLength() == 0 || password.getTextLength() == 0) {
Dialog.alert("Bạn phải nhập tên đăng nhập và mật khẩu");
}
else {
UiApp.getUiApplication().pushScreen(new Album());
}

}

protected void makeMenu(Menu menu, int instance) {

super.makeMenu(menu, instance);

MenuItem loginMenu = new MenuItem(new StringProvider("Đăng nhập"), 20, 10);
loginMenu.setCommand(new Command(loginHandler));
menu.add(loginMenu);

MenuItem clearMenu = new MenuItem(new StringProvider("Xóa"), 20, 10);
clearMenu.setCommand(new Command(clearHandler));
menu.add(clearMenu);
}

class LoginCommandHandler extends CommandHandler{
public void execute(ReadOnlyCommandMetadata metedata, Object context){
login();
}
}
class ClearCommandHandler extends CommandHandler{
public void execute(ReadOnlyCommandMetadata metedata, Object context){
clearText();
}

}

final class SplashScreen extends MainScreen
{
UiApplication _app;
/**
* Creates a new HelloWorldScreen object
*/
SplashScreen(UiApplication app)
{
_app = app;
Bitmap myBitmap = Bitmap.getBitmapResource("img/spashscreen.png");
BitmapField myBitmapField = new BitmapField(myBitmap);
add(myBitmapField);
startLoading();
}

public void startLoading() {
Thread loadThread = new Thread() {
public void run() {
// Make sure to invokeLater to avoid problems with the event thread.
try{
// Stay there for 5 seconds
Thread.sleep(5000);
} catch(java.lang.InterruptedException e){}

_app.invokeLater( new Runnable() {
public void run() {
_app.pushScreen(new Cubyn((SplashScreen)_app.getActiveScreen()));
}
});
}
};
loadThread.start();
}
}
}

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Help me........Splash Screen

use peters sampkes:
http://supportforums.blackberry.com/t5/Java-Development/Sample-quot-Please-Wait-quot-screen-part-1/t...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help me........Splash Screen