📄 uicontroller.java
字号:
/*
* 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.controller;
import com.funambol.mail.BodyPart;
import com.funambol.mail.Multipart;
import com.funambol.mailclient.Funambol;
import com.funambol.mailclient.cm.AlreadyExistentContactException;
import com.funambol.mailclient.cm.ContactManagerFactory;
import com.funambol.mailclient.sm.SyncClient;
import com.funambol.mailclient.ui.utils.ImageAttachment;
import com.funambol.mailclient.ui.utils.UiUtils;
import com.funambol.mailclient.ui.view.AboutScreen;
import com.funambol.mailclient.ui.view.AccountSettingsForm;
import com.funambol.mailclient.ui.view.AdCanvas;
import com.funambol.mailclient.ui.view.AddContactForm;
import com.funambol.mailclient.ui.view.AdvancedContactForm;
import com.funambol.mailclient.ui.view.AttachmentsList;
//#ifndef noPhoto
import com.funambol.mailclient.ui.view.CameraCanvas;
//#endif
import com.funambol.mailclient.ui.view.ComposeMessageForm;
import com.funambol.mailclient.ui.view.FolderList;
import com.funambol.mailclient.ui.view.Ads;
import com.funambol.mailclient.ui.view.ContactList;
import com.funambol.mailclient.ui.view.ViewMessage;
import com.funambol.mailclient.ui.view.FunambolAlert;
import com.funambol.mailclient.ui.view.GeneralSettingsForm;
import com.funambol.mailclient.ui.view.HelpScreen;
import com.funambol.mailclient.ui.view.LinkList;
import com.funambol.mailclient.ui.view.LogViewerForm;
import com.funambol.mailclient.ui.view.ContactPhoneNumbersList;
import com.funambol.mailclient.ui.view.Drawer;
//#ifndef noPhoto
import com.funambol.mailclient.ui.view.SendPhotoScreen;
//#endif
//import com.funambol.mailclient.ui.view.PhoneNumberList;
import com.funambol.mailclient.ui.view.SettingsList;
import com.funambol.mailclient.ui.view.DraftMessageList;
import com.funambol.mailclient.ui.view.InboxMessageList;
import com.funambol.mailclient.ui.view.MessageList;
import com.funambol.mailclient.ui.view.OutboxMessageList;
import com.funambol.mailclient.ui.view.SentMessageList;
import com.funambol.mailclient.ui.view.RecipientList;
import com.funambol.mailclient.ui.view.ModalPopup;
import com.funambol.mailclient.ui.view.PlatformRequestPopupAction;
import com.funambol.mailclient.loc.Localization;
import com.funambol.mailclient.cm.Contact;
import com.funambol.mailclient.cm.ContactManager;
import com.funambol.mailclient.cm.ContactManagerException;
import com.funambol.mailclient.ui.view.ViewAttachedImageScreen;
import com.funambol.mailclient.mm.MessageManager;
import com.funambol.mailclient.config.*;
import com.funambol.mail.Address;
import com.funambol.mail.Folder;
import com.funambol.mail.MailException;
import com.funambol.mail.Message;
import com.funambol.mail.MessageFlags;
import com.funambol.mail.Store;
import com.funambol.mailclient.ui.view.DrawerFactory;
import com.funambol.push.CTPService;
import com.funambol.syncml.spds.SyncException;
import com.funambol.syncml.spds.SourceConfig;
import com.funambol.syncml.protocol.SyncML;
import com.funambol.util.ConsoleAppender;
import com.funambol.util.MailDateFormatter;
import com.funambol.util.RMSAppender;
import com.funambol.util.StringUtil;
import com.funambol.util.ThreadPool;
import com.funambol.util.Log;
import com.funambol.util.MultipleAppender;
import com.funambol.util.SocketAppender;
import com.funambol.util.ThreadPoolMonitor;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Item;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStoreException;
//#ifdef isBlackberry
//# import net.rim.device.api.system.RadioInfo;
//# import com.funambol.util.BlackberryHelper;
//#endif
/**
* It is the Controller class that controls all interactions
* between screens and the model
* It maintains a pool of shared UI instances
*/
public class UIController {
private static final String RE = Localization.getMessages().RE_LABEL;
private static final String FW = Localization.getMessages().FW_LABEL;
public static final int CONNECTION_RETRY_TIME = 5;
public static final int SENT_MESSAGE = 0;
public static final int OUTGOING_MESSAGE = 1;
public static final int INCOMING_MESSAGE = 2;
public static final int COMMAND_TYPE = Command.OK;
//Possible sync caller
public static final int USER = 0;
public static final int SAN_MESSAGE = 1;
public static final int SCHEDULER = 2;
public static final int CONNECTION_ERROR_TIMER = 3;
public static int alarmCounter = 0;
public static Funambol midlet;
public static Display display;
// The command pool
//Blackberry gets low priority because softkeys include a back button.
//#ifdef isBlackberry
//# public static Command backCommand = new Command(Localization.getMessages().BACK_COMMAND, Command.BACK, 99);
//#else
public static Command backCommand =
new Command(Localization.getMessages().BACK_COMMAND,
Command.BACK, 0);
//#endif
public static Command selectCommand =
new Command(Localization.getMessages().SELECT_COMMAND,
UIController.COMMAND_TYPE, 0);
public static Command cancelCommand =
new Command(Localization.getMessages().CANCEL_COMMAND,
Command.BACK, 10);
public static Command saveCommand =
new Command(Localization.getMessages().SAVE_COMMAND,
UIController.COMMAND_TYPE, 1);
public static Command inboxCommand =
new Command(Localization.getMessages().INBOX_COMMAND,
UIController.COMMAND_TYPE, 1);
public static Command blackberryExitCommand = new Command(Localization.getMessages().EXIT_COMMAND_LABEL, Command.EXIT, 100);
public static Command nextCommand = new Command(Localization.getMessages().MESSAGE_VIEW_NEXT_MESSAGE, UIController.COMMAND_TYPE, -2);
public static Command previousCommand = new Command(Localization.getMessages().MESSAGE_VIEW_PREVIOUS_MESSAGE, UIController.COMMAND_TYPE, -1);
// The contact manager
private static ContactManager contactManager;
// The screen pool
public static ComposeMessageForm composeMessageScreen;
public static LogViewerForm logViewerScreen;
public static GeneralSettingsForm getMailSettingsScreen;
private static InboxMessageList inboxMessageList;
private static OutboxMessageList outboxMessageList;
private static SentMessageList sentMessageList;
private static DraftMessageList draftMessageList;
protected static ContactList contactList;
// The current message view
private static ViewMessage viewMessageScreen;
// The screen stack
public static Stack backStack = new Stack();
// Thread pool
private static ThreadPool threadPool;
private static Ads ad;
private ThreadPoolMonitor uiThreadMonitor;
private static final int MAX_NUM_THREADS = 5;
public static MessageManager messageManager = MessageManager.getInstance();
public static MailClientConfig mailClientConfig;
// Folder informations
private static Folder[] allFolders;
public static boolean otaStarted;
//public static long startAppProbe;
public static long startupFreeMem;
//private static long heapSize = Runtime.getRuntime().totalMemory();
// private static ContactListLoader contactListLoader;
private static MessageWriter messageWriter;
private static PlatformRequestHandler prh;
private static Drawer drawer;
private static FolderList folderList;
/** connection availability: if false the user must exit the application on:
* Nokia and SonyEricsson;
* Motorola For Linux OS;
**/
private static boolean offlineMode = false;
/** Holds the number of unread messages in the inbox. This field is not
* updated by the UIController directly, but each class that can change this
* value is responsible for keeping it up to date
**/
private static int inboxUnread = 0;
public static AccountSettingsForm accountSettingsForm;
/**
* True if this is the first sync action for this application session
* This force contacts sync at the first sync session performed by the
* user.
*/
public static boolean isFirstSync = true;
//#ifndef noPhoto
public static CameraCanvas cameraCanvas;
//#endif
private static ContactsLoader contactsLoader;
//used for temporary bb fix
private static long lastTimeStarKeypressed = 0;
public static AppProperties appProperties;
//The sync caller agent
private static int syncCaller=USER;
//public static boolean WAP_SIMULATION = true;
private UIController() {
}
public static void init(Funambol app) {
midlet = app;
display = Display.getDisplay(app);
appProperties = new AppProperties(app);
}
public static void initThreadPool() {
ThreadPoolMonitor uiThreadMonitor = new UIThreadPoolMonitor();
threadPool = new ThreadPool(uiThreadMonitor, MAX_NUM_THREADS);
}
public static ThreadPool getThreadPool() {
return threadPool;
}
public static void initLogger() {
MultipleAppender appender = new MultipleAppender();
//appender.addAppender(new SocketAppender("85.18.37.27:5123"));
// Set the appropriate appender and log level.
String logAppender = UIController.appProperties.get(AppProperties.LOG_APPENDER);
if (logAppender != null) {
// trimming the property
logAppender = logAppender.trim();
}
if ("console".equals(logAppender)) {
appender.addAppender(new ConsoleAppender());
//#ifdef SOCKET_APPENDER
//# } else if ("socket".equals(logAppender)) {
//# String socketServer = midlet.getAppProperty("LogSocketUrl");
//# appender.AddAppender(new SocketAppender(socketServer));
//#endif
} else { // using rmsappender
appender.addAppender(new RMSAppender(RMSAppender.LOGDBNAME));
}
/*appender.addAppender(new ConsoleAppender());
appender.addAppender(new RMSAppender(RMSAppender.LOGDBNAME));
Log.setLogLevel(Log.DEBUG); */
Log.initLog(appender, Log.getLogLevel());
}
/**
* Get the permission connection: if false the client
* cannot connect to the network
* @return true if the connection has been granted by the user
*/
public static boolean isSyncPermitted() {
return (!isSyncInProgress()) && !isOfflineMode();
}
/**
* Set the offline mode for this app session: if true the client
* cannot connect to the network.
* changing the offline mode here will change also the CTPService online mode
* @param mode set the offline mode
*/
protected static void setOfflineMode(boolean mode) {
offlineMode = mode;
CTPService.setOfflineMode(mode);
}
/**
*
* @return true if the app is currently in offline mode
*/
public static boolean isOfflineMode() {
return offlineMode;
}
/**
* enable or disable the sync commands in different view screens
*
* @param enable enable the commands if true, disable the commands if false
*/
public static void enableSyncCommands(boolean enable) {
Log.info("Enable Client's Sync Commands: " + enable);
if (contactList != null) {
contactList.enableSyncCommand(enable);
}
if (inboxMessageList != null) {
getInboxMessageList().enableSyncCommand(enable);
}
if (composeMessageScreen != null) {
getComposeMessageScreen().enableSendCommand(enable);
}
if (viewMessageScreen != null) {
viewMessageScreen.enableFullMessageCommand(enable);
}
if (logViewerScreen != null) {
logViewerScreen.enableSendCommand(enable);
}
if (getMailSettingsScreen != null) {
getMailSettingsScreen.enableResetInboxCommand(enable);
}
if (accountSettingsForm != null) {
accountSettingsForm.enableSaveCommand(enable);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -