/* Tibisay Movil Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e Investigacion en Tecnologias Libres - CENDITEL. La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o modificar este programa, reconociendo el derecho que la humanidad posee al libre acceso al conocimiento, bajo los términos de la licencia de software GPL versión 2.0 de la Free Software Foundation. Este programa se distribuye con la esperanza de que sea util, pero SIN NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o ADECUACION A UN PROPOSITO PARTICULAR. Para mayor información sobre los términos de la licencia ver el archivo llamado "gpl-2.0.txt" en ingles. */ package ve.gob.cenditel.tibisaymovil; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class PasswordDialog extends Dialog implements TextWatcher, OnClickListener { private PasswordView viewHolder; private DialogInterface.OnClickListener recreateListener = null; public PasswordDialog(Activity activity, int titleId, boolean recreate) { super(activity); this.viewHolder = new PasswordView(activity, titleId, recreate); } @Override public void onClick(View v) { this.hide(); AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); builder.setMessage(R.string.recreate_keystore_confirmation) .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { PasswordDialog.this.dismiss(); if (PasswordDialog.this.recreateListener != null) { PasswordDialog.this.recreateListener.onClick(dialog, id); } } }) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); PasswordDialog.this.show(); } }); builder.create().show(); } public void setAcceptListener(android.view.View.OnClickListener listener) { this.viewHolder.accept.setOnClickListener(listener); } public void setRecreateListener(OnClickListener listener) { this.recreateListener = listener; } public String getPassword() { return this.viewHolder.password.getText().toString(); } public void retry() { Toast.makeText(getContext(), R.string.incorrect_password, Toast.LENGTH_LONG).show(); this.viewHolder.password.setText(null); } @Override public void afterTextChanged(Editable s) { this.viewHolder.accept.setEnabled(this.viewHolder.password.length() > 0); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} private class PasswordView { public EditText password; public Button accept; public TextView title; public Button recreate; public PasswordView(Activity activity, int titleId, boolean recreate) { setOwnerActivity(activity); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.password); this.title = (TextView) findViewById(R.id.title); this.title.setText(titleId); this.password = (EditText) findViewById(R.id.password); if (recreate) { this.recreate = (Button) findViewById(R.id.button_recreate); this.recreate.setVisibility(View.VISIBLE); this.recreate.setOnClickListener(PasswordDialog.this); } this.accept = (Button) findViewById(R.id.button_accept); this.password.addTextChangedListener(PasswordDialog.this); } } }