PINEntryDialogpublic class PINEntryDialog extends Object implements CommandListenerImplements PIN entry dialog. |
Fields Summary |
---|
private static final int | CANCELLEDAnswer that indicates that the dialog was cancelled. | private static final int | CONFIRMEDAnswer that indicates successful completion. | private com.sun.midp.lcdui.DisplayEventHandler | displayEventHandlerCaches the display manager reference. | private Command | okCmdCommand object for "OK" command. | private Command | cancelCmdCommand object for "Cancel" command. | private Object | preemptTokenHolds the preempt token so the form can end. | private int | answerHolds the answer to the security question. | private TextField | tf1PIN entry text field. | private TextField | tf2PIN entry text field. | private PINAttributes | pin1Attributes of the 1st PIN. | private PINAttributes | pin2Attributes of the 2nd PIN. | private byte[] | data11st PIN data. | private byte[] | data22nd PIN data. |
Constructors Summary |
---|
public PINEntryDialog(com.sun.midp.security.SecurityToken token, int action, PINAttributes attr1, PINAttributes attr2)Construct PIN dialog.
String title = null;
String label1 = attr1.label;
String label2 = null;
pin1 = attr1;
pin2 = null;
switch (action) {
case ACLPermissions.CMD_VERIFY: {
// "PIN verification"
title = Resource.getString(ResourceConstants.
JSR177_PINDIALOG_TITLE_VERIFY);
break;
}
case ACLPermissions.CMD_CHANGE: {
// "Change PIN"
title = Resource.getString(ResourceConstants.
JSR177_PINDIALOG_TITLE_CHANGE);
// "New value" -> "Enter new PIN"
label2 = Resource.getString(ResourceConstants.
JSR177_PINDIALOG_ENTERPIN);
pin2 = attr1;
break;
}
case ACLPermissions.CMD_DISABLE: {
// "Disable PIN"
title = Resource.getString(ResourceConstants.
JSR177_PINDIALOG_TITLE_DISABLE);
break;
}
case ACLPermissions.CMD_ENABLE: {
// "Enable PIN";
title = Resource.getString(ResourceConstants.
JSR177_PINDIALOG_TITLE_ENABLE);
break;
}
case ACLPermissions.CMD_UNBLOCK: {
// "Unblock PIN"
title = Resource.getString(ResourceConstants.
JSR177_PINDIALOG_TITLE_UNBLOCK);
label1 = attr2.label;
label2 = attr1.label + " - " +
// "new value"
Resource.getString(ResourceConstants.
JSR177_PINDIALOG_NEWVALUE);
pin1 = attr2;
pin2 = attr1;
break;
}
}
Form form = new Form(title);
int flags = TextField.PASSWORD;
if (pin1.isNumeric()) {
flags |= TextField.NUMERIC;
}
tf1 = new TextField(label1, "", pin1.getMaxLength(), flags);
form.append(tf1);
if (pin2 != null) {
flags = TextField.SENSITIVE | TextField.NON_PREDICTIVE;
if (pin2.isNumeric()) {
flags |= TextField.NUMERIC;
}
tf2 = new TextField(label2, "", pin2.getMaxLength(), flags);
form.append(tf2);
}
form.addCommand(cancelCmd);
form.addCommand(okCmd);
form.setCommandListener(this);
if (displayEventHandler == null) {
displayEventHandler = DisplayEventHandlerFactory
.getDisplayEventHandler(token);
}
preemptToken = displayEventHandler.preemptDisplay(form, true);
|
Methods Summary |
---|
private boolean | checkInput()Verifies that the values entered are acceptable.
if (tf1.getString().trim().equals("")) {
return false;
}
data1 = pin1.transform(tf1.getString());
if (data1 == null) {
// PIN can't be formatted, pass empty PIN to update counter
data1 = new byte[8];
}
if (pin2 != null) {
data2 = pin2.transform(tf2.getString());
if (data2 == null) {
tf2.setString("");
return false;
}
} else {
data2 = null;
}
return true;
| public void | commandAction(Command c, Displayable s)Respond to a command issued on form.
if (c == okCmd) {
if (! checkInput()) {
return;
}
setAnswer(CONFIRMED);
} else {
setAnswer(CANCELLED);
}
| public java.lang.Object[] | getPINs()Get the entered values.
if (answer == CANCELLED) {
return null;
}
if (pin2 == null) {
return new Object[] {data1};
}
return new Object[] {data1, data2};
| private void | setAnswer(int theAnswer)Sets the user's answer and notifies waitForAnswer and
ends the form.
synchronized (this) {
answer = theAnswer;
displayEventHandler.donePreempting(preemptToken);
notify();
}
| public int | waitForAnswer()Waits for the user's answer.
synchronized (this) {
if (preemptToken == null) {
return CANCELLED;
}
try {
wait();
} catch (Throwable t) {
return CANCELLED;
}
return answer;
}
|
|