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

📄 advancedcontactform.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.Address;
import com.funambol.mail.MailException;
import com.funambol.mailclient.cm.ContactManagerException;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.cm.Contact;
import com.funambol.mailclient.loc.Localization;
import com.funambol.util.Log;
import com.funambol.util.StringUtil;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;


/**
 * Form containing the textfield for contact details:
 * First, Second name, second and third emails and phone contacts
 */
public class AdvancedContactForm extends Form implements CommandListener{
    private static final int MAX_TXTFIELD_SIZE=128;
    private Command okCommand =
            new Command(Localization.getMessages().GENERIC_OK, UIController.COMMAND_TYPE,0);
    private TextField txtFirstName =
            new TextField(Localization.getMessages().ACF_CONTACT_FIRSTNAME_LABEL,"",MAX_TXTFIELD_SIZE,TextField.ANY);
    private TextField txtLastName =
            new TextField(Localization.getMessages().ACF_CONTACT_LASTNAME_LABEL,"",MAX_TXTFIELD_SIZE,TextField.ANY);
    private TextField txtEmail2 =
            new TextField(Localization.getMessages().ACF_CONTACT_EMAIL_2_LABEL,"",MAX_TXTFIELD_SIZE,TextField.EMAILADDR);
    private TextField txtEmail3 =
            new TextField(Localization.getMessages().ACF_CONTACT_EMAIL_3_LABEL,"",MAX_TXTFIELD_SIZE,TextField.EMAILADDR);
    //private TextField txtHome =
    //        new TextField(Localization.getMessages().ACF_CONTACT_HOME_LABEL,"",MAX_TXTFIELD_SIZE,TextField.ANY);
    //private TextField txtJob =
    //        new TextField(Localization.getMessages().ACF_CONTACT_JOB_LABEL,"",MAX_TXTFIELD_SIZE,TextField.ANY);
    //private TextField txtMobile =
    //        new TextField(Localization.getMessages().ACF_CONTACT_MOBILE_LABEL,"",MAX_TXTFIELD_SIZE,TextField.ANY);
    private Contact contact;
    
    /**
     * Creates a new instance of AdvancedContactForm starting from a
     * contact passed from addContactForm
     */
    public AdvancedContactForm(Contact contact) {
        super(Localization.getMessages().ACF_ADVANCED_COMMAND_LABEL);
        this.contact=contact;
        this.addCommand(okCommand);
        this.addCommand(UIController.cancelCommand);
        this.setCommandListener(this);
        try {
            if (!StringUtil.isNullOrEmpty(contact.getFirstName())) {
                txtFirstName.setString(contact.getFirstName());
            }
            if (!StringUtil.isNullOrEmpty(contact.getLastName())) {
                txtLastName.setString(contact.getLastName());
            }
            if (!StringUtil.isNullOrEmpty(contact.getEmail_2())) {
                txtEmail2.setString(contact.getEmail_2());
            }
            
            if (!StringUtil.isNullOrEmpty(contact.getEmail_3())) {
                txtEmail3.setString(contact.getEmail_3());
            }
            /*if (!StringUtil.isNullOrEmpty(contact.getHomePhone())) {
                //Log.debug("Home Number: [" + contact.getHomePhone()+"]");
                txtHome.setString(contact.getHomePhone());
            }
            if (!StringUtil.isNullOrEmpty(contact.getJobPhone())) {
                //Log.debug("Job Number: [" + contact.getJobPhone()+"]");
                txtJob.setString(contact.getJobPhone());
            }
            if (!StringUtil.isNullOrEmpty(contact.getMobilePhone())) {
                //Log.debug("Mobile Number: [" + contact.getMobilePhone()+"]");
                txtMobile.setString(contact.getMobilePhone());
            }*/
        } catch (IllegalArgumentException ex) {
            Log.error("illegal argument in contact " + contact.toString());
            ex.printStackTrace();
        }
        append(txtFirstName);
        append(txtLastName);
        append(txtEmail2);
        append(txtEmail3);
        //append(txtHome);
        //append(txtJob);
        //append(txtMobile);
        setCommandListener(this);
    }
    
    private boolean checkEmailField(TextField field) {
        
        return ( StringUtil.isNullOrEmpty( field.getString( )) ||
                ( field.getString().indexOf("@")!=-1 ) &&
                field.getString().length()>2 );
    }
    
    
    public void commandAction(Command command, Displayable displayable) {
        if (command==okCommand) {
            
            if ( checkEmailField(txtEmail2) && checkEmailField(txtEmail3) ) {
                contact.setFirstName(txtFirstName.getString());
                contact.setLastName(txtLastName.getString());
                contact.setEmail_2(txtEmail2.getString());
                contact.setEmail_3(txtEmail3.getString());
                //contact.setHomePhone(txtHome.getString());
                //contact.setJobPhone(txtJob.getString());
                //contact.setMobilePhone(txtMobile.getString());
                UIController.showBackScreen();
            } else {
                UIController.showErrorAlert(
                        Localization.getMessages().INVALID_EMAIL_ADDRESS );
            }
        } else if (command == UIController.cancelCommand) {
            UIController.showBackScreen();
        }
        
    }
    
    
}

⌨️ 快捷键说明

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