@Override
  public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri uri = UserPackets.buildUserIdsUri();

    String selection, ids[];
    {
      // generate placeholders and string selection args
      ids = new String[mPubMasterKeyIds.length];
      StringBuilder placeholders = new StringBuilder("?");
      for (int i = 0; i < mPubMasterKeyIds.length; i++) {
        ids[i] = Long.toString(mPubMasterKeyIds[i]);
        if (i != 0) {
          placeholders.append(",?");
        }
      }
      // put together selection string
      selection =
          UserPackets.IS_REVOKED
              + " = 0"
              + " AND "
              + Tables.USER_PACKETS
              + "."
              + UserPackets.MASTER_KEY_ID
              + " IN ("
              + placeholders
              + ")";
    }

    return new CursorLoader(
        getActivity(),
        uri,
        USER_IDS_PROJECTION,
        selection,
        ids,
        Tables.USER_PACKETS
            + "."
            + UserPackets.MASTER_KEY_ID
            + " ASC"
            + ", "
            + Tables.USER_PACKETS
            + "."
            + UserPackets.USER_ID
            + " ASC");
  }
Esempio n. 2
0
 /** Write all known email addresses of a key (derived from user ids) to a given raw contact */
 private static void writeContactEmail(
     ArrayList<ContentProviderOperation> ops,
     ContentResolver resolver,
     long rawContactId,
     long masterKeyId) {
   ops.add(
       selectByRawContactAndItemType(
               ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI),
               rawContactId,
               ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
           .build());
   Cursor ids =
       resolver.query(
           UserPackets.buildUserIdsUri(masterKeyId),
           new String[] {UserPackets.USER_ID},
           UserPackets.IS_REVOKED + "=0",
           null,
           null);
   if (ids != null) {
     while (ids.moveToNext()) {
       KeyRing.UserId userId = KeyRing.splitUserId(ids.getString(0));
       if (userId.email != null) {
         ops.add(
             referenceRawContact(
                     ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI),
                     rawContactId)
                 .withValue(
                     ContactsContract.Data.MIMETYPE,
                     ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
                 .withValue(ContactsContract.CommonDataKinds.Email.DATA, userId.email)
                 .build());
       }
     }
     ids.close();
   }
 }