From eced1dd314ba651f862396c340492c6f2d9da926 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Fri, 14 Aug 2015 17:35:43 -0400 Subject: Move UI things to UI thread --- .../main/java/com/zeapo/pwdstore/SshKeyGen.java | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java b/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java index 40c44065..4fb5f0e3 100644 --- a/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java +++ b/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java @@ -153,21 +153,19 @@ public class SshKeyGen extends AppCompatActivity { } } - private class generateTask extends AsyncTask { + private class generateTask extends AsyncTask { private ProgressDialog pd; - protected Exception doInBackground(View... views) { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(views[0].getWindowToken(), 0); - - Spinner spinner = (Spinner) findViewById(R.id.length); - int length = (Integer) spinner.getSelectedItem(); - - EditText editText = (EditText) findViewById(R.id.passphrase); - String passphrase = editText.getText().toString(); + @Override + protected void onPreExecute() { + super.onPreExecute(); + pd = ProgressDialog.show(SshKeyGen.this, "", "Generating keys"); + } - editText = (EditText) findViewById(R.id.comment); - String comment = editText.getText().toString(); + protected Exception doInBackground(String... strings) { + int length = Integer.parseInt(strings[0]); + String passphrase = strings[1]; + String comment = strings[2]; JSch jsch = new JSch(); try { @@ -192,13 +190,6 @@ public class SshKeyGen extends AppCompatActivity { } } - @Override - protected void onPreExecute() { - super.onPreExecute(); - pd = ProgressDialog.show(SshKeyGen.this, "", "Generating keys"); - - } - @Override protected void onPostExecute(Exception e) { super.onPostExecute(e); @@ -230,6 +221,12 @@ public class SshKeyGen extends AppCompatActivity { // private and public key, then replaces the SshKeyGenFragment with a // ShowSshKeyFragment which displays the public key. public void generate(View view) { - new generateTask().execute(view); + String length = Integer.toString((Integer) ((Spinner) findViewById(R.id.length)).getSelectedItem()); + String passphrase = ((EditText) findViewById(R.id.passphrase)).getText().toString(); + String comment = ((EditText) findViewById(R.id.comment)).getText().toString(); + new generateTask().execute(length, passphrase, comment); + + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } -- cgit v1.2.3