⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 funambol.java

📁 moblie syncml mail javame
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission 
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License 
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably 
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

package com.funambol.mailclient;

import com.funambol.mailclient.config.ConfigException;
import java.io.IOException;
import java.util.Date;

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.io.PushRegistry;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.funambol.mail.MessageFlags;
import com.funambol.mail.Store;
import com.funambol.mailclient.config.ConfigManager;
import com.funambol.mailclient.config.MailClientConfig;
import com.funambol.mailclient.loc.Localization;
import com.funambol.mailclient.sm.SyncClient;
import com.funambol.mailclient.sm.SyncClientConfig;
import com.funambol.mailclient.ui.controller.AlarmManager;
import com.funambol.mailclient.ui.controller.AppProperties;
import com.funambol.mailclient.ui.controller.Killable;
import com.funambol.mailclient.ui.controller.LifeCycleController;
import com.funambol.mailclient.ui.controller.MessageHandler;
import com.funambol.mailclient.ui.controller.Theme;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.ui.view.ExitPopupAction;
import com.funambol.mailclient.ui.view.ModalPopup;
import com.funambol.mailclient.ui.view.SplashScreen;
import com.funambol.push.CTPListener;
import com.funambol.push.CTPService;
import com.funambol.push.OTAService;
import com.funambol.push.PushConfig;
import com.funambol.util.Log;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

//#ifdef isBlackberry
//# import com.funambol.util.BlackberryHelper;
//# import com.funambol.mailclient.ui.controller.UIConnectionHandler;

//#endif
public class Funambol extends MIDlet implements Killable, Runnable, CTPListener {
    
    private MailClientConfig mailClientConfig;
    private OTAService otaService;
    private CTPService ctpService;
    //private OTAService OTAConfigListener;
    private MessageHandler messageHandler;
    private InitConfigManager cm;
    private SplashScreen splashScreen;
    private static boolean hasFinished = false;
    
    public Funambol() {
        //startAppProbe = System.currentTimeMillis();
        splashScreen = new SplashScreen();
        Display.getDisplay(this).setCurrent(splashScreen);
    }
    
    protected void startApp() {

        if (LifeCycleController.isPaused == false) {

            // init localization for specific language
            //Localization.setMessages(new IT_LocalizedMessages());

            // Initialize the ThreadPoolMonitor
            UIController.initThreadPool();
            UIController.getThreadPool().startThread(this).setPriority(Thread.MAX_PRIORITY);
            
        } else {

            // see finally block in run method to understand reason of hasFinished usage
            if (hasFinished) {
            LifeCycleController.isPaused = false;
            LifeCycleController.getInstance().resume();
        }

        }
    }
    
    public void setSplashPhase(String message, int iconNumber) {
        splashScreen.setInitPhase(message, iconNumber);
    }
    
    public void setSplashPhase(String[] message, int iconNumber) {
        
        splashScreen.setInitPhase(message, iconNumber);
    }
    
    private void startSync(final boolean ok2Sync) {
        if (ok2Sync) {
            if (!UIController.otaStarted) {
                if (mailClientConfig.isSyncOnStartupEnabled()) {
                    Log.info("starting sync");
                    UIController.sync(true);
                } else {
                    Log.info("sync on startup disabled");
                }
            } else {
                Log.info("[FunambolMIDlet] Ota started the application... sync using SAN");
                
                // Workaround to avoid startsync failing with fake SMS incoming:
                // i.e. Sprint MotoV3m
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                }
                if ((!SyncClient.getSyncClient().isBusy()) &&
                     (otaService != null && !otaService.smsHandling)) {
                    Log.info("Sprint fix - starting sync due to fake OTA start");
                    UIController.sync(true);
                }
                
            }
        }
    }
    
    public void destroyApp(boolean unconditional) {
        Log.debug("DestroyAPP");
        ModalPopup popup =
                new ModalPopup(Localization.getMessages().POPUP_EXIT_TITLE,
                Localization.getMessages().POPUP_EXIT_TEXT,
                new ExitPopupAction());
        UIController.showModalPopup(popup, UIController.getInboxMessageList());
        
    }
    
    /**
     * Pausing the app means to put the Controller in paused mode.
     * In this way it will perform all the operations needed later when resuming
     */
    protected void pauseApp() {
        
        LifeCycleController.getInstance().pause();
        
    }
    
    /**
     * Exit the application. The exit method is invoked by the Controller
     * to exit the MIDlet
     */
    public void exit() throws MIDletStateChangeException {
      
        if (otaService != null) {
            otaService.stopService();
        }
        //OTAConfigListener.close();
        if (ctpService != null) {
            ctpService.stopService();
        }
        
        //#ifdef isBlackberry
        // need to remove the saved config 'cause sometimes static classes
        // are not removed in bb
        //# BlackberryHelper.removeSavedConfig();
        //# CTPService.getInstance().forceDisconnect();
        //#endif
       
        notifyDestroyed();
    }
    
    public void run() {
        
        try {
        boolean ok2Sync = false;

            boolean upgraded = false;


        UIController.init(this);
        
        //#ifdef isBlackberry
        //# 
        //# if (BlackberryHelper.shouldAskUserBeforeConnecting()) {
        //# Log.debug("[Funambol] need to use UIConnectionHandler");
        //# BlackberryHelper.setConnectionHandler(new UIConnectionHandler());
        //# }
        //#endif
        
        // Initialize Logging facility ASAP
        UIController.initLogger();
        Log.info("[FunambolMIDlet] Starting main thread");
        
        //UIController.startAppProbe = startAppProbe;
        UIController.startupFreeMem = Runtime.getRuntime().freeMemory();

        // Create the message handler which is responsible for handling push
        // notifications
        messageHandler = new MessageHandler();
        // This code is for backward compatibility. Migration from v6 to v6.5
        // Can be removed in future relase
        ConfigManager.upgrade();
        
        cm = new InitConfigManager(this);
        cm.initConfig();
        
        if (UIController.isFirstSync){
            checkForFunambolUpdate();
        }
        
        UIController.initMessageManager();
        // This code is for backward compatibility. Migration from v6 to v6.5
        // Can be removed in future relase
            upgraded = handleUpgrade();
        
        // loading opened and closed image, they'll be probably needed later and
        // this minimize the empty inbox for devices like nokia 6630
        Theme.getImageFromFlags(MessageFlags.OPENED);
        Theme.getImageFromFlags(0);


        ok2Sync = UIController.initInbox();
       
        cm.initListener();
        
        // Do not resync if we performed an upgrade
        startSync(ok2Sync && !upgraded);
        
        UIController.loadContacts();
        
        // If sync on startup is enabled, we wait for the sync authentication
        // to be completed. This allow the authentication to terminate before
        // starting CTP at the very first run.
        if (!mailClientConfig.isSyncOnStartupEnabled()) {
            startCTP();
        }
        } finally {
            // this is neeeded for first run after the installation on BB devices
            // since the app is paused and resumed at the startup before the run
            // method has time to finish, so we use hasFinished to ignore resume
            // requests until we're out of this run method

            hasFinished = true;
        }


    }
    
    private void checkForFunambolUpdate(){
        final String autoUpdateUrl = UIController.appProperties.get(AppProperties.AUTOUPDATE_URL);

        if (autoUpdateUrl!=null) {
            new Thread() {
                public void run() {
                    try {
                        HttpConnection hc = (HttpConnection) Connector.open(autoUpdateUrl);
                        hc.close();
                    } catch (Exception ex) {
                        Log.error("[Funambol] An update error occurred");	
                    }
                }
            }.start();
        }
    }

    /**
     * Restart CTP service. Stop current instance and create a new one. @see
     * startCTP for more details on starting the service.
     */
    public void restartCTP() {
        if (ctpService != null) {
            ctpService.stopService();
            startCTP();
        }
    }
   
    /**
     * Start the CTP service. The main purpose of this method is to provide the
     * service a valid configuration. The configuration is built taking
     * information from the SyncClientConfig.
     */
    public void startCTP() {
        try {

            // Start the CTP service (if enabled)
            //String ctp = getAppProperty("CTP");
            String ctp = UIController.appProperties.get(AppProperties.CTP);
            //#ifdef CtpPushRuntime
            //#    Log.info("enabling ctp");
            //#    ctp = "true";
            //#endif

            
            // setting config, ThreadPool and push notification listener
            PushConfig config = getPushConfig();
            ctpService = CTPService.getInstance();
            //#ifdef isBlackberry
            //# if (BlackberryHelper.shouldAskUserBeforeConnecting()) {
            //# Log.debug("[Funambol] need to use UIConnectionHandler");
            //# BlackberryHelper.setConnectionHandler(new UIConnectionHandler());
            //# }
            //#endif
            ctpService.setConfig(config);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -