4 * Authors: Nathaniel McCallum <npmccallum@redhat.com>
6 * Copyright (C) 2013 Nathaniel McCallum, Red Hat
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 package org.fedorahosted.freeotp;
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;
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;
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);
45 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
50 public void onTextChanged(CharSequence s, int start, int before, int count) {
51 mButton.setEnabled(false);
53 if (mIssuer.getText().length() == 0)
56 if (mLabel.getText().length() == 0)
59 if (mSecret.getText().length() == 0 ||
60 mSecret.getText().length() % 8 != 0)
63 if (mInterval.getText().length() == 0)
66 mButton.setEnabled(true);
70 public void afterTextChanged(Editable s) {