source: dispositivos_moviles/TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PasswordDialog.java @ 58c7f6a

Last change on this file since 58c7f6a was 8379cd8, checked in by Antonio Araujo Brett <aaraujo@…>, 11 years ago

Agregado encabezado de licencia a archivos fuentes.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2Tibisay Movil
3
4Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz
5(jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e
6Investigacion en Tecnologias Libres - CENDITEL.
7
8La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o
9modificar este programa, reconociendo el derecho que la humanidad posee al
10libre acceso al conocimiento, bajo los términos de la licencia de software
11GPL versión 2.0 de la Free Software Foundation.
12
13Este programa se distribuye con la esperanza de que sea util, pero SIN
14NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o
15ADECUACION A UN PROPOSITO PARTICULAR.
16
17Para mayor información sobre los términos de la licencia ver el archivo
18llamado "gpl-2.0.txt" en ingles.
19*/
20
21package ve.gob.cenditel.tibisaymovil;
22
23import android.app.Activity;
24import android.app.AlertDialog;
25import android.app.Dialog;
26import android.content.DialogInterface;
27import android.text.Editable;
28import android.text.TextWatcher;
29import android.view.View;
30import android.view.View.OnClickListener;
31import android.view.Window;
32import android.widget.Button;
33import android.widget.EditText;
34import android.widget.TextView;
35import android.widget.Toast;
36
37public 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}
Note: See TracBrowser for help on using the repository browser.