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

📄 funcanvascontactlist.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * 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.Address;
import com.funambol.mail.MailException;
import com.funambol.mail.Message;
import com.funambol.mailclient.Cache;
import com.funambol.mailclient.cm.Contact;
import com.funambol.mailclient.cm.ContactManagerException;
import com.funambol.mailclient.sm.SyncClient;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.ui.controller.UIThreadPoolMonitor;
import com.funambol.mailclient.ui.utils.UiUtils;
import com.funambol.mailclient.loc.Localization;
import com.funambol.util.Log;
import com.funambol.util.StringUtil;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.rms.RecordStoreException;

public class FunCanvasContactList extends FunCanvasList implements Runnable {
    
    /**
     * none is composed by Address.TO|Address.CC|Address.BCC
     **/
    public static final int NONE=Address.TO|Address.CC|Address.BCC;
    
    // margin constants
    private static final int V_MARGIN =3;
    private static final int H_MARGIN =5;
    
    private static Font labelFont;
    private static Font titleFont;
    
    private Drawer drawer;
    
    private Font font;
    
    private GraphicalTheme graphicalTheme;
    
    private ContactItem[] contactItems;
    
    private String[] searchString;
    
    /**
     * the message from wich the recipients are shown and to which the
     * recipients are set
     */
    private Message message;
    
    /**
     * the number to be shown in the upper left corner,
     */
    private int contactCount;
    
    
    private Command syncCommand;
    
    private Command searchCommand;
    
    private Command addContactCommand;
    
    private Command okCommand;
    
    private Command selectCommand;
    
    private Command editContactCommand;
    
    private Command deleteContactCommand;
    
    private Command saveContactCommand;
    
    private Command resetContactsCommand;
    
    
    /**
     * the contact loader. we need only one of this, sort of singleton.
     */
    private RMSContactLoader rmsContactLoader;
    
    
    public FunCanvasContactList() {
        this( new Message() );
        
    }
    
    /** Creates a new instance of FunCanvasContactList with the given message */
    public FunCanvasContactList(Message message) {
        super();
        this.message = message;
        this.drawer = UIController.getDrawer();
        this.font = drawer.getGraphicalTheme().getDefaultFont();
        this.labelFont = drawer.getGraphicalTheme().getBoldFont();
        this.titleFont = drawer.getGraphicalTheme().getTitleFont();
        this.graphicalTheme = drawer.getGraphicalTheme();
        setContactCount(getRmsCount());
        setTitle(getDefaultTitle());
        setCommandListener(this);
        initializeContactList();
//        keyMapper = new KeyMapper();
    }
    
    
    
    /**
     * reset the contact list using the given message.
     * @param message the message
     */
    public void resetContactList(Message message) {
        this.message = message;
        setContactCount(getRmsCount());
        setTitle(getDefaultTitle());
        contactItems=null;
        searchString = null;
        initializeContactList();
    }
    /**
     * @return the default title
     */
    public String getDefaultTitle() {
        return Localization.getMessages().SELECT_RECIPIENTS;
    }
    
    int paintElement(int elementId, Graphics g) {
        int h = 0;
        //can be null if trying to paint during a sync
        //Log.debug("painting element " + elementId);
        if (contactItems[elementId]!=null) {
            g.translate(0,current_paint_h);
            h=contactItems[elementId].paint(g) ;
            g.translate(0, -current_paint_h);
        }
        return h;
    }
    
    
    
    
    void handleKey(int keyCode) {
        //  Log.debug("Key!");
        if(getGameAction(keyCode)==Canvas.LEFT) {
            //  Log.debug("Left!");
            if (contactItems[getActiveElement()].hasMultipleEmails()) {
                contactItems[getActiveElement()].toPreviousEmail();
            } else {
                scroll(-1);
            }
            repaint();
        } else if (getGameAction(keyCode) == Canvas.RIGHT ) {
            //   Log.debug("Right!");
            if (contactItems[getActiveElement()].hasMultipleEmails()) {
                contactItems[getActiveElement()].toNextEmail();
            } else {
                scroll(1);
            }
            repaint();
        }
        /*
            Log.debug("keycode= " + keyCode + ", gameAction= " + getGameAction(keyCode) +
                    ", keyname= " + getKeyName(keyCode) + " Char: " +  (char) keyCode);
            keyMapper.addKey(keyCode);
            searchString= keyMapper.getStrings();
         
         */
    }
    
    /**
     * empty the search string
     */
    public void emptySearchString() {
        
        String[] s = new String[1];
        s[0]="";
        setSearchString(s);
        
    }
    
    void initCommands() {
        
        okCommand =
                new Command(Localization.getMessages().AL_OK_COMMAND,
                UIController.COMMAND_TYPE,5);
        addContactCommand =
                new Command(Localization.getMessages().AL_ADD_CONTACT_COMMAND,
                UIController.COMMAND_TYPE,30);
        searchCommand =
                new Command(Localization.getMessages().AL_SEARCH_COMMAND,
                UIController.COMMAND_TYPE, 40);
        syncCommand =
                new Command(Localization.getMessages().AL_SYNC_COMMAND,
                UIController.COMMAND_TYPE, 40);
        resetContactsCommand=
                new Command(Localization.getMessages().RESET_CONTACTS_COMMAD,
                UIController.COMMAND_TYPE, 45);
        selectCommand =
                new Command(Localization.getMessages().SELECT_COMMAND,
                UIController.COMMAND_TYPE,20);
        editContactCommand =
                new Command(Localization.getMessages().EDIT_COMMAND_LABEL,
                UIController.COMMAND_TYPE, 50);
        deleteContactCommand =
                new Command(Localization.getMessages().DELETE_COMMAND_LABEL,
                UIController.COMMAND_TYPE, 60);
        saveContactCommand  =
                new Command(Localization.getMessages().ABF_SAVE_CONTACT_COMMAND,
                UIController.COMMAND_TYPE, 70);
        
    }
    
    void addCommands() {
        
        addCommand(UIController.cancelCommand);
        
        // Do not show "Ok" until a contact is selected in TO
        // Now "addCommand(okCommand);" is in toNextState() and in addAddress
        // methocs in the ContactItem class
        //addCommand(okCommand);
        
        addCommand(addContactCommand);
        addCommand(searchCommand);
        
        if (!SyncClient.isBusy()){
            addCommand(syncCommand);
            addCommand(resetContactsCommand);
            
        }
    }
    
    
    /**
     * called when the contact list is set to a non empty list
     * removes item-specific commands
     */
    void removeItemCommands() {
        removeCommand(selectCommand);
        removeCommand(editContactCommand);
        removeCommand(deleteContactCommand);
        setFireCommand(null);
    }
    /**
     * called when the contact list is set to a non-empty list.
     * adds item-specific commands
     */
    void addItemCommands() {
        addCommand(selectCommand);
        addCommand(editContactCommand);
        addCommand(deleteContactCommand);
        setFireCommand(selectCommand);
    }
    
    void paintBackground(Graphics graphics) {
        drawer.drawCanvasBackground(graphics, getWidth(), getHeight());
    }
    
    /**
     * paint the title
     * @return the height of the painted area
     */
    public int paintTitle(Graphics g) {
        
        //  Log.debug("paint title!");
        
        String s;
        String title = getTitle();
        
        // keep this because otherwhise some motorola phones may throw a
        // nullpointer exception
        //TODO: check if still true when using canvas!
        if (title == null){
            //    Log.debug("title null... setting to empty string");
            title ="";
        }
        int num = Math.max(elements.length, contactCount);
        if (elements.length > 0) {
            s = " " + (getActiveElement()+1) + "/" + num;
        } else if (num == 0){
            s = " (Empty)";
        } else {
            s = " " + num;
        }
        int sWidh = titleFont.stringWidth(s);
        
        String shortTitle = UiUtils.cutString(title,getWidth()-sWidh,titleFont);
        drawer.drawTitleBackground(g,getWidth(), titleFont.getHeight());
        g.setFont(titleFont);
        g.setColor(drawer.getGraphicalTheme().getTitleColor());
        //not using drawTitle because we need to draw also the number of messages
        g.drawString(shortTitle,0,0,Graphics.TOP | Graphics.LEFT);
        g.drawString(s, getWidth(),0,Graphics.TOP | Graphics.RIGHT);
        return drawer.getGraphicalTheme().getTitleFont().getHeight();
    }
    
    /**
     * @return true if element is activable.
     *
     */
    boolean isActivable(int elementId) {
        return isVisible(elementId);
    }
    
    /**
     * @return true if element must be shown, i.e. if is selected or if
     * valid for the search performed ( if the contact first name, last name or visiblename
     * starts for one of the given strings, the element is visible )
     */

⌨️ 快捷键说明

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