[8379cd8] | 1 | /* |
---|
| 2 | Tibisay Movil |
---|
| 3 | |
---|
| 4 | Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz |
---|
| 5 | (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e |
---|
| 6 | Investigacion en Tecnologias Libres - CENDITEL. |
---|
| 7 | |
---|
| 8 | La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o |
---|
| 9 | modificar este programa, reconociendo el derecho que la humanidad posee al |
---|
| 10 | libre acceso al conocimiento, bajo los términos de la licencia de software |
---|
| 11 | GPL versión 2.0 de la Free Software Foundation. |
---|
| 12 | |
---|
| 13 | Este programa se distribuye con la esperanza de que sea util, pero SIN |
---|
| 14 | NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o |
---|
| 15 | ADECUACION A UN PROPOSITO PARTICULAR. |
---|
| 16 | |
---|
| 17 | Para mayor información sobre los términos de la licencia ver el archivo |
---|
| 18 | llamado "gpl-2.0.txt" en ingles. |
---|
| 19 | */ |
---|
| 20 | |
---|
[288126d] | 21 | package ve.gob.cenditel.tibisaymovil; |
---|
| 22 | |
---|
| 23 | import android.app.Activity; |
---|
| 24 | import android.app.AlertDialog; |
---|
| 25 | import android.app.Dialog; |
---|
| 26 | import android.content.DialogInterface; |
---|
| 27 | import android.text.Editable; |
---|
| 28 | import android.text.TextWatcher; |
---|
| 29 | import android.view.View; |
---|
| 30 | import android.view.View.OnClickListener; |
---|
| 31 | import android.view.Window; |
---|
| 32 | import android.widget.Button; |
---|
| 33 | import android.widget.EditText; |
---|
| 34 | import android.widget.TextView; |
---|
| 35 | import android.widget.Toast; |
---|
| 36 | |
---|
| 37 | public class PasswordDialog extends Dialog implements TextWatcher, OnClickListener { |
---|
| 38 | |
---|
| 39 | private PasswordView viewHolder; |
---|
| 40 | private DialogInterface.OnClickListener recreateListener = null; |
---|
| 41 | |
---|
| 42 | public PasswordDialog(Activity activity, int titleId, boolean recreate) { |
---|
| 43 | |
---|
| 44 | super(activity); |
---|
| 45 | |
---|
| 46 | this.viewHolder = new PasswordView(activity, titleId, recreate); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | @Override |
---|
| 50 | public void onClick(View v) { |
---|
| 51 | |
---|
| 52 | this.hide(); |
---|
| 53 | |
---|
| 54 | AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); |
---|
| 55 | builder.setMessage(R.string.recreate_keystore_confirmation) |
---|
| 56 | .setIcon(android.R.drawable.ic_dialog_alert) |
---|
| 57 | .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { |
---|
| 58 | public void onClick(DialogInterface dialog, int id) { |
---|
| 59 | PasswordDialog.this.dismiss(); |
---|
| 60 | if (PasswordDialog.this.recreateListener != null) { |
---|
| 61 | PasswordDialog.this.recreateListener.onClick(dialog, id); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | }) |
---|
| 65 | .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { |
---|
| 66 | public void onClick(DialogInterface dialog, int id) { |
---|
| 67 | dialog.cancel(); |
---|
| 68 | PasswordDialog.this.show(); |
---|
| 69 | } |
---|
| 70 | }); |
---|
| 71 | builder.create().show(); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | public void setAcceptListener(android.view.View.OnClickListener listener) { |
---|
| 75 | |
---|
| 76 | this.viewHolder.accept.setOnClickListener(listener); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public void setRecreateListener(OnClickListener listener) { |
---|
| 80 | |
---|
| 81 | this.recreateListener = listener; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public String getPassword() { |
---|
| 85 | |
---|
| 86 | return this.viewHolder.password.getText().toString(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public void retry() { |
---|
| 90 | |
---|
| 91 | Toast.makeText(getContext(), R.string.incorrect_password, Toast.LENGTH_LONG).show(); |
---|
| 92 | this.viewHolder.password.setText(null); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | @Override |
---|
| 96 | public void afterTextChanged(Editable s) { |
---|
| 97 | this.viewHolder.accept.setEnabled(this.viewHolder.password.length() > 0); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | @Override |
---|
| 101 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
---|
| 102 | |
---|
| 103 | @Override |
---|
| 104 | public void onTextChanged(CharSequence s, int start, int before, int count) {} |
---|
| 105 | |
---|
| 106 | private class PasswordView { |
---|
| 107 | |
---|
| 108 | public EditText password; |
---|
| 109 | public Button accept; |
---|
| 110 | public TextView title; |
---|
| 111 | public Button recreate; |
---|
| 112 | |
---|
| 113 | public PasswordView(Activity activity, int titleId, boolean recreate) { |
---|
| 114 | |
---|
| 115 | setOwnerActivity(activity); |
---|
| 116 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
---|
| 117 | setContentView(R.layout.password); |
---|
| 118 | |
---|
| 119 | this.title = (TextView) findViewById(R.id.title); |
---|
| 120 | this.title.setText(titleId); |
---|
| 121 | |
---|
| 122 | this.password = (EditText) findViewById(R.id.password); |
---|
| 123 | if (recreate) { |
---|
| 124 | this.recreate = (Button) findViewById(R.id.button_recreate); |
---|
| 125 | this.recreate.setVisibility(View.VISIBLE); |
---|
| 126 | this.recreate.setOnClickListener(PasswordDialog.this); |
---|
| 127 | } |
---|
| 128 | this.accept = (Button) findViewById(R.id.button_accept); |
---|
| 129 | |
---|
| 130 | this.password.addTextChangedListener(PasswordDialog.this); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|