AddSecretTextWatcher.java revision b76e85d5549ba6fc5535ec2a590bad9443bb14d8
2533N/A/*
2533N/A * FreeOTP
2533N/A *
2533N/A * Authors: Nathaniel McCallum <npmccallum@redhat.com>
2533N/A *
2533N/A * Copyright (C) 2013 Nathaniel McCallum, Red Hat
2533N/A *
2533N/A * Licensed under the Apache License, Version 2.0 (the "License");
2533N/A * you may not use this file except in compliance with the License.
2533N/A * You may obtain a copy of the License at
2533N/A *
2533N/A * http://www.apache.org/licenses/LICENSE-2.0
2533N/A *
2533N/A * Unless required by applicable law or agreed to in writing, software
2533N/A * distributed under the License is distributed on an "AS IS" BASIS,
2533N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2533N/A * See the License for the specific language governing permissions and
2533N/A * limitations under the License.
2533N/A */
2533N/A
2533N/Apackage com.forgerock.authenticator.add;
2533N/A
2533N/Aimport android.app.Activity;
2533N/Aimport android.text.Editable;
2533N/A
2533N/Apublic class AddSecretTextWatcher extends AddTextWatcher {
2533N/A public AddSecretTextWatcher(Activity activity) {
2533N/A super(activity);
2533N/A }
2533N/A
2533N/A @Override
2533N/A public void afterTextChanged(Editable s) {
2533N/A if (s.length() != 0) {
2533N/A // Ensure that = is only permitted at the end
2533N/A boolean haveData = false;
2533N/A for (int i = s.length() - 1; i >= 0; i--) {
2533N/A char c = s.charAt(i);
2533N/A if (c != '=')
2533N/A haveData = true;
2533N/A else if (haveData)
2533N/A s.delete(i, i + 1);
2533N/A }
2533N/A }
2533N/A
2533N/A super.afterTextChanged(s);
2533N/A }
2533N/A}
2533N/A