Changeset 531


Ignore:
Timestamp:
11/08/09 15:22:07 (3 years ago)
Author:
octorian
Message:

Added loading splash screen

Location:
trunk/LogicMail/src
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/LogicMail.java

    r495 r531  
    4040import net.rim.device.api.notification.NotificationsManager; 
    4141import net.rim.device.api.system.ApplicationManager; 
     42import net.rim.device.api.system.Bitmap; 
     43import net.rim.device.api.system.Display; 
    4244import net.rim.device.api.system.EventLogger; 
    4345import net.rim.device.api.system.RuntimeStore; 
     46import net.rim.device.api.ui.Field; 
     47import net.rim.device.api.ui.Font; 
     48import net.rim.device.api.ui.Screen; 
    4449import net.rim.device.api.ui.UiApplication; 
     50import net.rim.device.api.ui.component.BitmapField; 
     51import net.rim.device.api.ui.component.LabelField; 
     52import net.rim.device.api.ui.container.MainScreen; 
    4553 
    4654import org.logicprobe.LogicMail.model.MailManager; 
    4755import org.logicprobe.LogicMail.ui.NavigationController; 
    4856import org.logicprobe.LogicMail.ui.NotificationHandler; 
     57import org.logicprobe.LogicMail.ui.ThrobberField; 
    4958import org.logicprobe.LogicMail.conf.AccountConfig; 
    5059import org.logicprobe.LogicMail.conf.MailSettings; 
     
    6473 */ 
    6574public class LogicMail extends UiApplication { 
    66         NavigationController navigationController; 
     75        private NavigationController navigationController; 
     76        private Screen loadingScreen; 
    6777         
    6878    /** 
     
    8494        } 
    8595        else { 
    86                 // Load the configuration 
    87                 MailSettings.getInstance().loadSettings(); 
    88             // Set the language, if configured 
    89             String languageCode = 
    90                 MailSettings.getInstance().getGlobalConfig().getLanguageCode(); 
    91             if(languageCode != null && languageCode.length() > 0) { 
    92                 try { 
    93                     Locale.setDefault(Locale.get(languageCode)); 
    94                 } catch (Exception e) { } 
    95             } 
    96          
    97                 // Log application startup information 
    98                 if(EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
    99                     StringBuffer buf = new StringBuffer(); 
    100                     buf.append("Application startup\r\n"); 
    101                     buf.append("Date: "); 
    102                     buf.append(Calendar.getInstance().getTime().toString()); 
    103                     buf.append("\r\n"); 
    104                     buf.append("Name: "); 
    105                     buf.append(AppInfo.getName()); 
    106                     buf.append("\r\n"); 
    107                     buf.append("Version: "); 
    108                     buf.append(AppInfo.getVersion()); 
    109                     buf.append("\r\n"); 
    110                     buf.append("Platform: "); 
    111                     buf.append(AppInfo.getPlatformVersion()); 
    112                     buf.append("\r\n"); 
    113                     EventLogger.logEvent(AppInfo.GUID, buf.toString().getBytes(), EventLogger.INFORMATION); 
    114                 } 
    115  
    116                 // Initialize the data model explicitly 
    117                 MailManager.initialize(); 
     96                logStartupAppInfo(); 
    11897                 
    119                 // Initialize the notification handler 
    120                 NotificationHandler.getInstance().setEnabled(true); 
     98                createLoadingScreen(); 
    12199                 
    122                 // Initialize the navigation controller 
    123                 navigationController = new NavigationController(this); 
     100                Thread loadingThread = new Thread() { 
     101                        public void run() { 
     102                        // Load the configuration 
     103                        MailSettings.getInstance().loadSettings(); 
     104                        // Set the language, if configured 
     105                        String languageCode = 
     106                            MailSettings.getInstance().getGlobalConfig().getLanguageCode(); 
     107                        if(languageCode != null && languageCode.length() > 0) { 
     108                            try { 
     109                                Locale.setDefault(Locale.get(languageCode)); 
     110                            } catch (Exception e) { } 
     111                        } 
     112 
     113                        // Initialize the data model explicitly 
     114                        MailManager.initialize(); 
     115                         
     116                        // Initialize the notification handler 
     117                        NotificationHandler.getInstance().setEnabled(true); 
     118                         
     119                        // Initialize the navigation controller 
     120                        navigationController = new NavigationController(LogicMail.this); 
     121                         
     122                        invokeLater(new Runnable() { 
     123                                                public void run() { 
     124                                        // Push the mail home screen and pop 
     125                                                        // the loading screen 
     126                                        navigationController.displayMailHome(); 
     127                                        popScreen(loadingScreen); 
     128                                        loadingScreen = null; 
     129                                                } 
     130                        }); 
     131                        } 
     132                }; 
    124133                 
    125                 // Push the mail home screen 
    126                 navigationController.displayMailHome(); 
     134                pushScreen(loadingScreen); 
     135                loadingThread.start(); 
    127136        } 
    128137    } 
    129138 
     139        private void logStartupAppInfo() { 
     140                // Log application startup information 
     141                if(EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
     142                    StringBuffer buf = new StringBuffer(); 
     143                    buf.append("Application startup\r\n"); 
     144                    buf.append("Date: "); 
     145                    buf.append(Calendar.getInstance().getTime().toString()); 
     146                    buf.append("\r\n"); 
     147                    buf.append("Name: "); 
     148                    buf.append(AppInfo.getName()); 
     149                    buf.append("\r\n"); 
     150                    buf.append("Version: "); 
     151                    buf.append(AppInfo.getVersion()); 
     152                    buf.append("\r\n"); 
     153                    buf.append("Platform: "); 
     154                    buf.append(AppInfo.getPlatformVersion()); 
     155                    buf.append("\r\n"); 
     156                    EventLogger.logEvent(AppInfo.GUID, buf.toString().getBytes(), EventLogger.INFORMATION); 
     157                } 
     158        } 
     159 
     160    private void createLoadingScreen() { 
     161                loadingScreen = new MainScreen(); 
     162                int displayWidth = Display.getWidth(); 
     163                Bitmap splashLogo = Bitmap.getBitmapResource("splash-logo.png"); 
     164                Bitmap fieldSeparator = new Bitmap(displayWidth, 10); 
     165                int throbberSize = displayWidth / 4; 
     166                int fontHeight = Font.getDefault().getHeight(); 
     167                int spacerSize = (Display.getHeight() / 2) - ((splashLogo.getHeight() + throbberSize + fontHeight) / 2) - 10; 
     168                if(spacerSize < 0) { spacerSize = 0; } 
     169                Bitmap topSpacer = new Bitmap(displayWidth, spacerSize); 
     170                 
     171                loadingScreen.add(new BitmapField(topSpacer)); 
     172                loadingScreen.add(new BitmapField(splashLogo, Field.FIELD_HCENTER)); 
     173                loadingScreen.add(new BitmapField(fieldSeparator)); 
     174                loadingScreen.add(new ThrobberField(throbberSize, Field.FIELD_HCENTER)); 
     175                loadingScreen.add(new BitmapField(fieldSeparator)); 
     176        loadingScreen.add(new LabelField("Version " + AppInfo.getVersion(), Field.FIELD_HCENTER)); 
     177    } 
     178     
    130179    /** 
    131180     * Run the application. 
Note: See TracChangeset for help on using the changeset viewer.