/** * Insert a new child of kind {@link DataKind} into the given * {@link RawContactDelta}. Tries using the best {@link EditType} found using * {@link #getBestValidType(RawContactDelta, DataKind, boolean, int)}. */ public static ValuesDelta insertChild(RawContactDelta state, DataKind kind) { // Bail early if invalid kind if (kind == null) return null; // First try finding a valid primary EditType bestType = getBestValidType(state, kind, false, Integer.MIN_VALUE); if (bestType == null) { // No valid primary found, so expand search to secondary bestType = getBestValidType(state, kind, true, Integer.MIN_VALUE); } return insertChild(state, kind, bestType); }
/** * Checks if a new entry of the specified type can be added to the raw * contact. For example, Exchange only supports two "work" phone numbers, so * addition of a third would not be allowed. */ private static boolean isTypeAllowed(int type, ArrayList<ValuesDelta> entries, DataKind kind) { int max = 0; int size = kind.typeList.size(); for (int i = 0; i < size; i++) { EditType editType = kind.typeList.get(i); if (editType.rawValue == type) { max = editType.specificMax; break; } } if (max == 0) { // This type is not allowed at all return false; } if (max == -1) { // Unlimited instances of this type are allowed return true; } return getEntryCountByType(entries, kind.typeColumn, type) < max; }
/** * Find the {@link EditType} that describes the given {@link Cursor} row, * assuming the given {@link DataKind} dictates the possible types. */ public static EditType getCurrentType(Cursor cursor, DataKind kind) { if (kind.typeColumn == null) return null; final int index = cursor.getColumnIndex(kind.typeColumn); if (index == -1) return null; final int rawValue = cursor.getInt(index); return getType(kind, rawValue); }
parseStructuredNameExtra(context, accountType, state, extras); parseStructuredPostalExtra(accountType, state, extras); parseExtras(state, kind, extras, Insert.PHONE_TYPE, Insert.PHONE, Phone.NUMBER); parseExtras(state, kind, extras, Insert.SECONDARY_PHONE_TYPE, Insert.SECONDARY_PHONE, Phone.NUMBER); parseExtras(state, kind, extras, Insert.TERTIARY_PHONE_TYPE, Insert.TERTIARY_PHONE, Phone.NUMBER); parseExtras(state, kind, extras, Insert.EMAIL_TYPE, Insert.EMAIL, Email.DATA); parseExtras(state, kind, extras, Insert.SECONDARY_EMAIL_TYPE, Insert.SECONDARY_EMAIL, Email.DATA); parseExtras(state, kind, extras, Insert.TERTIARY_EMAIL_TYPE, Insert.TERTIARY_EMAIL, Email.DATA); fixupLegacyImType(extras); parseExtras(state, kind, extras, Insert.IM_PROTOCOL, Insert.IM_HANDLE, Im.DATA); || extras.containsKey(Insert.JOB_TITLE); final DataKind kindOrg = accountType.getKindForMimetype(Organization.CONTENT_ITEM_TYPE); if (hasOrg && RawContactModifier.canInsert(state, kindOrg)) { final ValuesDelta child = RawContactModifier.insertChild(state, kindOrg); if (hasNotes && RawContactModifier.canInsert(state, kindNotes)) { final ValuesDelta child = RawContactModifier.insertChild(state, kindNotes); parseValues(state, accountType, values);
final boolean canInsert = RawContactModifier.canInsert(state, kind); final boolean validValue = (value != null && TextUtils.isGraphic(value)); if (!validValue || !canInsert) return null; final int typeValue = extras.getInt(typeExtra, hasType ? BaseTypes.TYPE_CUSTOM : Integer.MIN_VALUE); final EditType editType = RawContactModifier.getBestValidType(state, kind, true, typeValue); final ValuesDelta child = RawContactModifier.insertChild(state, kind, editType); child.put(valueColumn, value.toString());
if (isEmpty(entry, kind)) { continue; for (ValuesDelta delta : entries) { if (!delta.isDelete()) { if (areEqual(delta, values, kind)) { addEntry = false; break; addEntry = adjustType(entry, entries, kind); if (entries != null && entries.size() > 0) { for (ValuesDelta delta : entries) { if (!delta.isDelete() && !isEmpty(delta, kind)) { addEntry = false; break; addEntry = adjustType(entry, entries, kind); if (!isEmpty(delta, kind)) { delta.put(Note.NOTE, delta.getAsString(Note.NOTE) + "\n" + values.getAsString(Note.NOTE));
/** @hide Public only for testing. */ public static void migrateGenericWithoutTypeColumn( RawContactDelta oldState, RawContactDelta newState, DataKind newDataKind) { final ArrayList<ValuesDelta> mimeEntries = ensureEntryMaxSize(newState, newDataKind, oldState.getMimeEntries(newDataKind.mimeType)); if (mimeEntries == null || mimeEntries.isEmpty()) { return; } for (ValuesDelta entry : mimeEntries) { ContentValues values = entry.getAfter(); if (values != null) { newState.addEntry(ValuesDelta.fromAfter(values)); } } }
private static void parseStructuredNameExtra( Context context, AccountType accountType, RawContactDelta state, Bundle extras) { RawContactModifier.ensureKindExists(state, accountType, StructuredName.CONTENT_ITEM_TYPE); final ValuesDelta child = state.getPrimaryEntry(StructuredName.CONTENT_ITEM_TYPE);
/** * Count up the frequency that each {@link EditType} appears in the given * {@link RawContactDelta}. The returned {@link SparseIntArray} maps from * {@link EditType#rawValue} to counts, with the total overall count stored * as {@link #FREQUENCY_TOTAL}. */ private static SparseIntArray getTypeFrequencies(RawContactDelta state, DataKind kind) { final SparseIntArray typeCount = new SparseIntArray(); // Find all entries for this kind, bailing early if none found final List<ValuesDelta> mimeEntries = state.getMimeEntries(kind.mimeType); if (mimeEntries == null) return typeCount; int totalCount = 0; for (ValuesDelta entry : mimeEntries) { // Only count visible entries if (!entry.isVisible()) continue; totalCount++; final EditType type = getCurrentType(entry, kind); if (type != null) { final int count = typeCount.get(type.rawValue); typeCount.put(type.rawValue, count + 1); } } typeCount.put(FREQUENCY_TOTAL, totalCount); return typeCount; }
final ArrayList<ValuesDelta> mimeEntries = ensureEntryMaxSize(newState, newDataKind, oldState.getMimeEntries(Event.CONTENT_ITEM_TYPE)); if (mimeEntries == null || mimeEntries.isEmpty()) {
/** * Find the {@link EditType} that describes the given {@link ContentValues} row, * assuming the given {@link DataKind} dictates the possible types. */ public static EditType getCurrentType(ContentValues entry, DataKind kind) { if (kind.typeColumn == null) return null; final Integer rawValue = entry.getAsInteger(kind.typeColumn); if (rawValue == null) return null; return getType(kind, rawValue); }
final ArrayList<ValuesDelta> mimeEntries = ensureEntryMaxSize(newState, newDataKind, oldState.getMimeEntries(StructuredPostal.CONTENT_ITEM_TYPE)); if (mimeEntries == null || mimeEntries.isEmpty()) {
/** * Find the {@link EditType} that describes the given * {@link ValuesDelta} row, assuming the given {@link DataKind} dictates * the possible types. */ public static EditType getCurrentType(ValuesDelta entry, DataKind kind) { final Long rawValue = entry.getAsLong(kind.typeColumn); if (rawValue == null) return null; return getType(kind, rawValue.intValue()); }