/** * Build an {@link RawContactDelta} using the given {@link RawContact} as a * starting point; the "before" snapshot. */ public static RawContactDelta fromBefore(RawContact before) { final RawContactDelta rawContactDelta = new RawContactDelta(); rawContactDelta.mValues = ValuesDelta.fromBefore(before.getValues()); rawContactDelta.mValues.setIdColumn(RawContacts._ID); for (final ContentValues values : before.getContentValues()) { rawContactDelta.addEntry(ValuesDelta.fromBefore(values)); } return rawContactDelta; }
/** * Find {@link RawContacts#_ID} of the requested {@link RawContactDelta}. */ public Long getRawContactId(int index) { if (index >= 0 && index < this.size()) { final RawContactDelta delta = this.get(index); final ValuesDelta values = delta.getValues(); if (values.isVisible()) { return values.getAsLong(RawContacts._ID); } } return null; }
public int getMimeEntriesCount(String mimeType, boolean onlyVisible) { final ArrayList<ValuesDelta> mimeEntries = getMimeEntries(mimeType); if (mimeEntries == null) return 0; int count = 0; for (ValuesDelta child : mimeEntries) { // Skip deleted items when requesting only visible if (onlyVisible && !child.isVisible()) continue; count++; } return count; }
/** * Processing to trim any empty {@link ValuesDelta} and {@link RawContactDelta} * from the given {@link RawContactDeltaList}, assuming the given {@link AccountTypeManager} * dictates the structure for various fields. This method ignores rows not * described by the {@link AccountType}. */ public static void trimEmpty(RawContactDeltaList set, AccountTypeManager accountTypes) { for (RawContactDelta state : set) { ValuesDelta values = state.getValues(); final String accountType = values.getAsString(RawContacts.ACCOUNT_TYPE); final String dataSet = values.getAsString(RawContacts.DATA_SET); final AccountType type = accountTypes.getAccountType(accountType, dataSet); trimEmpty(state, type); } }
public AccountType getAccountType(Context context) { return getAccountTypeManager(context).getAccountType(getAccountTypeString(), getDataSet()); }
/** * Return the AccountType that this raw-contact belongs to. */ public AccountType getRawContactAccountType(Context context) { ContentValues entityValues = getValues().getCompleteValues(); String type = entityValues.getAsString(RawContacts.ACCOUNT_TYPE); String dataSet = entityValues.getAsString(RawContacts.DATA_SET); return AccountTypeManager.getInstance(context).getAccountType(type, dataSet); }
public AccountType getAccountType(AccountTypeManager manager) { return manager.getAccountType(getAccountType(), getDataSet()); }
public void addAll(Iterator<?> iterator) { // Perform background query to pull contact details while (iterator.hasNext()) { // Read all contacts into local deltas to prepare for edits Object nextObject = iterator.next(); final RawContact before = nextObject instanceof Entity ? RawContact.createFrom((Entity) nextObject) : (RawContact) nextObject; final RawContactDelta rawContactDelta = RawContactDelta.fromBefore(before); add(rawContactDelta); } }
public String getAccountName() { return getValues().getAsString(RawContacts.ACCOUNT_NAME); }
/** * 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); }
public ValuesDelta createFromParcel(Parcel in) { final ValuesDelta values = new ValuesDelta(); values.readFromParcel(in); return values; }
@Override public void handleMessage(Message msg) { switch (msg.what) { case MESSAGE_LOAD_DATA: loadAccountsInBackground(); break; case MESSAGE_PROCESS_BROADCAST_INTENT: processBroadcastIntent((Intent) msg.obj); break; } } };
public AccountTypeManager getAccountTypeManager(Context context) { if (mAccountTypeManager == null) { mAccountTypeManager = AccountTypeManager.getInstance(context); } return mAccountTypeManager; }
/** * calls {@link #getSuperPrimaryEntry(String, boolean)} with true * @see #getSuperPrimaryEntry(String, boolean) */ public ValuesDelta getSuperPrimaryEntry(String mimeType) { return getSuperPrimaryEntry(mimeType, true); }
/** * Caches the result, which is useful when we switch from activity to activity, using the same * contact. If the next load is for a different contact, the cached result will be dropped */ public void cacheResult() { if (mContact == null || !mContact.isLoaded()) { sCachedResult = null; } else { sCachedResult = mContact; } } }
/** * When no "before" id, and has "after", action is "insert" */ public boolean isInsert() { return !beforeExists() && (mAfter != null); }
public String getAccountType() { return getValues().getAsString(RawContacts.ACCOUNT_TYPE); }
/** * Search all contained {@link RawContactDelta} for the first one with an * existing {@link RawContacts#_ID} value. Usually used when creating * {@link AggregationExceptions} during an update. */ public long findRawContactId() { for (RawContactDelta delta : this) { final Long rawContactId = delta.getValues().getAsLong(RawContacts._ID); if (rawContactId != null && rawContactId >= 0) { return rawContactId; } } return -1; }