/*
* Copyright 2009-2010 Marcel Zumstein, Oxinia GmbH
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package org.blync.client;
import java.io.IOException;
import javax.microedition.lcdui.*;
import org.blync.client.mail.MailMainScreen;
import org.blync.client.calendar.appointments.CalendarMonthScreen;
import org.blync.client.calendar.tasks.TasksScreen;
import org.blync.client.contacts.ContactsScreen;
/**
*
* @author Marcel
*/
public class MainScreen extends List implements CommandListener {
// private ChoiceGroup choiceGroup;
private LogScreen logger = LogScreen.getInstance();
private Command showListCommand;
private MailMainScreen mailScreen;
private CalendarMonthScreen calendarScreen;
private TasksScreen tasksScreen;
private ContactsScreen contactsScreen;
private SettingsScreen settingsScreen;
private boolean loaded = false;
private static final String MAIL_TITLE = Resources.get(Resources.MAIL);
private static final String CALENDAR_TITLE = Resources.get(Resources.CALENDAR);
private static final String TASKS_TITLE = Resources.get(Resources.TASKS);
private static final String CONTACTS_TITLE = Resources.get(Resources.CONTACTS);
private static final String SETTINGS_TITLE = Resources.get(Resources.SETTINGS);
public MainScreen() {
super("SyncClient", Choice.IMPLICIT);
addCommand(Commands.getSyncCommand());
addCommand(Commands.getRecoverCommand());
addCommand(Commands.getExitCommand());
addCommand(Commands.getShowLogCommand());
showListCommand = new Command(Resources.get(Resources.SHOW_LIST), Command.ITEM, 1);
setSelectCommand(showListCommand);
setCommandListener(this);
mailScreen = new MailMainScreen(this);
calendarScreen = new CalendarMonthScreen(this);
tasksScreen = new TasksScreen(this);
contactsScreen = new ContactsScreen(this);
settingsScreen = new SettingsScreen(this);
try {
Image mailIcon = Image.createImage("/Mail-48x48.png");
append(MAIL_TITLE, mailIcon);
// setFont(index, Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN, Font.SIZE_LARGE));
Image calendarIcon = Image.createImage("/Calendar-48x48.png");
append(CALENDAR_TITLE, calendarIcon);
Image tasksIcon = Image.createImage("/Tasks-48x48.png");
append(TASKS_TITLE, tasksIcon);
Image contactsIcon = Image.createImage("/Contacts-48x48.png");
append(CONTACTS_TITLE, contactsIcon);
Image settingsIcon = Image.createImage("/Settings-48x48.png");
append(SETTINGS_TITLE, settingsIcon);
}
catch (IOException e) {
logger.log(e.toString());
}
}
public void load() {
if (!loaded) {
mailScreen.load();
calendarScreen.load();
tasksScreen.load();
contactsScreen.load();
settingsScreen.load();
loaded = true;
}
}
public void commandAction(Command c, Displayable s) {
SessionTimer.reset();
if (c == showListCommand) {
showList();
}
else {
Commands.commandAction(c, s);
}
}
/*
public Syncable getInboxScreen() {
return mailScreen.getInboxScreen();
}
public Syncable getSentScreen() {
return mailScreen.getSentScreen();
}
public Syncable getDraftsScreen() {
return mailScreen.getDraftsScreen();
} */
/*
public Syncable getCalendarScreen() {
return calendarScreen;
}
*/
public Syncable getContactsScreen() {
return contactsScreen;
}
public MailMainScreen getMailScreen() {
return mailScreen;
}
private void showList() {
int index = getSelectedIndex();
if (index != -1) {
String list = getString(index);
if (list.equals(MainScreen.MAIL_TITLE)) {
DisplayController.setCurrentScreen(mailScreen);
}
else if (list.equals(MainScreen.CALENDAR_TITLE)) {
// TODO calendarScreen.loadData();
DisplayController.setCurrentScreen(calendarScreen);
}
else if (list.equals(MainScreen.TASKS_TITLE)) {
DisplayController.setCurrentScreen(tasksScreen);
}
else if (list.equals(MainScreen.CONTACTS_TITLE)) {
// contactsScreen.loadData();
DisplayController.setCurrentScreen(contactsScreen);
}
else if (list.equals(MainScreen.SETTINGS_TITLE)) {
DisplayController.setCurrentScreen(settingsScreen);
}
}
}
}