Search in sources :

Example 21 with ValuesDelta

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);
            }
        }
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta)

Example 22 with ValuesDelta

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));
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta)

Example 23 with ValuesDelta

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();
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta)

Example 24 with ValuesDelta

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;
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) Pair(android.util.Pair)

Example 25 with ValuesDelta

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;
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) Pair(android.util.Pair)

Aggregations

ValuesDelta (com.android.contacts.common.model.ValuesDelta)25 RawContactDelta (com.android.contacts.common.model.RawContactDelta)6 AccountType (com.android.contacts.common.model.account.AccountType)6 DataKind (com.android.contacts.common.model.dataitem.DataKind)5 Intent (android.content.Intent)3 View (android.view.View)3 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)3 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 Pair (android.util.Pair)2 ImageView (android.widget.ImageView)2 RadioButton (android.widget.RadioButton)2 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)2 FileNotFoundException (java.io.FileNotFoundException)2 Activity (android.app.Activity)1 ContentValues (android.content.ContentValues)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 Photo (android.provider.ContactsContract.CommonDataKinds.Photo)1