If you think the Android project bitfynd-wallet-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2012-2014 the original author or authors.
*//www.java2s.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package de.schildbach.wallet.ui;
import javax.annotation.Nonnull;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.TextView;
/**
* @author Andreas Schildbach
*/publicclass ImportDialogButtonEnablerListener implements TextWatcher, OnItemSelectedListener
{
privatefinal TextView passwordView;
privatefinal AlertDialog dialog;
public ImportDialogButtonEnablerListener(@Nonnull final TextView passwordView, @Nonnull final AlertDialog dialog)
{
this.passwordView = passwordView;
this.dialog = dialog;
handle();
}
@Override
publicvoid onItemSelected(final AdapterView<?> parent, final View view, finalint position, finallong id)
{
handle();
}
@Override
publicvoid onNothingSelected(final AdapterView<?> parent)
{
handle();
}
@Override
publicvoid afterTextChanged(final Editable s)
{
handle();
}
@Override
publicvoid beforeTextChanged(final CharSequence s, finalint start, finalint count, finalint after)
{
}
@Override
publicvoid onTextChanged(final CharSequence s, finalint start, finalint before, finalint count)
{
}
publicvoid handle()
{
finalboolean needsPassword = needsPassword();
finalboolean hasPassword = !passwordView.getText().toString().trim().isEmpty();
finalboolean hasFile = hasFile();
final Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
button.setEnabled(hasFile && (!needsPassword || hasPassword));
}
protectedboolean hasFile()
{
return true;
}
protectedboolean needsPassword()
{
return true;
}
}