diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org')
| -rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java | 60 | ||||
| -rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java | 43 | 
2 files changed, 57 insertions, 46 deletions
| 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 3094c0e19..14b1f3064 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -17,8 +17,12 @@  package org.sufficientlysecure.keychain.ui; +import android.app.ProgressDialog;  import android.content.Context; +import android.content.Intent;  import android.os.Bundle; +import android.os.Message; +import android.os.Messenger;  import android.support.v7.app.ActionBarActivity;  import android.text.Editable;  import android.text.TextWatcher; @@ -29,8 +33,13 @@ import android.widget.AutoCompleteTextView;  import android.widget.Button;  import android.widget.EditText; +import org.spongycastle.bcpg.sig.KeyFlags; +import org.sufficientlysecure.keychain.Constants;  import org.sufficientlysecure.keychain.R;  import org.sufficientlysecure.keychain.helper.ContactHelper; +import org.sufficientlysecure.keychain.service.KeychainIntentService; +import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; +import org.sufficientlysecure.keychain.service.SaveKeyringParcel;  import java.util.regex.Matcher; @@ -97,20 +106,65 @@ public class CreateKeyActivity extends ActionBarActivity {          createButton.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View v) { -                createKey(); +                createKeyCheck();              }          });      } -    private void createKey() { +    private void createKeyCheck() {          if (isEditTextNotEmpty(this, nameEdit)                  && isEditTextNotEmpty(this, emailEdit)                  && isEditTextNotEmpty(this, passphraseEdit)) { - +            createKey();          }      } +    private void createKey() { +        Intent intent = new Intent(this, KeychainIntentService.class); +        intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); + +        // Message is received after importing is done in KeychainIntentService +        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler( +                this, +                getString(R.string.progress_importing), +                ProgressDialog.STYLE_HORIZONTAL) { +            public void handleMessage(Message message) { +                // handle messages by standard KeychainIntentServiceHandler first +                super.handleMessage(message); + +                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { +                    CreateKeyActivity.this.finish(); +                } +            } +        }; + +        // fill values for this action +        Bundle data = new Bundle(); + +        SaveKeyringParcel parcel = new SaveKeyringParcel(); +        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() + ">"; +        parcel.mAddUserIds.add(userId); +        parcel. +        parcel.mNewPassphrase = passphraseEdit.getText().toString(); + +        // get selected key entries +        data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel); + +        intent.putExtra(KeychainIntentService.EXTRA_DATA, data); + +        // Create a new Messenger for the communication back +        Messenger messenger = new Messenger(saveHandler); +        intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); + +        saveHandler.showProgressDialog(this); + +        startService(intent); +    } +      /**       * Checks if text of given EditText is not empty. If it is empty an error is       * set and the EditText gets the focus. 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 b4daf1822..9cc623c83 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -93,10 +93,6 @@ public class KeyListActivity extends DrawerActivity {                  createKey();                  return true; -            case R.id.menu_key_list_create_expert: -                createKeyExpert(); -                return true; -              case R.id.menu_key_list_export:                  mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);                  return true; @@ -143,43 +139,4 @@ public class KeyListActivity extends DrawerActivity {          startActivity(intent);      } -    private void createKeyExpert() { -        Intent intent = new Intent(this, KeychainIntentService.class); -        intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); - -        // Message is received after importing is done in KeychainIntentService -        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler( -                this, -                getString(R.string.progress_importing), -                ProgressDialog.STYLE_HORIZONTAL) { -            public void handleMessage(Message message) { -                // handle messages by standard KeychainIntentServiceHandler first -                super.handleMessage(message); -                Bundle data = message.getData(); -                // OtherHelper.logDebugBundle(data, "message reply"); -            } -        }; - -        // fill values for this action -        Bundle data = new Bundle(); - -        SaveKeyringParcel parcel = new SaveKeyringParcel(); -        parcel.mAddSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null)); -        parcel.mAddSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null)); -        parcel.mAddUserIds.add("swagerinho"); -        parcel.mNewPassphrase = "swag"; - -        // get selected key entries -        data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel); - -        intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - -        // Create a new Messenger for the communication back -        Messenger messenger = new Messenger(saveHandler); -        intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - -        saveHandler.showProgressDialog(this); - -        startService(intent); -    }  }
\ No newline at end of file | 
