Exemplo n.º 1
0
  /**
   * Build layout based on mUserId, mKeys and mKeysUsages Vectors. It creates Views for every user
   * id and key.
   */
  private void buildLayout() {
    // Build layout based on given userIds and keys
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    LinearLayout container = (LinearLayout) findViewById(R.id.edit_key_container);
    mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
    mUserIdsView.setType(Id.type.user_id);
    mUserIdsView.setUserIds(mUserIds);
    container.addView(mUserIdsView);
    mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
    mKeysView.setType(Id.type.key);
    mKeysView.setKeys(mKeys, mKeysUsages);
    container.addView(mKeysView);

    updatePassPhraseButtonText();
  }
Exemplo n.º 2
0
  /**
   * Returns usage selections of keys from the SectionView
   *
   * @param keysView
   * @return
   */
  private Vector<Integer> getKeysUsages(SectionView keysView) throws PGPMain.GeneralException {
    Vector<Integer> getKeysUsages = new Vector<Integer>();

    ViewGroup keyEditors = keysView.getEditors();

    if (keyEditors.getChildCount() == 0) {
      throw new PGPMain.GeneralException(getString(R.string.error_keyNeedsMasterKey));
    }

    for (int i = 0; i < keyEditors.getChildCount(); ++i) {
      KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i);
      getKeysUsages.add(editor.getUsage());
    }

    return getKeysUsages;
  }
Exemplo n.º 3
0
  /**
   * Returns user ids from the SectionView
   *
   * @param userIdsView
   * @return
   */
  private Vector<String> getUserIds(SectionView userIdsView) throws PGPMain.GeneralException {
    Vector<String> userIds = new Vector<String>();

    ViewGroup userIdEditors = userIdsView.getEditors();

    boolean gotMainUserId = false;
    for (int i = 0; i < userIdEditors.getChildCount(); ++i) {
      UserIdEditor editor = (UserIdEditor) userIdEditors.getChildAt(i);
      String userId = null;
      try {
        userId = editor.getValue();
      } catch (UserIdEditor.NoNameException e) {
        throw new PGPMain.GeneralException(this.getString(R.string.error_userIdNeedsAName));
      } catch (UserIdEditor.NoEmailException e) {
        throw new PGPMain.GeneralException(
            this.getString(R.string.error_userIdNeedsAnEmailAddress));
      } catch (UserIdEditor.InvalidEmailException e) {
        throw new PGPMain.GeneralException(e.getMessage());
      }

      if (userId.equals("")) {
        continue;
      }

      if (editor.isMainUserId()) {
        userIds.insertElementAt(userId, 0);
        gotMainUserId = true;
      } else {
        userIds.add(userId);
      }
    }

    if (userIds.size() == 0) {
      throw new PGPMain.GeneralException(getString(R.string.error_keyNeedsAUserId));
    }

    if (!gotMainUserId) {
      throw new PGPMain.GeneralException(getString(R.string.error_mainUserIdMustNotBeEmpty));
    }

    return userIds;
  }
Exemplo n.º 4
0
 private long getMasterKeyId() {
   if (mKeysView.getEditors().getChildCount() == 0) {
     return 0;
   }
   return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyID();
 }