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

📄 uicontroller.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    
    /**
     * displays a edit contact screen and update the given FunAddressList after
     * the edit.
     *
     *
     * @param displayable: the displayable to be pushed in the stack
     * contact: the contact to be edited
     * contactList: the adddresslist to be updated (can be null if not needed)
     */
    public static Displayable showEditContactScreen(Displayable displayable,
            Contact contact, FunCanvasContactList contactList, boolean isNew) {
        backStack.push(displayable);
        Displayable contactForm=new AddContactForm(contact, contactList, isNew);
        UIController.display.setCurrent(contactForm);
        return contactForm;
    }
    
    /**
     * Show an info alert with autodismiss
     */
    public static void showAlert(String message) {
        showAlert(message, AlertType.INFO, true);
    }
    
    /**
     * Show an info alert with autodismiss and a displayable
     * to open after it's been dismissed.
     */
    public static void showAlert(String message, Displayable displayable) {
        showAlert(message, AlertType.INFO, true, displayable);
        
    }
    
    /**
     * Show an error alert without autodismiss
     */
    public static void showErrorAlert(String message) {
        showAlert(message, AlertType.ERROR, false);
    }
    
    /**
     * Show an info alert without autodismiss and a displayable
     * to open after it's been dismissed.
     */
    public static void showErrorAlert(String message, Displayable displayable) {
        showAlert(message, AlertType.ERROR, false, displayable);
    }
    
    /**
     * Show an alert with given message, alert type and autodismiss.
     * This is the generic method called by the others.
     */
    private static void showAlert(String message, AlertType alertType, boolean autoDismiss) {
        Alert messageAlert = getFunambolAlert(message, alertType, autoDismiss);
        display.setCurrent(messageAlert);
    }
    
    /**
     * Show an alert with given message, alert type, autodismiss and next displayable
     */
    public static void showAlert(String message, AlertType alertType,
            boolean autoDismiss, Displayable displayable) {
        Alert messageAlert = getFunambolAlert(message, alertType, autoDismiss);
        display.setCurrent(messageAlert, displayable);
    }
    
    public static void showAbout(Displayable displayable) {
        backStack.push(displayable);
        //display.setCurrent(new AboutForm());
        display.setCurrent(new AboutScreen());
    }
    
    
    /**
     * Utilites methods managing the Model
     */
    
    
    public static void replyMessage(Message message) {
        Message replyMessage=new Message();
        //TODO: exception handling
        try {
            replyMessage.setTo(message.getReplyTo());
            replyMessage.setSubject(RE + message.getSubject());
        } catch (MailException ex) {
            ex.printStackTrace();
            Log.error("unable to set content into reply " +
                    "message, error getting 'from' field from message");
        }
        delayedFlag(message, MessageFlags.ANSWERED);
        updateComposeMessageScreen(replyMessage,getReplyText(message));
        getContactList().emptySearchString();
        showComposeMessageScreen(display.getCurrent(),getComposeMessageScreen().body);
    }
    
    
    
    /**
     * set the message as the original message in composemessagescreen, the next
     * time the send / sendlater commandaction is performed the given flag will
     * be set to true
     *
     * @param message the message to be set as the original message in
     * composemessageform
     *
     * @param flag the flag (one of MessageFlags constants) to be set to true
     */
    private static void delayedFlag(final Message message, final int flag) {
        //Log.debug("UIController: trying to set read message flag");
        //setRepliedFlag(message);
        MessageFlags flags = new MessageFlags();
        flags.setFlags(message.getFlags().getFlags());
        if (!flags.isSet(flag)) {
            flags.setFlag(flag, true);
            getComposeMessageScreen().setFlagsToSet(flags);
            try {
                getComposeMessageScreen().setOriginalMessage(
                        new MessageInfo(message, new FolderInfo(
                        message.getParent().getName(), StoreFactory.getStore())));
            } catch (MailException ex) {
                Log.error("error forwarding message while creating messageinfo " +
                        "from original message");
                ex.printStackTrace();
            }
        }
    }
    
    
    /**
     * create a new forward message and show the compose message screen
     *
     * @param message the message to be forwarded (body content will be appended
     * at the bottom of the email)
     */
    public static void forwardMessage(Message message) {
        
        Message forwardMessage=new Message();
        
        forwardMessage.setSubject(FW + message.getSubject());
        /*try {
            messageManager.updateMessageFlag(message, MessageFlags.FORWARDED, true);
        } catch (MailException ex) {
            Log.error("forwardMessage: "+ex.toString());
            ex.printStackTrace();
        }*/
        
        delayedFlag(message, MessageFlags.FORWARDED);
        UIController.updateComposeMessageScreen(forwardMessage,getForwardText(message));
        getContactList().emptySearchString();
        showComposeMessageScreen(display.getCurrent(), getComposeMessageScreen().recipientStringItem);
        
    }
    
    
    
    /**
     * update the message list that contain the given message
     *
     * @param message the message
     */
    private static void updateMessageList(Message message) {
        if (message.getParent()==null) {
            //updateAllMessageLists(message);
            Log.error("Message without parent");
            return;
        } else {
            if (message.getParent().getName().equals(Store.INBOX)) {
                //Log.debug("UIController: message from inbox, updating inbox");
                updateInboxMessageList(message);
            } else if (message.getParent().getName().equals(Store.OUTBOX)) {
                //Log.debug("UIController: message from outbox, updating outbox");
                updateOutboxMessageList(message);
            } else if (message.getParent().getName().equals(Store.SENT)) {
                //Log.debug("UIController: message from sent, updating sent");
                updateSentMessageList(message);
            }  else if (message.getParent().getName().equals(Store.DRAFTS)) {
                //Log.debug("UIController: message from draft, updating draft");
                updateDraftMessageList(message);
            } else {
                Log.error("Unkown folder");
            }
        }
        
    }
    
    /*
    private static void updateAllMessageLists(Object o) {
        updateInboxMessageList(o);
        updateOutboxMessageList(o);
        updateDraftMessageList(o);
        updateSentMessageList(o);
    }*/
    
    public static void updateMessageList(Object o, int theFolder) {
        FolderInfo folderInfo=getFolderInfo(theFolder);
        FunCanvasMessageList messageList;
        switch ( theFolder ) {
            case MessageManager.INBOX:
                messageList = getInboxMessageList();
                break;
            case MessageManager.OUTBOX:
                messageList = getOutboxMessageList();
                break;
            case MessageManager.DRAFTS:
                messageList = getDraftMessageList();
                break;
            case MessageManager.SENT:
                messageList = getSentMessageList();
                break;
            default:
                messageList = getInboxMessageList();
        }
        if (o == null) {
            messageList.setTitle(messageList.getDefaultTitle());
            messageList.setMessageInfoList(getSortedMessageInfo(folderInfo));
        } else if (o instanceof Message)  {
            messageList.setMessageInfoList(getSortedMessageInfo(folderInfo));
        } else if (o instanceof String) {
            if (o.toString().length() == 0 ) {
                messageList.setTitle(messageList.getDefaultTitle());
            } else {
                messageList.setTitle(o.toString());
            }
        }
        
    }
    
    
    public static void updateDraftMessageList(Object o) {
        updateMessageList(o,MessageManager.DRAFTS);
    }
    
    public static void updateSentMessageList(Object o) {
        updateMessageList(o,MessageManager.SENT);
    }
    
    public static void updateInboxMessageList(Object o) {
        updateMessageList(o,MessageManager.INBOX);
    }
    
    public static void updateOutboxMessageList(Object o) {
        updateMessageList(o,MessageManager.OUTBOX);
    }
//    private static void debug(String s) {
//        Log.debug("UIController:"+ s);
//    }
    
//    private static void error(String s) {
//        Log.error("UIController:"+ s);
//    }
    
    /**
     * open a url.
     *
     * @param url the url to be opened in the default browser (device dependent)
     */
    public static void openUrl(String url) {
        Log.info("Opening url: [" + url + "]");
        try {
            // In Nokia S60 device the platformRequest
            // doesn't open link without "http://"
            if (url.startsWith("www"))
                url = "http://"+url;
            midlet.platformRequest( url);
        } catch (ConnectionNotFoundException ex) {
            ex.printStackTrace();
            Log.error("openUrl: " + ex.toString());
            showErrorAlert("Error opening URL.");
            
        } catch (Exception e) {
            e.printStackTrace();
            Log.error("openUrl: " + e.toString());
        }
        
    }
    
    /**
     * save tha given contact
     *
     * @param contact the contact to be saved
     * @param isNew true if contact is new, false if editing existent contact
     * @trows AlreadyExistentContactException if contact already exists
     */
    public static void saveContact(Contact contact, boolean isNew)
    throws ContactManagerException, AlreadyExistentContactException  {
        if (isNew) {
            contactManager.addContact(contact, true);
        } else {
            contactManager.updateContact(contact);
        }
        showBackScreen();
    }
    
    /** getSortedMessageInfo is synchronized to avoid potential issues
     * on concurrent access to the INbox elements in the storage
     * @return a sorted messageinfo with items from the given folderinfo
     */
    public synchronized static MessageInfo[] getSortedMessageInfo(FolderInfo folder) {
        MessageInfo[] list = null;//new MessageInfo[0];
        try {
            list = folder.getMsgList();
            if (list.length>0) {
                return bubbleSortPerDate(list);
            } else {
                return list;
            }
        } catch (Exception ex) {
            Log.error("Error occurred sorting message list: " + ex.getMessage());
            ex.printStackTrace();
            
            return list;
        }
        
    }
    
    
    /**
     * A sort algorithm to order the messages in the view Inbox as per sent date
     */
    public static MessageInfo[] bubbleSortPerDate(MessageInfo[] list) {
        int n = list.length;
        for (int pass = 1; pass < n; pass++) {  // count how many times
            // This next loop becomes shorter and shorter
            for (int i = 0; i < n-pass; i++) {
                if (list[i].received.getTime() < list[i+1].received.getTime()) {
                    // exchange elements
                    MessageInfo temp = list[i];
                    list[i] = list[i+1];
                    list[i+1] = temp;
                }
            }
        }
        
        return list;
    }
    
    /**
     * Nullify addressList reference (current implementation does NOTHING.
     *
     */
    
    //TODO: remove this ASAP if it's confirmed as useless
    
    public static void destroyAddressList() {
        //    contactList=null;
        
        //   getContactList().resetContactList(new Message());
    }
    
    
    /**
     * reset the account deleting the store and startng a new
     * refresh_from_server sync
     */
    public static void resetAccount() {
        try {
            // For RAZR bug: wait before showing a new displayable
            //UIController.sleep(10);
            //UIController.showAlert(Localization.getMessages().RESETTING_ACCOUNT_MSG);

⌨️ 快捷键说明

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