use of es.gob.jmulticard.card.dnie.CustomTextInputCallback in project jmulticard by ctt-gob-es.
the class DnieCallbackHandler method handle.
@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
if (callbacks != null) {
for (final Callback cb : callbacks) {
if (cb != null) {
if (cb instanceof CustomTextInputCallback) {
final UIPasswordCallbackCan uip = new UIPasswordCallbackCan(// $NON-NLS-1$
Messages.getString("CanPasswordCallback.0"), null, // $NON-NLS-1$
Messages.getString("CanPasswordCallback.0"), // $NON-NLS-1$
Messages.getString("CanPasswordCallback.2"));
((CustomTextInputCallback) cb).setText(new String(uip.getPassword()));
return;
} else if (cb instanceof CustomAuthorizeCallback) {
DialogBuilder.showSignatureConfirmDialog((CustomAuthorizeCallback) cb);
return;
} else if (cb instanceof PasswordCallback) {
final CommonPasswordCallback uip = new CommonPasswordCallback(((PasswordCallback) cb).getPrompt(), // $NON-NLS-1$
Messages.getString("CommonPasswordCallback.1"), true);
((PasswordCallback) cb).setPassword(uip.getPassword());
return;
} else {
// $NON-NLS-1$
LOGGER.severe("Callback no soportada: " + cb.getClass().getName());
}
}
}
} else {
// $NON-NLS-1$
LOGGER.warning("Se ha recibido un array de Callbacks nulo");
}
throw new UnsupportedCallbackException(null);
}
use of es.gob.jmulticard.card.dnie.CustomTextInputCallback in project jmulticard by ctt-gob-es.
the class DnieNFCCallbackHandler method handle.
@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
if (callbacks != null) {
for (final Callback cb : callbacks) {
if (cb instanceof PasswordCallback) {
final PinDialog dialog = new PinDialog(false, this.activity, cb, this.dialogDone);
final FragmentTransaction ft = ((FragmentActivity) this.activity).getSupportFragmentManager().beginTransaction();
final ShowPinDialogTask spdt = new ShowPinDialogTask(dialog, ft, this.activity, this.dialogDone);
final String input = spdt.getInput();
((PasswordCallback) cb).setPassword(input.toCharArray());
return;
}
String input;
if (cb instanceof CustomTextInputCallback) {
if (this.passwordCallback == null) {
final PinDialog dialog = new PinDialog(true, this.activity, cb, this.dialogDone);
final FragmentTransaction ft = ((FragmentActivity) this.activity).getSupportFragmentManager().beginTransaction();
final ShowPinDialogTask spdt = new ShowPinDialogTask(dialog, ft, this.activity, this.dialogDone);
input = spdt.getInput();
} else {
input = new String(this.passwordCallback.getPassword());
// En caso de fallar el primer CAN lo pedira de nuevo al ususario
this.passwordCallback = null;
}
((CustomTextInputCallback) cb).setText(input);
return;
}
if (cb instanceof CustomAuthorizeCallback) {
return;
}
LOGGER.severe(cb.getClass().getName());
}
} else {
// $NON-NLS-1$
LOGGER.warning("Se ha recibido un array de Callbacks nulo");
throw new UnsupportedCallbackException(null);
}
}
use of es.gob.jmulticard.card.dnie.CustomTextInputCallback in project jmulticard by ctt-gob-es.
the class PinDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Builder alertDialogBuilder = new AlertDialog.Builder(this.activity);
final LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
final View view;
if (this.isCan) {
alertDialogBuilder.setTitle(R.string.can_intro);
view = layoutInflater.inflate(R.layout.dialog_can, null);
final TextView textV = (TextView) view.findViewById(R.id.tvPin);
} else {
alertDialogBuilder.setTitle(R.string.pin_intro);
view = layoutInflater.inflate(R.layout.dialog_pin, null);
final TextView textV = (TextView) view.findViewById(R.id.tvPin);
textV.setText(this.title);
}
final EditText editTextPin = (EditText) view.findViewById(R.id.etPin);
alertDialogBuilder.setView(view);
alertDialogBuilder.setNegativeButton(this.activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
dialog.dismiss();
synchronized (PinDialog.this.dialogDone) {
PinDialog.this.dialogDone.notify();
}
}
});
alertDialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (editTextPin.getText() != null && !"".equals(editTextPin.getText().toString())) {
// $NON-NLS-1$
dialog.dismiss();
setPassword(editTextPin.getText().toString());
if (callback instanceof PasswordCallback) {
final PasswordCallback pc = (PasswordCallback) callback;
pc.setPassword(editTextPin.getText().toString().toCharArray());
} else if (callback instanceof CustomTextInputCallback) {
final CustomTextInputCallback pc = (CustomTextInputCallback) callback;
pc.setText(editTextPin.getText().toString());
}
synchronized (PinDialog.this.dialogDone) {
PinDialog.this.dialogDone.notify();
}
} else {
// TODO: Gestionar este caso
// $NON-NLS-1$ //$NON-NLS-2$
Log.e("es.gob.jmulticard", "El pin no puede ser vacio o nulo");
synchronized (PinDialog.this.dialogDone) {
PinDialog.this.dialogDone.notify();
}
}
}
});
alertDialogBuilder.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(final DialogInterface dialog, final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
dialog.dismiss();
return true;
}
return false;
}
});
return alertDialogBuilder.create();
}
Aggregations