/** * Return the total number of {@link ValuesDelta} contained. */ public int getEntryCount(boolean onlyVisible) { int count = 0; for (String mimeType : mEntries.keySet()) { count += getMimeEntriesCount(mimeType, onlyVisible); } return count; }
/** * For the given {@link RawContactDelta}, determine if the given * {@link DataKind} could be inserted under specific * {@link AccountType}. */ public static boolean canInsert(RawContactDelta state, DataKind kind) { // Insert possible when have valid types and under overall maximum final int visibleCount = state.getMimeEntriesCount(kind.mimeType, true); final boolean validTypes = hasValidTypes(state, kind); final boolean validOverall = (kind.typeOverallMax == -1) || (visibleCount < kind.typeOverallMax); return (validTypes && validOverall); }
/** * Ensure that at least one of the given {@link DataKind} exists in the * given {@link RawContactDelta} state, and try creating one if none exist. * @return The child (either newly created or the first existing one), or null if the * account doesn't support this {@link DataKind}. */ public static ValuesDelta ensureKindExists( RawContactDelta state, AccountType accountType, String mimeType) { final DataKind kind = accountType.getKindForMimetype(mimeType); final boolean hasChild = state.getMimeEntriesCount(mimeType, true) > 0; if (kind != null) { if (hasChild) { // Return the first entry. return state.getMimeEntries(mimeType).get(0); } else { // Create child when none exists and valid kind final ValuesDelta child = insertChild(state, kind); if (kind.mimeType.equals(Photo.CONTENT_ITEM_TYPE)) { child.setFromTemplate(true); } return child; } } return null; }