📄 contactitem.java
字号:
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* 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 Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
package com.funambol.mailclient.ui.view;
import com.funambol.mail.Address;
import com.funambol.mail.MailException;
import com.funambol.mailclient.cm.Contact;
import com.funambol.mailclient.loc.Localization;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.ui.utils.UiUtils;
import com.funambol.util.Log;
import com.funambol.util.StringUtil;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
* a class that describes a contactitem objec.
* this class provides methods for handling the state of the contact
* (unselected, selected as TO, CC, BCC), for managing the selected email address
* (default, secondary or tertiary address), for creating an Address from the
* ContactItem and for painting the contactitem on a given graphics object
*/
public class ContactItem {
/**
* ADDRESS_STATE_NONE is composed by Address.TO|Address.CC|Address.BCC and shifted.
* this way we're sure that ADDRESS_STATE_NONE is different from each of Address.TO,
* Address.CC, Address.BCC
*/
public static final int ADDRESS_STATE_NONE=( Address.TO | Address.CC | Address.BCC ) <<1;
/**
* current state of the contact. one of ContactItem.ADDRESS_STATE_NONE, Address.TO,
* Address.CC, Address.BCC
*/
private int state;
/**
* the contact
*/
private Contact contact;
/**
* the selected email index.
* one of Contact.DEFAULT_EMAIL, Contact.SECONDARY_EMAIL,
* Contact.TERTIARY_EMAIL
*
*/
private int selectedEmailIndex;
/**
* the height of this contact items
*/
private int height;
/**
* the horizontal margin used while painting the contactItem
*/
private int H_MARGIN = 5;
/**
* the vertical margin used while painting the contactItem
*/
private int V_MARGIN = 3;
/**
* the drawer used for background painting
*/
private Drawer drawer;
/**
* the graphical theme used for colors and font
*/
private GraphicalTheme graphicalTheme;
/**
* standard font
*/
private Font font;
/**
* label font
*/
private Font labelFont;
/**
* max label (TO:, CC:, BCC:) width in pixel, used for
* correct spacing
*/
private int maxLabelWidth;
/**
* is this contact active?
*/
private boolean active;
private boolean lastActive;
/**
* Creates a new instance of ContactItem with state=ADDRESS_STATE_NONE
* and selectedEmail = Contact.DEFAULT_EMAIL. This is exactly the same
* as calling ContactItem(c, ContactItem.ADDRESS_STATE_NONE, Contact.DEFAULT_EMAIL
*/
public ContactItem(Contact c) {
this(c, ADDRESS_STATE_NONE, Contact.DEFAULT_EMAIL);
}
/**
* create a new ContactItem with given data
*
*
* @param contact the contact
* @param state one of Address.TO Address.CC Address.BCC or
* FunCanvasContactList.ADDRESS_STATE_NONE
* @param selectedEmail one of Contact.DEFAULT, Contact.SECONDARY_EMAIL
* or Contact.TERTIARY_EMAIL
*/
public ContactItem(Contact c, int state, int selectedEmail) {
this.contact = c;
this.state = state;
this.selectedEmailIndex = selectedEmail;
this.drawer = UIController.getDrawer();
this.graphicalTheme = drawer.getGraphicalTheme();
this.font = drawer.getGraphicalTheme().getDefaultFont();
this.labelFont = drawer.getGraphicalTheme().getBoldFont();
}
/**
* change the state of the item the the next one. <br>
* sequence is ADDRESS_STATE_NONE -> TO -> CC -> BCC -> ADDRESS_STATE_NONE ...
*
* @return the state at the end of the method call, as one of
* <ul>
* <li>ADDRESS_STATE_NONE</li>
* <li>Address.TO</li>
* <li>Address.CC</li>
* <li>Address.BCC</li>
* </ul>
*/
public int toNextState() {
switch (state) {
case ADDRESS_STATE_NONE:
state=Address.TO;
break;
case Address.TO:
state=Address.CC;
break;
case Address.CC:
state=Address.BCC;
break;
case Address.BCC:
state=ADDRESS_STATE_NONE;
break;
default:
state=ADDRESS_STATE_NONE;
}
return state;
}
/**
* cycle to the next email changing the value of selectedImailIndex
* sequence is
* DEFAULT_EMAIL -> SECONDARY_EMAIL -> TERTIARY_EMAIL -> DEFAULT_EMAIL
*/
public void toNextEmail() {
//we know we have at least 2 emails, and we have defaultemail
switch (selectedEmailIndex) {
case Contact.DEFAULT_EMAIL:
if (! StringUtil.isNullOrEmpty( contact.getEmail_2()) ) {
selectedEmailIndex = Contact.SECONDARY_EMAIL;
} else {
selectedEmailIndex = Contact.TERTIARY_EMAIL;
}
break;
case Contact.SECONDARY_EMAIL:
if (! StringUtil.isNullOrEmpty( contact.getEmail_3()) ) {
selectedEmailIndex = Contact.TERTIARY_EMAIL;
} else {
selectedEmailIndex = Contact.DEFAULT_EMAIL;
}
break;
default: //tertiary or unknown cases
selectedEmailIndex = Contact.DEFAULT_EMAIL;
break;
}
}
/**
* cycle to the previous email changing the value of selectedImailIndex.
* Sequence is:
* DEFAULT_EMAIL -> TERTIARY_EMAIL -> SECONDARY_EMAIL -> DEFAULT_EMAIL
*
*/
public void toPreviousEmail() {
switch (selectedEmailIndex) {
case Contact.DEFAULT_EMAIL:
if (! StringUtil.isNullOrEmpty( contact.getEmail_3()) ) {
selectedEmailIndex = Contact.TERTIARY_EMAIL;
} else {
selectedEmailIndex = Contact.SECONDARY_EMAIL;
}
break;
case Contact.TERTIARY_EMAIL:
if (! StringUtil.isNullOrEmpty( contact.getEmail_2()) ) {
selectedEmailIndex = Contact.SECONDARY_EMAIL;
} else {
selectedEmailIndex = Contact.DEFAULT_EMAIL;
}
break;
default: //secondary and unknown
selectedEmailIndex = Contact.DEFAULT_EMAIL;
break;
}
}
/**
* @return the contact in use.
*/
public Contact getContact() {
return contact;
}
/**
* @return the address or null if no email is selected
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -