📄 inboxmessagelist.java
字号:
foldersCommand =
new Command(Localization.getMessages().FOLDERS_COMMAND_LABEL,
UIController.COMMAND_TYPE, 40);
settingsCommand =
new Command(Localization.getMessages().OPTIONS_COMMAND_LABEL,
UIController.COMMAND_TYPE, 50);
helpCommand =
new Command(Localization.getMessages().HELP_COMMAND_LABEL,
UIController.COMMAND_TYPE, 60);
exitCommand =
new Command(Localization.getMessages().EXIT_COMMAND_LABEL,
UIController.COMMAND_TYPE, 70);
syncCommand = new Command(Localization.getMessages().SYNC_COMMAND_LABEL, syncCmdType, 5);
deleteCommand =
new Command(Localization.getMessages().DELETE_COMMAND_LABEL,
UIController.COMMAND_TYPE, 20);
flagCommand =
new Command(Localization.getMessages().FLAG_COMMAND_LABEL,
UIController.COMMAND_TYPE, 30);
unflagCommand =
new Command(Localization.getMessages().UNFLAG_COMMAND_LABEL,
UIController.COMMAND_TYPE, 30);
photoCommand =
new Command(Localization.getMessages().PHOTO_COMMAND_LABEL,
UIController.COMMAND_TYPE, 20);
//#ifdef isBlackberry
//# backgroundCommand = new Command(Localization.getMessages().BB_BACKGROUND_COMMAND, Command.BACK, 99);
//#else
backgroundCommand = new Command(Localization.getMessages().STD_BACKGROUND_COMMAND, UIController.COMMAND_TYPE, 69);
//#endif
}
public void run() {
load();
}
public void load() {
/* displayInboxMessageList(false); */
// loading opened and closed image, they'll be probably needed later and
// this minimize the empty inbox for devices like nokia 6630
Theme.getImageFromFlags(MessageFlags.OPENED);
Theme.getImageFromFlags(0);
isLoadingMessages = true;
int i = 0;
MessageManager mm = MessageManager.getInstance();
try {
Folder f = mm.getFolder(MessageManager.INBOX);
int tot = f.getMessageCount();
String[] s = {Localization.getMessages().INBOX_LOADING, " "};
Message msg = mm.getFirstMessage(f);
while (msg != null) {
addMessage(msg);
/*if (i == 10) {
UIController.display.setCurrent(this);
}*/
i++;
s[1] = "(" + i + "/" + tot + ")";
UIController.midlet.setSplashPhase(s, 0);
msg = mm.getNextMessage(f);
}
UIController.midlet.setSplashPhase("Opening Inbox", 0);
} catch (Exception e) {
// can happen if a message is deleted while we're in the cycle
Log.error("Exception loading message " + i + " from inbox. " +
"Some messages have probably been deleted.");
e.printStackTrace();
} finally {
setMinimumDisplayedMessageCount(COUNT_NONE);
UIController.display.setCurrent(this);
isLoadingMessages = false;
}
}
/**
* display the inbox message list reloading messages from RMS
* @param resetTitle if true the title is set to the default title
*/
public void displayInboxMessageList(boolean resetTitle) {
setMessageList(UIController.getSortedMessages(MessageManager.INBOX));
if (resetTitle) {
resetTitle();
}
UIController.display.setCurrent(this);
}
protected void handleKey(int keyCode) {
// handle the shortcut to flag a message with KEY_STAR key (*)
Log.debug("keyCode= " + keyCode);
Log.debug("getGameAction(keyCode)= " + getGameAction(keyCode));
if (keyCode == KEY_STAR && !ad.isEnabled()) {
if (activatedFlagCommand) {
commandAction(flagCommand, this);
} else {
commandAction(unflagCommand, this);
}
} /*
//TODO: TOREMOVE once debug is done
//#ifdef isBlackberry
//#
//# else if (keyCode == KEY_NUM1) {
//# Log.debug("saving httpconfig 0 ");
//# BlackberryHelper.saveHttpConfig(0);
//# }
//# else if (keyCode == KEY_NUM2) {
//# Log.debug("saving httpconfig 1 ");
//# BlackberryHelper.saveHttpConfig(1);
//# }
//# else if (keyCode == KEY_NUM3) {
//# Log.debug("saving httpconfig 2 ");
//# BlackberryHelper.saveHttpConfig(2);
//# }
//# else if (keyCode == KEY_NUM4) {
//# Log.debug("saving httpconfig 3 ");
//# BlackberryHelper.saveHttpConfig(3);
//# }
//#endif
/* else if (keyCode == KEY_NUM0) {
Log.debug("forcing disconnect of ctp");
CTPService.getInstance().forceDisconnect();
} else if (keyCode == KEY_NUM8) {
Log.debug("forcing restart of ctp");
CTPService.getInstance().restartService();
} else if (keyCode == KEY_NUM7) {
Log.debug("forcing stop of ctp");
CTPService.getInstance().stopService();
} else if (keyCode == KEY_NUM9) {
Log.debug("forcing start of ctp");
CTPService.getInstance().startService();
}*/ // end TOREMOVE once debug is done
// handle the shortcut to delete a message
else if (UIController.isClearKey(keyCode)) {
deleteMessage();
}
}
protected void keyPressed(int keyCode) {
if (!UIController.isSyncInProgress()) {
setTitle(getDefaultTitle());
}
super.keyPressed(keyCode);
}
protected void activate(int activeElement) {
super.activate(activeElement);
boolean activeMessageFlag = false;
Message m = getSelectedMessage();
if (m != null) {
activeMessageFlag = m.getFlags().isSet(MessageFlags.FLAGGED);
removeCommand(flagCommand);
removeCommand(unflagCommand);
if (activeMessageFlag) {
activatedFlagCommand = false;
addCommand(unflagCommand);
} else {
activatedFlagCommand = true;
addCommand(flagCommand);
}
}
}
public void updateMessageFlags(String msgId, MessageFlags flags) {
int p = search(msgId);
if (p >= 0) {
Message msg = getMessageAt(p);
// Log.debug(this, "updating message flags for message " + msgId);
msg.setFlags(flags);
countUnread();
repaint();
} else {
// Log.debug(this, "message " + msgId + " not found");
}
}
/**
* enable or disable the sync command and the reset inbox command
* @param enable if true enable the command, if false disable the commands
*/
public void enableSyncCommand(boolean enable) {
Log.debug(this, "Enable sync commands: " + enable);
if (enable) {
addCommand(syncCommand);
} else {
removeCommand(syncCommand);
}
}
/**
* @return true if the inbox is loading messages (i.e. the inbox is in the
* run() method)
*/
public boolean isLoadingMessages() {
return isLoadingMessages;
}
/**
* force the ad to move to the next ad
*/
public void toNextAd() {
ad.toNextAd();
}
protected void setElements(Vector messages) {
super.setElements(messages);
countUnread();
}
public void addMessage(Message msg) {
super.addMessage(msg);
countUnread();
}
public void deleteMessageAt(int position) {
super.deleteMessageAt(position);
countUnread();
}
public void paint(Graphics graphics) {
// Since we are repainting the inbox, we consider messages as being read
UserNotificationManager.getInstance().hideNewEmailIcon();
super.paint(graphics);
}
private void countUnread() {
// For performance reasons we do not use the Folder method to count
// the number of messages with the OPENED flag unset. Because that
// would require accessing the storage, while we have the list of
// messages already available here.
int unread = 0;
for (int i = 0; i < elements.size(); ++i) {
Message msg = (Message) elements.elementAt(i);
MessageFlags flags = msg.getFlags();
if (!flags.isSet(MessageFlags.OPENED)) {
++unread;
}
}
UIController.setInboxUnreadCounter(unread);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -