contactlist.java
来自「moblie syncml mail javame」· Java 代码 · 共 1,147 行 · 第 1/3 页
JAVA
1,147 行
/*
* 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.mail.Message;
import com.funambol.mailclient.cm.Contact;
import com.funambol.mailclient.loc.LocalizedMessages;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.ui.utils.UiUtils;
import com.funambol.mailclient.loc.Localization;
import com.funambol.util.Log;
import com.funambol.util.StringUtil;
import com.funambol.util.ThreadPool;
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;
public class ContactList extends List implements
ContactItemCollectionListener {
// 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;
/**
* the message from wich the recipients are shown and to which the
* recipients are set. It's protected to allow access from the
* recipient list
*/
protected Message message;
/**
* the number to be shown in the upper left corner,
*/
private int contactCount;
// commands
private Command syncCommand;
private Command addContactCommand;
private Command okCommand;
private Command selectCommand;
private Command editContactCommand;
private Command deleteContactCommand;
private Command saveContactCommand;
private Command resetContactsCommand;
protected Command toContactCommand;
protected Command ccContactCommand;
protected Command bccContactCommand;
protected Command clearContactCommand;
private Command cancelCommand;
private ContactItemCollection coll;
//private Command callCommand;
private Command searchCommand;
private Command clearSearchCommand;
private T9Search t9;
private BasicContactItemFilter basicFilter;
// are we filtering the contact list?
private boolean filtering = false;
private String[] subtitle;
public ContactList() {
this(new Message());
}
/** Creates a new instance of ContactList with the given message */
public ContactList(Message message) {
super();
this.message = message;
this.drawer = UIController.getDrawer();
this.titleFont = drawer.getGraphicalTheme().getTitleFont();
setSubtitle(Localization.getMessages().KEYPAD_TO_SEARCH);
setTitle(getDefaultTitle());
setCommandListener(this);
t9 = new T9Search();
basicFilter = new BasicContactItemFilter();
initializeContactList();
}
/*
* Used to add/remove menu commands based on the current selection.
* @see com.funambol.mailclient.ui.view.FunCanvasList#updateItemContext()
*/
protected void updateItemContext() {
//Null check
if (getActiveContactItem() == null) {
return;
}
//Happens when we are viewing contacts in an email.
if (clearContactCommand == null || bccContactCommand == null ||
ccContactCommand == null || toContactCommand == null) {
return;
}
//#ifdef isBlackberry
//# //For BlackBerry
//# //Start with all item commands. Remove ones we do not want.
//# addItemCommands();
//# switch (getActiveContactItem().getState()) {
//# case ContactItem.ADDRESS_STATE_NONE: {
//# removeCommand( clearContactCommand );
//# enableDisableOKCommand();
//# break;
//# }
//# case Address.BCC: {
//# removeCommand( bccContactCommand );
//# addCommand( okCommand );
//# addCommand( clearContactCommand );
//# break;
//# }
//# case Address.CC: {
//# removeCommand( ccContactCommand );
//# addCommand( okCommand );
//# addCommand( clearContactCommand );
//# break;
//# }
//# case Address.TO: {
//# removeCommand( toContactCommand );
//# addCommand( okCommand );
//# addCommand( clearContactCommand );
//# break;
//# }
//# }
//#endif
}
/**
* reset the contact list using the given message.
* @param message the message
*/
public void resetContactList(Message message) {
this.message = message;
setContactCount(getRmsCount());
setTitle(getDefaultTitle());
resetSubtitle();
emptySearchString();
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 (elements.elementAt(elementId) != null) {
g.translate(0, current_paint_h);
h = ((ContactItem) elements.elementAt(elementId)).paint(g, isActive(elementId));
g.translate(0, -current_paint_h);
}
return h;
}
public ContactItem getActiveContactItem() {
return (ContactItem) getActiveElement();
}
private boolean isLeftKey(int dir, int keyCode) {
boolean isLeftKey =
((dir == Canvas.LEFT) &&
((keyCode < 0) || (keyCode == Canvas.LEFT)));
return isLeftKey;
}
private boolean isRightKey(int dir, int keyCode) {
boolean isRightKey =
((dir == Canvas.RIGHT) &&
((keyCode < 0) || (keyCode == Canvas.RIGHT)));
return isRightKey;
}
void handleKey(int keyCode) {
int dir = getGameAction(keyCode);
//Spacebar events do not map with getGameAction. Use keycode
//#ifdef isBlackberry
//keycode 32 is spacebar
//# if(keyCode == 32) {
//# if(getActiveContact() != null) {
//# commandAction( toContactCommand, this );
//# }
//# return;
//keycode 10 is enter
//# } else if (keyCode == 10) {
//# if (getActiveContactItem().hasMultipleEmails()) {
//# getActiveContactItem().toNextEmail();
//# }
//# //Keycode 8 is delete on blackberry
//# } else if (keyCode == 8) {
//# if (getActiveContact() !=null) {
//# commandAction( deleteContactCommand,this);
//# }
//# }
//#endif
if (isLeftKey(dir, keyCode)) {
// Log.debug("Left!");
if (getActiveContactItem().hasMultipleEmails()) {
getActiveContactItem().toPreviousEmail();
} else {
scroll(-1);
}
repaint();
return;
} else if (isRightKey(dir, keyCode)) {
// Log.debug("Right!");
if (getActiveContactItem().hasMultipleEmails()) {
getActiveContactItem().toNextEmail();
} else {
scroll(1);
}
repaint();
return;
}
/*
Log.debug("keycode= " + keyCode + ", gameAction= " + getGameAction(keyCode) +
", keyname= " + getKeyName(keyCode) + " Char: " + (char) keyCode);
keyMapper.addKey(keyCode);
searchString= keyMapper.getStrings();
*/
// we set the filter if needed
if (coll.getFilter() == basicFilter) {
// we need to add the current string to the t9 field
t9.setString(basicFilter.getSearchString());
coll.setFilter(t9);
}
// clear
if (UIController.isClearKey(keyCode)) {
coll.getFilter().clear();
coll.setToBeFiltered(true);
//#ifdef searchform
//# removeCommand(clearSearchCommand);
//# addCommand(searchCommand);
//#endif
} else if ((keyCode > 0) && (!isSoftKey(dir, keyCode))) {
Log.info("adding key " + keyCode);
t9.addKey(keyCode);
coll.setToBeFiltered(true);
//#ifdef searchform
//# removeCommand(searchCommand);
//# addCommand(clearSearchCommand);
//#endif
}
if (coll.isToBeFiltered()) {
//repainting only the subtitle
filtering = true;
setSubtitle(generateSubtitle());
repaint();
serviceRepaints();
try {
super.setElements(coll.getItems(coll.NONE));
filtering = false;
setSubtitle(generateSubtitle());
repaint();
rewindList();
} catch (NoMatchingContactsException ex) {
// nothing to do if no contacts has been found
Log.info("No matching contacts found, nothing to change.");
setSubtitle(Localization.getMessages().NO_MATCHING_RESULTS);
repaint();
serviceRepaints();
// ex.printStackTrace();
filtering = false;
}
}
}
protected void paint(Graphics graphics) {
if (graphics.getClipHeight() < getHeight()) {
// cleaning title & subtitle background
Log.info("cleaning background");
graphics.setColor(UIController.getDrawer().getGraphicalTheme().
getBackgroundColor());
//graphics.setColor(0xff0000);
graphics.fillRect(0, 0, graphics.getClipWidth(), graphics.getClipHeight());
paintTitle(graphics);
} else {
super.paint(graphics);
}
}
/**
* empty the search string
*/
public void emptySearchString() {
coll.getFilter().clear();
}
protected void initCommands() {
int callCmdType = Command.BACK;
//#ifdef UseOKCmd
//# callCmdType = UIController.COMMAND_TYPE;
//#endif
okCommand =
new Command(Localization.getMessages().AL_OK_COMMAND,
UIController.COMMAND_TYPE, 5);
selectCommand =
new Command(Localization.getMessages().SELECT_COMMAND,
UIController.COMMAND_TYPE, 6);
toContactCommand = new Command(Localization.getMessages().TO_LABEL, UIController.COMMAND_TYPE, 21);
ccContactCommand = new Command(Localization.getMessages().CC_LABEL, UIController.COMMAND_TYPE, 22);
bccContactCommand = new Command(Localization.getMessages().BCC_LABEL, UIController.COMMAND_TYPE, 23);
clearContactCommand = new Command(Localization.getMessages().REMOVE_CONTACT_COMMAND, UIController.COMMAND_TYPE, 24);
editContactCommand =
new Command(Localization.getMessages().EDIT_COMMAND_LABEL,
UIController.COMMAND_TYPE, 30);
deleteContactCommand =
new Command(Localization.getMessages().DELETE_COMMAND_LABEL,
UIController.COMMAND_TYPE, 40);
searchCommand =
new Command(Localization.getMessages().AL_SEARCH_COMMAND,
UIController.COMMAND_TYPE, 50);
clearSearchCommand =
new Command(Localization.getMessages().AL_CLEAR_SEARCH_COMMAND,
UIController.COMMAND_TYPE, 50);
addContactCommand =
new Command(Localization.getMessages().AL_ADD_CONTACT_COMMAND,
UIController.COMMAND_TYPE, 29);
syncCommand =
new Command(Localization.getMessages().AL_SYNC_COMMAND,
UIController.COMMAND_TYPE, 70);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?