📄 menu.java
字号:
/*
MujMail - Simple mail client for J2ME
Copyright (C) 2006 Nguyen Son Tung <n.sontung@gmail.com>
Copyright (C) 2006 Martin Stefan <martin.stefan@centrum.cz>
Copyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package mujmail;
import java.util.Enumeration;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mujmail.account.MailAccount;
import mujmail.tasks.TasksManager;
import mujmail.util.Functions;
import java.util.Hashtable;
import mujmail.tasks.BackgroundTask;
import mujmail.tasks.ConditionalActionRunner.SampleTestTask;
import mujmail.tasks.TasksManagerUI;
//#ifdef MUJMAIL_SEARCH
import mujmail.search.SearchWindows;
//#endif
//#ifdef MUJMAIL_DEBUG_CONSOLE
import mujmail.debug.DebugConsoleUI;
//#endif
//#ifdef MUJMAIL_SYNC
import mujmail.account.Sync;
//#endif
//#ifdef MUJMAIL_TOUCH_SCR
import mujmail.pointer.MujMailPointerEventListener;
import mujmail.pointer.MujMailPointerEventProducer;
//#endif
class MenuItem {
String name;
String value;
int actionKey; //a keyboard shortcut
Image img; //an icon
public MenuItem(String name, String value, int actionKey, Image img) {
this.name = name;
this.value = value;
this.actionKey = actionKey;
this.img = img;
}
}
class MenuTab {
String name;
int outlineColor;
int fillColor;
int actionKey;
Image img;
Vector item;
}
/**
* Represents menu of this application.
* To add items to the menu of the application, edit this class - see
* constructor.
*
*/
public class Menu extends Canvas implements CommandListener {
private static final boolean DEBUG = false; // Debuggin output for this class
public static final byte ACTION = 0;
public static final byte FOLDERS = 1;
public static final byte SETTINGS = 2;
public static final byte ACCOUNTS = 3;
public static final byte UTILS = 4;
public static final byte MAX_TABS = 5;
public static final int BACKGROUND_COLOR = 0x00CCCCCC;
public static final int OUTLINE_COLOR = 0x007766FF;
public static final int FILL_COLOR = 0x00FFFFFF;
public static final int GREY_OUTLINE_COLOR = 0x007777EE;
public static final int GREY_FILL_COLOR = 0x00BBBBFF;
public static final int FONT_COLOR = 0x00000000;
public static final int SCROLLBAR_COLOR = 0x00FF0000;
public static final int SCROLLBAR_BGCOLOR = 0x00CCCCCC;
//public static final byte USR_BOX_FIRST_POSITION = 6; /// First empty position after standart mail boxes and separator where user mail box can take place
/* TODO: refactor: replace numbers of order of items in menu with constants
* for example: tabs[tabContext].item.elementAt(0)
* replace with tabs[tabContext].item.elementAt(INBOX_ORDER)
*/
public static final byte MENU_ACT_INBOX = 0;
public static final byte MENU_ACT_RETRIEVE_MAILS = MENU_ACT_INBOX + 1;
public static final byte MENU_ACT_WRITE_MAIL = MENU_ACT_RETRIEVE_MAILS + 1;
public static final byte MENU_ACT_SENDALL = MENU_ACT_WRITE_MAIL + 1;
//#ifdef MUJMAIL_SEARCH
public static final byte MENU_ACT_SEARCH_MAILS = MENU_ACT_SENDALL + 1;
//#else
//# public static final byte MENU_ACT_SEARCH_MAILS = MENU_ACT_SENDALL;
//#endif
public static final byte MENU_ACT_PUSH = MENU_ACT_SEARCH_MAILS + 1;
public static final byte MENU_ACT_DISCONNECT = MENU_ACT_PUSH + 1;
public static final byte MENU_ACT_SERVERS_INBOX_SYNC = MENU_ACT_DISCONNECT + 1;
public static final byte MENU_ACT_SIZE = MENU_ACT_SERVERS_INBOX_SYNC + 1; // Lease this as last element
public static final byte MENU_FOLDERS_INBOX = 0;
public static final byte MENU_FOLDERS_OUTBOX = MENU_FOLDERS_INBOX + 1;
public static final byte MENU_FOLDERS_SENTBOX = MENU_FOLDERS_OUTBOX + 1;
public static final byte MENU_FOLDERS_DRAFT = MENU_FOLDERS_SENTBOX + 1;
public static final byte MENU_FOLDERS_TRASH = MENU_FOLDERS_DRAFT + 1;
public static final byte MENU_FOLDERS_SEPARATOR = MENU_FOLDERS_TRASH + 1;
public static final byte MENU_FOLDERS_USERBOX_FIRST = MENU_FOLDERS_SEPARATOR + 1; /// First empty position after standart mail boxes and separator where user mail box can take place
public static final byte MENU_SETTINGS_SMTP = 0;
public static final byte MENU_SETTINGS_RETRIEVING = MENU_SETTINGS_SMTP + 1;
public static final byte MENU_SETTINGS_STORING_MAILS = MENU_SETTINGS_RETRIEVING + 1;
public static final byte MENU_SETTINGS_APPEARANCE = MENU_SETTINGS_STORING_MAILS + 1;
public static final byte MENU_SETTINGS_OTHER = MENU_SETTINGS_APPEARANCE + 1;
public static final byte MENU_SETTINGS_POLLING = MENU_SETTINGS_OTHER + 1;
public static final byte MENU_SETTINGS_MUJMAIL_SERVER = MENU_SETTINGS_POLLING + 1;
public static final byte MENU_SETTINGS_SIZE = MENU_SETTINGS_MUJMAIL_SERVER + 1; // Lease this as last element
public static final byte MENU_UTILS_ADRESSBOOK = 0;
//#ifdef MUJMAIL_SYNC
public static final byte MENU_UTILS_BACKUP_SETTINGS = MENU_UTILS_ADRESSBOOK + 1;
public static final byte MENU_UTILS_RESTORE_SETTINGS = MENU_UTILS_BACKUP_SETTINGS + 1;
//#else
//# public static final byte MENU_UTILS_RESTORE_SETTINGS = MENU_UTILS_ADRESSBOOK;
//#endif
public static final byte MENU_UTILS_CLEAR_DB = MENU_UTILS_RESTORE_SETTINGS + 1;
public static final byte MENU_UTILS_ABOUT = MENU_UTILS_CLEAR_DB + 1;
public static final byte MENU_UTILS_TASK_MANAGER = MENU_UTILS_ABOUT + 1;
public static final byte MENU_UTILS_RUN_SAMPLE_TASK = MENU_UTILS_TASK_MANAGER + 1;
//#ifdef MUJMAIL_DEBUG_CONSOLE
public static final byte MENU_UTILS_DEB_MENU = MENU_UTILS_RUN_SAMPLE_TASK + 1; // Debug
//#else
//# public static final byte MENU_UTILS_DEB_MENU = MENU_UTILS_RUN_SAMPLE_TASK; // no meniu debug entry, no adding space
//#endif
public static final byte MENU_UTILS_SIZE = MENU_UTILS_DEB_MENU + 1; // Lease this as last element
Command exit, cmdNew, change, delete, setPrimary, retrieve, select, clear;
//#ifdef MUJMAIL_USR_FOLDERS
/// User Folders commands
Command fldAdd, fldEdit, fldDel;
//#endif
MenuTab[] tabs = new MenuTab[MAX_TABS];
Image imAction, imInbox, imFolders, imSettings, imAccounts,
imWriteAct, imRetrieveAct, imSendallAct, imPollAct, imClearDB, imDisc,
imPrimaryAcc, imActiveAcc, imInActiveAcc,
imUtilities, imBook, imAbout, imSync, imTaskManager;
//#ifdef MUJMAIL_SYNC
Image imBackup, imRestore;
//#endif
//#ifdef MUJMAIL_SEARCH
Image imSearch;
//#endif
//#ifdef MUJMAIL_DEBUG_CONSOLE
Image imDebug;
//#endif
MujMail mujMail;
// tab positioning
byte firstTab = 0;
byte currTab = 0;
byte maxTabs;
byte selectedTab = 0;
// item positioning
short currItem = 0;
short firstItem = 0;
short selectedItem = 0;
// action key variables
boolean starPressed = false, poundPressed = false;
int fontHeight;
int clientHeight;
// TickerTask
Timer timer;
short sindex, aindex;
boolean sStarted, aStarted;
String tickerText1, tickerText2;
//#ifdef MUJMAIL_TOUCH_SCR
private final MujMailPointerEventProducer pointerEventTransformer;
//#endif
private Font getFirstLineFont() {
if (Settings.fontSize == Settings.FONT_NORMAL)
return Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
else
return Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
}
private Font getSecondLineFont() {
if (Settings.fontSize == Settings.FONT_NORMAL)
return Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
else
return Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
}
private class TickerTask extends TimerTask {
public void run() {
repaint();
}
}
ActionKeyTask actionKeyTask;
private class ActionKeyTask extends TimerTask {
public void run() {
if (starPressed) {
starPressed = false;
}
if (poundPressed) {
poundPressed = false;
}
repaint();
}
}
Timer refreshTimer;
private class RefreshTask extends TimerTask {
byte tab;
public RefreshTask(byte tab) {
this.tab = tab;
}
public void run() {
if (getSelectedTab() == tab) {
refresh(tab, timer == null);
} //repaint() only if it's not tickering already
else {
cancelRefreshTask();
}
}
}
/**
* Creates a new instance of Menu
* @param mujMail the main application
*/
public Menu(MujMail mujMail) {
this.mujMail = mujMail;
exit = new Command(Lang.get(Lang.BTN_EXIT), Command.EXIT, 0);
cmdNew = new Command(Lang.get(Lang.BTN_AS_NEW), Command.ITEM, 1);
change = new Command(Lang.get(Lang.BTN_EDIT), Command.ITEM, 2);
delete = new Command(Lang.get(Lang.BTN_DELETE), Command.ITEM, 4);
setPrimary = new Command(Lang.get(Lang.BTN_AS_SET_PRIMARY), Command.ITEM, 5);
retrieve = new Command(Lang.get(Lang.BTN_RTV_NEW_MAILS), Command.ITEM, 0);
//button select is here just to make it more convenient on the real phone,
//where pressing fire would not always trigger CommandListener() (but key '5' does ironically).
select = new Command(Lang.get(Lang.BTN_SELECT), Command.OK, 0);
clear = new Command(Lang.get(Lang.BTN_CLEAR), Command.ITEM, 6);
//#ifdef MUJMAIL_USR_FOLDERS
fldAdd = new Command(Lang.get(Lang.BTN_USR_FLD_ADD), Command.ITEM, 1);
fldDel = new Command(Lang.get(Lang.BTN_DELETE), Command.ITEM, 2);
fldEdit = new Command(Lang.get(Lang.BTN_EDIT), Command.ITEM, 3);
//#endif
imAction = Functions.getIcon("menu_action.png");
imInbox = Functions.getIcon("act_inbox.png");
imFolders = Functions.getIcon("menu_folders.png");
imSettings = Functions.getIcon("menu_settings.png");
imAccounts = Functions.getIcon("menu_accounts.png");
imUtilities = Functions.getIcon("menu_utilities.png");
imWriteAct = Functions.getIcon("act_write.png");
imRetrieveAct = Functions.getIcon("act_retrieve.png");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -