mirror of
https://github.com/vanitasvitae/EnigmAndroid.git
synced 2024-09-27 18:29:33 +02:00
99 lines
3.7 KiB
Java
99 lines
3.7 KiB
Java
|
package de.vanitasvitae.enigmandroid.layout;
|
||
|
|
||
|
import android.app.AlertDialog;
|
||
|
import android.app.Dialog;
|
||
|
import android.content.DialogInterface;
|
||
|
import android.text.Editable;
|
||
|
import android.text.TextWatcher;
|
||
|
import android.util.Log;
|
||
|
import android.view.View;
|
||
|
import android.widget.ArrayAdapter;
|
||
|
import android.widget.Button;
|
||
|
import android.widget.EditText;
|
||
|
import android.widget.Spinner;
|
||
|
import android.widget.TextView;
|
||
|
import android.widget.Toast;
|
||
|
|
||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||
|
import de.vanitasvitae.enigmandroid.R;
|
||
|
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
||
|
|
||
|
/**
|
||
|
* Builder for the dialog that is used to get settings for the rings
|
||
|
* Copyright (C) 2015 Paul Schaub
|
||
|
|
||
|
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 2 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, write to the Free Software Foundation, Inc.,
|
||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||
|
* @author vanitasvitae
|
||
|
*/
|
||
|
public class PassphraseDialogBuilder
|
||
|
{
|
||
|
MainActivity main;
|
||
|
View passphraseDialogView;
|
||
|
EditText passphrase;
|
||
|
Button positive;
|
||
|
public PassphraseDialogBuilder()
|
||
|
{
|
||
|
main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
|
||
|
passphraseDialogView = View.inflate(main, R.layout.dialog_passphrase, null);
|
||
|
passphrase = (EditText) passphraseDialogView.findViewById(R.id.passphrase);
|
||
|
passphrase.addTextChangedListener(new TextWatcher() {
|
||
|
@Override
|
||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void afterTextChanged(Editable s) {
|
||
|
if(s.length() > 0) positive.setEnabled(true);
|
||
|
else positive.setEnabled(false);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void showDialog()
|
||
|
{
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(main);
|
||
|
builder.setTitle(R.string.hint_passphrase);
|
||
|
Dialog d = builder.setView(passphraseDialogView)
|
||
|
.setCancelable(true)
|
||
|
.setPositiveButton(R.string.dialog_positiv, new DialogInterface.OnClickListener()
|
||
|
{
|
||
|
public void onClick(DialogInterface dialog, int id)
|
||
|
{
|
||
|
String pass = passphrase.getText().toString();
|
||
|
main.createStateFromSeed(pass);
|
||
|
String message = main.getResources().getString(R.string.dialog_passphrase_set)
|
||
|
+" \'" + pass + "\'";
|
||
|
Toast.makeText(main, message, Toast.LENGTH_LONG).show();
|
||
|
}
|
||
|
})
|
||
|
.setNegativeButton(R.string.dialog_negativ, new DialogInterface.OnClickListener() {
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
dialog.cancel();
|
||
|
Toast.makeText(main, R.string.dialog_abort,
|
||
|
Toast.LENGTH_SHORT).show();
|
||
|
}
|
||
|
}).create();
|
||
|
d.show();
|
||
|
positive = ((AlertDialog)d).getButton(AlertDialog.BUTTON_POSITIVE);
|
||
|
positive.setEnabled(false);
|
||
|
}
|
||
|
}
|