root/trunk/LogicMail/src/org/logicprobe/LogicMail/LogicMail.java

Revision 354, 5.2 kB (checked in by octorian, 3 weeks ago)

Autostart hooks and initial notification implementation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*-
2 * Copyright (c) 2006, Derek Konigsberg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the project nor the names of its
15 *    contributors may be used to endorse or promote products derived
16 *    from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package org.logicprobe.LogicMail;
33
34import java.util.Calendar;
35
36import net.rim.blackberry.api.homescreen.HomeScreen;
37import net.rim.device.api.notification.NotificationsConstants;
38import net.rim.device.api.notification.NotificationsManager;
39import net.rim.device.api.system.ApplicationManager;
40import net.rim.device.api.system.EventLogger;
41import net.rim.device.api.ui.UiApplication;
42import org.logicprobe.LogicMail.ui.MailHomeScreen;
43import org.logicprobe.LogicMail.ui.NotificationHandler;
44import org.logicprobe.LogicMail.conf.MailSettings;
45
46/*
47 * Logging levels:
48 *  EventLogger.ALWAYS_LOG   = 0
49 *  EventLogger.SEVERE_ERROR = 1
50 *  EventLogger.ERROR        = 2
51 *  EventLogger.WARNING      = 3
52 *  EventLogger.INFORMATION  = 4
53 *  EventLogger.DEBUG_INFO   = 5
54 */
55
56/**
57 * Main class for the application.
58 */
59public class LogicMail extends UiApplication {
60    /**
61     * Instantiates a new instance of the application.
62     *
63     * @param autoStart True if this is the autostart instance, false for normal startup
64     */
65    public LogicMail(boolean autoStart) {
66        if(autoStart) {
67                doAutoStart();
68        }
69        else {
70                // Load the configuration
71                MailSettings.getInstance().loadSettings();
72       
73                // Log application startup information
74                if(EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) {
75                    StringBuffer buf = new StringBuffer();
76                    buf.append("Application startup\r\n");
77                    buf.append("Date: ");
78                    buf.append(Calendar.getInstance().getTime().toString());
79                    buf.append("\r\n");
80                    buf.append("Name: ");
81                    buf.append(AppInfo.getName());
82                    buf.append("\r\n");
83                    buf.append("Version: ");
84                    buf.append(AppInfo.getVersion());
85                    buf.append("\r\n");
86                    EventLogger.logEvent(AppInfo.GUID, buf.toString().getBytes(), EventLogger.INFORMATION);
87                }
88
89                // Initialize the notification handler
90                NotificationHandler.getInstance().setEnabled(true);
91               
92                // Push the mail home screen
93                pushScreen(new MailHomeScreen());
94        }
95    }
96
97    /**
98     * Run the application.
99     */
100    public void run() {
101        enterEventDispatcher();
102    }
103   
104    /** The constant event source object. */
105    private static final Object eventSource = new Object() {
106                public String toString() {
107                return "LogicMail New Message";
108                }
109        };
110       
111    /**
112     * Method to execute in autostart mode.
113     */
114    private void doAutoStart() {
115        invokeLater(new Runnable()
116        {
117            public void run()
118            {
119                ApplicationManager myApp = ApplicationManager.getApplicationManager();
120                boolean keepGoing = true;
121
122                while (keepGoing)
123                {
124                    if (myApp.inStartup())
125                    {
126                        try { Thread.sleep(1000); }
127                        catch (Exception ex) { }
128                    }
129                    else
130                    {
131                        // The BlackBerry has finished its startup process
132                        // Configure the rollover icons
133                        HomeScreen.updateIcon(AppInfo.getIcon(), 0);
134                        HomeScreen.setRolloverIcon(AppInfo.getRolloverIcon(), 0);
135                       
136                        // Configure the notification source
137                        NotificationsManager.registerSource(AppInfo.GUID, eventSource, NotificationsConstants.CASUAL);
138                       
139                        keepGoing = false;
140                    }
141                 }
142                 //Exit the application.
143                 System.exit(0);
144            }
145        });     
146    }
147} 
Note: See TracBrowser for help on using the browser.