Ejemplo n.º 1
0
  private void loadData(Uri dataUri) {
    mDataUri = dataUri;

    Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());

    mActionEncryptFiles.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            encrypt(mDataUri, false);
          }
        });
    mActionEncryptText.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            encrypt(mDataUri, true);
          }
        });
    mActionCertify.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            certify(mDataUri);
          }
        });
    mActionEdit.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            editKey(mDataUri);
          }
        });
    mActionUpdate.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            try {
              updateFromKeyserver(mDataUri, new ProviderHelper(getActivity()));
            } catch (NotFoundException e) {
              Notify.showNotify(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR);
            }
          }
        });

    mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0);
    mUserIds.setAdapter(mUserIdsAdapter);

    // Prepare the loaders. Either re-connect with an existing ones,
    // or start new ones.
    getLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
    getLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
  }
  private void loadData(Uri dataUri) {
    if (dataUri.equals(mDataUri)) {
      Log.d(Constants.TAG, "Same URI, no need to load the data again!");
      return;
    }

    mDataUri = dataUri;

    Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());

    { // label whether secret key is available, and edit button if it is
      final long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), mDataUri);
      if (ProviderHelper.hasSecretKeyByMasterKeyId(getActivity(), masterKeyId)) {
        // set this attribute. this is a LITTLE unclean, but we have the info available
        // right here, so why not.
        mSecretKey.setTextColor(getResources().getColor(R.color.emphasis));
        mSecretKey.setText(R.string.secret_key_yes);

        // certify button
        // TODO this button MIGHT be useful if the user wants to
        // certify a private key with another...
        // mActionCertify.setVisibility(View.GONE);

        // edit button
        mActionEdit.setVisibility(View.VISIBLE);
        mActionEdit.setOnClickListener(
            new View.OnClickListener() {
              public void onClick(View view) {
                Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
                editIntent.setData(
                    KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(
                        Long.toString(masterKeyId)));
                editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
                startActivityForResult(editIntent, 0);
              }
            });
      } else {
        mSecretKey.setTextColor(Color.BLACK);
        mSecretKey.setText(getResources().getString(R.string.secret_key_no));

        // certify button
        mActionCertify.setVisibility(View.VISIBLE);
        // edit button
        mActionEdit.setVisibility(View.GONE);
      }

      // TODO see todo note above, doing this here for now
      mActionCertify.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View view) {
              certifyKey(
                  KeychainContract.KeyRings.buildPublicKeyRingsByMasterKeyIdUri(
                      Long.toString(masterKeyId)));
            }
          });
    }

    mActionEncrypt.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            encryptToContact(mDataUri);
          }
        });

    mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0);
    mUserIds.setAdapter(mUserIdsAdapter);

    mKeysAdapter = new ViewKeyKeysAdapter(getActivity(), null, 0);
    mKeys.setAdapter(mKeysAdapter);

    // Prepare the loaders. Either re-connect with an existing ones,
    // or start new ones.
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID_KEYRING, null, this);
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID_KEYS, null, this);
  }