]> Pileus Git - ~andy/freeotp/blob - src/org/fedorahosted/freeotp/ManualSecretTextWatcher.java
Migrate Manual token entry to use a DialogFragment
[~andy/freeotp] / src / org / fedorahosted / freeotp / ManualSecretTextWatcher.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
26 public class ManualSecretTextWatcher extends ManualTextWatcher {
27         public ManualSecretTextWatcher(AlertDialog dialog) {
28                 super(dialog);
29         }
30
31         @Override
32         public void afterTextChanged(Editable s) {
33                 if (s.length() != 0) {
34                         // Ensure that = is only permitted at the end
35                         boolean haveData = false;
36                         for (int i = s.length() - 1; i >= 0; i--) {
37                                 char c = s.charAt(i);
38                                 if (c != '=')
39                                         haveData = true;
40                                 else if (haveData)
41                                         s.delete(i, i + 1);
42                         }
43                 }
44
45                 super.afterTextChanged(s);
46         }
47 }