Search in sources :

Example 16 with ValuesDelta

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

the class ConfirmReplaceDetailActivity method showContent.

private void showContent() {
    List<ValuesDelta> mValuesDelta = mRawContactDelta.getMimeEntries(mMimeType);
    int count = mValuesDelta.size();
    mList = new ArrayList<>();
    String DATA_TYPE = (mMimeType == Phone.CONTENT_ITEM_TYPE) ? Phone.NUMBER : Email.DATA;
    if (count == 1) {
        String singleReplaceNumber = mValuesDelta.get(0).getAsString(DATA_TYPE);
        mList.add(singleReplaceNumber);
        singleNumberView.setText(singleReplaceNumber);
        singleLayout.setVisibility(View.VISIBLE);
        replaceTitleView.setText(R.string.replace_number_title_1);
    } else {
        for (int i = 0; i < count; i++) {
            ValuesDelta valuesDelta = mValuesDelta.get(i);
            String number = valuesDelta.getAsString(DATA_TYPE);
            mList.add(number);
            RadioButton radioButton = new RadioButton(this);
            radioButton.setText(number);
            radioGroup.addView(radioButton);
            if (i == 0) {
                radioGroup.check(radioButton.getId());
            }
        }
        replaceTitleView.setText(R.string.replace_number_title_2);
        replaceTitleView.setTypeface(null, Typeface.BOLD);
        radioGroup.setVisibility(View.VISIBLE);
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) RadioButton(android.widget.RadioButton)

Example 17 with ValuesDelta

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

the class CompactRawContactsEditorView method getPhotos.

/**
 * Returns a data holder for every non-default/non-empty photo from each raw contact, whether
 * the raw contact is writable or not.
 */
public ArrayList<CompactPhotoSelectionFragment.Photo> getPhotos() {
    final ArrayList<CompactPhotoSelectionFragment.Photo> photos = new ArrayList<>();
    final Bundle updatedPhotos = mListener == null ? null : mListener.getUpdatedPhotos();
    final List<KindSectionData> kindSectionDataList = mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE);
    for (int i = 0; i < kindSectionDataList.size(); i++) {
        final KindSectionData kindSectionData = kindSectionDataList.get(i);
        final AccountType accountType = kindSectionData.getAccountType();
        final List<ValuesDelta> valuesDeltas = kindSectionData.getNonEmptyValuesDeltas();
        if (valuesDeltas.isEmpty())
            continue;
        for (int j = 0; j < valuesDeltas.size(); j++) {
            final ValuesDelta valuesDelta = valuesDeltas.get(j);
            final Bitmap bitmap = EditorUiUtils.getPhotoBitmap(valuesDelta);
            if (bitmap == null)
                continue;
            final CompactPhotoSelectionFragment.Photo photo = new CompactPhotoSelectionFragment.Photo();
            photo.titleRes = accountType.titleRes;
            photo.iconRes = accountType.iconRes;
            photo.syncAdapterPackageName = accountType.syncAdapterPackageName;
            photo.valuesDelta = valuesDelta;
            photo.primary = valuesDelta.isSuperPrimary();
            photo.kindSectionDataListIndex = i;
            photo.valuesDeltaListIndex = j;
            photo.photoId = valuesDelta.getId();
            if (updatedPhotos != null) {
                photo.updatedPhotoUri = (Uri) updatedPhotos.get(String.valueOf(kindSectionData.getRawContactDelta().getRawContactId()));
            }
            final CharSequence accountTypeLabel = accountType.getDisplayLabel(getContext());
            photo.accountType = accountTypeLabel == null ? "" : accountTypeLabel.toString();
            final String accountName = kindSectionData.getRawContactDelta().getAccountName();
            photo.accountName = accountName == null ? "" : accountName;
            photos.add(photo);
        }
    }
    return photos;
}
Also used : Bundle(android.os.Bundle) ValuesDelta(com.android.contacts.common.model.ValuesDelta) ArrayList(java.util.ArrayList) Photo(android.provider.ContactsContract.CommonDataKinds.Photo) AccountType(com.android.contacts.common.model.account.AccountType) Bitmap(android.graphics.Bitmap)

Example 18 with ValuesDelta

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

the class ContactEditorFragment method bindEditors.

@Override
protected void bindEditors() {
    // if mState is null
    if (mState.isEmpty()) {
        return;
    }
    // blank form.  When the data is not ready, skip. This method will be called multiple times.
    if ((mIsEdit && !mExistingContactDataReady) || (mHasNewContact && !mNewContactDataReady)) {
        return;
    }
    // Sort the editors
    Collections.sort(mState, mComparator);
    // Remove any existing editors and rebuild any visible
    mContent.removeAllViews();
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
    int numRawContacts = mState.size();
    for (int i = 0; i < numRawContacts; i++) {
        // TODO ensure proper ordering of entities in the list
        final RawContactDelta rawContactDelta = mState.get(i);
        if (!rawContactDelta.isVisible())
            continue;
        final AccountType type = rawContactDelta.getAccountType(accountTypes);
        final long rawContactId = rawContactDelta.getRawContactId();
        if (mRawContactIdToDisplayAlone != -1 && mRawContactIdToDisplayAlone != rawContactId) {
            continue;
        }
        final BaseRawContactEditorView editor;
        if (!type.areContactsWritable()) {
            editor = (BaseRawContactEditorView) inflater.inflate(R.layout.raw_contact_readonly_editor_view, mContent, false);
        } else {
            editor = (RawContactEditorView) inflater.inflate(R.layout.raw_contact_editor_view, mContent, false);
        }
        editor.setListener(this);
        final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(mContext).getAccounts(true);
        if (mHasNewContact && !mNewLocalProfile && accounts.size() > 1) {
            addAccountSwitcher(mState.get(0), editor);
        }
        editor.setEnabled(isEnabled());
        if (mRawContactIdToDisplayAlone != -1) {
            editor.setCollapsed(false);
        } else if (mExpandedEditors.containsKey(rawContactId)) {
            editor.setCollapsed(mExpandedEditors.get(rawContactId));
        } else {
            // By default, only the first editor will be expanded.
            editor.setCollapsed(i != 0);
        }
        mContent.addView(editor);
        editor.setState(rawContactDelta, type, mViewIdGenerator, isEditingUserProfile());
        if (mRawContactIdToDisplayAlone != -1) {
            editor.setCollapsible(false);
        } else {
            editor.setCollapsible(numRawContacts > 1);
        }
        // Set up the photo handler.
        bindPhotoHandler(editor, type, mState);
        // If a new photo was chosen but not yet saved, we need to update the UI to
        // reflect this.
        final Uri photoUri = updatedPhotoUriForRawContact(rawContactId);
        if (photoUri != null)
            editor.setFullSizedPhoto(photoUri);
        if (editor instanceof RawContactEditorView) {
            final Activity activity = getActivity();
            final RawContactEditorView rawContactEditor = (RawContactEditorView) editor;
            final ValuesDelta nameValuesDelta = rawContactEditor.getNameEditor().getValues();
            final EditorListener structuredNameListener = new EditorListener() {

                @Override
                public void onRequest(int request) {
                    // Make sure the activity is running
                    if (activity.isFinishing()) {
                        return;
                    }
                    if (!isEditingUserProfile()) {
                        if (request == EditorListener.FIELD_CHANGED) {
                            if (!nameValuesDelta.isSuperPrimary()) {
                                unsetSuperPrimaryForAllNameEditors();
                                nameValuesDelta.setSuperPrimary(true);
                            }
                            acquireAggregationSuggestions(activity, rawContactEditor.getNameEditor().getRawContactId(), rawContactEditor.getNameEditor().getValues());
                        } else if (request == EditorListener.FIELD_TURNED_EMPTY) {
                            if (nameValuesDelta.isSuperPrimary()) {
                                nameValuesDelta.setSuperPrimary(false);
                            }
                        }
                    }
                }

                @Override
                public void onDeleteRequested(Editor removedEditor) {
                }
            };
            final StructuredNameEditorView nameEditor = rawContactEditor.getNameEditor();
            nameEditor.setEditorListener(structuredNameListener);
            rawContactEditor.setAutoAddToDefaultGroup(mAutoAddToDefaultGroup);
            if (!isEditingUserProfile() && isAggregationSuggestionRawContactId(rawContactId)) {
                acquireAggregationSuggestions(activity, rawContactEditor.getNameEditor().getRawContactId(), rawContactEditor.getNameEditor().getValues());
            }
        }
    }
    setGroupMetaData();
    // Show editor now that we've loaded state
    mContent.setVisibility(View.VISIBLE);
    // Refresh Action Bar as the visibility of the join command
    // Activity can be null if we have been detached from the Activity
    invalidateOptionsMenu();
    updatedExpandedEditorsMap();
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) ContactEditorActivity(com.android.contacts.activities.ContactEditorActivity) Activity(android.app.Activity) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType) Uri(android.net.Uri) LayoutInflater(android.view.LayoutInflater) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) ContactEditor(com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor) EditorListener(com.android.contacts.editor.Editor.EditorListener)

Example 19 with ValuesDelta

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

the class ContactEditorFragment method unsetSuperPrimaryForAllNameEditors.

private void unsetSuperPrimaryForAllNameEditors() {
    for (int i = 0; i < mContent.getChildCount(); i++) {
        final View view = mContent.getChildAt(i);
        if (view instanceof RawContactEditorView) {
            final RawContactEditorView rawContactEditorView = (RawContactEditorView) view;
            final StructuredNameEditorView nameEditorView = rawContactEditorView.getNameEditor();
            if (nameEditorView != null) {
                final ValuesDelta valuesDelta = nameEditorView.getValues();
                if (valuesDelta != null) {
                    valuesDelta.setSuperPrimary(false);
                }
            }
        }
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 20 with ValuesDelta

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

the class CompactKindSectionView method updateEmptyNonNameEditors.

private void updateEmptyNonNameEditors(boolean shouldAnimate) {
    // Prune excess empty editors
    final List<View> emptyEditors = getEmptyEditors();
    if (emptyEditors.size() > 1) {
        // If there is more than 1 empty editor, then remove it from the list of editors.
        int deleted = 0;
        for (final View view : emptyEditors) {
            // there is more values delta so we must also count number of editors deleted.
            if (view.findFocus() == null) {
                deleteView(view, shouldAnimate);
                deleted++;
                if (deleted == emptyEditors.size() - 1)
                    break;
            }
        }
        return;
    }
    // Determine if we should add a new empty editor
    final DataKind dataKind = mKindSectionDataList.get(0).getDataKind();
    final RawContactDelta rawContactDelta = mKindSectionDataList.get(0).getRawContactDelta();
    if (// There is nothing we can do.
    dataKind == null || // We have already reached the maximum number of editors, don't add any more.
    !RawContactModifier.canInsert(rawContactDelta, dataKind) || // We have already reached the maximum number of empty editors, don't add any more.
    emptyEditors.size() == 1) {
        return;
    }
    // Add a new empty editor
    if (mShowOneEmptyEditor) {
        final String mimeType = mKindSectionDataList.getMimeType();
        if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType) && mEditors.getChildCount() > 0) {
            return;
        }
        final ValuesDelta values = RawContactModifier.insertChild(rawContactDelta, dataKind);
        final Editor.EditorListener editorListener = Event.CONTENT_ITEM_TYPE.equals(mimeType) ? new EventEditorListener() : new NonNameEditorListener();
        final View view = addNonNameEditorView(rawContactDelta, dataKind, values, editorListener);
        showView(view, shouldAnimate);
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

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