Beispiel #1
0
  public static void seperate(Context c, long rawContactID) {
    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
    Cursor cursor =
        c.getContentResolver()
            .query(
                RawContacts.CONTENT_URI,
                new String[] {RawContacts.CONTACT_ID},
                RawContacts._ID + " = '" + rawContactID + "'",
                null,
                null);
    if (cursor.moveToFirst()) {
      long contactID = cursor.getLong(cursor.getColumnIndex(RawContacts.CONTACT_ID));
      Set<Long> ids = getRawContacts(c, contactID, rawContactID);
      for (long id : ids) {
        ContentProviderOperation.Builder builder =
            ContentProviderOperation.newUpdate(ContactsContract.AggregationExceptions.CONTENT_URI);
        builder.withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID1, rawContactID);
        builder.withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, id);
        builder.withValue(
            ContactsContract.AggregationExceptions.TYPE,
            ContactsContract.AggregationExceptions.TYPE_KEEP_SEPARATE);
        operationList.add(builder.build());
      }

      if (operationList.size() > 0)
        try {
          c.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
        } catch (RemoteException e) {
          Log.e("Error", e.getLocalizedMessage());
        } catch (OperationApplicationException e) {
          Log.e("Error", e.getLocalizedMessage());
        }
    }
    cursor.close();
  }
Beispiel #2
0
  private void buildSpeaker(
      boolean isInsert, Speaker speaker, ArrayList<ContentProviderOperation> list) {
    Uri allSpeakersUri =
        ScheduleContractHelper.setUriAsCalledFromSyncAdapter(ScheduleContract.Speakers.CONTENT_URI);
    Uri thisSpeakerUri =
        ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Speakers.buildSpeakerUri(speaker.id));

    ContentProviderOperation.Builder builder;
    if (isInsert) {
      builder = ContentProviderOperation.newInsert(allSpeakersUri);
    } else {
      builder = ContentProviderOperation.newUpdate(thisSpeakerUri);
    }

    list.add(
        builder
            .withValue(ScheduleContract.SyncColumns.UPDATED, System.currentTimeMillis())
            .withValue(ScheduleContract.Speakers.SPEAKER_ID, speaker.id)
            .withValue(ScheduleContract.Speakers.SPEAKER_NAME, speaker.name)
            .withValue(ScheduleContract.Speakers.SPEAKER_ABSTRACT, speaker.bio)
            .withValue(ScheduleContract.Speakers.SPEAKER_COMPANY, speaker.company)
            .withValue(ScheduleContract.Speakers.SPEAKER_IMAGE_URL, speaker.thumbnailUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_PLUSONE_URL, speaker.plusoneUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_TWITTER_URL, speaker.twitterUrl)
            .withValue(
                ScheduleContract.Speakers.SPEAKER_IMPORT_HASHCODE, speaker.getImportHashcode())
            .build());
  }
 public void buildCapsuleInsert(Capsule capsule, boolean withYield) {
   // Build the INSERT operation
   ContentProviderOperation.Builder builder =
       ContentProviderOperation.newInsert(CapsuleContract.Capsules.CONTENT_URI);
   builder.withValues(Capsules.buildContentValues(capsule));
   builder.withYieldAllowed(withYield);
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
 public void buildCapsuleUpdate(Capsule capsule, boolean withYield) {
   // URI for updating a Capsule
   Uri uri = ContentUris.withAppendedId(CapsuleContract.Capsules.CONTENT_URI, capsule.getId());
   // Build the UPDATE operation
   ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri);
   builder.withValues(Capsules.buildContentValues(capsule));
   builder.withYieldAllowed(withYield);
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
  public static ContentProviderOperation buildBatchOperation(JSONObject jsonObject)
      throws JSONException {
    ContentProviderOperation.Builder builder =
        ContentProviderOperation.newInsert(QuoteProvider.Quotes.CONTENT_URI);

    if (!jsonObject.getString(CHANGE).equals(NULL) && !jsonObject.getString(BID).equals(NULL)) {
      String change = jsonObject.getString(CHANGE);
      builder.withValue(QuoteColumns.SYMBOL, jsonObject.getString(SYMBOL));
      builder.withValue(QuoteColumns.BIDPRICE, truncateBidPrice(jsonObject.getString(BID)));
      builder.withValue(
          QuoteColumns.PERCENT_CHANGE,
          truncateChange(jsonObject.getString(CHANGE_IN_PERCENT), true));
      builder.withValue(QuoteColumns.CHANGE, truncateChange(change, false));
      builder.withValue(QuoteColumns.ISCURRENT, 1);
      if (change.charAt(0) == '-') {
        builder.withValue(QuoteColumns.ISUP, 0);
      } else {
        builder.withValue(QuoteColumns.ISUP, 1);
      }

    } else {
      return null;
    }
    return builder.build();
  }
 public void buildOwnershipInsert(
     CapsuleOwnership ownership, boolean withYield, CapsuleContract.SyncStateAction syncAction) {
   // Build the URI
   Uri uri =
       CapsuleOperations.appendDirtyQueryParam(syncAction, CapsuleContract.Ownerships.CONTENT_URI);
   // Build the INSERT operation
   ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
   builder.withValues(Ownerships.buildContentValues(ownership));
   builder.withYieldAllowed(withYield);
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
 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;
 }
 public void buildDiscoveryUpdate(
     CapsuleDiscovery discovery, boolean withYield, CapsuleContract.SyncStateAction syncAction) {
   // Build the URI
   Uri uri =
       CapsuleOperations.appendDirtyQueryParam(
           syncAction,
           ContentUris.withAppendedId(
               CapsuleContract.Discoveries.CONTENT_URI, discovery.getDiscoveryId()));
   // Build the UPDATE operation
   ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri);
   builder.withValues(Discoveries.buildContentValues(discovery));
   builder.withYieldAllowed(withYield);
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
Beispiel #9
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!");
  }
 public void buildOwnershipInsert(
     CapsuleOwnership ownership,
     boolean withYield,
     int capsuleIdBackRefIndex,
     CapsuleContract.SyncStateAction syncAction) {
   // Build the URI
   Uri uri =
       CapsuleOperations.appendDirtyQueryParam(syncAction, CapsuleContract.Ownerships.CONTENT_URI);
   // Build the INSERT operation
   ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
   builder.withValues(Ownerships.buildContentValues(ownership));
   builder.withYieldAllowed(withYield);
   // Add the back value reference index for the Capsule ID
   if (capsuleIdBackRefIndex >= 0) {
     builder.withValueBackReference(CapsuleContract.Ownerships.CAPSULE_ID, capsuleIdBackRefIndex);
   }
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
Beispiel #11
0
  private void buildVideo(boolean isInsert, Video video, ArrayList<ContentProviderOperation> list) {
    Uri allVideosUri =
        ScheduleContractHelper.setUriAsCalledFromSyncAdapter(ScheduleContract.Videos.CONTENT_URI);
    Uri thisVideoUri =
        ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Videos.buildVideoUri(video.id));

    ContentProviderOperation.Builder builder;
    if (isInsert) {
      builder = ContentProviderOperation.newInsert(allVideosUri);
    } else {
      builder = ContentProviderOperation.newUpdate(thisVideoUri);
    }

    if (TextUtils.isEmpty(video.vid)) {
      LOGW(TAG, "Ignoring video with missing video ID.");
      return;
    }

    String thumbUrl = video.thumbnailUrl;
    if (TextUtils.isEmpty(thumbUrl)) {
      // Oops, missing thumbnail URL. Let's improvise.
      // NOTE: this method of obtaining a thumbnail URL from the video ID
      // is unofficial and might not work in the future; that's why we use
      // it only as a fallback in case we don't get a thumbnail URL in the incoming data.
      thumbUrl = String.format(Locale.US, Config.VIDEO_LIBRARY_FALLBACK_THUMB_URL_FMT, video.vid);
      LOGW(TAG, "Video with missing thumbnail URL: " + video.vid + ". Using fallback: " + thumbUrl);
    }

    list.add(
        builder
            .withValue(ScheduleContract.Videos.VIDEO_ID, video.id)
            .withValue(ScheduleContract.Videos.VIDEO_YEAR, video.year)
            .withValue(ScheduleContract.Videos.VIDEO_TITLE, video.title.trim())
            .withValue(ScheduleContract.Videos.VIDEO_DESC, video.desc)
            .withValue(ScheduleContract.Videos.VIDEO_VID, video.vid)
            .withValue(ScheduleContract.Videos.VIDEO_TOPIC, video.topic)
            .withValue(ScheduleContract.Videos.VIDEO_SPEAKERS, video.speakers)
            .withValue(ScheduleContract.Videos.VIDEO_THUMBNAIL_URL, thumbUrl)
            .withValue(ScheduleContract.Videos.VIDEO_IMPORT_HASHCODE, video.getImportHashcode())
            .build());
  }
  /** {@inheritDoc} */
  @Override
  public ArrayList<ContentProviderOperation> parse(XmlPullParser parser, ContentResolver resolver)
      throws XmlPullParserException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    // Walk document, parsing any incoming entries
    int type;
    while ((type = parser.next()) != END_DOCUMENT) {
      if (type == START_TAG && ENTRY.equals(parser.getName())) {
        // Process single spreadsheet row at a time
        final SpreadsheetEntry entry = SpreadsheetEntry.fromParser(parser);

        final String speakerId = sanitizeId(entry.get(Columns.SPEAKER_TITLE), true);
        final Uri speakerUri = Speakers.buildSpeakerUri(speakerId);

        // Check for existing details, only update when changed
        final long localUpdated = queryItemUpdated(speakerUri, resolver);
        final long serverUpdated = entry.getUpdated();
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
          Log.v(TAG, "found speaker " + entry.toString());
          Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
        }
        if (localUpdated >= serverUpdated) continue;

        // Clear any existing values for this speaker, treating the
        // incoming details as authoritative.
        batch.add(ContentProviderOperation.newDelete(speakerUri).build());

        final ContentProviderOperation.Builder builder =
            ContentProviderOperation.newInsert(Speakers.CONTENT_URI);

        builder.withValue(SyncColumns.UPDATED, serverUpdated);
        builder.withValue(Speakers.SPEAKER_ID, speakerId);
        builder.withValue(Speakers.SPEAKER_NAME, entry.get(Columns.SPEAKER_TITLE));
        builder.withValue(Speakers.SPEAKER_IMAGE_URL, entry.get(Columns.SPEAKER_IMAGE_URL));
        builder.withValue(Speakers.SPEAKER_COMPANY, entry.get(Columns.SPEAKER_COMPANY));
        builder.withValue(Speakers.SPEAKER_ABSTRACT, entry.get(Columns.SPEAKER_ABSTRACT));
        builder.withValue(Speakers.SPEAKER_URL, entry.get(Columns.SPEAKER_URL));

        // Normal speaker details ready, write to provider
        batch.add(builder.build());
      }
    }

    return batch;
  }
Beispiel #13
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());
    }
  }
Beispiel #14
0
 private void saveDirection(String polyline) {
   ContentProviderOperation.Builder b =
       ContentProviderOperation.newInsert(DirectionMetaData.TableMetaData.CONTENT_URI);
   b.withValue(DirectionMetaData.TableMetaData.END_ADDRESS, mTripLeg.destName);
   b.withValue(DirectionMetaData.TableMetaData.OVERVIEW_POLYLINE, polyline);
   b.withValue(DirectionMetaData.TableMetaData.START_ADDRESS, mTripLeg.originName);
   b.withValue(DirectionMetaData.TableMetaData.TRIP_LEG_ID, mTripLeg.id);
   b.withValue(DirectionMetaData.TableMetaData.DIRECTION_MODE, getMode(mTripLeg));
   mDbOperations.add(b.build());
 }
 public boolean checkOperationBuilder(
     String accountType,
     ContentProviderOperation.Builder builder,
     Cursor cursor,
     int type,
     String commd) {
   if (type == TYPE_OPERATION_INSERT) {
     builder.withValue(Data.DATA2, 2);
     return true;
   }
   return false;
 }
  @Override
  public ArrayList<ContentProviderOperation> parse(String parser, ContentResolver resolver)
      throws IOException, JSONException {
    // TODO Auto-generated method stub

    Log.v("TAG", "ENTER INTO DASHBORED");

    ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>();

    ContentProviderOperation.Builder builder_delete =
        ContentProviderOperation.newDelete(Dashboards.CONTENT_URI);
    batch.add(builder_delete.build());

    if (parser != null) {
      Gson gson = new Gson();
      dashBoard = gson.fromJson(parser, Dashboard.class);
      final ContentProviderOperation.Builder builder =
          ContentProviderOperation.newInsert(Dashboards.CONTENT_URI);
      builder.withValue(Dashboards.PATIENT_ID, dashBoard.getPatientId());
      builder.withValue(Dashboards.JSON, parser);
      batch.add(builder.build());

      Log.v("dashboard", dashBoard.getPatientId());
      Log.v("TAG", "LOADED INTO DATABASE");
    }
    return batch;
  }
Beispiel #17
0
 public static void mergeWithContact(Context c, long rawContactID, long contactID) {
   ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
   Set<Long> ids = getRawContacts(c, contactID, rawContactID);
   for (long id : ids) {
     ContentProviderOperation.Builder builder =
         ContentProviderOperation.newUpdate(ContactsContract.AggregationExceptions.CONTENT_URI);
     builder.withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID1, rawContactID);
     builder.withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, id);
     builder.withValue(
         ContactsContract.AggregationExceptions.TYPE,
         ContactsContract.AggregationExceptions.TYPE_KEEP_TOGETHER);
     operationList.add(builder.build());
   }
   if (operationList.size() > 0)
     try {
       c.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
     } catch (RemoteException e) {
       Log.e("Error", e.getLocalizedMessage());
     } catch (OperationApplicationException e) {
       Log.e("Error", e.getLocalizedMessage());
     }
 }
 public void buildDiscoveryUpdate(
     CapsuleDiscovery discovery,
     boolean withYield,
     int capsuleIdBackRefIndex,
     CapsuleContract.SyncStateAction syncAction) {
   // Build the URI
   Uri uri =
       CapsuleOperations.appendDirtyQueryParam(
           syncAction,
           ContentUris.withAppendedId(
               CapsuleContract.Discoveries.CONTENT_URI, discovery.getDiscoveryId()));
   // Build the UPDATE operation
   ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri);
   builder.withValues(Discoveries.buildContentValues(discovery));
   builder.withYieldAllowed(withYield);
   // Add the back value reference for the Capsule ID
   if (capsuleIdBackRefIndex >= 0) {
     builder.withValueBackReference(CapsuleContract.Discoveries.CAPSULE_ID, capsuleIdBackRefIndex);
   }
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
  private static long getCalendar(Account account) {
    // Find the Last.fm calendar if we've got one
    Uri calenderUri =
        Calendars.CONTENT_URI
            .buildUpon()
            .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
            .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
            .build();
    Cursor c1 =
        mContentResolver.query(calenderUri, new String[] {BaseColumns._ID}, null, null, null);
    if (c1.moveToNext()) {
      return c1.getLong(0);
    } else {
      ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();

      ContentProviderOperation.Builder builder =
          ContentProviderOperation.newInsert(
              Calendars.CONTENT_URI
                  .buildUpon()
                  .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                  .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                  .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                  .build());
      builder.withValue(Calendars.ACCOUNT_NAME, account.name);
      builder.withValue(Calendars.ACCOUNT_TYPE, account.type);
      builder.withValue(Calendars.NAME, "Last.fm Events");
      builder.withValue(Calendars.CALENDAR_DISPLAY_NAME, "Last.fm Events");
      builder.withValue(Calendars.CALENDAR_COLOR, 0xD51007);
      builder.withValue(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_RESPOND);
      builder.withValue(Calendars.OWNER_ACCOUNT, account.name);
      builder.withValue(Calendars.SYNC_EVENTS, 1);
      operationList.add(builder.build());
      try {
        mContentResolver.applyBatch(CalendarContract.AUTHORITY, operationList);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return -1;
      }
      return getCalendar(account);
    }
  }
 public final String toString() {
   StringBuilder localStringBuilder = new StringBuilder("Op: ");
   if (a != null) {}
   for (Object localObject = a;
       ;
       localObject = ((ContentProviderOperation.Builder) localObject).build()) {
     localStringBuilder.append(f[0]);
     localObject = ((ContentProviderOperation) localObject).getUri();
     localStringBuilder.append(' ');
     localStringBuilder.append(((Uri) localObject).getPath());
     if (c != null) {
       localStringBuilder.append("Back value of ").append(c).append(": ").append(d);
     }
     return localStringBuilder.toString();
     if (b == null) {
       throw new IllegalArgumentException("Operation must have CPO.Builder");
     }
     localObject = b;
     if (c != null) {
       ((ContentProviderOperation.Builder) localObject).withValueBackReference(c, d + 0);
     }
   }
 }
Beispiel #21
0
  /**
   * Inserts postal data into the builder object. Note that the data structure of ContactsContract
   * is different from that defined in vCard. So some conversion may be performed in this method.
   * See also { {@link #getVCardPostalElements(ContentValues)}
   */
  public static void insertStructuredPostalDataUsingContactsStruct(
      int vcardType,
      final ContentProviderOperation.Builder builder,
      final ContactStruct.PostalData postalData) {
    builder.withValueBackReference(StructuredPostal.RAW_CONTACT_ID, 0);
    builder.withValue(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);

    builder.withValue(StructuredPostal.TYPE, postalData.type);
    if (postalData.type == StructuredPostal.TYPE_CUSTOM) {
      builder.withValue(StructuredPostal.LABEL, postalData.label);
    }

    builder.withValue(StructuredPostal.POBOX, postalData.pobox);
    // Extended address is dropped since there's no relevant entry in
    // ContactsContract.
    builder.withValue(StructuredPostal.STREET, postalData.street);
    builder.withValue(StructuredPostal.CITY, postalData.localty);
    builder.withValue(StructuredPostal.REGION, postalData.region);
    builder.withValue(StructuredPostal.POSTCODE, postalData.postalCode);
    builder.withValue(StructuredPostal.COUNTRY, postalData.country);

    builder.withValue(
        StructuredPostal.FORMATTED_ADDRESS, postalData.getFormattedAddress(vcardType));
    if (postalData.isPrimary) {
      builder.withValue(Data.IS_PRIMARY, 1);
    }
  }
Beispiel #22
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});
 }
 /**
  * Consider building the given {@link ContentProviderOperation.Builder} and appending it to the
  * given list, which only happens if builder is valid.
  */
 private void possibleAdd(
     ArrayList<ContentProviderOperation> diff, ContentProviderOperation.Builder builder) {
   if (builder != null) {
     diff.add(builder.build());
   }
 }
  private static void parseSession(
      XmlPullParser parser, ArrayList<ContentProviderOperation> batch, ContentResolver resolver)
      throws XmlPullParserException, IOException {
    final int depth = parser.getDepth();
    ContentProviderOperation.Builder builder =
        ContentProviderOperation.newInsert(Sessions.CONTENT_URI);
    builder.withValue(Sessions.UPDATED, 0);

    long startTime = -1;
    long endTime = -1;
    String title = null;
    String sessionId = null;
    String trackId = null;

    String tag = null;
    int type;
    while (((type = parser.next()) != END_TAG || parser.getDepth() > depth)
        && type != END_DOCUMENT) {
      if (type == START_TAG) {
        tag = parser.getName();
      } else if (type == END_TAG) {
        tag = null;
      } else if (type == TEXT) {
        final String text = parser.getText();
        if (Tags.START.equals(tag)) {
          startTime = ParserUtils.parseTime(text);
        } else if (Tags.END.equals(tag)) {
          endTime = ParserUtils.parseTime(text);
        } else if (Tags.ROOM.equals(tag)) {
          final String roomId = Rooms.generateRoomId(text);
          builder.withValue(Sessions.ROOM_ID, roomId);
        } else if (Tags.TRACK.equals(tag)) {
          trackId = Tracks.generateTrackId(text);
        } else if (Tags.ID.equals(tag)) {
          sessionId = text;
        } else if (Tags.TITLE.equals(tag)) {
          title = text;
        } else if (Tags.ABSTRACT.equals(tag)) {
          builder.withValue(Sessions.SESSION_ABSTRACT, text);
        }
      }
    }

    if (sessionId == null) {
      sessionId = Sessions.generateSessionId(title);
    }

    builder.withValue(Sessions.SESSION_ID, sessionId);
    builder.withValue(Sessions.SESSION_TITLE, title);

    // Use empty strings to make sure SQLite search trigger has valid data
    // for updating search index.
    builder.withValue(Sessions.SESSION_ABSTRACT, "");
    builder.withValue(Sessions.SESSION_REQUIREMENTS, "");
    builder.withValue(Sessions.SESSION_KEYWORDS, "");

    final String blockId = ParserUtils.findBlock(title, startTime, endTime);
    builder.withValue(Sessions.BLOCK_ID, blockId);

    // Propagate any existing starred value
    final Uri sessionUri = Sessions.buildSessionUri(sessionId);
    final int starred = querySessionStarred(sessionUri, resolver);
    if (starred != -1) {
      builder.withValue(Sessions.SESSION_STARRED, starred);
    }

    batch.add(builder.build());

    if (trackId != null) {
      // TODO: support parsing multiple tracks per session
      final Uri sessionTracks = Sessions.buildTracksDirUri(sessionId);
      batch.add(
          ContentProviderOperation.newInsert(sessionTracks)
              .withValue(SessionsTracks.SESSION_ID, sessionId)
              .withValue(SessionsTracks.TRACK_ID, trackId)
              .build());
    }
  }
  private static void addContact(Context context, Account account, JuickUser user) {
    //     Log.i(TAG, "Adding contact: " + name);
    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();

    // Create our RawContact
    ContentProviderOperation.Builder builder =
        ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
    builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
    builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
    builder.withValue(RawContacts.SYNC1, user.UName);
    operationList.add(builder.build());

    // Nickname
    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
    builder.withValueBackReference(ContactsContract.CommonDataKinds.Nickname.RAW_CONTACT_ID, 0);
    builder.withValue(
        ContactsContract.Data.MIMETYPE,
        ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
    builder.withValue(ContactsContract.CommonDataKinds.Nickname.NAME, user.UName);
    operationList.add(builder.build());

    // StructuredName
    if (user.FullName != null) {
      builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
      builder.withValueBackReference(
          ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);
      builder.withValue(
          ContactsContract.Data.MIMETYPE,
          ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
      builder.withValue(
          ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, user.FullName);
      operationList.add(builder.build());
    }

    // Photo
    Bitmap photo = Utils.downloadImage("http://i.juick.com/a/" + user.UID + ".png");
    if (photo != null) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      photo.compress(Bitmap.CompressFormat.PNG, 100, baos);
      builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
      builder.withValueBackReference(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, 0);
      builder.withValue(
          ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
      builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, baos.toByteArray());
      operationList.add(builder.build());
    }

    // link to profile
    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
    builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
    builder.withValue(
        ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.com.juick.profile");
    builder.withValue(ContactsContract.Data.DATA1, user.UID);
    builder.withValue(ContactsContract.Data.DATA2, user.UName);
    builder.withValue(ContactsContract.Data.DATA3, context.getString(R.string.Juick_profile));
    builder.withValue(ContactsContract.Data.DATA4, user.UName);
    operationList.add(builder.build());

    try {
      mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
    } catch (Exception e) {
      //      Log.e(TAG, "Something went wrong during creation! " + e);
      e.printStackTrace();
    }
  }
Beispiel #26
0
 private static ContentProviderOperation.Builder referenceRawContact(
     ContentProviderOperation.Builder builder, long rawContactId) {
   return rawContactId == -1
       ? builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
       : builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
 }
Beispiel #27
0
 private static void a(Account paramAccount, String paramString1, String paramString2)
 {
   g5.b(z[3] + paramString1 + z[9] + paramString2);
   ArrayList localArrayList = new ArrayList();
   ContentProviderOperation.Builder localBuilder1 = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
   localBuilder1.withValue(z[4], paramAccount.name);
   localBuilder1.withValue(z[10], paramAccount.type);
   localBuilder1.withValue(z[13], paramString2);
   localArrayList.add(localBuilder1.build());
   ContentProviderOperation.Builder localBuilder2 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
   localBuilder2.withValueBackReference(z[6], 0);
   localBuilder2.withValue(z[11], z[8]);
   localBuilder2.withValue(z[0], paramString1);
   localArrayList.add(localBuilder2.build());
   ContentProviderOperation.Builder localBuilder3 = ContentProviderOperation.newInsert(a(ContactsContract.Data.CONTENT_URI));
   localBuilder3.withValueBackReference(z[6], 0);
   localBuilder3.withValue(z[11], z[2]);
   localBuilder3.withValue(z[0], paramString2);
   localBuilder3.withValue(z[12], App.Mb.getString(2131296836));
   localBuilder3.withValue(z[1], "+" + paramString2.substring(0, paramString2.indexOf("@")));
   localArrayList.add(localBuilder3.build());
   try
   {
     App.ib.applyBatch(z[5], localArrayList);
     return;
   }
   catch (Exception localException)
   {
     while (true)
       g5.d(z[7] + paramString1 + z[9] + paramString2 + localException.toString());
   }
 }
Beispiel #28
0
  private void insertSingleContact(String name, String phone, String email, boolean starred) {
    final ArrayList<ContentProviderOperation> operationList =
        new ArrayList<ContentProviderOperation>();
    ContentProviderOperation.Builder builder =
        ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
    builder.withValue(ContactsContract.RawContacts.STARRED, starred ? 1 : 0);
    operationList.add(builder.build());

    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
    builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0);
    builder.withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);
    operationList.add(builder.build());

    if (phone != null) {
      builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
      builder.withValueBackReference(Phone.RAW_CONTACT_ID, 0);
      builder.withValue(ContactsContract.Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
      builder.withValue(Phone.TYPE, Phone.TYPE_MOBILE);
      builder.withValue(Phone.NUMBER, phone);
      builder.withValue(ContactsContract.Data.IS_PRIMARY, 1);
      operationList.add(builder.build());
    }
    if (email != null) {
      builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
      builder.withValueBackReference(Email.RAW_CONTACT_ID, 0);
      builder.withValue(ContactsContract.Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
      builder.withValue(Email.TYPE, Email.TYPE_HOME);
      builder.withValue(Email.DATA, email);
      operationList.add(builder.build());
    }

    try {
      mContext.getContentResolver().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()));
    }
  }
Beispiel #29
0
 private static void a(Account paramAccount, ArrayList<zq> paramArrayList)
 {
   boolean bool = b;
   ArrayList localArrayList1 = new ArrayList();
   StringBuilder localStringBuilder = new StringBuilder();
   ArrayList localArrayList2 = new ArrayList();
   Iterator localIterator = paramArrayList.iterator();
   int k;
   for (int i = 0; ; i = k)
     while (true)
     {
       zq localzq;
       if (localIterator.hasNext())
       {
         localzq = (zq)localIterator.next();
         if (4 + localArrayList1.size() < a);
       }
       try
       {
         App.ib.applyBatch(z[5], localArrayList1);
         localArrayList1.clear();
         if (i > 0);
         localStringBuilder.delete(0, localStringBuilder.length());
         if (localzq.b.indexOf("@") <= 0)
         {
           localArrayList2.add(localzq);
           if (!bool);
         }
         else
         {
           int j = localArrayList1.size();
           localStringBuilder.append(localzq).append(z[9]);
           ContentProviderOperation.Builder localBuilder1 = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
           localBuilder1.withValue(z[4], paramAccount.name);
           localBuilder1.withValue(z[10], paramAccount.type);
           localBuilder1.withValue(z[13], localzq.b);
           localArrayList1.add(localBuilder1.build());
           ContentProviderOperation.Builder localBuilder2 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
           localBuilder2.withValueBackReference(z[6], j);
           localBuilder2.withValue(z[11], z[8]);
           localBuilder2.withValue(z[0], localzq.h);
           localArrayList1.add(localBuilder2.build());
           ContentProviderOperation.Builder localBuilder3 = ContentProviderOperation.newInsert(a(ContactsContract.Data.CONTENT_URI));
           localBuilder3.withValueBackReference(z[6], j);
           localBuilder3.withValue(z[11], z[2]);
           localBuilder3.withValue(z[0], localzq.b);
           localBuilder3.withValue(z[12], App.Mb.getString(2131296836));
           localBuilder3.withValue(z[1], "+" + localzq.b.substring(0, localzq.b.indexOf("@")));
           localArrayList1.add(localBuilder3.build());
           if (Build.VERSION.SDK_INT >= 14)
           {
             ContentProviderOperation.Builder localBuilder4 = ContentProviderOperation.newUpdate(ContactsContract.AggregationExceptions.CONTENT_URI);
             localBuilder4.withValue(z[26], Long.valueOf(localzq.a()));
             localBuilder4.withValueBackReference(z[28], j);
             localBuilder4.withValue(z[24], Integer.valueOf(1));
             localArrayList1.add(localBuilder4.build());
           }
           k = i + 1;
           if (!bool)
             break;
         }
       }
       catch (Exception localException2)
       {
         try
         {
           while (true)
           {
             if (!localArrayList1.isEmpty())
             {
               App.ib.applyBatch(z[5], localArrayList1);
               localArrayList1.clear();
             }
             localStringBuilder.delete(0, localStringBuilder.length());
             return;
             localException2 = localException2;
             g5.d(z[25] + i + "/" + localException2.toString());
           }
         }
         catch (Exception localException1)
         {
           while (true)
           {
             g5.d(z[27] + localException1.toString());
             App.w.a(localArrayList2);
           }
         }
         finally
         {
           App.w.a(localArrayList2);
         }
       }
     }
 }
 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();
 }