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;
    }
  }
  private void updateView() {
    if (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0) {
      mSelectKeysButton.setText(getString(R.string.select_keys_button_default));
    } else {
      mSelectKeysButton.setText(
          getResources()
              .getQuantityString(
                  R.plurals.select_keys_button,
                  mEncryptionKeyIds.length,
                  mEncryptionKeyIds.length));
    }

    if (mSecretKeyId == Constants.key.none) {
      mSign.setChecked(false);
      mMainUserId.setText("");
      mMainUserIdRest.setText("");
    } else {
      // See if we can get a user_id from a unified query
      String[] userId;
      try {
        String userIdResult =
            (String)
                mProviderHelper.getUnifiedData(
                    mSecretKeyId, KeyRings.USER_ID, ProviderHelper.FIELD_TYPE_STRING);
        userId = PgpKeyHelper.splitUserId(userIdResult);
      } catch (ProviderHelper.NotFoundException e) {
        userId = null;
      }
      if (userId != null && userId[0] != null) {
        mMainUserId.setText(userId[0]);
      } else {
        mMainUserId.setText(getResources().getString(R.string.user_id_no_name));
      }
      if (userId != null && userId[1] != null) {
        mMainUserIdRest.setText(userId[1]);
      } else {
        mMainUserIdRest.setText("");
      }
      mSign.setChecked(true);
    }
  }
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)
    switch (loader.getId()) {
      case LOADER_ID_KEYRING:
        if (data.moveToFirst()) {
          // get name, email, and comment from USER_ID
          String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(KEYRING_INDEX_USER_ID));
          if (mainUserId[0] != null) {
            getActivity().setTitle(mainUserId[0]);
            mName.setText(mainUserId[0]);
          } else {
            getActivity().setTitle(R.string.user_id_no_name);
            mName.setText(R.string.user_id_no_name);
          }
          mEmail.setText(mainUserId[1]);
          mComment.setText(mainUserId[2]);
        }

        break;
      case LOADER_ID_USER_IDS:
        mUserIdsAdapter.swapCursor(data);
        break;
      case LOADER_ID_KEYS:
        // the first key here is our master key
        if (data.moveToFirst()) {
          // get key id from MASTER_KEY_ID
          long keyId = data.getLong(KEYS_INDEX_KEY_ID);
          String keyIdStr = PgpKeyHelper.convertKeyIdToHex(keyId);
          mKeyId.setText(keyIdStr);

          // get creation date from CREATION
          if (data.isNull(KEYS_INDEX_CREATION)) {
            mCreation.setText(R.string.none);
          } else {
            Date creationDate = new Date(data.getLong(KEYS_INDEX_CREATION) * 1000);

            mCreation.setText(
                DateFormat.getDateFormat(getActivity().getApplicationContext())
                    .format(creationDate));
          }

          // get expiry date from EXPIRY
          if (data.isNull(KEYS_INDEX_EXPIRY)) {
            mExpiry.setText(R.string.none);
          } else {
            Date expiryDate = new Date(data.getLong(KEYS_INDEX_EXPIRY) * 1000);

            mExpiry.setText(
                DateFormat.getDateFormat(getActivity().getApplicationContext()).format(expiryDate));
          }

          String algorithmStr =
              PgpKeyHelper.getAlgorithmInfo(
                  data.getInt(KEYS_INDEX_ALGORITHM), data.getInt(KEYS_INDEX_KEY_SIZE));
          mAlgorithm.setText(algorithmStr);

          byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT);
          if (fingerprintBlob == null) {
            // FALLBACK for old database entries
            fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri);
          }
          String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true);

          mFingerprint.setText(OtherHelper.colorizeFingerprint(fingerprint));
        }

        mKeysAdapter.swapCursor(data);
        break;

      default:
        break;
    }
  }