]> Pileus Git - ~andy/freeotp/blob - src/org/fedorahosted/freeotp/ManualTextWatcher.java
Add native camera support
[~andy/freeotp] / src / org / fedorahosted / freeotp / ManualTextWatcher.java
1 /*
2  * FreeOTP
3  *
4  * Authors: Nathaniel McCallum <npmccallum@redhat.com>
5  *
6  * Copyright (C) 2013  Nathaniel McCallum, Red Hat
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 package org.fedorahosted.freeotp;
22
23 import android.app.AlertDialog;
24 import android.text.Editable;
25 import android.text.TextWatcher;
26 import android.widget.Button;
27 import android.widget.EditText;
28
29 public class ManualTextWatcher implements TextWatcher {
30         private final Button mButton;
31         private final EditText mIssuer;
32         private final EditText mLabel;
33         private final EditText mSecret;
34         private final EditText mInterval;
35
36         public ManualTextWatcher(AlertDialog dialog) {
37                 mButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
38                 mIssuer = (EditText) dialog.findViewById(R.id.issuer);
39                 mLabel = (EditText) dialog.findViewById(R.id.label);
40                 mSecret = (EditText) dialog.findViewById(R.id.secret);
41                 mInterval = (EditText) dialog.findViewById(R.id.interval);
42         }
43
44         @Override
45         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
46
47         }
48
49         @Override
50         public void onTextChanged(CharSequence s, int start, int before, int count) {
51                 mButton.setEnabled(false);
52
53                 if (mIssuer.getText().length() == 0)
54                         return;
55
56                 if (mLabel.getText().length() == 0)
57                         return;
58
59                 if (mSecret.getText().length() == 0 ||
60                         mSecret.getText().length() % 8 != 0)
61                         return;
62
63                 if (mInterval.getText().length() == 0)
64                         return;
65
66                 mButton.setEnabled(true);
67         }
68
69         @Override
70         public void afterTextChanged(Editable s) {
71
72         }
73 }