private Builder buildAssertHelper() {
   final boolean isContactInsert = mValues.isInsert();
   ContentProviderOperation.Builder builder = null;
   if (!isContactInsert) {
     // Assert version is consistent while persisting changes
     final Long beforeId = mValues.getId();
     final Long beforeVersion = mValues.getAsLong(RawContacts.VERSION);
     if (beforeId == null || beforeVersion == null) return builder;
     builder = ContentProviderOperation.newAssertQuery(mContactsQueryUri);
     builder.withSelection(RawContacts._ID + "=" + beforeId, null);
     builder.withValue(RawContacts.VERSION, beforeVersion);
   }
   return builder;
 }
示例#2
0
  private void deleteAllSimContacts(final ContentResolver resolver) {
    final ArrayList<ContentProviderOperation> operationList =
        new ArrayList<ContentProviderOperation>();

    ContentProviderOperation.Builder builder =
        ContentProviderOperation.newDelete(RawContacts.CONTENT_URI);
    builder.withSelection(RawContacts.ACCOUNT_TYPE + "==?", new String[] {"sim"});
    operationList.add(builder.build());

    try {
      resolver.applyBatch(ContactsContract.AUTHORITY, operationList);
    } catch (RemoteException e) {
      Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
    } catch (OperationApplicationException e) {
      Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
    }
    Log.d(TAG, "delete sim task!");
  }
 private static ContentProviderOperation updateEvent(
     long calendar_id, Account account, Event event, long raw_id) {
   ContentProviderOperation.Builder builder;
   if (raw_id != -1) {
     builder =
         ContentProviderOperation.newUpdate(
             Events.CONTENT_URI
                 .buildUpon()
                 .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                 .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                 .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                 .build());
     builder.withSelection(Events._ID + " = '" + raw_id + "'", null);
   } else {
     builder =
         ContentProviderOperation.newInsert(
             Events.CONTENT_URI
                 .buildUpon()
                 .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                 .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                 .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                 .build());
   }
   long dtstart = event.getStartDate().getTime();
   long dtend = dtstart + (1000 * 60 * 60);
   if (event.getEndDate() != null) dtend = event.getEndDate().getTime();
   builder.withValue(Events.CALENDAR_ID, calendar_id);
   builder.withValue(Events.DTSTART, dtstart);
   builder.withValue(Events.DTEND, dtend);
   builder.withValue(Events.TITLE, event.getTitle());
   builder.withValue(
       Events.EVENT_LOCATION,
       event.getVenue().getName()
           + "\n"
           + event.getVenue().getLocation().getCity()
           + "\n"
           + event.getVenue().getLocation().getCountry());
   if (Integer.valueOf(event.getStatus()) == 1)
     builder.withValue(Events.STATUS, Events.STATUS_TENTATIVE);
   else builder.withValue(Events.STATUS, Events.STATUS_CONFIRMED);
   builder.withValue(Events._SYNC_ID, Long.valueOf(event.getId()));
   return builder.build();
 }
示例#4
0
  public static void updateContactPhoto(
      ContentResolver c, long rawContactId, Photo pic, boolean primary) {
    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();

    // insert new picture
    try {
      if (pic.data != null) {
        // delete old picture
        String where =
            ContactsContract.Data.RAW_CONTACT_ID
                + " = '"
                + rawContactId
                + "' AND "
                + ContactsContract.Data.MIMETYPE
                + " = '"
                + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
                + "'";
        Log.i(TAG, "Deleting picture: " + where);

        ContentProviderOperation.Builder builder =
            ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI);
        builder.withSelection(where, null);
        operationList.add(builder.build());
        builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
        builder.withValue(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, rawContactId);
        builder.withValue(
            ContactsContract.Data.MIMETYPE,
            ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
        builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, pic.data);
        builder.withValue(ContactsContract.Data.SYNC2, String.valueOf(pic.timestamp));
        builder.withValue(ContactsContract.Data.SYNC3, pic.url);
        if (primary) builder.withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
        operationList.add(builder.build());
      }
      c.applyBatch(ContactsContract.AUTHORITY, operationList);

    } catch (Exception e) {
      // TODO Auto-generated catch block
      Log.e("ERROR:", e.toString());
    }
  }
示例#5
0
 private static ContentProviderOperation.Builder selectByRawContactAndItemType(
     ContentProviderOperation.Builder builder, long rawContactId, String itemType) {
   return builder.withSelection(
       ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?",
       new String[] {Long.toString(rawContactId), itemType});
 }
  private static ContentProviderOperation updateEvent(
      long calendar_id, Account account, Event event, long raw_id) {
    ContentProviderOperation.Builder builder;
    if (raw_id != -1) {
      builder =
          ContentProviderOperation.newUpdate(
              Events.CONTENT_URI
                  .buildUpon()
                  .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                  .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                  .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                  .build());
      builder.withSelection(Events._ID + " = '" + raw_id + "'", null);
    } else {
      builder =
          ContentProviderOperation.newInsert(
              Events.CONTENT_URI
                  .buildUpon()
                  .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                  .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                  .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                  .build());
    }
    long dtstart = event.getStartDate().getTime();
    long dtend = dtstart + (1000 * 60 * 60);
    if (event.getEndDate() != null) dtend = event.getEndDate().getTime();
    builder.withValue(Events.CALENDAR_ID, calendar_id);
    builder.withValue(Events.DTSTART, dtstart);
    builder.withValue(Events.DTEND, dtend);
    builder.withValue(Events.TITLE, event.getTitle());

    String location = "";
    if (event.getVenue().getName().length() > 0) location += event.getVenue().getName() + "\n";
    if (event.getVenue().getLocation().getCity().length() > 0)
      location += event.getVenue().getLocation().getCity() + "\n";
    if (event.getVenue().getLocation().getCountry().length() > 0)
      location += event.getVenue().getLocation().getCountry() + "\n";

    builder.withValue(Events.EVENT_LOCATION, location);

    String description = "http://www.last.fm/event/" + event.getId() + "\n\n";

    if (event.getArtists().length > 0) {
      description += "LINEUP\n";
      for (String artist : event.getArtists()) {
        description += artist + "\n";
      }
      description += "\n";
    }

    if (event.getDescription() != null && event.getDescription().length() > 0) {
      description += "MORE DETAILS\n";
      description += event.getDescription();
    }

    builder.withValue(Events.DESCRIPTION, description);

    if (Integer.valueOf(event.getStatus()) == 1)
      builder.withValue(Events.STATUS, Events.STATUS_TENTATIVE);
    else builder.withValue(Events.STATUS, Events.STATUS_CONFIRMED);
    builder.withValue(Events._SYNC_ID, Long.valueOf(event.getId()));
    return builder.build();
  }