contactlist.java
来自「moblie syncml mail javame」· Java 代码 · 共 1,147 行 · 第 1/3 页
JAVA
1,147 行
resetContactsCommand =
new Command(Localization.getMessages().RESET_CONTACTS_COMMAD,
UIController.COMMAND_TYPE, 80);
saveContactCommand =
new Command(Localization.getMessages().ABF_SAVE_CONTACT_COMMAND,
UIController.COMMAND_TYPE, 70);
cancelCommand = new Command(Localization.getMessages().CANCEL_COMMAND, Command.BACK, 90);
//callCommand =
// new Command(Localization.getMessages().CALL_NUMBER_COMMAND,
// callCmdType, 1);
}
protected void addCommands() {
super.addCommands();
addCommand(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);
// be sure to have not null addContactCommand
if (addContactCommand != null) {
addCommand(addContactCommand);
}
enableSyncCommand(UIController.isSyncPermitted());
}
/**
* called when the contact list is set to a non empty list
* removes item-specific commands
*/
void removeItemCommands() {
removeCommand(selectCommand);
removeCommand(editContactCommand);
removeCommand(deleteContactCommand);
//#ifdef isBlackberry
//# if (toContactCommand != null) {
//# removeCommand( toContactCommand );
//# }
//# if (ccContactCommand != null) {
//# removeCommand( ccContactCommand );
//# }
//# if (bccContactCommand != null) {
//# removeCommand( bccContactCommand );
//# }
//# if (clearContactCommand != null) {
//# removeCommand( clearContactCommand );
//# }
//#endif
setFireCommand(null);
//#ifdef searchform
//# removeCommand(searchCommand);
//#endif
}
/**
* called when the contact list is set to a non-empty list.
* adds item-specific commands
*/
protected void addItemCommands() {
//#ifdef isBlackberry
//# if (toContactCommand != null) {
//# addCommand( toContactCommand );
//# setFireCommand( toContactCommand );
//# }
//# if (ccContactCommand != null) {
//# addCommand( ccContactCommand );
//# }
//# if (bccContactCommand != null) {
//# addCommand( bccContactCommand );
//# }
//# if (clearContactCommand != null) {
//# addCommand( clearContactCommand );
//# }
//#else
addCommand(selectCommand);
setFireCommand(selectCommand);
//#endif
addCommand(editContactCommand);
addCommand(deleteContactCommand);
//#ifdef searchform
//# addCommand(searchCommand);
//#endif
}
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();
// Use method getFunTitle instead getTitle for
// double titlebar in Nokia S40
String title = getFunTitle();
// 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.size(), contactCount);
if (elements.size() > 0) {
s = " " + (getActiveElementId() + 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);
int h = titleFont.getHeight();
g.translate(0, h);
int t = drawSubtitle(g);
g.translate(0, -h);
return h + t;
}
/**
* draw a subtitle giving the users hints about how to use the keypad to
* search contacts
* @param g the Graphincs object to paint on
* @param h the height of the already painted area. drawSubtitle should not
* paint at
* @return the height of the painted area
*/
protected int drawSubtitle(final Graphics g) {
//not drawing if no contacts are present
if (elements.size() == 0) {
return 0;
}
g.setColor(drawer.getGraphicalTheme().getForegroundColor());
for (int i = 0; i < subtitle.length; i++) {
g.drawString(subtitle[i], getWidth() / 2,
drawer.getGraphicalTheme().getTitleFont().getHeight() * i,
Graphics.TOP | Graphics.HCENTER);
}
int h2 = drawer.getGraphicalTheme().getTitleFont().getHeight() * (subtitle.length);
g.drawLine(0, h2, getWidth(), h2);
return h2;
}
/**
* @return true if element is activable.
*/
boolean isActivable(int elementId) {
return isVisible(elementId);
}
/**
* @return true if element must be shown
*/
boolean isVisible(int elementId) {
return true;
}
public void commandAction(Command command, Displayable displayable) {
if (command == cancelCommand) {
//if this is not null, we reset the title
if (UIController.composeMessageScreen != null) {
UIController.getComposeMessageScreen().setDefaultTitle();
}
// we may have some contactitems in the middle of the list
// to a state other than NONE, we need to clear them!
int num = UiUtils.getMessageAddresses(message).size();
for (int i = num; i < elements.size(); i++) {
((ContactItem) elements.elementAt(i)).setState(ContactItem.ADDRESS_STATE_NONE);
}
UIController.showBackScreen();
} // if we have the search command
else if (command == searchCommand) {
UIController.display.setCurrent(new SearchAddressForm(this));
} else if (command == clearSearchCommand) {
// sending a 0 to clear the search
this.handleKey(Canvas.KEY_NUM0);
} else if (command == okCommand) {
// we may have some contacts in the current message that have
// been unselected, we need to put them back in the right position
coll.partialSort(0, UiUtils.getMessageAddresses(message).size(), coll.ALPHABETICALLY);
updateMessageRecipients();
UIController.updateComposeMessageScreen(message);
/*
ContactItemComparator c = getContactItemCollection().getComparator();
getContactItemCollection().setComparator(new StateContactItemComparator());
getContactItemCollection().forceSort();
getContactItemCollection().setComparator(c);
getContactItemCollection().setToBeSorted(false);
*/
UIController.showComposeMessageScreen(
null, UIController.getComposeMessageScreen().subject);
/*
UIController.getThreadPool().startThread(
new Thread() {
public void run() {
Log.debug("Setting coll message");
coll.setMessage(message);
if (coll.isToBeSorted()) {
//Log.debug("Thread sorting contacts");
coll.forceSort();
//Log.debug("finished sorting contacts");
}
}
}
);*/
} else if (command == addContactCommand) {
if (UIController.checkContactListFull()) {
UIController.showErrorAlert(
Localization.getMessages().AB_LIMIT_ERROR_MSG);
return;
}
updateMessageRecipients();
UIController.showAddContactScreen(UIController.display.getCurrent(), this);
} else if (command == syncCommand) {
this.setTitle(Localization.getMessages().FAL_SYNC_IN_PROGRESS);
UIController.setSyncCaller(UIController.USER);
UIController.synchContacts();
} //item command
else if (command == selectCommand) {
if (getActiveContactItem().toNextState() != ContactItem.ADDRESS_STATE_NONE) {
//we can add the ok command
addCommand(okCommand);
} else {
enableDisableOKCommand();
}
;
repaint();
} else if (command == toContactCommand) {
getActiveContactItem().setState(Address.TO);
updateItemContext();
repaint();
} else if (command == ccContactCommand) {
getActiveContactItem().setState(Address.CC);
updateItemContext();
repaint();
} else if (command == bccContactCommand) {
getActiveContactItem().setState(Address.BCC);
updateItemContext();
repaint();
} else if (command == clearContactCommand) {
getActiveContactItem().setState(ContactItem.ADDRESS_STATE_NONE);
updateItemContext();
repaint();
} else if (command == editContactCommand) {
UIController.showEditContactScreen(this, getActiveContact(), this, false);
} else if (command == deleteContactCommand) {
deleteContact();
// removeContactItem(getActiveElementId());
//setContactCount(getRmsCount());
} else if (command == resetContactsCommand) {
ModalPopup popup =
new ModalPopup(Localization.getMessages().RESET_REQUEST,
Localization.getMessages().RESETCONTACTS_MESSAGE,
new ResetContactsPopupAction());
UIController.showModalPopup(popup, this);
} //else if (command == callCommand){
// UIController.phoneCall(getActiveContact(), this);
// }
else {
super.commandAction(command, displayable);
}
}
private void deleteContact() {
Contact contact = getActiveContact();
if (UIController.getConfig().getDeleteConfirmation()) {
ModalPopup popup =
new ModalPopup(Localization.getMessages().POPUP_DELETE_CONTACT_TITLE,
Localization.getMessages().POPUP_DELETE_CONTACT_TEXT,
new DeleteContactPopupAction(contact));
UIController.showModalPopup(popup, this);
} else {
UIController.deleteContact(contact);
// The ContactManager will inform all listeners (including this
// object) that an item has been deleted. But the update
// implementation does not force a repaint, so we must do it here.
repaint();
}
}
private void updateMessageRecipients() {
message.removeAllRecipients(Address.TO);
message.removeAllRecipients(Address.CC);
message.removeAllRecipients(Address.BCC);
Address address;
Vector selected = coll.getSelectedItems();
for (int i = 0; i < selected.size(); i++) {
ContactItem item = (ContactItem) selected.elementAt(i);
address = item.getAddress();
if (address != null) {
// Log.debug("Address: " + address.getEmail());
try {
message.addRecipient(address);
} catch (MailException me) {
Log.error(this, "mail exception updateMessageRecipients:" + me.toString());
me.printStackTrace();
}
}
}
}
/**
* initialize the contact list
*/
public void initializeContactList() {
initializeContactList(ContactItemCollection.ALPHABETICALLY);
}
protected void setContactItemList(final Vector contactItems) {
// Log.debug("Setting new contact item vector of " + contactItems.size() + " elements");
super.setElements(contactItems);
enableDisableOKCommand();
updateItemContext();
repaint();
}
public Contact getActiveContact() {
return getActiveContactItem().getContact();
}
/**
* set the search string array to the given array.
*
* @param string an array containing the strings to be used by
* isVisible function ( if the contact first name, last name or visiblename
* starts for one of the given strings, the element is visible )
*/
public void setSearchString(String string) {
ContactItemFilter oldFilter = coll.getFilter();
String oldString = null;
if (oldFilter == basicFilter) {
// keeping the old string in case we need a rollback
oldString = basicFilter.getSearchString();
}
coll.setFilter(basicFilter);
basicFilter.setSearchString(string);
coll.setToBeFiltered(true);
//#ifdef searchform
//# removeCommand(searchCommand);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?