📄 uicontroller.java
字号:
}
/**
* init the inbox: calls initmessagemanager, displays
* the inbox with the cached messages, then starts the thread that loads the
* messages from the rms
*
* @return true if the account has been set, false otherwise.
* The account is considered set if the url is different from
* Account.DEFAULT_URL and if the username and password are not empty.
*
*/
public static boolean initInbox() {
boolean accountSet = false;
try {
inboxMessageList = new InboxMessageList(new Vector());
outboxMessageList = null;
draftMessageList = null;
sentMessageList = null;
accountSet = mailClientConfig.getMailAccount().isSet();
// If the account information has been already set
if (accountSet) {
/*display.setCurrent(inboxMessageList);
inboxMessageList.repaint();
inboxMessageList.serviceRepaints();*/
// this starts the thread that load messages from rms
//Thread removed for all devices
//Thread t = threadPool.startThread(inboxMessageList);
//t.setPriority(Thread.MIN_PRIORITY);
inboxMessageList.load();
} else {
Log.info("initInbox: go to account settings.");
// Some devices, like the RAZR, don't show two display
// if the calls to display.setcurrent are too close.
//sleep(10);
showAlert(Localization.getMessages().CONFIG_NOT_SET,
AlertType.INFO, false, getAccountSettingsForm(inboxMessageList));
//showAlert(Localization.getMessages().CONFIG_NOT_SET, getAccountSettingsForm(inboxMessageList));
// setting minimum displayed message count
inboxMessageList.setMinimumDisplayedMessageCount(
InboxMessageList.COUNT_NONE);
}
} catch (Exception ex) {
Log.error("[initInbox] Error: " + ex);
ex.printStackTrace();
}
return accountSet;
}
/**
* Suspend the current thread for the given number of seconds
*
* @param millis the time to wait (milliseconds)
*/
public static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (Exception e) {
Log.error("sleep interrupted.");
}
}
/**
* init the messagemanager and the store
*/
public static void initMessageManager() {
try {
//Log.debug("MessageManager init");
messageManager = MessageManager.getInstance();
initStore(false);
} catch (Exception ex) {
Log.error("UIController: error init MessageManager " + ex);
ex.printStackTrace();
}
}
/**
* init the message store
* @param reset if true the folders will be erased and recreated
*/
public static void initStore(boolean reset) throws MailException {
messageManager.initStore(reset);
if (reset) {
allFolders = null;
}
}
/**
*
* showXXX methods managing the views
*
*/
/**
* This method retrieves the screen to go back from the Stack
*/
public static void showBackScreen() /*throws Exception*/ {
try {
Displayable screen = backStack.pop();
// If the screen is the inbox, cleanup the other screens
if (screen == inboxMessageList) {
showInboxScreen();
} else {
display.setCurrent(screen);
}
} catch (Exception ex) {
Log.error("ShowBackScreen: " + ex.toString());
showInboxScreen();
}
}
/**
* show the current composeMessageScreen, performing no updates. <br/>
* @param backScreen the screen that needs to be bounded to the back button
* in the compose message screen
* @param item the item that will be focused
*
* if you need to update the messagescreen use updateComposeMessageScreen
* functions
**/
public static void showComposeMessageScreen(Displayable backScreen, Item item) {
if (backScreen != null) {
backStack.push(backScreen);
} else {
backStack.push(inboxMessageList);
}
getComposeMessageScreen().setDefaultTitle();
display.setCurrentItem(item);
}
/**
* show the compose message screen ready for a new message to be composed
*/
public static void composeNewMessage(Displayable backScreen) {
if (!contactsLoader.isLocked()) {
Message m = new Message();
getComposeMessageScreen().setMessage(new Message());
// we need to set the message here, because
// composemessagescree.setmessage does not
// (for speed reasons)
getContactList().setMessage(m);
getContactList().emptySearchString();
getContactList().SortAlphabetically();
showContactList(display.getCurrent());
} else {
showErrorAlert(
Localization.getMessages().CONTACTSLOADER_LOCKED_ERROR,
backScreen);
}
}
/**
* update ComposeMessageScreen message.
* the message remains unchanged
**/
public static void updateComposeMessageScreen(Message message) {
getComposeMessageScreen().setMessage(message);
}
/**
* update ComposeMessageScreen toAppend string.
* the toAppend string remains unchanged
**/
public static void updateComposeMessageScreen(String toAppend) {
getComposeMessageScreen().setToAppend(toAppend);
}
/**
* update ComposeMessageScreen toAppend string and message
**/
public static void updateComposeMessageScreen(Message message, String toAppend) {
updateComposeMessageScreen(message);
updateComposeMessageScreen(toAppend);
}
/**
* return the composemessageform and create it if needed
*/
public static ComposeMessageForm getComposeMessageScreen() {
if (composeMessageScreen == null) {
composeMessageScreen = new ComposeMessageForm();
}
return composeMessageScreen;
}
/**
* show the inbox screen, cleaning the stack and freeing not used objects
* and memory
*/
public static void showInboxScreen() {
backStack.clear();
outboxMessageList = null;
sentMessageList = null;
draftMessageList = null;
composeMessageScreen = null;
if (!isSyncInProgress()) {
getInboxMessageList().resetTitle();
}
getInboxMessageList().toNextAd();
display.setCurrent(getInboxMessageList());
//#ifdef low_mem
//# freeMemory();
//#endif
}
/** If the freeMemory is low, try to collect some memory */
public static long freeMemory() {
long mem = Runtime.getRuntime().freeMemory();
if (mem < 10000) {
Log.info(">> freeMemory is low: " + Runtime.getRuntime().freeMemory());
try {
System.gc();
Thread.sleep(1);
} catch (InterruptedException ex) {
// just ignore it
Log.error("interrupted exception freeing memory");
}
mem = Runtime.getRuntime().freeMemory();
}
return mem;
}
/**
* Display the outbox screen.
*/
public static void showOutboxScreen(Displayable backScreen) {
backStack.push(backScreen);
//TODO: use lazy initInbox
updateOutboxMessageList(null);
display.setCurrent(getOutboxMessageList());
}
/**
* push current screen in the backstack and display the sent message list
*
*@param backscreen the displayable to be pushed in the stack,
* often the current displayable
*/
public static void showSentScreen(Displayable backScreen) {
backStack.push(backScreen);
updateSentMessageList(null);
UIController.display.setCurrent(getSentMessageList());
}
/**
* push current screen in the backstack and display the draft message list
*
*@param backscreen the displayable to be pushed in the stack,
* often the current displayable
*/
public static void showDraftScreen(Displayable backScreen) {
backStack.push(backScreen);
updateDraftMessageList(null);
UIController.display.setCurrent(getDraftMessageList());
}
/**
* push current screen in the backstack and display the view message screen
* with the given message.
*<br>
*the message read flag will be set to true if needed
*
*
*
* @param backscreen the displayable to be pushed in the stack,
* often the current displayable
* @param message the message to be displayed
*/
public static void showViewMessageScreen(Displayable backScreen, Message message) {
backStack.push(backScreen);
Log.debug("message flag opened = " + message.getFlags().isSet(MessageFlags.OPENED));
if (!message.getFlags().isSet(MessageFlags.OPENED)) {
changeReadFlag(message);
}
viewMessageScreen = new ViewMessage(message);
viewMessageScreen.resetTitle();
if (!contactsLoader.isLocked()) {
viewMessageScreen.enableCallCommand();
}
display.setCurrent(viewMessageScreen);
}
public static void enableCallSenderCommand() {
if (display.getCurrent() instanceof ViewMessage) {
viewMessageScreen.enableCallCommand();
}
}
/**
* Create the folder list and display it if not yet created.
*
* @param backscreen the displayable to be pushed in the stack,
* @param selectedFolder the folder to be selected showing the list
* often the current displayable
*/
public static void showFolderList(Displayable displayable, int selectedFolder) {
backStack.push(displayable);
if (folderList == null) {
folderList = new FolderList();
}
folderList.updateCounters();
folderList.setSelectedFolder(selectedFolder);
display.setCurrent(folderList);
}
/**
* Create the folder list and display it
* @param backscreen the displayable to be pushed in the stack,
* often the current displayable
*/
public static void showFolderList(Displayable displayable) {
showFolderList(displayable, MessageManager.INBOX);
}
/**
* opens a list of links in the given message body
* @param body the string to be searched for links
* @param backscreen the displayable to be pushed in the stack,
* often the current displayable
*
*/
public static void showLinkList(Displayable displayable, String body) {
backStack.push(displayable);
display.setCurrent(new LinkList(body));
}
/**
* opens a list of attachments in the given message
* @param backscreen the displayable to be pushed in the stack,
* @param message containing the attachments
* often the current displayable
*
*/
public static void showAttachmentsList(Displayable displayable, Message message) {
backStack.push(displayable);
display.setCurrent(new AttachmentsList(message));
}
/*
public static void showPhoneNumberList(Displayable displayable, String body) {
backStack.push(displayable);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -