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

📄 uicontroller.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            
            //delete message store
            messageManager.initStore(true);
            //delete contact list and related PIM Item Queue
            if (contactManager==null) {
                contactManager=
                        ContactManagerFactory.getContactManager(ContactManager.RMS_TYPE);
            }
            // reset the inbox view
            resetInboxMessageList();
            showInboxScreen();
            
            // empty the contact list (to free memory)
            contactManager.resetContactList();
            if (contactList != null) {
                contactList.resetContactList(new Message());
            }
            //initialize new account's messages and contacts
            sync(SyncML.ALERT_CODE_REFRESH_FROM_SERVER, true);
            getInboxMessageList().setMinimumDisplayedMessageCount(0);
        } catch (RecordStoreException rse) {
            Log.error("resetAccount: " + rse.toString());
            // TODO: ALERT ??
            showInboxScreen();
        } catch (MailException me) {
            Log.error("resetAccount: " + me.toString());
            // TODO: ALERT ??
            showInboxScreen();
        }
    }
    
    /**
     * show the inbox and requests a refresh from server sync
     */
    public static void resetInboxFromServer() throws RecordStoreException, MailException {
       
        showInboxScreen();
        Log.debug("starting refresh from server...");
        sync(SyncML.ALERT_CODE_REFRESH_FROM_SERVER, false);
    }
    
    
    /**
     * reinit the contacts from server
     */
    public static void resetContacts() {
        try {
            contactManager.resetContactList();
            if (contactList != null) {
                contactList.resetContactList(new Message());
            }
            SyncTaskManager stm = getSyncTaskManager();
            stm.setSyncMessages(false);
            stm.setResetContacts(true);
            stm.setSyncMode(SyncML.ALERT_CODE_REFRESH_FROM_SERVER);
            if (!stm.addObserver(new MessageListUpdater())) {
                Log.error("SyncTaskManager reached max number of observers! ");
            }
            
            getThreadPool().startThread(stm);
            
            
        } catch (SyncException ex) {
            ex.printStackTrace();
            Log.error("SyncException in resetcontacts " + ex.toString());
        }
        // sync(true);
    }
    
    public static void updateLogLevel(int logLevel) {
        Log.setLogLevel(logLevel);
        mailClientConfig.setLogLevel(logLevel);
        saveNewConfig(mailClientConfig);
    }
    
    public static FunCanvasInboxMessageList getInboxMessageList() {
        if (inboxMessageList==null) {
            MessageInfo[] list =
                    getSortedMessageInfo(getFolderInfo(MessageManager.INBOX));
            inboxMessageList=new FunCanvasInboxMessageList( list );
        }
        return inboxMessageList;
    }
    
    private static FunCanvasOutboxMessageList getOutboxMessageList() {
        if (outboxMessageList==null) {
            outboxMessageList=new FunCanvasOutboxMessageList(
                    getSortedMessageInfo(getFolderInfo(messageManager.OUTBOX)));
        }
        return outboxMessageList;
    }
    
    private static FunCanvasSentMessageList getSentMessageList() {
        if (sentMessageList==null) {
            sentMessageList=new FunCanvasSentMessageList(
                    getSortedMessageInfo(getFolderInfo(MessageManager.SENT)));
        }
        return sentMessageList;
    }
    
    private static FunCanvasDraftMessageList getDraftMessageList() {
        if (draftMessageList==null) {
            draftMessageList=new FunCanvasDraftMessageList(
                    getSortedMessageInfo(getFolderInfo(MessageManager.DRAFTS)));
        }
        return draftMessageList;
    }
    
    
    /**
     * change the followup flag to the given messageinfo and start a separate
     * thread for saving the change to the rms
     */
    public static void changeFollowUpFlag(final MessageInfo messageInfo) {
        
        boolean isFlagged = messageInfo.flags.isSet(MessageFlags.FLAGGED);
        messageInfo.flags.setFlag(MessageFlags.FLAGGED, !isFlagged);
        
        UIController.getThreadPool().startThread(
                new Thread() {
            public void run() {
                try {
                    changeFlag(messageInfo.getMessage(), MessageFlags.FLAGGED);
                } catch (MailException ex) {
                    Log.error("MailException changing followup flag");
                    ex.printStackTrace();
                }
            }
        }
        );
        
    }
    
    public static void changeFollowUpFlag(Message message) {
        changeFlag(message, MessageFlags.FLAGGED);
    }
    
   /* public static void changeReadFlag(final MessageInfo messageInfo) {
        boolean isRead = messageInfo.flags.isSet(MessageFlags.OPENED);
        messageInfo.flags.setFlag(MessageFlags.OPENED, !isRead);
    
        UIController.getThreadPool().startThread(
                new Thread() {
            public void run() {
                try {
                    changeFlag(messageInfo.getMessage(), MessageFlags.OPENED);
                } catch (MailException ex) {
                    ex.printStackTrace();
                }
            }
        }
        );
    }*/
    
    public static void changeReadFlag(Message message) {
        Log.debug("changing read flag");
        changeFlag(message, MessageFlags.OPENED);
    }
    
    
    
    /**
     * change the flag on the fly and start a thread to save the message
     * on rms.
     */
    private static void changeFlag(Message message, int flag) {
        boolean isFlagged=message.getFlags().isSet(flag);
        //message.getFlags().setFlag(flag, isFlagged);
        message.getFlags().setFlag(flag,!isFlagged);
        threadedWriteMessageToFolder(message);
        
        if ( message.getParent().getName().equals(Store.INBOX )) {
            //Log.debug("message is in inbox");
            try {
                getInboxMessageList().addMessage(new MessageInfo(
                        message, new FolderInfo(
                        message.getParent().getName(), StoreFactory.getStore()
                        )));
            } catch (MailException ex) {
                ex.printStackTrace();
                Log.error("UIController changeFlag() MailException  changing " +
                        "flag for message " + message.getSubject());
            }
        } else {
            //Log.debug("parent.fullname = " + message.getParent().getFullName());
            //Log.debug("parent.name = " + message.getParent().getName());
            updateMessageList(message);
        }
        
        //message.getFlags().setFlag(flag, !isFlagged);
        //updateMessageList(message);
    }
    
    
    /**
     * save a message to its parent folder and call the messageManager to add
     * the message to the queue
     */
    private static void threadedWriteMessageToFolder(final Message message) {
        
        
        
        // new Thread(new MessageWriter(message)).start();
        
        UIController.threadPool.startThread(getMessageWriter(message));
        
        
        
        /* UIController.threadPool.startThread(new Thread() {
            public void run() {
                Log.debug("messaggio " + message.getSubject());
                //Flags changes notification for eventual sync process
                /*messageManager.updateMessageFlags(message, message.getFlags());
                try {
                   message.getParent().appendMessage(message);
         
                } catch (StoreException ex) {
                    Log.error("threadedWriteMessageToFolder: ", ex.toString() );
                    ex.printStackTrace();
                } catch (MailException ex) {
                    Log.error("threadedWriteMessageToFolder: ", ex.toString() );
                    ex.printStackTrace();
                }
        }
        }
        );*/
    }
    
    /**
     * returns the corresponging folderinfo, folder should be one of
     *
     * MessageManager.INBOX
     * MessageManager.OUTBOX
     * MessageManager.DRAFT
     * MessageManager.SENT
     */
    public static FolderInfo getFolderInfo(int folder) {
        
        if (folderInfo==null)
            folderInfo =  messageManager.getRootFolders();
        
        return folderInfo[folder];
    }
    
    public static void sendMessage(Message message) {
        UIController.showInboxScreen();
        
        /*
         * this is to avoid that a message edited and sent from within the
         * Drafts once sent remains in the Drafts while it is in the Outbox
         */
        if (message.getParent() != null) {
            if (Store.DRAFTS.equals(message.getParent().getName())) {
                try {
                    message.getParent().deleteMessage(message);
                } catch (MailException ex) {
                    Log.error("sendMessage: "+ex);
                    ex.printStackTrace();
                }
            }
        }
        
        try {
            message.setSentDate(new Date());
            message.setReceivedDate(new Date());
            getFolderInfo(messageManager.OUTBOX).getFolder().appendMessage(message);
            
            
            //sync(false);
            
        } catch (Exception ex) {
            Log.error("Error moving message to Outbox");
            ex.printStackTrace();
            showErrorAlert(Localization.getMessages().SAVE_OUTBOX_ERROR);
        } finally {
            //    destroyAddressList();
        }
        
        sync(false);
        
    }
    
    /**
     * Start the sync of the messages, and optionally of the contacts
     * if the parameter syncContacts is true. The sync is done using the
     * default sync type defined for the source.
     */
    public static void sync(boolean syncContacts) {
        sync(-1, syncContacts);
    }
    
    /**
     * Start the SyncTaskManager to send/receive email and, if
     * syncContacts is true, also to update the address book.
     * NOTE: if the contact sync is disabled in the config,
     *       the contact sync is not started, regardless of the value of
     *       the parameter syncContacts.
     *
     * @param syncMode the mode of the sync, as defined in SyncML class.
     *                 If the value -1 is passed, the default
     *                 value defined for the source will be used.
     * @param syncContacts true if the SyncTaskManager should sync
     *                     the contacts too.
     */
    public static void sync(int syncMode, boolean syncContacts) {
        
        //Log.debug("Sync starting...");
        try {
            SyncTaskManager stm = getSyncTaskManager();
            if(syncMode != -1) {
                stm.setSyncMode(syncMode);
            }
            stm.setResetContacts(syncContacts);
            stm.setSyncMessages(true);
            //     Log.info(">>stm prepared: "+Runtime.getRuntime().freeMemory());
            
            stm.addObserver(new MessageListUpdater());
            getThreadPool().startThread(stm);
            //      Log.info(">>stm started: "+Runtime.getRuntime().freeMemory());
            
        } catch (Exception e) {
            e.printStackTrace();
            Log.error("UIController.sync: " + e.toString());
        }
        //Log.debug("Thread for sync started...");
        
    }
    
    public static void sendLaterMessage(Message message) {
        try {
            /*
             * this is to avoid that a message in the Outbox once edited and
             * saved (i.e. stored in the Drafts) remains in the Outbox while
             * it is in the Drafts
             */
            if (message.getParent() != null) {
                if ("/Drafts".equals(message.getParent().getFullName()))
                    getFolderInfo(messageManager.DRAFTS).getFolder().deleteMessage(message);
            }
            message.setSentDate(new Date());
            message.setReceivedDate(new Date());
            getFolderInfo(messageManager.OUTBOX).getFolder().appendMessage(message);
            //Log.debug("Message moved to outbox: "+ message.getParent().getName());
        } catch (Exception ex) {
            Log.error("SendLaterMessage: " + ex.toString());
            ex.printStackTrace();
        }
        //updateOutboxMessageList(message);
        //updateDraftMessageList(message);
        //updateInboxMessageList(null);   //XXX why this???
        
        showAlert(
                Localization.getMessages().COMPOSE_MESSAGE_FORM_SAVED_TO_OUTBOX,
                getInboxMessageList());
        
        // destroyAddressList();
    }
    
    public static void saveMessage(Message message) {
        try {

⌨️ 快捷键说明

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