/** shows a notification */ private void showNotification(NotificationManager nm, String path, int titleId){ String notifyPath = path; Notification n = new Notification.Builder(this) .setContentTitle(getString(titleId)) .setContentText(notifyPath) .setSmallIcon(android.R.drawable.stat_notify_sync) .setOngoing(true) .getNotification(); nm.notify(NOTIFICATION_ID, n); }
protected Builder buildOrganization(Builder builder, Contact contact) { if (contact.getOrganization() == null && contact.getJobTitle() == null && contact.getJobDescription() == null) return null; ezvcard.property.Organization organization = contact.getOrganization(); String company = null, department = null; if (organization != null) { Iterator<String> org = organization.getValues().iterator(); if (org.hasNext()) company = org.next(); if (org.hasNext()) department = org.next(); } return builder .withValue(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE) .withValue(Organization.COMPANY, company) .withValue(Organization.DEPARTMENT, department) .withValue(Organization.TITLE, contact.getJobTitle()) .withValue(Organization.JOB_DESCRIPTION, contact.getJobDescription()); }
/** * Build a list of {@link ContentProviderOperation} that will assert any * "before" state hasn't changed. This is maintained separately so that all * asserts can take place before any updates occur. */ public void buildAssert(ArrayList<ContentProviderOperation> buildInto) { final boolean isContactInsert = mValues.isInsert(); 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; final ContentProviderOperation.Builder builder = ContentProviderOperation .newAssertQuery(mContactsQueryUri); builder.withSelection(RawContacts._ID + "=" + beforeId, null); builder.withValue(RawContacts.VERSION, beforeVersion); buildInto.add(builder.build()); } }
/** * Build a {@link ContentProviderOperation} that will transform our * "before" state into our "after" state, using insert, update, or * delete as needed. */ public ContentProviderOperation.Builder buildDiff(Uri targetUri) { Builder builder = null; if (isInsert()) { // Changed values are "insert" back-referenced to Contact mAfter.remove(mIdColumn); builder = ContentProviderOperation.newInsert(targetUri); builder.withValues(mAfter); } else if (isDelete()) { // When marked for deletion and "before" exists, then "delete" builder = ContentProviderOperation.newDelete(targetUri); builder.withSelection(mIdColumn + "=" + getId(), null); } else if (isUpdate()) { // When has changes and "before" exists, then "update" builder = ContentProviderOperation.newUpdate(targetUri); builder.withSelection(mIdColumn + "=" + getId(), null); builder.withValues(mAfter); } return builder; }
@Override public void resolveBackRefs(ConvertibleToOperation convertible, Builder builder) { if (mValueBackRefs != null && mValueBackRefs.containsKey(convertible)) { ContentValues values = new ContentValues(); for (ValueBackRef valueBackRef : mValueBackRefs.get(convertible)) { values.put(valueBackRef.column, getParentPosition(valueBackRef.parent)); } builder.withValueBackReferences(values); } if (mSelectionBackRefs != null) { for (SelectionBackRef selectionBackRef : mSelectionBackRefs.get(convertible)) { builder.withSelectionBackReference( selectionBackRef.selectionArgumentIndex, getParentPosition(selectionBackRef.parent) ); } } mParentsPosition.put(convertible, mParentsPosition.size()); }
private static void buildInsertOperations(SQLiteDatabase dbImport, Uri uri, String table, ArrayList<ContentProviderOperation> operations) { Log.v(TAG, "buildInsertOperations: uri = " + uri + ", table=" + table); Cursor c = dbImport.query(false, table, null, null, null, null, null, null, null); if (c != null) { try { if (c.moveToFirst()) { int columnCount = c.getColumnCount(); do { Builder builder = ContentProviderOperation.newInsert(uri); for (int i = 0; i < columnCount; i++) { String columnName = c.getColumnName(i); Object value = c.getString(i); builder.withValue(columnName, value); } operations.add(builder.build()); } while (c.moveToNext()); } } finally { c.close(); } } }
public void addDelete(DeleteString deletes) { int deleteCount = deletes.getCount(); if (deleteCount > 0) { Builder delete = ContentProviderOperation.newDelete(VideoStoreInternal.FILES_SCANNED); String deleteSelection = BaseColumns._ID + " IN (" + deletes.toString() + ")"; if (DBG) Log.d(TAG, "delete WHERE " + deleteSelection); delete.withSelection(deleteSelection, null); mUpdateExecutor.add(delete.build()); mDeletes += deleteCount; } }
public void deleteAllExceptRemoteIds(String[] preserveIds) { String where; if (preserveIds.length != 0) { where = entryColumnRemoteId() + " NOT IN (" + SQLUtils.quoteArray(preserveIds) + ")"; } else where = entryColumnRemoteId() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()) .withSelection(entryColumnParentID() + "=? AND (" + where + ")", new String[]{String.valueOf(id)}); pendingOperations.add(builder .withYieldAllowed(true) .build()); }
public void deleteAllExceptUIDs(String[] preserveUids) { String where; if (preserveUids.length != 0) { where = entryColumnUID() + " NOT IN (" + SQLUtils.quoteArray(preserveUids) + ")"; } else where = entryColumnUID() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()) .withSelection(entryColumnParentID() + "=? AND (" + where + ")", new String[]{String.valueOf(id)}); pendingOperations.add(builder .withYieldAllowed(true) .build()); }
void populateReminders(Event e) throws RemoteException { // reminders Uri remindersUri = Reminders.CONTENT_URI.buildUpon() .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .build(); @Cleanup Cursor c = providerClient.query(remindersUri, new String[]{ /* 0 */ Reminders.MINUTES, Reminders.METHOD }, Reminders.EVENT_ID + "=?", new String[]{String.valueOf(e.getLocalID())}, null); while (c != null && c.moveToNext()) { //Duration duration = new Duration.Builder().prior(true).minutes(c.getInt(0)).build(); Duration duration = new Duration.Builder().minutes(c.getInt(0)).build(); Trigger trigger = new Trigger(duration, Related.START); VAlarm alarm = VAlarm.display(trigger, e.getSummary()); e.addAlarm(alarm); } }
@SuppressLint("InlinedApi") protected Builder buildAttendee(Builder builder, Attendee attendee) { String email = attendee.getEmail(); String cn = attendee.getCommonName(); if (cn != null) builder = builder.withValue(Attendees.ATTENDEE_NAME, cn); int type = Attendees.TYPE_NONE; if (attendee.getCalendarUserType() == CalendarUserType.RESOURCE) type = Attendees.TYPE_RESOURCE; else { int relationship; if (attendee.getRole() == Role.CHAIR) relationship = Attendees.RELATIONSHIP_ORGANIZER; else { relationship = Attendees.RELATIONSHIP_ATTENDEE; } builder = builder.withValue(Attendees.ATTENDEE_RELATIONSHIP, relationship); } int status = Attendees.ATTENDEE_STATUS_NONE; ParticipationStatus partStat = attendee.getParticipationStatus(); if (partStat == null || partStat == ParticipationStatus.NEEDS_ACTION) status = Attendees.ATTENDEE_STATUS_INVITED; else if (partStat == ParticipationStatus.ACCEPTED) status = Attendees.ATTENDEE_STATUS_ACCEPTED; else if (partStat == ParticipationStatus.DECLINED) status = Attendees.ATTENDEE_STATUS_DECLINED; else if (partStat == ParticipationStatus.TENTATIVE) status = Attendees.ATTENDEE_STATUS_TENTATIVE; return builder .withValue(Attendees.ATTENDEE_EMAIL, email) .withValue(Attendees.ATTENDEE_TYPE, type) .withValue(Attendees.ATTENDEE_STATUS, status); }
protected Builder buildReminder(Builder builder, VAlarm alarm) { int minutes = 0; if (alarm.getTrigger() != null && alarm.getTrigger().getDuration() != null) //minutes = duration.getDays() * 24*60 + duration.getHours()*60 + duration.getMinutes(); minutes = (int)(alarm.getTrigger().getDuration().toMillis()/60000); Log.d(TAG, "Adding alarm " + minutes + " min before"); return builder .withValue(Reminders.METHOD, Reminders.METHOD_ALERT) .withValue(Reminders.MINUTES, minutes); }
protected Builder newDataInsertBuilder(Uri dataUri, String refFieldName, long raw_ref_id, Integer backrefIdx) { Builder builder = ContentProviderOperation.newInsert(syncAdapterURI(dataUri)); if (backrefIdx != -1) return builder.withValueBackReference(refFieldName, backrefIdx); else return builder.withValue(refFieldName, raw_ref_id); }
public void deleteAllExceptRemoteIds(String[] preserveIds) { String where; if (preserveIds.length != 0) { where = entryColumnRemoteId() + " NOT IN (" + SQLUtils.quoteArray(preserveIds) + ")"; } else where = entryColumnRemoteId() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null); pendingOperations.add(builder .withYieldAllowed(true) .build()); }
public void deleteAllExceptUIDs(String[] preserveUids) { String where; if (preserveUids.length != 0) { where = entryColumnUID() + " NOT IN (" + SQLUtils.quoteArray(preserveUids) + ")"; } else where = entryColumnUID() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null); pendingOperations.add(builder .withYieldAllowed(true) .build()); }
@Override protected Builder buildEntry(Builder builder, Resource resource) { Contact contact = (Contact)resource; return builder .withValue(RawContacts.ACCOUNT_NAME, account.name) .withValue(RawContacts.ACCOUNT_TYPE, account.type) .withValue(entryColumnRemoteId(), contact.getId()) .withValue(entryColumnUID(), contact.getUid()) .withValue(entryColumnETag(), contact.getETag()) .withValue(COLUMN_UNKNOWN_PROPERTIES, contact.getUnknownProperties()) .withValue(RawContacts.STARRED, contact.isStarred()); }
protected Builder buildStructuredName(Builder builder, Contact contact) { return builder .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) .withValue(StructuredName.PREFIX, contact.getPrefix()) .withValue(StructuredName.DISPLAY_NAME, contact.getDisplayName()) .withValue(StructuredName.GIVEN_NAME, contact.getGivenName()) .withValue(StructuredName.MIDDLE_NAME, contact.getMiddleName()) .withValue(StructuredName.FAMILY_NAME, contact.getFamilyName()) .withValue(StructuredName.SUFFIX, contact.getSuffix()) .withValue(StructuredName.PHONETIC_GIVEN_NAME, contact.getPhoneticGivenName()) .withValue(StructuredName.PHONETIC_MIDDLE_NAME, contact.getPhoneticMiddleName()) .withValue(StructuredName.PHONETIC_FAMILY_NAME, contact.getPhoneticFamilyName()); }
protected Builder buildEmail(Builder builder, ezvcard.property.Email email) { int typeCode = 0; String typeLabel = null; boolean is_primary = false; for (EmailType type : email.getTypes()) if (type == EmailType.PREF) is_primary = true; else if (type == EmailType.HOME) typeCode = Email.TYPE_HOME; else if (type == EmailType.WORK) typeCode = Email.TYPE_WORK; else if (type == Contact.EMAIL_TYPE_MOBILE) typeCode = Email.TYPE_MOBILE; if (typeCode == 0) { if (email.getTypes().isEmpty()) typeCode = Email.TYPE_OTHER; else { typeCode = Email.TYPE_CUSTOM; typeLabel = xNameToLabel(email.getTypes().iterator().next().getValue()); } } builder = builder .withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE) .withValue(Email.ADDRESS, email.getValue()) .withValue(Email.TYPE, typeCode) .withValue(Email.IS_PRIMARY, is_primary ? 1 : 0) .withValue(Phone.IS_SUPER_PRIMARY, is_primary ? 1 : 0);; if (typeLabel != null) builder = builder.withValue(Email.LABEL, typeLabel); return builder; }
protected Builder buildEvent(Builder builder, DateOrTimeProperty date, int type) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); if (date.getDate() == null) { Log.i(TAG, "Ignoring contact event without date"); return null; } return builder .withValue(Data.MIMETYPE, CommonDataKinds.Event.CONTENT_ITEM_TYPE) .withValue(CommonDataKinds.Event.TYPE, type) .withValue(CommonDataKinds.Event.START_DATE, formatter.format(date.getDate())); }
public Builder addValues(Builder builder) { builder.withValue(Columns.SESSION_TYPE_ID.getName(), mID) .withValue(Columns.SESSION_TYPE_DEFAULT_TIME.getName(), mDefaultTimeLength) .withValue(Columns.SESSION_TYPE_PROGRAM_ID.getName(), mProgramID) .withValue(Columns.SESSION_TYPE_NAME.getName(), mName); return builder; }
public Builder addValues(Builder builder) { builder.withValue(Columns.LOCATION_TAX1.getName(), mTax1) .withValue(Columns.LOCATION_TAX2.getName(), mTax2) .withValue(Columns.LOCATION_TAX3.getName(), mTax3) .withValue(Columns.LOCATION_TAX4.getName(), mTax4) .withValue(Columns.LOCATION_TAX5.getName(), mTax5) .withValue(Columns.LOCATION_TREAT_ROOM.getName(), mTreatmentRoom) .withValue(Columns.LOCATION_HAS_CLASSES.getName(), mHasClass ? 1:0) .withValue(Columns.LOCATION_LONGITUDE.getName(), mLongitude) .withValue(Columns.LOCATION_LATITUDE.getName(), mLatitude) .withValue(Columns.LOCATION_SITE_ID.getName(), mSiteID) .withValue(Columns.LOCATION_SQFT.getName(), mFacilitySquareFeet) .withValue(Columns.LOCATION_NAME.getName(), mName); return builder; }
/** * Append all operations needed to store the current contact to a set of * operations. * @param contact The current contact with metadata. * @param operations A set of operations to be extended. */ public void persist(RawContact contact, ArrayList<ContentProviderOperation> operations) { int operationsStart = operations.size(); Builder operation; if (contact.getID() == -1) { operation = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); } else { operation = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI); operation.withSelection(RawContacts._ID + "=?", new String[]{Long.toString(contact.getID())}); } ContentValues values = new ContentValues(); put(values, contact); operation.withValues(values); operations.add(operation.build()); for (Metadata data: contact.getMetadata().values()) { values.clear(); put(values, data); if (data instanceof DeletedMetadata) { operation = ContentProviderOperation.newDelete(Data.CONTENT_URI); operation.withValues(values); operation.withSelection(Data._ID + "=?", new String[]{Long.toString(contact.getID())}); operations.add(operation.build()); continue; } if (data.getID() == -1) { operation = ContentProviderOperation.newInsert(Data.CONTENT_URI); } else { operation = ContentProviderOperation.newUpdate(Data.CONTENT_URI); operation.withSelection(Data._ID + "=?", new String[]{Long.toString(data.getID())}); } if (contact.getID() == -1) { operation.withValueBackReference(Data.RAW_CONTACT_ID, operationsStart); values.remove(Data.RAW_CONTACT_ID); } else { values.put(Data.RAW_CONTACT_ID, contact.getID()); } operation.withValues(values); operations.add(operation.build()); } }
/** * 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()); } }
@Override public ArrayList<ContentProviderOperation> operations() { ArrayList<ContentProviderOperation> providerOperations = Lists.newArrayListWithCapacity(operations.size()); BackRefResolver backRefResolver = getBackRefResolver(); for (ConvertibleToOperation convertible : operations) { final Builder builder = convertible.toContentProviderOperationBuilder(mUriDecorator); backRefResolver.resolveBackRefs(convertible, builder); providerOperations.add(builder.build()); } return providerOperations; }
/** * In a single database transaction, delete all the cells from the current database, read the data from the given importDb file, create a batch of * corresponding insert operations, and execute the inserts. */ private static void importDatabase(Context context, File importDb) throws RemoteException, OperationApplicationException { Log.d("importDb=" + importDb); SQLiteDatabase dbImport = SQLiteDatabase.openDatabase(importDb.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY); ArrayList<ContentProviderOperation> operations = new ArrayList<>(); operations.add(ContentProviderOperation.newDelete(LogColumns.CONTENT_URI).build()); operations.add(ContentProviderOperation.newDelete(RideColumns.CONTENT_URI).build()); Uri insertUri = new Uri.Builder().authority(BikeyProvider.AUTHORITY).appendPath(RideColumns.TABLE_NAME) .appendQueryParameter(BikeyProvider.QUERY_NOTIFY, "false").build(); buildInsertOperations(context, dbImport, insertUri, RideColumns.TABLE_NAME, operations); insertUri = new Uri.Builder().authority(BikeyProvider.AUTHORITY).appendPath(LogColumns.TABLE_NAME) .appendQueryParameter(BikeyProvider.QUERY_NOTIFY, "false").build(); buildInsertOperations(context, dbImport, insertUri, LogColumns.TABLE_NAME, operations); dbImport.close(); }
/** * Parse a given {@link News} entry, building * {@link ContentProviderOperation} to define it locally. */ private static void parseMessage(JsonParser parser, ArrayList<ContentProviderOperation> batch, ContentResolver resolver) throws JsonParseException, IOException { Builder builder = ContentProviderOperation.newInsert(News.CONTENT_URI); builder.withValue(News.NEWS_NEW, 1); String fieldName = null; JsonToken token; while ((token = parser.nextToken()) != END_OBJECT) { if (token == FIELD_NAME) { fieldName = parser.getCurrentName(); } else if (token == VALUE_STRING) { final String text = parser.getText(); if (Fields.DATE.equals(fieldName)) { final String id = News.generateNewsId(text); builder.withValue(News.NEWS_ID, id); builder.withValue(News.NEWS_DATE, text); } else if (Fields.MESSAGE.equals(fieldName)) { builder.withValue(News.NEWS_TEXT, text); } } } batch.add(builder.build()); }
public void addUpdate(FileScanInfo update, long fileId) { Builder builder = ContentProviderOperation.newUpdate(VideoStoreInternal.FILES_SCANNED); builder.withValues(update.toContentValues()); builder.withSelection(SELECT_ID, new String[]{ String.valueOf(fileId) }); mUpdateExecutor.add(builder.build()); }
public void addSaveOperation(ArrayList<ContentProviderOperation> list, Map<String, Long> poster2IdMap) { if (list == null) return; // create ContentValues for this episode ContentValues values = new ContentValues(); values.put(ScraperStore.Episode.VIDEO_ID, Long.valueOf(mVideoId)); values.put(ScraperStore.Episode.NAME, mTitle); if(mAired != null) { values.put(ScraperStore.Episode.AIRED, Long.valueOf(mAired.getTime())); } values.put(ScraperStore.Episode.RATING, Float.valueOf(mRating)); values.put(ScraperStore.Episode.PLOT, mPlot); values.put(ScraperStore.Episode.SEASON, Integer.valueOf(mSeason)); values.put(ScraperStore.Episode.NUMBER, Integer.valueOf(mEpisode)); values.put(ScraperStore.Episode.SHOW, Long.valueOf(mShowId)); values.put(ScraperStore.Episode.IMDB_ID, mImdbId); values.put(ScraperStore.Episode.ONLINE_ID, Long.valueOf(mOnlineId)); values.put(ScraperStore.Episode.ACTORS_FORMATTED, getActorsFormatted()); values.put(ScraperStore.Episode.DIRECTORS_FORMATTED, getDirectorsFormatted()); ScraperImage pic = getEpisodePicture(); if(pic!=null && pic.getLargeFile()!=null) values.put(ScraperStore.Episode.PICTURE, pic.getLargeFile()); File cover = getCover(); String coverPath = (cover != null) ? cover.getPath() : null; if (coverPath != null && !coverPath.isEmpty()) values.put(ScraperStore.Episode.COVER, coverPath); // need to find the poster id in the database ScraperImage poster = getDefaultPoster(); if (poster != null) { Long posterId = poster2IdMap.get(poster.getLargeFile()); values.put(ScraperStore.Episode.POSTER_ID, posterId); } // build list of operations Builder cop = null; int firstIndex = list.size(); // first insert the episode base info - item 0 for backreferences cop = ContentProviderOperation.newInsert(ScraperStore.Episode.URI.BASE); cop.withValues(values); list.add(cop.build()); // then directors etc for(String director: mDirectors) { cop = ContentProviderOperation.newInsert(ScraperStore.Director.URI.EPISODE); cop.withValue(ScraperStore.Episode.Director.NAME, director); cop.withValueBackReference(ScraperStore.Episode.Director.EPISODE, firstIndex); list.add(cop.build()); } for(String actorName: mActors.keySet()) { cop = ContentProviderOperation.newInsert(ScraperStore.Actor.URI.EPISODE); cop.withValue(ScraperStore.Episode.Actor.NAME, actorName); cop.withValueBackReference(ScraperStore.Episode.Actor.EPISODE, firstIndex); cop.withValue(ScraperStore.Episode.Actor.ROLE, mActors.get(actorName)); list.add(cop.build()); } }
protected Recurrence parseRecurrence(String property, TimeZone tz) throws ParseException { RRule tmpRecRule = new RRule(property); Recurrence.Frequency freq = null; switch(tmpRecRule.getFreq()) { case DAILY: freq = Recurrence.Frequency.DAILY; break; case HOURLY: freq = Recurrence.Frequency.HOURLY; break; case MINUTELY: freq = Recurrence.Frequency.MINUTELY; break; case MONTHLY: freq = Recurrence.Frequency.MONTHLY; break; case SECONDLY: freq = Recurrence.Frequency.SECONDLY; break; case WEEKLY: freq = Recurrence.Frequency.WEEKLY; break; case YEARLY: freq = Recurrence.Frequency.YEARLY; break; default: //Fail quietly } List<Recurrence.DayOfWeek> dows = new ArrayList<Recurrence.DayOfWeek>(); for (WeekdayNum wday: tmpRecRule.getByDay()) { switch(wday.wday) { case MO: dows.add(Recurrence.DayOfWeek.MONDAY); break; case TU: dows.add(Recurrence.DayOfWeek.TUESDAY); break; case WE: dows.add(Recurrence.DayOfWeek.WEDNESDAY); break; case TH: dows.add(Recurrence.DayOfWeek.THURSDAY); break; case FR: dows.add(Recurrence.DayOfWeek.FRIDAY); break; case SA: dows.add(Recurrence.DayOfWeek.SATURDAY); break; case SU: dows.add(Recurrence.DayOfWeek.SUNDAY); break; default: //Fail quietly } } Recurrence tmpRec = new Recurrence.Builder(freq) .interval(tmpRecRule.getInterval()) .count(tmpRecRule.getCount()) .until(dateValueToDate(tmpRecRule.getUntil())) .byDay(dows) .byHour(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByHour())))) .byMinute(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByMinute())))) .byMonth(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByMonth())))) .byMonthDay(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByMonthDay())))) .bySecond(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getBySecond())))) .byWeekNo(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByWeekNo())))) .byYearDay(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByYearDay())))) .build(); return tmpRec; }
protected void queueOperation(Builder builder) { if (builder != null) pendingOperations.add(builder.build()); }
protected Builder buildPhoneNumber(Builder builder, Telephone number) { int typeCode = Phone.TYPE_OTHER; String typeLabel = null; boolean is_primary = false; Set<TelephoneType> types = number.getTypes(); // preferred number? if (types.contains(TelephoneType.PREF)) is_primary = true; // 1 Android type <-> 2 VCard types: fax, cell, pager if (types.contains(TelephoneType.FAX)) { if (types.contains(TelephoneType.HOME)) typeCode = Phone.TYPE_FAX_HOME; else if (types.contains(TelephoneType.WORK)) typeCode = Phone.TYPE_FAX_WORK; else typeCode = Phone.TYPE_OTHER_FAX; } else if (types.contains(TelephoneType.CELL)) { if (types.contains(TelephoneType.WORK)) typeCode = Phone.TYPE_WORK_MOBILE; else typeCode = Phone.TYPE_MOBILE; } else if (types.contains(TelephoneType.PAGER)) { if (types.contains(TelephoneType.WORK)) typeCode = Phone.TYPE_WORK_PAGER; else typeCode = Phone.TYPE_PAGER; // types with 1:1 translation } else if (types.contains(TelephoneType.HOME)) { typeCode = Phone.TYPE_HOME; } else if (types.contains(TelephoneType.WORK)) { typeCode = Phone.TYPE_WORK; } else if (types.contains(Contact.PHONE_TYPE_CALLBACK)) { typeCode = Phone.TYPE_CALLBACK; } else if (types.contains(TelephoneType.CAR)) { typeCode = Phone.TYPE_CAR; } else if (types.contains(Contact.PHONE_TYPE_COMPANY_MAIN)) { typeCode = Phone.TYPE_COMPANY_MAIN; } else if (types.contains(TelephoneType.ISDN)) { typeCode = Phone.TYPE_ISDN; } else if (types.contains(TelephoneType.PREF)) { typeCode = Phone.TYPE_MAIN; } else if (types.contains(Contact.PHONE_TYPE_RADIO)) { typeCode = Phone.TYPE_RADIO; } else if (types.contains(TelephoneType.TEXTPHONE)) { typeCode = Phone.TYPE_TELEX; } else if (types.contains(TelephoneType.TEXT)) { typeCode = Phone.TYPE_TTY_TDD; } else if (types.contains(Contact.PHONE_TYPE_ASSISTANT)) { typeCode = Phone.TYPE_ASSISTANT; } else if (types.contains(Contact.PHONE_TYPE_MMS)) { typeCode = Phone.TYPE_MMS; } else if (!types.isEmpty()) { TelephoneType type = types.iterator().next(); typeCode = Phone.TYPE_CUSTOM; typeLabel = xNameToLabel(type.getValue()); } builder = builder .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) .withValue(Phone.NUMBER, number.getText()) .withValue(Phone.TYPE, typeCode) .withValue(Phone.IS_PRIMARY, is_primary ? 1 : 0) .withValue(Phone.IS_SUPER_PRIMARY, is_primary ? 1 : 0); if (typeLabel != null) builder = builder.withValue(Phone.LABEL, typeLabel); return builder; }
protected Builder buildPhoto(Builder builder, byte[] photo) { return builder .withValue(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE) .withValue(Photo.PHOTO, photo); }
protected Builder buildIMPP(Builder builder, Impp impp) { int typeCode = 0; String typeLabel = null; for (ImppType type : impp.getTypes()) if (type == ImppType.HOME) typeCode = Im.TYPE_HOME; else if (type == ImppType.WORK || type == ImppType.BUSINESS) typeCode = Im.TYPE_WORK; if (typeCode == 0) if (impp.getTypes().isEmpty()) typeCode = Im.TYPE_OTHER; else { typeCode = Im.TYPE_CUSTOM; typeLabel = xNameToLabel(impp.getTypes().iterator().next().getValue()); } int protocolCode = 0; String protocolLabel = null; String protocol = impp.getProtocol(); if (protocol == null) { Log.w(TAG, "Ignoring IMPP address without protocol"); return null; } // SIP addresses are IMPP entries in the VCard but locally stored in SipAddress rather than Im boolean sipAddress = false; if (impp.isAim()) protocolCode = Im.PROTOCOL_AIM; else if (impp.isMsn()) protocolCode = Im.PROTOCOL_MSN; else if (impp.isYahoo()) protocolCode = Im.PROTOCOL_YAHOO; else if (impp.isSkype()) protocolCode = Im.PROTOCOL_SKYPE; else if (protocol.equalsIgnoreCase("qq")) protocolCode = Im.PROTOCOL_QQ; else if (protocol.equalsIgnoreCase("google-talk")) protocolCode = Im.PROTOCOL_GOOGLE_TALK; else if (impp.isIcq()) protocolCode = Im.PROTOCOL_ICQ; else if (impp.isXmpp() || protocol.equalsIgnoreCase("jabber")) protocolCode = Im.PROTOCOL_JABBER; else if (protocol.equalsIgnoreCase("netmeeting")) protocolCode = Im.PROTOCOL_NETMEETING; else if (protocol.equalsIgnoreCase("sip")) sipAddress = true; else { protocolCode = Im.PROTOCOL_CUSTOM; protocolLabel = protocol; } if (sipAddress) // save as SIP address builder = builder .withValue(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE) .withValue(Im.DATA, impp.getHandle()) .withValue(Im.TYPE, typeCode); else { // save as IM address builder = builder .withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE) .withValue(Im.DATA, impp.getHandle()) .withValue(Im.TYPE, typeCode) .withValue(Im.PROTOCOL, protocolCode); if (protocolLabel != null) builder = builder.withValue(Im.CUSTOM_PROTOCOL, protocolLabel); } if (typeLabel != null) builder = builder.withValue(Im.LABEL, typeLabel); return builder; }
protected Builder buildNickName(Builder builder, String nickName) { return builder .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE) .withValue(Nickname.NAME, nickName); }
protected Builder buildNote(Builder builder, String note) { return builder .withValue(Data.MIMETYPE, Note.CONTENT_ITEM_TYPE) .withValue(Note.NOTE, note); }
protected Builder buildAddress(Builder builder, Address address) { /* street po.box (extended) * region * postal code city * country */ String formattedAddress = address.getLabel(); if (StringUtils.isEmpty(formattedAddress)) { String lineStreet = StringUtils.join(new String[] { address.getStreetAddress(), address.getPoBox(), address.getExtendedAddress() }, " "), lineLocality = StringUtils.join(new String[] { address.getPostalCode(), address.getLocality() }, " "); List<String> lines = new LinkedList<String>(); if (lineStreet != null) lines.add(lineStreet); if (address.getRegion() != null && !address.getRegion().isEmpty()) lines.add(address.getRegion()); if (lineLocality != null) lines.add(lineLocality); formattedAddress = StringUtils.join(lines, "\n"); } int typeCode = 0; String typeLabel = null; for (AddressType type : address.getTypes()) if (type == AddressType.HOME) typeCode = StructuredPostal.TYPE_HOME; else if (type == AddressType.WORK) typeCode = StructuredPostal.TYPE_WORK; if (typeCode == 0) if (address.getTypes().isEmpty()) typeCode = StructuredPostal.TYPE_OTHER; else { typeCode = StructuredPostal.TYPE_CUSTOM; typeLabel = xNameToLabel(address.getTypes().iterator().next().getValue()); } builder = builder .withValue(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE) .withValue(StructuredPostal.FORMATTED_ADDRESS, formattedAddress) .withValue(StructuredPostal.TYPE, typeCode) .withValue(StructuredPostal.STREET, address.getStreetAddress()) .withValue(StructuredPostal.POBOX, address.getPoBox()) .withValue(StructuredPostal.NEIGHBORHOOD, address.getExtendedAddress()) .withValue(StructuredPostal.CITY, address.getLocality()) .withValue(StructuredPostal.REGION, address.getRegion()) .withValue(StructuredPostal.POSTCODE, address.getPostalCode()) .withValue(StructuredPostal.COUNTRY, address.getCountry()); if (typeLabel != null) builder = builder.withValue(StructuredPostal.LABEL, typeLabel); return builder; }
protected Builder buildURL(Builder builder, String url) { return builder .withValue(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE) .withValue(Website.URL, url); }
private Builder newDataInsertBuilder(long raw_contact_id, Integer backrefIdx) { return newDataInsertBuilder(dataURI(), Data.RAW_CONTACT_ID, raw_contact_id, backrefIdx); }
public Builder addValues(Builder builder) { builder.withValue(Columns.PROGRAM_ID.getName(), mID) .withValue(Columns.PROGRAM_NAME.getName(), mName) .withValue(Columns.PROGRAM_SCHED_TYPE.getName(), mScheduleType); return builder; }