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