contactlist.java
来自「moblie syncml mail javame」· Java 代码 · 共 1,147 行 · 第 1/3 页
JAVA
1,147 行
//# addCommand(clearSearchCommand);
//#endif
try {
this.setElements(coll.getItems(coll.NONE));
setSubtitle(Localization.getMessages().ZERO_TO_CLEAR);
} catch (NoMatchingContactsException ex) {
Log.info("no matching contacts found, doing nothing");
this.setSubtitle(Localization.getMessages().NO_MATCHING_RESULTS);
//rollback
coll.setFilter(oldFilter);
//#ifdef searchform
//# removeCommand(clearSearchCommand);
//# addCommand(searchCommand);
//#endif
if (oldString != null) {
// if we're here we have set the filter back to basicfilter, so
// we can set the string back to what it was
basicFilter.setSearchString(oldString);
}
}
rewindList();
repaint();
}
/**
* add an address to the list of the message recipients
* @param address the adderss to be added
*/
public void addAddress(Address address) {
ContactItemComparator oldComparator = coll.getComparator();
try {
// apart from this new address, the contact
// list is sorted, so we don't need to use the complete sorter
// but we can just use the one based on the state of the items
message.addRecipient(address);
coll.addAddress(address);
addCommand(okCommand);
} catch (MailException ex) {
ex.printStackTrace();
Log.error("Unable to add recipient " + address.getEmail() + "to message");
} finally {
SortByState();
}
}
/**
* calls resetHeight() method of the active contact item.
* This need to be called when the active elements height should be
* recalculated, maybe because a secondary email address has been added
*/
void resetActiveElementHeight() {
getActiveContactItem().resetHeight();
}
// check if we should add or remove the ok command.
// ok command is added if there is at least one
protected void enableDisableOKCommand() {
if (elements.size() == 0) {
removeCommand(okCommand);
return;
}
// check current selected item before, since it has higher probability
// of being a recipient
if (getActiveContactItem().getState() != ContactItem.ADDRESS_STATE_NONE) {
addCommand(okCommand);
return;
}
// check each item
for (int i = 0; i < elements.size(); i++) {
if (((ContactItem) elements.elementAt(i)).getState() != ContactItem.ADDRESS_STATE_NONE) {
addCommand(okCommand);
break;
} else {
// no contact is in TO, CC or BCC. booo!
removeCommand(okCommand);
}
}
}
// return contact count
private int getRmsCount() {
return UIController.getContactManager().getContactCount();
}
/**
* set the contact count to be shown in the upper left corner
* @param count the contact count to be shown in the upper left corner,
* if a negative number is passed, the contact count used will be the
* total number of contacts in rms
*/
public void setContactCount(int count) {
if (count < 0) {
count = getRmsCount();
}
contactCount = count;
}
/**
* enable or disable the sync command and the reset contacts command
* @param enable if true enable the command, if false disable the command
*/
public void enableSyncCommand(boolean enable) {
Log.debug(this, "Enable sync commands: " + enable);
if (enable) {
//These are null when viewing an email's contacts. Perform null check.
if (syncCommand != null) {
addCommand(syncCommand);
}
if (resetContactsCommand != null) {
addCommand(resetContactsCommand);
}
} else {
removeCommand(syncCommand);
removeCommand(resetContactsCommand);
}
}
/**
* if the given contact is in the list, it is set as the active element.
* @param contact the contact that must be set as active element
*
*/
public void activateElement(Contact contact) {
int id = -1;
for (int i = 0; i < elements.size(); i++) {
if (((ContactItem) elements.elementAt(i)).getContact().getDefaultEmail().equals(contact.getDefaultEmail())) {
id = i;// contactItems.elementAt(i).getElementID();
break;
}
}
if (id > 0) {
setActiveElement(id);
}
}
/**
* Scan the contact list looking for a contact with given
* email addres as the default email
* @param email is the given contact mail
* @return the Contact with the give email address , or null if
* the contact is not present
*/
public Contact exists(String email) {
for (int i = 0; i < elements.size(); i++) {
if (((ContactItem) elements.elementAt(i)).getContact().getDefaultEmail().equals(email)) {
return ((ContactItem) elements.elementAt(i)).getContact();
}
}
return null;
}
/**
* remove the specified contat item from the
* contactitem vector.
* @param toRemove the position of the item
* to be removed in the elemnts vector
*/
private void removeContactItem(int toRemove) {
elements.removeElementAt(toRemove);
if (elements.size() < 1) {
removeItemCommands();
}
}
// is given element active?
private boolean isActive(int elementId) {
return elementId == getActiveElementId();
}
//return contact item collection
private ContactItemCollection getContactItemCollection() {
if (coll == null) {
// Log.debug("Creating contactitemCollection for the very first time");
coll = new ContactItemCollection(message);
coll.setListener(this);
coll.setFilter(t9);
}
return coll;
}
/**
* set the contact list message. contact list is updated and resorted.
* if message has no recipients, contact list is sortted alphabetically,
* otherwhise is sorted based on the state of the items
*/
public void setMessage(Message message) {
this.message = message;
getContactItemCollection().setMessage(message);
if (UiUtils.getMessageAddresses(message).size() == 0) {
initializeContactList(ContactItemCollection.ALPHABETICALLY);
} else {
initializeContactList(ContactItemCollection.BY_STATE);
}
}
/**
*sort the contact items alphabetically
*/
public void SortAlphabetically() {
Sort(ContactItemCollection.ALPHABETICALLY);
}
/**
* sort the contact list in alpabetical or state order
*
*/
private void Sort(int mode) {
try {
setContactItemList(coll.getItems(mode));
} catch (NoMatchingContactsException ex) {
ex.printStackTrace();
setContactItemList(new Vector());
}
}
/**
*sort the contact items by state
*/
public void SortByState() {
Sort(ContactItemCollection.BY_STATE);
}
/**
* called when an update happens.
* used to add and remove item commands if needed
*/
// TODO: think about the repaints. on add, remove and edit we should repaint
// the items, but check that the elements vector is really in sync with the
// contactitemscollection vector.
public void update(ContactItemCollectionEvent event) {
switch (event.getEventCode()) {
case ContactItemCollectionEvent.EVENT_CODE_ADD_CONTACTITEM:
case ContactItemCollectionEvent.EVENT_CODE_SORT_CONTACTITEM_LIST:
case ContactItemCollectionEvent.EVENT_CODE_FILTER_CONTACTITEM_LIST:
Log.info("contactlist: end filtering event received");
if (elements.size() > 0) {
removeItemCommands();
addItemCommands();
// Log.info("adding item commands");
}
break;
case ContactItemCollectionEvent.EVENT_CODE_DELETE_CONTACTITEM:
if (elements.size() == 0) {
removeItemCommands();
// Log.info("removing item commands");
}
break;
case ContactItemCollectionEvent.EVENT_CODE_RESET_CONTACTITEM_LIST:
removeItemCommands();
if (elements.size() > 0) {
addItemCommands();
}
// Log.info("removing item commands due to reset");
break;
default:
// Log.info("Update notify received, code is " + event.getEventCode());
break;
}
}
public void activate(int newActiveElement) {
super.activate(newActiveElement);
//setCallCommand();
}
/* private void setCallCommand() {
removeCommand(callCommand);
if (elements.size() > 0) {
if (!StringUtil.isNullOrEmpty(getActiveContact().getHomePhone())
|| !StringUtil.isNullOrEmpty(getActiveContact().getJobPhone())
|| !StringUtil.isNullOrEmpty(getActiveContact().getMobilePhone())){
addCommand(callCommand);
}
}
}
*/
/**
* generate current subtitle, based on the state of the contact list.
* subtitle is one array of
* <ul>
* <li>CONTACT_LIST_SEARCHING</li>
* <li>KEYPAD_TO_SEARCH</li>
* <li>ZERO_TO_CLEAR</li>
* </ul>
*/
private String[] generateSubtitle() {
String[] subtitle;
String s;
if (filtering) {
s = Localization.getMessages().CONTACT_LIST_SEARCHING;
} else if (t9.getStrings() == null) {
s = Localization.getMessages().KEYPAD_TO_SEARCH;
}/* else if ( t9.getStrings().size() == 0 && elements.size() == 0) {
s = Localization.getMessages().NO_MATCHING_RESULTS;
}*/ else {
s = Localization.getMessages().ZERO_TO_CLEAR;
}
subtitle = UiUtils.getStringArray(s,
getWidth(), UIController.getDrawer().getGraphicalTheme().getTitleFont());
return subtitle;
}
private void setSubtitle(String subtitle) {
setSubtitle(UiUtils.getStringArray(subtitle, getWidth(),
UIController.getDrawer().getGraphicalTheme().getTitleFont()));
}
private void setSubtitle(String[] subtitle) {
this.subtitle = subtitle;
repaint(0, 0, getWidth(), UIController.getDrawer().getGraphicalTheme().
getTitleFont().getHeight());
}
private void initializeContactList(int sortingMode) {
try {
setContactItemList(getContactItemCollection().getItems(sortingMode));
} catch (NoMatchingContactsException ex) {
Log.info("no matching contact found, using empty vector");
setContactItemList(new Vector());
// ex.printStackTrace();
}
}
/**
* reset the subtitle
*/
public void resetSubtitle() {
setSubtitle(generateSubtitle());
}
//---------------------- ResetContactsPopupAction Class -------------------//
/**
* popupaction to reset contacts
*/
class ResetContactsPopupAction implements PopupAction {
public ResetContactsPopupAction() {
}
public void cancel() {
UIController.showBackScreen();
}
public void confirm() {
// disableSyncCommand(true);
// UIController.enableSyncCommands(false);
UIController.showInboxScreen();
UIController.setSyncCaller(UIController.USER);
UIController.resetContacts();
// UIController.enableSyncCommands(true);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?