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

📄 funcanvasinboxmessagelist.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
字号:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 */

package com.funambol.mailclient.ui.view;

import com.funambol.mail.MailException;

import com.funambol.mailclient.Cache;
import com.funambol.mail.MessageFlags;
import com.funambol.mailclient.mm.MessageInfo;
import com.funambol.mailclient.mm.MessageManager;
import com.funambol.mailclient.sm.SyncClient;

import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.loc.Localization;
import com.funambol.util.Log;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.rms.RecordStoreException;


public class FunCanvasInboxMessageList extends FunCanvasMessageList implements Runnable {
    private Command openCommand;
    private Command composeCommand;
    private Command flagCommand;
    private Command unflagCommand;
    private Command foldersCommand;
    private Command settingsCommand;
    private Command aboutCommand;
    private Command exitCommand;
    private Command syncCommand;
    private Command deleteCommand;
    
    private boolean activatedFlagCommand;
    /**
     * if elements.length is < then totalmessageCount, minimumDisplayedMessageCount is
     * displayed in the title bar
     */
    private int minimumDisplayedMessageCount;
    
    /** Creates a new instance of FunInboxMessageList */
    
    
    public FunCanvasInboxMessageList(MessageInfo[] msgInfo) {
        super(msgInfo);
        try {
            setMinimumDisplayedMessageCount(
                    UIController.getFolderInfo(MessageManager.INBOX)
                    .getFolder().getMessageCount());
            
        } catch (MailException ex) {
            Log.error(this, "unable to open inbox for message count");
            ex.printStackTrace();
        }
        if(!SyncClient.isBusy()) {
            enableSyncCommand(true);
        }
    }
    
    /**
     * set the minimum displayed message count
     */
    public void setMinimumDisplayedMessageCount(int count) {
        this.minimumDisplayedMessageCount = count;
        Log.debug(this, "minimum message count set to " + minimumDisplayedMessageCount);
        repaint();
    }
    
    public String getDefaultTitle() {
        //String title = Localization.getMessages("InboxMessageListTitle");
        return "Inbox";
    }
    
    protected void addCommands() {
        addCommand(composeCommand);
        addCommand(foldersCommand);
        
        addCommand(settingsCommand);
        addCommand(aboutCommand);
        
        
        
        //#ifndef Nokia6630
        //#ifndef Nokia6630_T
        //nokia 6630 adds an exit command by default, so we don't need to add our
        addCommand(exitCommand);
        //#endif
        //#endif
        
    }
    
    /**
     * called by implementation when a list of elements with lenght >0 is set
     */
    protected void addItemCommands() {
        addCommand(openCommand);
        addCommand(deleteCommand);
        setFireCommand(openCommand);
    }
    
    /**
     * called by implementation when a list of elements with lenght = 0 is set
     */
    protected void removeItemCommands() {
        removeCommand(flagCommand);
        removeCommand(unflagCommand);
        removeCommand(openCommand);
        removeCommand(deleteCommand);
        setFireCommand(null);
    }
    
    protected int getDisplayedMessageCount() {
        return Math.max(minimumDisplayedMessageCount,elements.length);
    }
    
    public void commandAction(Command command, Displayable displayable) {
        super.commandAction(command, displayable);
        if (command == composeCommand) {
            UIController.composeNewMessage(UIController.display.getCurrent());
        } else if (command == foldersCommand ) {
            UIController.showFolderList(this);
        }  else if (command == settingsCommand) {
            UIController.showSettings(this);
        } else if (command == aboutCommand) {
            UIController.showAbout(this);
            
        } else if (command == exitCommand) {
            
            UIController.midlet.destroyApp(false);
            
        } else if (command == syncCommand) {
            UIController.sync(false);
        }
        // ---- item commands --- //
        else if (command == openCommand) {
            String origTitle = getTitle();
            setTitle("Opening Message...");
            this.repaint();
            this.serviceRepaints();
            UIController.showViewMessageScreen(this, getSelectedMessageInfo());
            setTitle(origTitle);
        } else if (command == flagCommand || command == unflagCommand) {
            UIController.changeFollowUpFlag(getSelectedMessageInfo());
            activate(getActiveElement());
        } else if (command==deleteCommand) {
            FunModalPopup popup =
                    new FunModalPopup(Localization.getMessages().POPUP_DELETE_MESSAGE_TITLE,
                    Localization.getMessages().POPUP_DELETE_MESSAGE_TEXT,
                    new DeletePopupAction(getSelectedMessageInfo()));
            UIController.showModalPopup(popup, this);
        }
    }
    
    protected void initCommands() {
        int syncCmdType = Command.BACK;
//#ifdef Moto
        syncCmdType = UIController.COMMAND_TYPE;
//#endif
//#ifdef Moto_T
        syncCmdType = UIController.COMMAND_TYPE;
//#endif

        openCommand =
                new Command("View",
                UIController.COMMAND_TYPE,8);
        composeCommand =
                new Command("Compose",
                UIController.COMMAND_TYPE, 10);
        foldersCommand =
                new Command("Folders",
                UIController.COMMAND_TYPE,40);
        settingsCommand =
                new Command("Options",
                UIController.COMMAND_TYPE,50);
        aboutCommand =
                new Command("About",
                UIController.COMMAND_TYPE,60);
        exitCommand =
                new Command("Exit",
                UIController.COMMAND_TYPE,70);
        syncCommand =
                new Command("Get Mail", syncCmdType, 5);
        deleteCommand =
                new Command("Delete",
                UIController.COMMAND_TYPE,20);
        flagCommand =
                new Command(Localization.getMessages().FLAG_COMMAND_LABEL,
                UIController.COMMAND_TYPE,30);;
                unflagCommand =
                        new Command(Localization.getMessages().UNFLAG_COMMAND_LABEL,
                        UIController.COMMAND_TYPE,30);;
    }
    
    public void run() {
        displayInboxMessageList(false);
    }
    
    public void setMessageInfoList(MessageInfo[] msgInfoList) {
        super.setMessageInfoList(msgInfoList);
        setMinimumDisplayedMessageCount(0);
    }
    
    
    /**
     * display the inbox message list reloading messages from RMS
     * @param resetTitle if true the title is set to the default title
     * 
     */
    public void displayInboxMessageList(boolean resetTitle) {
        setMessageInfoList(UIController.getSortedMessageInfo(
                UIController.getFolderInfo(MessageManager.INBOX)));
        
        if (resetTitle) {
            resetTitle();
        }
        
        UIController.display.setCurrent(this);
    }
    
    protected void handleKey(int keyCode) {
        if (keyCode == KEY_STAR) {
            if(activatedFlagCommand)
                commandAction(flagCommand, this);
            else
                commandAction(unflagCommand, this);
        }
    }

    public void saveSnapshot() {
        try {
            Cache.saveMsgSnapShot(Cache.INBOX, getMessageInfoList());
        } catch (Exception ex) {
            ex.printStackTrace();
            Log.error("UIController: error saving snapshot: " + ex.toString());
        }
    }
    
    protected void activate(int activeElement){
        super.activate(activeElement);
        boolean activeMessageFlag = false;
        
        MessageInfo m = getSelectedMessageInfo();
        if ( m != null )  {
            activeMessageFlag = m.flags.isSet(MessageFlags.FLAGGED);
            removeCommand(flagCommand);
            removeCommand(unflagCommand);
            if( activeMessageFlag){
                activatedFlagCommand = false;
                addCommand(unflagCommand);
            } else{
                activatedFlagCommand = true;
                addCommand(flagCommand);
            }
        }
    }
    
    
    public void updateMessageFlags(String msgId, MessageFlags flags) {
        int p = search(msgId);
        if (p>=0) {
            // Log.debug(this, "updating message flags for message " + msgId);
            getMessageInfoAt(p).flags = flags;
            repaint();
        } else {
            // Log.debug(this, "message " + msgId + " not found");
        }
    }
    /**
     * enable or disable the sync command and the reset inbox command
     * @param enable if true enable the command, if false disable the commands
     */
    public void enableSyncCommand(boolean enable) {
        if (enable) {
            addCommand(syncCommand);
        } else {
            removeCommand(syncCommand);
        }
    }
}

⌨️ 快捷键说明

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