Search in sources :

Example 1 with RawContactDelta

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

the class CompactRawContactsEditorView method addAccountInfo.

private void addAccountInfo(RawContactDeltaList rawContactDeltas) {
    mAccountHeaderContainer.setVisibility(View.GONE);
    mAccountSelectorContainer.setVisibility(View.GONE);
    mRawContactContainer.setVisibility(View.GONE);
    if (mPrimaryNameKindSectionData == null)
        return;
    final RawContactDelta rawContactDelta = mPrimaryNameKindSectionData.first.getRawContactDelta();
    // Get the account information for the primary raw contact delta
    final Pair<String, String> accountInfo = mIsUserProfile ? EditorUiUtils.getLocalAccountInfo(getContext(), rawContactDelta.getAccountName(), rawContactDelta.getAccountType(mAccountTypeManager)) : EditorUiUtils.getAccountInfo(getContext(), rawContactDelta.getAccountName(), rawContactDelta.getAccountType(mAccountTypeManager));
    // Either the account header or selector should be shown, not both.
    final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(getContext()).getAccounts(true);
    if (mHasNewContact && !mIsUserProfile) {
        if (accounts.size() > 1) {
            addAccountSelector(accountInfo, rawContactDelta);
        } else {
            addAccountHeader(accountInfo);
        }
    } else if (mIsUserProfile || !shouldHideAccountContainer(rawContactDeltas)) {
        addAccountHeader(accountInfo);
    }
    // The raw contact selector should only display linked raw contacts that can be edited in
    // the full editor (i.e. they are not newly created raw contacts)
    final RawContactAccountListAdapter adapter = new RawContactAccountListAdapter(getContext(), getRawContactDeltaListForSelector(rawContactDeltas));
    if (adapter.getCount() > 0) {
        final String accountsSummary = getResources().getQuantityString(R.plurals.compact_editor_linked_contacts_selector_title, adapter.getCount(), adapter.getCount());
        addRawContactAccountSelector(accountsSummary, adapter);
    }
}
Also used : AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 2 with RawContactDelta

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

the class CompactRawContactsEditorView method addRawContactAccountSelector.

private void addRawContactAccountSelector(String accountsSummary, final RawContactAccountListAdapter adapter) {
    mRawContactContainer.setVisibility(View.VISIBLE);
    mRawContactSummary.setText(accountsSummary);
    mRawContactContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(getContext(), null);
            popup.setWidth(mRawContactContainer.getWidth());
            popup.setAnchorView(mRawContactContainer);
            popup.setAdapter(adapter);
            popup.setModal(true);
            popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    UiClosables.closeQuietly(popup);
                    if (mListener != null) {
                        final long rawContactId = adapter.getItemId(position);
                        final Uri rawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId);
                        final RawContactDelta rawContactDelta = adapter.getItem(position);
                        final AccountTypeManager accountTypes = AccountTypeManager.getInstance(getContext());
                        final AccountType accountType = rawContactDelta.getAccountType(accountTypes);
                        final boolean isReadOnly = !accountType.areContactsWritable();
                        mListener.onRawContactSelected(rawContactUri, rawContactId, isReadOnly);
                    }
                }
            });
            popup.show();
        }
    });
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) AdapterView(android.widget.AdapterView) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Uri(android.net.Uri) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 3 with RawContactDelta

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

the class CompactRawContactsEditorView method getRawContactDeltaListForSelector.

private RawContactDeltaList getRawContactDeltaListForSelector(RawContactDeltaList rawContactDeltas) {
    // Sort raw contacts so google accounts come first
    Collections.sort(rawContactDeltas, new RawContactDeltaComparator(getContext()));
    final RawContactDeltaList result = new RawContactDeltaList();
    for (RawContactDelta rawContactDelta : rawContactDeltas) {
        if (rawContactDelta.isVisible() && rawContactDelta.getRawContactId() > 0) {
            // Only add raw contacts that can be opened in the editor
            result.add(rawContactDelta);
        }
    }
    // in the compact editor in the full editor
    if (result.size() == 1 && result.get(0).getRawContactAccountType(getContext()).areContactsWritable()) {
        result.clear();
        return result;
    }
    return result;
}
Also used : RawContactDeltaList(com.android.contacts.common.model.RawContactDeltaList) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 4 with RawContactDelta

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

the class CompactRawContactsEditorView method addAccountHeader.

private void addAccountHeader(Pair<String, String> accountInfo) {
    mAccountHeaderContainer.setVisibility(View.VISIBLE);
    // Set the account name
    final String accountName = TextUtils.isEmpty(accountInfo.first) ? accountInfo.second : accountInfo.first;
    mAccountHeaderName.setVisibility(View.VISIBLE);
    mAccountHeaderName.setText(accountName);
    // Set the account type
    final String selectorTitle = getResources().getString(R.string.compact_editor_account_selector_title);
    mAccountHeaderType.setText(selectorTitle);
    // Set the icon
    if (mPrimaryNameKindSectionData != null) {
        final RawContactDelta rawContactDelta = mPrimaryNameKindSectionData.first.getRawContactDelta();
        if (rawContactDelta != null) {
            final AccountType accountType = rawContactDelta.getRawContactAccountType(getContext());
            mAccountHeaderIcon.setImageDrawable(accountType.getDisplayIcon(getContext()));
        }
    }
    // Set the content description
    mAccountHeaderContainer.setContentDescription(EditorUiUtils.getAccountInfoContentDescription(accountName, selectorTitle));
}
Also used : RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 5 with RawContactDelta

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

the class ContactEditorBaseFragment method createNewRawContactDelta.

/**
 * Returns a {@link RawContactDelta} for a new contact suitable for addition into
 * {@link #mState}.
 *
 * If oldState and oldAccountType are specified, the state specified by those parameters
 * is migrated to the result {@link RawContactDelta}.
 */
private RawContactDelta createNewRawContactDelta(AccountWithDataSet account, AccountType accountType, RawContactDelta oldState, AccountType oldAccountType) {
    final RawContact rawContact = new RawContact();
    if (account != null) {
        rawContact.setAccount(account);
    } else {
        rawContact.setAccountToLocal();
    }
    final RawContactDelta result = new RawContactDelta(ValuesDelta.fromAfter(rawContact.getValues()));
    if (oldState == null) {
        // Parse any values from incoming intent
        RawContactModifier.parseExtras(mContext, accountType, result, mIntentExtras);
    } else {
        RawContactModifier.migrateStateForNewContact(mContext, oldState, result, oldAccountType, accountType);
    }
    // Ensure we have some default fields (if the account type does not support a field,
    // ensureKind will not add it, so it is safe to add e.g. Event)
    RawContactModifier.ensureKindExists(result, accountType, Phone.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, Email.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, Organization.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, Event.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, StructuredPostal.CONTENT_ITEM_TYPE);
    // Set the correct URI for saving the contact as a profile
    if (mNewLocalProfile) {
        result.setProfileQueryUri();
    }
    return result;
}
Also used : RawContact(com.android.contacts.common.model.RawContact) 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