From 5eb414a22b28c93e47fe7f62ee786b898d9a21d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 25 Jul 2014 01:34:29 +0200 Subject: [PATCH 1/2] Program flow fixes --- .../keychain/helper/Preferences.java | 2 +- .../keychain/ui/CreateKeyActivity.java | 46 ++++++++++--------- .../keychain/ui/FirstTimeActivity.java | 27 ++++++++--- .../keychain/ui/KeyListActivity.java | 16 ++----- 4 files changed, 48 insertions(+), 43 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java index e55c14a2a..5d765b663 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java @@ -139,7 +139,7 @@ public class Preferences { editor.commit(); } - public boolean getFirstTime() { + public boolean isFirstTime() { return mSharedPreferences.getBoolean(Constants.Pref.FIRST_TIME, true); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index d2073d9a7..fe1b7e688 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -45,10 +45,10 @@ import java.util.regex.Matcher; public class CreateKeyActivity extends ActionBarActivity { - AutoCompleteTextView nameEdit; - AutoCompleteTextView emailEdit; - EditText passphraseEdit; - Button createButton; + AutoCompleteTextView mNameEdit; + AutoCompleteTextView mEmailEdit; + EditText mPassphraseEdit; + Button mCreateButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,19 +56,19 @@ public class CreateKeyActivity extends ActionBarActivity { setContentView(R.layout.create_key_activity); - nameEdit = (AutoCompleteTextView) findViewById(R.id.name); - emailEdit = (AutoCompleteTextView) findViewById(R.id.email); - passphraseEdit = (EditText) findViewById(R.id.passphrase); - createButton = (Button) findViewById(R.id.create_key_button); + mNameEdit = (AutoCompleteTextView) findViewById(R.id.name); + mEmailEdit = (AutoCompleteTextView) findViewById(R.id.email); + mPassphraseEdit = (EditText) findViewById(R.id.passphrase); + mCreateButton = (Button) findViewById(R.id.create_key_button); - emailEdit.setThreshold(1); // Start working from first character - emailEdit.setAdapter( + mEmailEdit.setThreshold(1); // Start working from first character + mEmailEdit.setAdapter( new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, ContactHelper.getPossibleUserEmails(this) ) ); - emailEdit.addTextChangedListener(new TextWatcher() { + mEmailEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @@ -83,27 +83,28 @@ public class CreateKeyActivity extends ActionBarActivity { if (email.length() > 0) { Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email); if (emailMatcher.matches()) { - emailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, + mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.uid_mail_ok, 0); } else { - emailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, + mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.uid_mail_bad, 0); } } else { // remove drawable if email is empty - emailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } } }); - nameEdit.setThreshold(1); // Start working from first character - nameEdit.setAdapter( + + mNameEdit.setThreshold(1); // Start working from first character + mNameEdit.setAdapter( new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, ContactHelper.getPossibleUserNames(this) ) ); - createButton.setOnClickListener(new View.OnClickListener() { + mCreateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createKeyCheck(); @@ -113,9 +114,9 @@ public class CreateKeyActivity extends ActionBarActivity { } private void createKeyCheck() { - if (isEditTextNotEmpty(this, nameEdit) - && isEditTextNotEmpty(this, emailEdit) - && isEditTextNotEmpty(this, passphraseEdit)) { + if (isEditTextNotEmpty(this, mNameEdit) + && isEditTextNotEmpty(this, mEmailEdit) + && isEditTextNotEmpty(this, mPassphraseEdit)) { createKey(); } } @@ -134,6 +135,7 @@ public class CreateKeyActivity extends ActionBarActivity { super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { + CreateKeyActivity.this.setResult(RESULT_OK); CreateKeyActivity.this.finish(); } } @@ -146,9 +148,9 @@ public class CreateKeyActivity extends ActionBarActivity { parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.CERTIFY_OTHER, null)); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.SIGN_DATA, null)); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, null)); - String userId = nameEdit.getText().toString() + " <" + emailEdit.getText().toString() + ">"; + String userId = mNameEdit.getText().toString() + " <" + mEmailEdit.getText().toString() + ">"; parcel.mAddUserIds.add(userId); - parcel.mNewPassphrase = passphraseEdit.getText().toString(); + parcel.mNewPassphrase = mPassphraseEdit.getText().toString(); // get selected key entries data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java index aa4120d2c..4271b2d5a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/FirstTimeActivity.java @@ -25,6 +25,7 @@ import android.view.Window; import android.widget.Button; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.Preferences; public class FirstTimeActivity extends ActionBarActivity { @@ -47,9 +48,7 @@ public class FirstTimeActivity extends ActionBarActivity { mSkipSetup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(FirstTimeActivity.this, KeyListActivity.class); - startActivity(intent); - finish(); + finishSetup(); } }); @@ -58,8 +57,7 @@ public class FirstTimeActivity extends ActionBarActivity { public void onClick(View v) { Intent intent = new Intent(FirstTimeActivity.this, ImportKeysActivity.class); intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN); - startActivity(intent); - finish(); + startActivityForResult(intent, 1); } }); @@ -67,11 +65,26 @@ public class FirstTimeActivity extends ActionBarActivity { @Override public void onClick(View v) { Intent intent = new Intent(FirstTimeActivity.this, CreateKeyActivity.class); - startActivity(intent); - finish(); + startActivityForResult(intent, 1); } }); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (resultCode == RESULT_OK) { + finishSetup(); + } + } + + private void finishSetup() { + Preferences prefs = Preferences.getPreferences(this); + prefs.setFirstTime(false); + Intent intent = new Intent(FirstTimeActivity.this, KeyListActivity.class); + startActivity(intent); + finish(); + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 9cc623c83..095762283 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -17,28 +17,19 @@ package org.sufficientlysecure.keychain.ui; -import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; import android.view.Menu; import android.view.MenuItem; import com.devspark.appmsg.AppMsg; -import org.spongycastle.bcpg.sig.KeyFlags; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.Constants.choice.algorithm; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainDatabase; -import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.SaveKeyringParcel; -import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd; import org.sufficientlysecure.keychain.util.Log; import java.io.IOException; @@ -51,11 +42,10 @@ public class KeyListActivity extends DrawerActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // if this is the first time show first time activity Preferences prefs = Preferences.getPreferences(this); - if (prefs.getFirstTime()) { - prefs.setFirstTime(false); - Intent intent = new Intent(this, FirstTimeActivity.class); - startActivity(intent); + if (prefs.isFirstTime()) { + startActivity(new Intent(this, FirstTimeActivity.class)); finish(); return; } From 9ea514855080513664ed7a95bb658e59cfb1bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 25 Jul 2014 01:34:57 +0200 Subject: [PATCH 2/2] Update libs --- extern/openpgp-api-lib | 2 +- extern/spongycastle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index cd1a6748d..869ab96e6 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit cd1a6748dd7a4c7a251a4f75eb289955dfbb1058 +Subproject commit 869ab96e6dcd4821fd5360248429e49dae6fbaca diff --git a/extern/spongycastle b/extern/spongycastle index c142a844b..a68ebd1ff 160000 --- a/extern/spongycastle +++ b/extern/spongycastle @@ -1 +1 @@ -Subproject commit c142a844b680652adb751a193a4e4a926a4c080b +Subproject commit a68ebd1ffc5af880903b2905c17e4f6ac0f13988