summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-08-14 17:35:43 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-08-14 17:35:43 -0400
commiteced1dd314ba651f862396c340492c6f2d9da926 (patch)
treeccca2954ba240556ec4f7030749eac2ef956cb28 /app/src/main
parent838471ec3a4dca2f4c652a43ea73d063559a00d1 (diff)
Move UI things to UI thread
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java37
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java12
-rw-r--r--app/src/main/res/layout/fragment_show_ssh_key.xml1
3 files changed, 25 insertions, 25 deletions
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<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);
-
- 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 {
@@ -193,13 +191,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);
pd.dismiss();
@@ -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);
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index 285f2316..9a5c83d4 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -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,11 +252,13 @@ 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);
- setResult(RESULT_OK);
- finish();
+ if (!fromPreferences) {
+ setResult(RESULT_OK);
+ finish();
+ }
}
private void copySshKey(Uri uri) throws IOException {
diff --git a/app/src/main/res/layout/fragment_show_ssh_key.xml b/app/src/main/res/layout/fragment_show_ssh_key.xml
index e81ae8c4..b01a5873 100644
--- a/app/src/main/res/layout/fragment_show_ssh_key.xml
+++ b/app/src/main/res/layout/fragment_show_ssh_key.xml
@@ -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"/>