@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; }
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()); } }
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(); }
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 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()); }
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 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()); } }
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 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())); } }
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()); }
/** {@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; }
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()); }
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(); }
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 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()); }
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()); } }
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(); } }
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 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); } } } }
/** * 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 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(); }
private static void importOneSimContact( final Cursor cursor, final ContentResolver resolver, Account account) { final NamePhoneTypePair namePhoneTypePair = new NamePhoneTypePair( cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))); final String name = namePhoneTypePair.name; final int phoneType = namePhoneTypePair.phoneType; final String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1)); final String emailAddresses = null; final String[] emailAddressArray; if (!TextUtils.isEmpty(emailAddresses)) { emailAddressArray = emailAddresses.split(","); } else { emailAddressArray = null; } final ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); if (account != null) { builder.withValue(RawContacts.ACCOUNT_NAME, account.name); builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); } else { builder.withValues(sEmptyContentValues); } operationList.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); builder.withValue(StructuredName.DISPLAY_NAME, name); operationList.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Phone.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); builder.withValue(Phone.TYPE, phoneType); builder.withValue(Phone.NUMBER, phoneNumber); builder.withValue(Data.IS_PRIMARY, 1); operationList.add(builder.build()); if (emailAddresses != null) { for (String emailAddress : emailAddressArray) { builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Email.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE); builder.withValue(Email.TYPE, Email.TYPE_MOBILE); builder.withValue(Email.DATA, emailAddress); 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())); } }