]> Pileus Git - ~andy/freeotp/blob - src/org/fedorahosted/freeotp/AddTokenTextWatcher.java
5102ddd17dc5fd6d52d5229e27ae205f7719d9c5
[~andy/freeotp] / src / org / fedorahosted / freeotp / AddTokenTextWatcher.java
1 package org.fedorahosted.freeotp;
2
3 import android.app.AlertDialog;
4 import android.text.Editable;
5 import android.text.TextWatcher;
6 import android.widget.Button;
7 import android.widget.EditText;
8
9 public class AddTokenTextWatcher implements TextWatcher {
10         private final AlertDialog dialog;
11
12         public AddTokenTextWatcher(AlertDialog dialog) {
13                 this.dialog = dialog;
14         }
15
16         @Override
17         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
18
19         }
20
21         @Override
22         public void onTextChanged(CharSequence s, int start, int before, int count) {
23                 Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
24
25                 b.setEnabled(false);
26
27                 if (((EditText) dialog.findViewById(R.id.issuer)).getText().length() == 0)
28                         return;
29
30                 if (((EditText) dialog.findViewById(R.id.id)).getText().length() == 0)
31                         return;
32
33                 if (((EditText) dialog.findViewById(R.id.secret)).getText().length() == 0 ||
34                         ((EditText) dialog.findViewById(R.id.secret)).getText().length() % 8 != 0)
35                         return;
36
37                 if (((EditText) dialog.findViewById(R.id.interval)).getText().length() == 0)
38                         return;
39
40                 b.setEnabled(true);
41         }
42
43         @Override
44         public void afterTextChanged(Editable s) {
45
46         }
47 }