[288126d] | 1 | package ve.gob.cenditel.tibisaymovil; |
---|
| 2 | |
---|
| 3 | import android.app.Activity; |
---|
| 4 | import android.app.AlertDialog; |
---|
| 5 | import android.app.Dialog; |
---|
| 6 | import android.content.DialogInterface; |
---|
| 7 | import android.text.Editable; |
---|
| 8 | import android.text.TextWatcher; |
---|
| 9 | import android.view.View; |
---|
| 10 | import android.view.View.OnClickListener; |
---|
| 11 | import android.view.Window; |
---|
| 12 | import android.widget.Button; |
---|
| 13 | import android.widget.EditText; |
---|
| 14 | import android.widget.TextView; |
---|
| 15 | import android.widget.Toast; |
---|
| 16 | |
---|
| 17 | public class PasswordDialog extends Dialog implements TextWatcher, OnClickListener { |
---|
| 18 | |
---|
| 19 | private PasswordView viewHolder; |
---|
| 20 | private DialogInterface.OnClickListener recreateListener = null; |
---|
| 21 | |
---|
| 22 | public PasswordDialog(Activity activity, int titleId, boolean recreate) { |
---|
| 23 | |
---|
| 24 | super(activity); |
---|
| 25 | |
---|
| 26 | this.viewHolder = new PasswordView(activity, titleId, recreate); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | @Override |
---|
| 30 | public void onClick(View v) { |
---|
| 31 | |
---|
| 32 | this.hide(); |
---|
| 33 | |
---|
| 34 | AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); |
---|
| 35 | builder.setMessage(R.string.recreate_keystore_confirmation) |
---|
| 36 | .setIcon(android.R.drawable.ic_dialog_alert) |
---|
| 37 | .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { |
---|
| 38 | public void onClick(DialogInterface dialog, int id) { |
---|
| 39 | PasswordDialog.this.dismiss(); |
---|
| 40 | if (PasswordDialog.this.recreateListener != null) { |
---|
| 41 | PasswordDialog.this.recreateListener.onClick(dialog, id); |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | }) |
---|
| 45 | .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { |
---|
| 46 | public void onClick(DialogInterface dialog, int id) { |
---|
| 47 | dialog.cancel(); |
---|
| 48 | PasswordDialog.this.show(); |
---|
| 49 | } |
---|
| 50 | }); |
---|
| 51 | builder.create().show(); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | public void setAcceptListener(android.view.View.OnClickListener listener) { |
---|
| 55 | |
---|
| 56 | this.viewHolder.accept.setOnClickListener(listener); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | public void setRecreateListener(OnClickListener listener) { |
---|
| 60 | |
---|
| 61 | this.recreateListener = listener; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | public String getPassword() { |
---|
| 65 | |
---|
| 66 | return this.viewHolder.password.getText().toString(); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | public void retry() { |
---|
| 70 | |
---|
| 71 | Toast.makeText(getContext(), R.string.incorrect_password, Toast.LENGTH_LONG).show(); |
---|
| 72 | this.viewHolder.password.setText(null); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | @Override |
---|
| 76 | public void afterTextChanged(Editable s) { |
---|
| 77 | this.viewHolder.accept.setEnabled(this.viewHolder.password.length() > 0); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | @Override |
---|
| 81 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
---|
| 82 | |
---|
| 83 | @Override |
---|
| 84 | public void onTextChanged(CharSequence s, int start, int before, int count) {} |
---|
| 85 | |
---|
| 86 | private class PasswordView { |
---|
| 87 | |
---|
| 88 | public EditText password; |
---|
| 89 | public Button accept; |
---|
| 90 | public TextView title; |
---|
| 91 | public Button recreate; |
---|
| 92 | |
---|
| 93 | public PasswordView(Activity activity, int titleId, boolean recreate) { |
---|
| 94 | |
---|
| 95 | setOwnerActivity(activity); |
---|
| 96 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
---|
| 97 | setContentView(R.layout.password); |
---|
| 98 | |
---|
| 99 | this.title = (TextView) findViewById(R.id.title); |
---|
| 100 | this.title.setText(titleId); |
---|
| 101 | |
---|
| 102 | this.password = (EditText) findViewById(R.id.password); |
---|
| 103 | if (recreate) { |
---|
| 104 | this.recreate = (Button) findViewById(R.id.button_recreate); |
---|
| 105 | this.recreate.setVisibility(View.VISIBLE); |
---|
| 106 | this.recreate.setOnClickListener(PasswordDialog.this); |
---|
| 107 | } |
---|
| 108 | this.accept = (Button) findViewById(R.id.button_accept); |
---|
| 109 | |
---|
| 110 | this.password.addTextChangedListener(PasswordDialog.this); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|