Move UI things to UI thread

This commit is contained in:
Matthew Wong 2015-08-14 17:35:43 -04:00
parent 838471ec3a
commit eced1dd314
3 changed files with 25 additions and 25 deletions

View file

@ -153,21 +153,19 @@ public class SshKeyGen extends AppCompatActivity {
}
}
private class generateTask extends AsyncTask<View, Void, Exception> {
private class generateTask extends AsyncTask<String, Void, Exception> {
private ProgressDialog pd;
protected Exception doInBackground(View... views) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(views[0].getWindowToken(), 0);
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = ProgressDialog.show(SshKeyGen.this, "", "Generating keys");
}
Spinner spinner = (Spinner) findViewById(R.id.length);
int length = (Integer) spinner.getSelectedItem();
EditText editText = (EditText) findViewById(R.id.passphrase);
String passphrase = editText.getText().toString();
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);
}
}

View file

@ -86,7 +86,7 @@ public class UserPreference extends AppCompatActivity {
findPreference("ssh_keygen").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
callingActivity.makeSshKey();
callingActivity.makeSshKey(true);
return true;
}
});
@ -202,7 +202,7 @@ public class UserPreference extends AppCompatActivity {
getSshKey();
break;
case "make_ssh_key":
makeSshKey();
makeSshKey(false);
break;
case "git_external":
selectExternalGitRepository();
@ -252,12 +252,14 @@ public class UserPreference extends AppCompatActivity {
/**
* Opens a key generator to generate a public/private key pair
*/
public void makeSshKey() {
public void makeSshKey(boolean fromPreferences) {
Intent intent = new Intent(getApplicationContext(), SshKeyGen.class);
startActivity(intent);
if (!fromPreferences) {
setResult(RESULT_OK);
finish();
}
}
private void copySshKey(Uri uri) throws IOException {
InputStream sshKey = this.getContentResolver().openInputStream(uri);

View file

@ -21,6 +21,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/ssh_keygen_tip"
android:textAppearance="?android:attr/textAppearanceMedium"/>