PasswordScreen.java

/*
 * Copyright © 2013 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 com.nokia.mid.ui.IconCommand;
import javax.microedition.lcdui.*;

// Shows a password field used to decrypt a message
class PasswordScreen
        extends Form
        implements CommandListener {

    private final SATSAMIDlet midlet;
    private final Command commandBack = new Command("Back", Command.BACK, 1);
    
    /**Creates a new IconCommand with the given label, type, priority and system icon id. */
    private final IconCommand commandDecryptAction1 = new IconCommand("OK", Command.OK, 1,IconCommand.OK);
    private int index;
    TextField passwordField;

    PasswordScreen(SATSAMIDlet midlet) {
        super(null);
        this.midlet = midlet;
        createForm();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == commandBack) {
            midlet.showEncryptedMessage(index);
        } if ( c == commandDecryptAction1){
        	midlet.showDecryptedMessage(index,
                    passwordField.getString());
        }
    }

    void setIndex(int index) {
        this.index = index;
        createForm();
    }

    private void createForm() {
        deleteAll();
        setTitle("Enter password to decrypt.");
        passwordField = new TextField("Password",
                "",
                16,
                TextField.PASSWORD);
        append(passwordField);
        addCommand(commandBack);
        addCommand(commandDecryptAction1);
        setCommandListener(this);
    }
}