Ignore:
Timestamp:
11/22/09 15:19:25 (2 years ago)
Author:
octorian
Message:
 
File:
1 edited

Legend:

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

    r531 r553  
    5353 
    5454import org.logicprobe.LogicMail.model.MailManager; 
     55import org.logicprobe.LogicMail.ui.BlankSeparatorField; 
    5556import org.logicprobe.LogicMail.ui.NavigationController; 
    5657import org.logicprobe.LogicMail.ui.NotificationHandler; 
     
    7374 */ 
    7475public class LogicMail extends UiApplication { 
    75         private NavigationController navigationController; 
    76         private Screen loadingScreen; 
    77          
     76    private NavigationController navigationController; 
     77    private Screen loadingScreen; 
     78 
    7879    /** 
    7980     * Instantiates a new instance of the application. 
     
    8283     */ 
    8384    public LogicMail(String[] args) { 
    84         boolean autoStart = false; 
    85         for(int i=0; i<args.length; i++) { 
    86                 if(args[i].indexOf("autostartup") != -1) { 
    87                         autoStart = true;                        
    88                 } 
    89         } 
    90         AppInfo.initialize(args); 
    91          
    92         if(autoStart) { 
    93                 doAutoStart(); 
    94         } 
    95         else { 
    96                 logStartupAppInfo(); 
    97                  
    98                 createLoadingScreen(); 
    99                  
    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                 }; 
    133                  
    134                 pushScreen(loadingScreen); 
    135                 loadingThread.start(); 
    136         } 
    137     } 
    138  
    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         } 
     85        boolean autoStart = false; 
     86        for(int i=0; i<args.length; i++) { 
     87            if(args[i].indexOf("autostartup") != -1) { 
     88                autoStart = true;                        
     89            } 
     90        } 
     91        AppInfo.initialize(args); 
     92 
     93        if(autoStart) { 
     94            doAutoStart(); 
     95        } 
     96        else { 
     97            logStartupAppInfo(); 
     98 
     99            createLoadingScreen(); 
     100 
     101            Thread loadingThread = new Thread() { 
     102                public void run() { 
     103                    // Load the configuration 
     104                    MailSettings.getInstance().loadSettings(); 
     105                    // Set the language, if configured 
     106                    String languageCode = 
     107                        MailSettings.getInstance().getGlobalConfig().getLanguageCode(); 
     108                    if(languageCode != null && languageCode.length() > 0) { 
     109                        try { 
     110                            Locale.setDefault(Locale.get(languageCode)); 
     111                        } catch (Exception e) { } 
     112                    } 
     113 
     114                    // Initialize the data model explicitly 
     115                    MailManager.initialize(); 
     116 
     117                    // Initialize the notification handler 
     118                    NotificationHandler.getInstance().setEnabled(true); 
     119 
     120                    // Initialize the navigation controller 
     121                    navigationController = new NavigationController(LogicMail.this); 
     122 
     123                    try { 
     124                        sleep(2000); 
     125                    } catch (InterruptedException e) { 
     126                        // TODO Auto-generated catch block 
     127                        e.printStackTrace(); 
     128                    } 
     129                     
     130                    invokeLater(new Runnable() { 
     131                        public void run() { 
     132                            // Push the mail home screen and pop 
     133                            // the loading screen 
     134                            navigationController.displayMailHome(); 
     135                            popScreen(loadingScreen); 
     136                            loadingScreen = null; 
     137                        } 
     138                    }); 
     139                } 
     140            }; 
     141 
     142            pushScreen(loadingScreen); 
     143            loadingThread.start(); 
     144        } 
     145    } 
     146 
     147    private void logStartupAppInfo() { 
     148        // Log application startup information 
     149        if(EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
     150            StringBuffer buf = new StringBuffer(); 
     151            buf.append("Application startup\r\n"); 
     152            buf.append("Date: "); 
     153            buf.append(Calendar.getInstance().getTime().toString()); 
     154            buf.append("\r\n"); 
     155            buf.append("Name: "); 
     156            buf.append(AppInfo.getName()); 
     157            buf.append("\r\n"); 
     158            buf.append("Version: "); 
     159            buf.append(AppInfo.getVersion()); 
     160            buf.append("\r\n"); 
     161            buf.append("Platform: "); 
     162            buf.append(AppInfo.getPlatformVersion()); 
     163            if(PlatformInfo.getInstance().hasTouchscreen()) { 
     164                buf.append(' '); 
     165                buf.append("(touch)"); 
     166            } 
     167            buf.append("\r\n"); 
     168            EventLogger.logEvent(AppInfo.GUID, buf.toString().getBytes(), EventLogger.INFORMATION); 
     169        } 
     170    } 
    159171 
    160172    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)); 
     173        loadingScreen = new MainScreen(); 
     174        int displayWidth = Display.getWidth(); 
     175        int displayHeight = Display.getHeight(); 
     176        int fieldSpacerSize = displayHeight / 24; 
     177        Bitmap splashLogo = Bitmap.getBitmapResource("splash-logo.png"); 
     178        int throbberSize = displayWidth / 4; 
     179        int fontHeight = Font.getDefault().getHeight(); 
     180        int spacerSize = (displayHeight / 2) - ((splashLogo.getHeight() + throbberSize + fontHeight) / 2) - fieldSpacerSize; 
     181        if(spacerSize < 0) { spacerSize = 0; } 
     182 
     183        loadingScreen.add(new BlankSeparatorField(spacerSize)); 
     184        loadingScreen.add(new BitmapField(splashLogo, Field.FIELD_HCENTER)); 
     185        loadingScreen.add(new BlankSeparatorField(fieldSpacerSize)); 
     186        loadingScreen.add(new ThrobberField(throbberSize, Field.FIELD_HCENTER)); 
     187        loadingScreen.add(new BlankSeparatorField(fieldSpacerSize)); 
    176188        loadingScreen.add(new LabelField("Version " + AppInfo.getVersion(), Field.FIELD_HCENTER)); 
    177189    } 
    178      
     190 
    179191    /** 
    180192     * Run the application. 
    181193     */ 
    182194    public void run() { 
    183         enterEventDispatcher(); 
    184     } 
    185      
     195        enterEventDispatcher(); 
     196    } 
     197 
    186198    /** 
    187199     * Method to execute in autostart mode. 
     
    215227                        Hashtable eventSourceMap = new Hashtable(numAccounts); 
    216228                        for(int i=0; i<numAccounts; i++) { 
    217                                 AccountConfig accountConfig = mailSettings.getAccountConfig(i); 
    218                                 LogicMailEventSource eventSource = 
    219                                         new LogicMailEventSource(accountConfig.getAcctName(), accountConfig.getUniqueId()); 
    220                                 NotificationsManager.registerSource( 
    221                                         eventSource.getEventSourceId(), 
    222                                         eventSource, 
    223                                         NotificationsConstants.CASUAL); 
    224                                 eventSourceMap.put(new Long(accountConfig.getUniqueId()), eventSource); 
     229                            AccountConfig accountConfig = mailSettings.getAccountConfig(i); 
     230                            LogicMailEventSource eventSource = 
     231                                new LogicMailEventSource(accountConfig.getAcctName(), accountConfig.getUniqueId()); 
     232                            NotificationsManager.registerSource( 
     233                                    eventSource.getEventSourceId(), 
     234                                    eventSource, 
     235                                    NotificationsConstants.CASUAL); 
     236                            eventSourceMap.put(new Long(accountConfig.getUniqueId()), eventSource); 
    225237                        } 
    226                          
     238 
    227239                        // Save the registered event sources in the runtime store 
    228240                        RuntimeStore.getRuntimeStore().put(AppInfo.GUID, eventSourceMap); 
    229241                        keepGoing = false; 
    230242                    } 
    231                  } 
    232                  //Exit the application. 
    233                  System.exit(0); 
     243                } 
     244                //Exit the application. 
     245                System.exit(0); 
    234246            } 
    235247        }); 
Note: See TracChangeset for help on using the changeset viewer.