FileDocCategorySizeDatePackage
MessageInboxScreen.javaAPI DocWireless Messaging API3792Mon Nov 10 21:11:18 GMT 2003wmafw

MessageInboxScreen.java

/*
 *  MessageInboxScreen.java
 *
 *  Author: C. Enrique Ortiz, October 2003
 *
 *  Companion source code to "Advanced Messaging Coding with JSR 120".
 *
 *  Based on original work by C. Enrique Ortiz.
 *
 *  COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.
 *  The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
 *  The use of the software is subject to the terms of the end-user license
 *  agreement which accompanies or is included with the software. The software is
 *  provided "as is" and Sony Ericsson specifically disclaim any warranty or
 *  condition whatsoever regarding merchantability or fitness for a specific
 *  purpose, title or non-infringement. No warranty of any kind is made in
 *  relation to the condition, suitability, availability, accuracy, reliability,
 *  merchantability and/or non-infringement of the software provided herein.
 */

package wmafw;

import javax.microedition.lcdui.*;
import java.util.Vector;

/**
 * MessageInboxScreen displays the short message inbox.
 */
class MessageInboxScreen
{
    /************/
    /* Commands */
    /************/
    /** View Command */
    protected static Command VIEW = new Command(UIConstants.TXT_VIEW, Command.SCREEN, 1);
    /** Compose Command */
    protected static Command NEW = new Command(UIConstants.TXT_COMPOSE, Command.SCREEN, 2);
    /** Back Command */
    protected static Command BACK = new Command(UIConstants.TXT_BACK, Command.BACK, 3);
    /** Reset Command */
    protected static Command RESET = new Command(UIConstants.TXT_RESET, Command.BACK, 4);

    /******/
    /* UI */
    /******/
    /** Current display context */
    private Display display;
    /** The command listener responsible of application navigation */
    private CommandListener commandListener;
    /** The menu screen */
    private List list;

    /**
     * Constructor.
     * @param d is the display context.
     * @param cl is the command listener for this screen.
     */
    protected MessageInboxScreen(Display d, CommandListener cl) {
        display = d;
        commandListener = cl;
        list = new List(UIConstants.TXT_SMS_INBOX, List.IMPLICIT);
        list.addCommand(VIEW);
        list.addCommand(NEW);
        list.addCommand(BACK);
        list.addCommand(RESET);
        list.setCommandListener(commandListener);
    }

    /**
     * Make the main menu visible.
     * @param inbox is the inbox to display.
     */
    protected void showScreen(Vector inbox) {
        //  Set the inbox' content.
        setInbox(inbox);
        //  Display the list.
        if (display != null) display.setCurrent(list);
    }

    /**
     * Make the main menu visible.
     * @param inbox is the inbox to display.
     */
    protected void setInbox(Vector inbox) {
        try {
            //  First, clear the list.
            for (int i=list.size()-1; i>=0; i--) {
                list.delete(i);
            }
            //  Now, populate the list.
            for (int i=0; i<inbox.size(); i++) {
                ShortMessage sm = (ShortMessage) inbox.elementAt(i);
                list.append(UIConstants.TXT_FROM+sm.from, null);
            }
        } catch (Exception e) {
            System.out.println("setInbox Exception: " + e);
        }
    }

    /**
     * Returns the main menu Displayable.
     * @return the message inbox screen.
     */
    protected Displayable getScreen() {
        return list;
    }

    /**
     * Returns the main menu selected item.
     * @return the index of the selected entry in the menu.
     */
    protected int getMenuSelection() {
        return list.getSelectedIndex();
    }
}