Search in sources :

Example 16 with RawContactDelta

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

the class CompactRawContactsEditorView method shouldHideAccountContainer.

// Returns true if there are multiple writable rawcontacts and no read-only ones,
// or there are both writable and read-only rawcontacts.
private boolean shouldHideAccountContainer(RawContactDeltaList rawContactDeltas) {
    int writable = 0;
    int readonly = 0;
    for (RawContactDelta rawContactDelta : rawContactDeltas) {
        if (rawContactDelta.isVisible() && rawContactDelta.getRawContactId() > 0) {
            if (rawContactDelta.getRawContactAccountType(getContext()).areContactsWritable()) {
                writable++;
            } else {
                readonly++;
            }
        }
    }
    return (writable > 1 || (writable > 0 && readonly > 0));
}
Also used : RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 17 with RawContactDelta

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

the class ContactEditorBaseFragment method onSplitContactConfirmed.

@Override
public void onSplitContactConfirmed(boolean hasPendingChanges) {
    if (mState.isEmpty()) {
        // This may happen when this Fragment is recreated by the system during users
        // confirming the split action (and thus this method is called just before onCreate()),
        // for example.
        Log.e(TAG, "mState became null during the user's confirming split action. " + "Cannot perform the save action.");
        return;
    }
    if (!hasPendingChanges && mHasNewContact) {
        // If the user didn't add anything new, we don't want to split out the newly created
        // raw contact into a name-only contact so remove them.
        final Iterator<RawContactDelta> iterator = mState.iterator();
        while (iterator.hasNext()) {
            final RawContactDelta rawContactDelta = iterator.next();
            if (rawContactDelta.getRawContactId() < 0) {
                iterator.remove();
            }
        }
    }
    mState.markRawContactsForSplitting();
    save(SaveMode.SPLIT);
}
Also used : RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 18 with RawContactDelta

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

the class ContactEditorBaseFragment method createLocalRawContactDelta.

/**
 * Returns a {@link RawContactDelta} for a local contact suitable for addition into
 * {@link #mState}.
 */
private static RawContactDelta createLocalRawContactDelta() {
    final RawContact rawContact = new RawContact();
    rawContact.setAccountToLocal();
    final RawContactDelta result = new RawContactDelta(ValuesDelta.fromAfter(rawContact.getValues()));
    result.setProfileQueryUri();
    return result;
}
Also used : RawContact(com.android.contacts.common.model.RawContact) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 19 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta 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 20 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta 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

RawContactDelta (com.android.contacts.common.model.RawContactDelta)20 AccountType (com.android.contacts.common.model.account.AccountType)7 ValuesDelta (com.android.contacts.common.model.ValuesDelta)6 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)5 Uri (android.net.Uri)4 RawContact (com.android.contacts.common.model.RawContact)4 RawContactDeltaList (com.android.contacts.common.model.RawContactDeltaList)4 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)3 DataKind (com.android.contacts.common.model.dataitem.DataKind)3 Intent (android.content.Intent)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Activity (android.app.Activity)1 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentProviderResult (android.content.ContentProviderResult)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 OperationApplicationException (android.content.OperationApplicationException)1 Cursor (android.database.Cursor)1