*/
void addMenuItems(final MainScreen mainScreen) {
final MenuItemWithIcon appendUnreadMessage =
new MenuItemWithIcon("Append Unread Message", 0,
"img/sm_add_message.png");
appendUnreadMessage.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
// Create a new message
final DemoMessage message = new DemoMessage();
message.setSender("John Smith");
message.setSubject("Hello from John");
message.setMessage("Hello Chris. Do you know that you can get a BlackBerry Smartphone cheaper through the Message List Demo Store?");
message.setReceivedTime(System.currentTimeMillis());
message.setPreviewPicture(CommunicationSimulatorThread
.getRandomPhotoImage());
// Store message
final MessageListDemoStore messageStore =
MessageListDemoStore.getInstance();
synchronized (messageStore) {
messageStore.addInboxMessage(message);
}
Dialog.alert("Unread message was added to inbox");
// Notify folder
final ApplicationMessageFolder inboxFolder =
messageStore.getInboxFolder();
inboxFolder.fireElementAdded(message, true);
}
}));
mainScreen.addMenuItem(appendUnreadMessage);
final MenuItemWithIcon appendOpenedMessage =
new MenuItemWithIcon("Append Opened Message", 1,
"img/sm_add_message.png");
appendOpenedMessage.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
// Create a new message
final DemoMessage message = new DemoMessage();
message.setSender("Maria Rosevelt");
message.setSubject("How have you been?");
message.setMessage("Hi Chris. I haven't seen you in ages. Let's do lunch!");
message.setReceivedTime(System.currentTimeMillis() - 2 * 24
* 60 * 60 * 1000L);
message.setPreviewPicture(CommunicationSimulatorThread
.getRandomPhotoImage());
message.markRead();
// Store message
final MessageListDemoStore messageStore =
MessageListDemoStore.getInstance();
synchronized (messageStore) {
messageStore.addInboxMessage(message);
}
Dialog.alert("Opened message was added to inbox");
// Notify folder
messageStore.getInboxFolder().fireElementAdded(message);
}
}));
mainScreen.addMenuItem(appendOpenedMessage);
final MenuItemWithIcon appendMessagesInBulk =
new MenuItemWithIcon("Append Messages in Bulk", 2,
"sm_add_messages_bulk");
appendMessagesInBulk.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
final MessageListDemoStore messageStore =
MessageListDemoStore.getInstance();
synchronized (messageStore) {
for (int i = 1; i <= MAX_MSGS; i++) {
// Create a new message
final DemoMessage message = new DemoMessage();
message.setSender("Mark Duval");
message.setSubject(i + " of " + MAX_MSGS);
message.setMessage("Please pick up milk and bread on the way home.");
message.setReceivedTime(System.currentTimeMillis());
message.setPreviewPicture(CommunicationSimulatorThread
.getRandomPhotoImage());
// Store message in the runtime store
messageStore.addInboxMessage(message);
}
// Notify folder
final ApplicationMessageFolder inboxFolder =
messageStore.getInboxFolder();
inboxFolder.fireReset(true);
}
Dialog.alert("Bulk messages were added to inbox");
}
}));
mainScreen.addMenuItem(appendMessagesInBulk);
final MenuItemWithIcon startCommunicationThread =
new MenuItemWithIcon("Start Communication Thread", 3,
"sm_start_auto");
startCommunicationThread.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
if (_commThread != null) {
Dialog.alert("Communication thread already running");
return;
}
_commThread = new CommunicationSimulatorThread();
_commThread.start();
Dialog.alert("Communication thread started successfully.\n After dismissing this dialog, press the End (red phone) key and"
+ " open the Messages application from the home screen.");
}
}));
mainScreen.addMenuItem(startCommunicationThread);
final MenuItemWithIcon stopCommunicationThread =
new MenuItemWithIcon("Stop Communication Thread", 4,
"sm_stop_auto");
stopCommunicationThread.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
if (_commThread == null) {
Dialog.alert("Communication thread is not running");
return;
}
_commThread.stopRunning();
_commThread = null;
Dialog.alert("Communication thread stopped.");
}
}));
mainScreen.addMenuItem(stopCommunicationThread);
final MenuItemWithIcon viewMessagesInMessageList =
new MenuItemWithIcon("View Messages In Message List", 5,
"sm_open_messages_app");
viewMessagesInMessageList.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,