public void drawPublicKey() {
    PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(this, mPubKeyId);

    if (pubring != null) {
      PGPPublicKey key = PgpKeyHelper.getMasterKey(pubring);
      String masterKeyIdHex = PgpKeyHelper.convertKeyIdToHex(mPubKeyId);

      // get relevant UI elements
      TextView keyIdHex = (TextView) findViewById(R.id.public_key_master_key_hex);
      TextView keyUserId = (TextView) findViewById(R.id.public_key_user_id);
      TextView keyUserIdRest = (TextView) findViewById(R.id.public_key_user_id_rest);

      if (key != null) {
        String userId = PgpKeyHelper.getMainUserIdSafe(this, key);

        String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
        String userName, userEmail;

        if (userIdSplit[0] != null) {
          userName = userIdSplit[0];
        } else {
          userName = getResources().getString(R.string.user_id_no_name);
        }

        if (userIdSplit[1] != null) {
          userEmail = userIdSplit[1];
        } else {
          userEmail = getResources().getString(R.string.error_user_id_no_email);
        }

        keyIdHex.setText(masterKeyIdHex);

        keyUserId.setText(userName);
        keyUserIdRest.setText(userEmail);
        keyUserId.setVisibility(View.VISIBLE);
        keyUserIdRest.setVisibility(View.VISIBLE);
      } else {
        Log.e(Constants.TAG, "this shouldn't happen. key == 0!");
        finish();
        return;
      }
    } else {
      Log.e(Constants.TAG, "this shouldn't happen. pubring == 0!");
      finish();
      return;
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.certify_key_activity);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setHomeButtonEnabled(false);

    mSelectKeyFragment =
        (SelectSecretKeyLayoutFragment)
            getSupportFragmentManager().findFragmentById(R.id.sign_key_select_key_fragment);
    mSelectKeyFragment.setCallback(this);
    mSelectKeyFragment.setFilterCertify(true);

    mSelectKeyserverSpinner = (Spinner) findViewById(R.id.sign_key_keyserver);
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            this,
            android.R.layout.simple_spinner_item,
            Preferences.getPreferences(this).getKeyServers());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSelectKeyserverSpinner.setAdapter(adapter);

    mUploadKeyCheckbox = (CheckBox) findViewById(R.id.sign_key_upload_checkbox);
    if (!mUploadKeyCheckbox.isChecked()) {
      mSelectKeyserverSpinner.setEnabled(false);
    } else {
      mSelectKeyserverSpinner.setEnabled(true);
    }

    mUploadKeyCheckbox.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
              mSelectKeyserverSpinner.setEnabled(false);
            } else {
              mSelectKeyserverSpinner.setEnabled(true);
            }
          }
        });

    mSignButton = (BootstrapButton) findViewById(R.id.sign_key_sign_button);
    mSignButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (mPubKeyId != 0) {
              if (mMasterKeyId == 0) {
                mSelectKeyFragment.setError(getString(R.string.select_key_to_sign));
              } else {
                initiateSigning();
              }
            }
          }
        });

    mDataUri = getIntent().getData();
    if (mDataUri == null) {
      Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
      finish();
      return;
    }

    PGPPublicKeyRing signKey = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, mDataUri);

    if (signKey != null) {
      mPubKeyId = PgpKeyHelper.getMasterKey(signKey).getKeyID();
      drawPublicKey();
    }
    if (mPubKeyId == 0) {
      Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!");
      finish();
      return;
    }
  }