use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class RawContactEditorView method addToDefaultGroupIfNeeded.
/**
* If automatic addition to the default group was requested (see
* {@link #setAutoAddToDefaultGroup}, checks if the raw contact is in any
* group and if it is not adds it to the default group (in case of Google
* contacts that's "My Contacts").
*/
private void addToDefaultGroupIfNeeded() {
if (!mAutoAddToDefaultGroup || mGroupMetaData == null || mGroupMetaData.isClosed() || mState == null) {
return;
}
boolean hasGroupMembership = false;
ArrayList<ValuesDelta> entries = mState.getMimeEntries(GroupMembership.CONTENT_ITEM_TYPE);
if (entries != null) {
for (ValuesDelta values : entries) {
Long id = values.getGroupRowId();
if (id != null && id.longValue() != 0) {
hasGroupMembership = true;
break;
}
}
}
if (!hasGroupMembership) {
long defaultGroupId = getDefaultGroupId();
if (defaultGroupId != -1) {
ValuesDelta entry = RawContactModifier.insertChild(mState, mGroupMembershipKind);
if (entry != null) {
entry.setGroupRowId(defaultGroupId);
}
}
}
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class StructuredNameEditorView method switchFromStructuredNameToFullName.
private void switchFromStructuredNameToFullName() {
ValuesDelta values = getValues();
if (!mChanged) {
values.setDisplayName(mSnapshot.getDisplayName());
return;
}
Map<String, String> structuredNameMap = valuesToStructuredNameMap(values);
String displayName = NameConverter.structuredNameToDisplayName(getContext(), structuredNameMap);
if (!TextUtils.isEmpty(displayName)) {
eraseStructuredName(values);
values.put(StructuredName.DISPLAY_NAME, displayName);
}
mSnapshot.getContentValues().clear();
mSnapshot.setDisplayName(values.getDisplayName());
mSnapshot.setMimeType(StructuredName.CONTENT_ITEM_TYPE);
for (String field : structuredNameMap.keySet()) {
mSnapshot.getContentValues().put(field, structuredNameMap.get(field));
}
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class StructuredNameEditorView method getDisplayName.
/**
* Returns the display name currently displayed in the editor.
*/
public String getDisplayName() {
final ValuesDelta valuesDelta = getValues();
rebuildFullName(valuesDelta);
if (hasShortAndLongForms() && areOptionalFieldsVisible()) {
final Map<String, String> structuredNameMap = valuesToStructuredNameMap(valuesDelta);
final String displayName = NameConverter.structuredNameToDisplayName(getContext(), structuredNameMap);
if (!TextUtils.isEmpty(displayName)) {
return displayName;
}
}
return valuesDelta.getDisplayName();
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class KindSectionDataList method getEntryToWrite.
/**
* Returns the primary KindSectionData and ValuesDelta that should be written for this List.
*/
public Pair<KindSectionData, ValuesDelta> getEntryToWrite(long id, AccountWithDataSet primaryAccount, boolean isUserProfile) {
final String mimeType = getMimeType();
if (mimeType == null)
return null;
if (!isUserProfile) {
if (id > 0) {
// Look for a match for the ID that was passed in
for (KindSectionData kindSectionData : this) {
if (kindSectionData.getAccountType().areContactsWritable()) {
final ValuesDelta valuesDelta = kindSectionData.getValuesDeltaById(id);
if (valuesDelta != null) {
vlog(mimeType + ": matched kind section data to write by ID");
return new Pair<>(kindSectionData, valuesDelta);
}
}
}
}
// Look for a super primary entry
for (KindSectionData kindSectionData : this) {
if (kindSectionData.getAccountType().areContactsWritable()) {
final ValuesDelta valuesDelta = kindSectionData.getSuperPrimaryValuesDelta();
if (valuesDelta != null) {
vlog(mimeType + ": matched kind section data to write by super primary");
return new Pair<>(kindSectionData, valuesDelta);
}
}
}
// Use the first writable contact that matches the primary account
if (primaryAccount != null) {
for (KindSectionData kindSectionData : this) {
if (kindSectionData.getAccountType().areContactsWritable()) {
if (matchesAccount(primaryAccount, kindSectionData.getRawContactDelta()) && !kindSectionData.getValuesDeltas().isEmpty()) {
vlog(mimeType + ": matched kind section data to write by primary " + "account");
return new Pair<>(kindSectionData, kindSectionData.getValuesDeltas().get(0));
}
}
}
}
}
// Just return the first writable entry.
for (KindSectionData kindSectionData : this) {
if (kindSectionData.getAccountType().areContactsWritable()) {
// Create an entry if necessary
RawContactModifier.ensureKindExists(kindSectionData.getRawContactDelta(), kindSectionData.getAccountType(), mimeType);
if (!kindSectionData.getValuesDeltas().isEmpty()) {
vlog(mimeType + ": falling back to first kind section data to write");
return new Pair<>(kindSectionData, kindSectionData.getValuesDeltas().get(0));
}
}
}
wlog(mimeType + ": no writable kind section data found");
return null;
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class KindSectionDataList method getEntryToDisplay.
/**
* Returns the KindSectionData and ValuesDelta that should be displayed to the user.
*/
public Pair<KindSectionData, ValuesDelta> getEntryToDisplay(long id) {
final String mimeType = getMimeType();
if (mimeType == null)
return null;
if (id > 0) {
// Look for a match for the ID that was passed in
for (KindSectionData kindSectionData : this) {
final ValuesDelta valuesDelta = kindSectionData.getValuesDeltaById(id);
if (valuesDelta != null) {
vlog(mimeType + ": matched kind section data to display by ID");
return new Pair<>(kindSectionData, valuesDelta);
}
}
}
// Look for a super primary entry
for (KindSectionData kindSectionData : this) {
final ValuesDelta valuesDelta = kindSectionData.getSuperPrimaryValuesDelta();
if (valuesDelta != null) {
vlog(mimeType + ": matched kind section data to display by super primary");
return new Pair<>(kindSectionData, valuesDelta);
}
}
// Fall back to the first non-empty value
for (KindSectionData kindSectionData : this) {
final ValuesDelta valuesDelta = kindSectionData.getFirstNonEmptyValuesDelta();
if (valuesDelta != null) {
vlog(mimeType + ": using first non empty value to display");
return new Pair<>(kindSectionData, valuesDelta);
}
}
for (KindSectionData kindSectionData : this) {
final List<ValuesDelta> valuesDeltaList = kindSectionData.getValuesDeltas();
if (!valuesDeltaList.isEmpty()) {
vlog(mimeType + ": falling back to first empty entry to display");
final ValuesDelta valuesDelta = valuesDeltaList.get(0);
return new Pair<>(kindSectionData, valuesDelta);
}
}
wlog(mimeType + ": no kind section data found to display");
return null;
}
Aggregations