Search in sources :

Example 1 with ValuesDelta

use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.

the class CompactRawContactsEditorView method setPrimaryPhoto.

/**
 * Marks the raw contact photo given as primary for the aggregate contact and updates the
 * UI.
 */
public void setPrimaryPhoto(CompactPhotoSelectionFragment.Photo photo) {
    // Find the values delta to mark as primary
    final KindSectionDataList kindSectionDataList = mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE);
    if (photo.kindSectionDataListIndex < 0 || photo.kindSectionDataListIndex >= kindSectionDataList.size()) {
        wlog("Invalid kind section data list index");
        return;
    }
    final KindSectionData kindSectionData = kindSectionDataList.get(photo.kindSectionDataListIndex);
    final List<ValuesDelta> valuesDeltaList = kindSectionData.getNonEmptyValuesDeltas();
    if (photo.valuesDeltaListIndex >= valuesDeltaList.size()) {
        wlog("Invalid values delta list index");
        return;
    }
    // Update values delta
    final ValuesDelta valuesDelta = valuesDeltaList.get(photo.valuesDeltaListIndex);
    valuesDelta.setFromTemplate(false);
    unsetSuperPrimaryFromAllPhotos();
    valuesDelta.setSuperPrimary(true);
    // Update the UI
    mPhotoView.setPhoto(valuesDelta, mMaterialPalette);
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta)

Example 2 with ValuesDelta

use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.

the class ContactEditorFragment method hasMoreThanOnePhoto.

/**
 * Returns true if there is currently more than one photo on screen.
 */
private boolean hasMoreThanOnePhoto() {
    int countWithPicture = 0;
    final int numEntities = mState.size();
    for (int i = 0; i < numEntities; i++) {
        final RawContactDelta entity = mState.get(i);
        if (entity.isVisible()) {
            final ValuesDelta primary = entity.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE);
            if (primary != null && primary.getPhoto() != null) {
                countWithPicture++;
            } else {
                final long rawContactId = entity.getRawContactId();
                final Uri uri = mUpdatedPhotos.getParcelable(String.valueOf(rawContactId));
                if (uri != null) {
                    try {
                        mContext.getContentResolver().openInputStream(uri);
                        countWithPicture++;
                    } catch (FileNotFoundException e) {
                    }
                }
            }
            if (countWithPicture > 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) FileNotFoundException(java.io.FileNotFoundException) RawContactDelta(com.android.contacts.common.model.RawContactDelta) Uri(android.net.Uri)

Example 3 with ValuesDelta

use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.

the class PhoneticNameEditorView method hasData.

public boolean hasData() {
    ValuesDelta entry = getEntry();
    String family = entry.getPhoneticFamilyName();
    String middle = entry.getPhoneticMiddleName();
    String given = entry.getPhoneticGivenName();
    return !TextUtils.isEmpty(family) || !TextUtils.isEmpty(middle) || !TextUtils.isEmpty(given);
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta)

Example 4 with ValuesDelta

use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.

the class RawContactEditorView method setState.

/**
 * Set the internal state for this view, given a current
 * {@link RawContactDelta} state and the {@link AccountType} that
 * apply to that state.
 */
@Override
public void setState(RawContactDelta state, AccountType type, ViewIdGenerator vig, boolean isProfile) {
    mState = state;
    // Remove any existing sections
    mFields.removeAllViews();
    // Bail if invalid state or account type
    if (state == null || type == null)
        return;
    setId(vig.getId(state, null, null, ViewIdGenerator.NO_VIEW_INDEX));
    // Make sure we have a StructuredName
    RawContactModifier.ensureKindExists(state, type, StructuredName.CONTENT_ITEM_TYPE);
    mRawContactId = state.getRawContactId();
    // Fill in the account info
    final Pair<String, String> accountInfo = isProfile ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type) : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
    if (accountInfo.first == null) {
        // Hide this view so the other text view will be centered vertically
        mAccountHeaderNameTextView.setVisibility(View.GONE);
    } else {
        mAccountHeaderNameTextView.setVisibility(View.VISIBLE);
        mAccountHeaderNameTextView.setText(accountInfo.first);
    }
    mAccountHeaderTypeTextView.setText(accountInfo.second);
    updateAccountHeaderContentDescription();
    // The account selector and header are both used to display the same information.
    mAccountSelectorTypeTextView.setText(mAccountHeaderTypeTextView.getText());
    mAccountSelectorTypeTextView.setVisibility(mAccountHeaderTypeTextView.getVisibility());
    mAccountSelectorNameTextView.setText(mAccountHeaderNameTextView.getText());
    mAccountSelectorNameTextView.setVisibility(mAccountHeaderNameTextView.getVisibility());
    // Showing the account header at the same time as the account selector drop down is
    // confusing. They should be mutually exclusive.
    mAccountHeader.setVisibility(mAccountSelector.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
    mAccountIconImageView.setImageDrawable(state.getRawContactAccountType(getContext()).getDisplayIcon(getContext()));
    // Show photo editor when supported
    RawContactModifier.ensureKindExists(state, type, Photo.CONTENT_ITEM_TYPE);
    setHasPhotoEditor((type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null));
    getPhotoEditor().setEnabled(isEnabled());
    mName.setEnabled(isEnabled());
    mPhoneticName.setEnabled(isEnabled());
    // Show and hide the appropriate views
    mFields.setVisibility(View.VISIBLE);
    mName.setVisibility(View.VISIBLE);
    mPhoneticName.setVisibility(View.VISIBLE);
    mGroupMembershipKind = type.getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE);
    if (mGroupMembershipKind != null) {
        mGroupMembershipView = (GroupMembershipView) mInflater.inflate(R.layout.item_group_membership, mFields, false);
        mGroupMembershipView.setKind(mGroupMembershipKind);
        mGroupMembershipView.setEnabled(isEnabled());
    }
    // Create editor sections for each possible data kind
    for (DataKind kind : type.getSortedDataKinds()) {
        // Skip kind of not editable
        if (!kind.editable)
            continue;
        final String mimeType = kind.mimeType;
        if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
            // Handle special case editor for structured name
            final ValuesDelta primary = state.getPrimaryEntry(mimeType);
            mName.setValues(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME), primary, state, false, vig);
            if (!(SimContactsConstants.ACCOUNT_TYPE_SIM).equals(type.accountType)) {
                mPhoneticName.setValues(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME), primary, state, false, vig);
                // It is useful to use Nickname outside of a KindSectionView so that we can
                // treat it as a part of StructuredName's fake KindSectionView, even though
                // it uses adifferent CP2 mime-type. We do a bit of extra work below to make
                // this possible.
                final DataKind nickNameKind = type.getKindForMimetype(Nickname.CONTENT_ITEM_TYPE);
                if (nickNameKind != null) {
                    ValuesDelta primaryNickNameEntry = state.getPrimaryEntry(nickNameKind.mimeType);
                    if (primaryNickNameEntry == null) {
                        primaryNickNameEntry = RawContactModifier.insertChild(state, nickNameKind);
                    }
                    mNickName.setValues(nickNameKind, primaryNickNameEntry, state, false, vig);
                    mNickName.setDeletable(false);
                } else {
                    mPhoneticName.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.editor_padding_between_editor_views));
                    mNickName.setVisibility(View.GONE);
                }
            } else {
                // sim card can't store expand fields,so set it disabled.
                mName.setExpansionViewContainerDisabled();
                mPhoneticName.setVisibility(View.GONE);
                mNickName.setVisibility(View.GONE);
            }
        } else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) {
            // Handle special case editor for photos
            final ValuesDelta primary = state.getPrimaryEntry(mimeType);
            getPhotoEditor().setValues(kind, primary, state, false, vig);
        } else if (GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType)) {
            if (mGroupMembershipView != null) {
                mGroupMembershipView.setState(state);
                mFields.addView(mGroupMembershipView);
            }
        } else if (DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME.equals(mimeType) || DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType) || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) {
            // Don't create fields for each of these mime-types. They are handled specially.
            continue;
        } else {
            // Otherwise use generic section-based editors
            if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) {
                if (SimContactsConstants.ACCOUNT_TYPE_SIM.equals(type.accountType)) {
                    int sub = SimContactsConstants.SLOT1;
                    if (SimContactsConstants.SIM_NAME_2.equals(state.getAccountName())) {
                        sub = SimContactsConstants.SLOT2;
                    }
                    EditType typeHome = new EditType(Phone.TYPE_HOME, Phone.getTypeLabelResource(Phone.TYPE_HOME));
                    if (!MoreContactUtils.canSaveAnr(getContext(), sub)) {
                        kind.typeOverallMax = 1;
                        if (null != kind.typeList) {
                            // When the sim card is not 3g the interface should
                            // remove the TYPE_HOME number view.
                            kind.typeList.remove(typeHome);
                        }
                    } else {
                        kind.typeOverallMax = MoreContactUtils.getOneSimAnrCount(getContext(), sub) + 1;
                        if (null != kind.typeList && !kind.typeList.contains(typeHome)) {
                            // When the sim card is 3g the interface should
                            // add the TYPE_HOME number view.
                            kind.typeList.add(typeHome);
                        }
                    }
                }
            } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType)) {
                if (SimContactsConstants.ACCOUNT_TYPE_SIM.equals(type.accountType)) {
                    int sub = SimContactsConstants.SLOT1;
                    if (SimContactsConstants.SIM_NAME_2.equals(state.getAccountName())) {
                        sub = SimContactsConstants.SLOT2;
                    }
                    if (!MoreContactUtils.canSaveEmail(getContext(), sub)) {
                        continue;
                    } else {
                        kind.typeOverallMax = MoreContactUtils.getOneSimEmailCount(getContext(), sub);
                    }
                }
            }
            if (kind.fieldList == null)
                continue;
            final KindSectionView section = (KindSectionView) mInflater.inflate(R.layout.item_kind_section, mFields, false);
            section.setEnabled(isEnabled());
            section.setState(kind, state, /* readOnly =*/
            false, vig);
            mFields.addView(section);
        }
    }
    addToDefaultGroupIfNeeded();
}
Also used : EditType(com.android.contacts.common.model.account.AccountType.EditType) ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind)

Example 5 with ValuesDelta

use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.

the class RawContactReadOnlyEditorView method setState.

/**
 * Set the internal state for this view, given a current
 * {@link RawContactDelta} state and the {@link AccountType} that
 * apply to that state.
 */
@Override
public void setState(RawContactDelta state, AccountType type, ViewIdGenerator vig, boolean isProfile) {
    // Remove any existing sections
    mGeneral.removeAllViews();
    // Bail if invalid state or source
    if (state == null || type == null)
        return;
    // Make sure we have StructuredName
    RawContactModifier.ensureKindExists(state, type, StructuredName.CONTENT_ITEM_TYPE);
    // Fill in the header info
    mAccountName = state.getAccountName();
    mAccountType = state.getAccountType();
    mDataSet = state.getDataSet();
    final Pair<String, String> accountInfo = isProfile ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type) : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
    if (accountInfo.first == null) {
        // Hide this view so the other text view will be centered vertically
        mAccountHeaderNameTextView.setVisibility(View.GONE);
    } else {
        mAccountHeaderNameTextView.setVisibility(View.VISIBLE);
        mAccountHeaderNameTextView.setText(accountInfo.first);
    }
    mAccountHeaderTypeTextView.setText(accountInfo.second);
    updateAccountHeaderContentDescription();
    mAccountIconImageView.setImageDrawable(state.getRawContactAccountType(getContext()).getDisplayIcon(getContext()));
    // TODO: Expose data set in the UI somehow?
    mRawContactId = state.getRawContactId();
    ValuesDelta primary;
    // Photo
    DataKind kind = type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
    if (kind != null) {
        RawContactModifier.ensureKindExists(state, type, Photo.CONTENT_ITEM_TYPE);
        boolean hasPhotoEditor = type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null;
        setHasPhotoEditor(hasPhotoEditor);
        primary = state.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE);
        getPhotoEditor().setValues(kind, primary, state, !type.areContactsWritable(), vig);
    }
    // Name
    primary = state.getPrimaryEntry(StructuredName.CONTENT_ITEM_TYPE);
    mName.setText(primary != null ? primary.getAsString(StructuredName.DISPLAY_NAME) : getContext().getString(R.string.missing_name));
    if (type.getEditContactActivityClassName() != null) {
        mEditExternallyButton.setVisibility(View.VISIBLE);
    } else {
        mEditExternallyButton.setVisibility(View.GONE);
    }
    final Resources res = getContext().getResources();
    // Phones
    final ArrayList<ValuesDelta> phones = state.getMimeEntries(Phone.CONTENT_ITEM_TYPE);
    final Drawable phoneDrawable = getResources().getDrawable(R.drawable.ic_phone_24dp);
    final String phoneContentDescription = res.getString(R.string.header_phone_entry);
    if (phones != null) {
        boolean isFirstPhoneBound = true;
        for (ValuesDelta phone : phones) {
            final String phoneNumber = phone.getPhoneNumber();
            if (TextUtils.isEmpty(phoneNumber)) {
                continue;
            }
            final String formattedNumber = PhoneNumberUtilsCompat.formatNumber(phoneNumber, phone.getPhoneNormalizedNumber(), GeoUtil.getCurrentCountryIso(getContext()));
            CharSequence phoneType = null;
            if (phone.hasPhoneType()) {
                phoneType = Phone.getTypeLabel(res, phone.getPhoneType(), phone.getPhoneLabel());
            }
            bindData(phoneDrawable, phoneContentDescription, formattedNumber, phoneType, isFirstPhoneBound, true);
            isFirstPhoneBound = false;
        }
    }
    // Emails
    final ArrayList<ValuesDelta> emails = state.getMimeEntries(Email.CONTENT_ITEM_TYPE);
    final Drawable emailDrawable = getResources().getDrawable(R.drawable.ic_email_24dp);
    final String emailContentDescription = res.getString(R.string.header_email_entry);
    if (emails != null) {
        boolean isFirstEmailBound = true;
        for (ValuesDelta email : emails) {
            final String emailAddress = email.getEmailData();
            if (TextUtils.isEmpty(emailAddress)) {
                continue;
            }
            CharSequence emailType = null;
            if (email.hasEmailType()) {
                emailType = Email.getTypeLabel(res, email.getEmailType(), email.getEmailLabel());
            }
            bindData(emailDrawable, emailContentDescription, emailAddress, emailType, isFirstEmailBound);
            isFirstEmailBound = false;
        }
    }
    // Hide mGeneral if it's empty
    if (mGeneral.getChildCount() > 0) {
        mGeneral.setVisibility(View.VISIBLE);
    } else {
        mGeneral.setVisibility(View.GONE);
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind) Drawable(android.graphics.drawable.Drawable) Resources(android.content.res.Resources)

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