ListScreen.java

/**
 * Copyright (c) 2012 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia 
Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.satsa;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

// Main UI screen showing the list of available messages
class ListScreen
        extends List
        implements CommandListener {

    private final SATSAMIDlet midlet;
    private final Command commandExit = new Command("Exit", Command.EXIT, 1);
    private final Command commandShow = new Command("Show", Command.ITEM, 1);
    private final Command commandNew = new Command("Create new", Command.SCREEN, 2); // changed from ITEM type
    private final Command commandDelete = new Command("Delete this", Command.ITEM, 3);

    ListScreen(SATSAMIDlet midlet) {
        super("Messages", List.IMPLICIT);
        this.midlet = midlet;
        createList();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == commandExit) {
            midlet.exitMIDlet();
        }
        else if (c == commandShow) {
            midlet.showEncryptedMessage(getSelectedIndex());
        }
        else if (c == commandDelete) {
            midlet.deleteMessage(getSelectedIndex());
        }
        else if (c == commandNew) {
            midlet.showNewMessage();
        }
        else if(this.getSelectedIndex()>-1) {
        	midlet.showEncryptedMessage(getSelectedIndex());
        }
        
     
    }

    void setNumber(int number) {
        deleteAll();
        for (int i = 1; i <= number; i++) {
            append("Message " + i, null);
        }
    }

    private void createList() {
        addCommand(commandExit);
        addCommand(commandDelete);
        addCommand(commandNew);
        addCommand(commandShow);
        setCommandListener(this);
    }
}