PocketMagic

PocketMagic

Where Technology meets magic


Android
45 Posts
BlackBerry
4 Posts
Electronics
68 Posts
Hardware
120 Posts
High Voltage
49 Posts
iPhone
4 Posts
Linux
2 Posts
Nuclear
20 Posts
Optics
11 Posts
Photography
7 Posts
Photoshop
3 Posts
Research
19 Posts
Reviews
18 Posts
Robotics
8 Posts
Security
7 Posts
Software
73 Posts
Symbian
2 Posts
Tubes
18 Posts
Windows
3 Posts
Windows Mobile
11 Posts

Top Articles!       See PocketMagic on Facebook


uRADMonitor - Online Radiation monitoring station | 14845 Views | Rate 70.36
uRADMonitor - Online Radiation monitoring station
Developing for Blackberry 10 | 65 Views | Rate 65
Developing for Blackberry 10
Bluetooth and iOS - Use Bluetooth in your iPhone apps | 17857 Views | Rate 57.98
Bluetooth and iOS - Use Bluetooth in your iPhone apps
NMEA GPS Library for AVR Microcontrollers | 4788 Views | Rate 57
NMEA GPS Library for AVR Microcontrollers
Building a robot – Part 2 | 4555 Views | Rate 44.66
Building a robot – Part 2
Programmatically Injecting Events on Android - Part 2 | 4899 Views | Rate 44.54
Programmatically Injecting Events on Android - Part 2
Simple Switched power Supplies | 15954 Views | Rate 41.55
Simple Switched power Supplies
Capacitor Discharge Microspot Welder / Cutter | 11225 Views | Rate 36.21
Capacitor Discharge Microspot Welder / Cutter

 
  

BlackBerry Splash Screen


By Radu Motisan Posted on January 12th, 2012 , 687 Views (Rate 1.39)



  




A splash screen is an application window, that appears at startup, usually showing some logo. It lasts for only a few seconds, then the application workflow continues (eg. next screen pops up).

But how to do this for BlackBerry, programmatically?

First you create a new project. The entry point should be:

  1.  
  2. /**
  3.   * Entry point for application
  4.   *
  5.   * @param args
  6.   * Command line arguments (not used)
  7.   */
  8. public static void main( String[] args ) {
  9. // Create a new instance of the application and make the currently
  10. // running thread the application's event dispatch thread.
  11. MainApp theApp = new MainApp();
  12. theApp.enterEventDispatcher();
  13. }
  14.  
  15. /**
  16.   * Creates a new MainApp object
  17.   */
  18. public MainApp() {
  19. // init app globals
  20. g_nScreenWidth = Display.getHeight();
  21. g_nScreenHeight = Display.getWidth();
  22.  
  23. // Push a screen onto the UI stack for rendering.
  24. splashScreen = new SplashScreen();
  25. pushScreen( splashScreen );
  26. }
  27.  

When the SplashScreen class loads, we use an image in resources as the splash image to display:

  1.  
  2. BitmapField bmp = new BitmapField(
  3. Utils.getFitBitmapImage("splash1.png",MainApp.g_nScreenWidth, MainApp.g_nScreenHeight),
  4. BitmapField.FIELD_HCENTER | BitmapField.FIELD_VCENTER);
  5.  
  6. HorizontalFieldManager rowHolder = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL|
  7. Field.FIELD_HCENTER | USE_ALL_HEIGHT );
  8. rowHolder.add(bmp);
  9. add(rowHolder);
  10.  

This helper function is used to resize a given resource bitmap to match a rectangular area. This can be used to shrink or enlarge the image, it can also be used to make the image cover to whole screen.

  1.  
  2. // Resize a bitmap proportionally (shrink or enlarge) to make it fit a maxX x maxY rectangle
  3. static public Bitmap getFitBitmapImage(String imagename, int maxX, int maxY)
  4. {
  5.  
  6. EncodedImage image = EncodedImage.getEncodedImageResource(imagename);
  7.  
  8. int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
  9. int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
  10.  
  11. //double ratio = (double)ratioX / (double) ratioY;
  12. double rx = (double) image.getWidth() / (double)maxX;
  13. double ry = (double) image.getHeight() / (double)maxY;
  14. double r = 0;
  15. if (rx > ry) r = rx; else r= ry;
  16. double w = (double) image.getWidth() / r;
  17. double h = (double) image.getHeight() / r;
  18.  
  19. int width = (int) w;
  20. int height = (int) h;
  21.  
  22. int requiredWidthFixed32 = Fixed32.toFP(width);
  23. int requiredHeightFixed32 = Fixed32.toFP(height);
  24.  
  25. int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
  26. int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
  27.  
  28. image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
  29.  
  30. return image.getBitmap();
  31. }
  32.  

To make the program load the next class automatically and skip the splash screen use:

  1.  
  2. MainApp.homeScreen = new HomeScreen();
  3. UiApplication.getUiApplication().invokeLater(new Runnable() {
  4. public void run() {
  5. UiApplication.getUiApplication().pushScreen(MainApp.homeScreen);
  6. UiApplication.getUiApplication().popScreen(MainApp.splashScreen);
  7. }
  8. }, 2000, false);
  9.  

Complete code here:
SplashScreen






  

More on PocketMagic:

CDV-742 Dosimeter and CDV-750 Dosimeter Charger | 105 Views | Rate 26.25
CDV-742 Dosimeter and CDV-750 Dosimeter Charger
Programmatically Injecting Events on Android - Part 1 | 10065 Views | Rate 26.08
Programmatically Injecting Events on Android - Part 1
Victoreen CDV-717 Remote Gamma Survey dosimeter | 103 Views | Rate 25.75
Victoreen CDV-717 Remote Gamma Survey dosimeter
Atmega8 and enc28J60 for ethernet support | 7162 Views | Rate 24.36
Atmega8 and enc28J60 for ethernet support
How to set the AVR Fusebits | 1665 Views | Rate 23.79
How to set the AVR Fusebits
ATMega128 and HD44780 LCD using 3 Wires with the 74HC164 | 2022 Views | Rate 22.98
ATMega128 and HD44780 LCD using 3 Wires with the 74HC164

Thank you for commenting. Your comment won't show until approved, which can take some time.

Please copy the string ilO0zn to the field below: