Search in sources :

Example 21 with AccountType

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

the class ContactDeletionInteractionTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // This test requires that the screen be turned on.
    mUtils = new IntegrationTestUtils(getInstrumentation());
    mUtils.acquireScreenWakeLock(getInstrumentation().getTargetContext());
    mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
    InjectedServices services = new InjectedServices();
    services.setContentResolver(mContext.getContentResolver());
    AccountType readOnlyAccountType = new BaseAccountType() {

        @Override
        public boolean areContactsWritable() {
            return false;
        }
    };
    readOnlyAccountType.accountType = READONLY_ACCOUNT_TYPE;
    AccountType writableAccountType = new BaseAccountType() {

        @Override
        public boolean areContactsWritable() {
            return true;
        }
    };
    writableAccountType.accountType = WRITABLE_ACCOUNT_TYPE;
    ContactsApplication.injectServices(services);
    final MockAccountTypeManager mockManager = new MockAccountTypeManager(new AccountType[] { writableAccountType, readOnlyAccountType }, null);
    AccountTypeManager.setInstanceForTest(mockManager);
    mContactsProvider = mContext.getContactsProvider();
}
Also used : InjectedServices(com.android.contacts.common.testing.InjectedServices) BaseAccountType(com.android.contacts.common.model.account.BaseAccountType) MockAccountTypeManager(com.android.contacts.common.test.mocks.MockAccountTypeManager) IntegrationTestUtils(com.android.contacts.common.test.IntegrationTestUtils) ContactsMockContext(com.android.contacts.common.test.mocks.ContactsMockContext) BaseAccountType(com.android.contacts.common.model.account.BaseAccountType) AccountType(com.android.contacts.common.model.account.AccountType)

Example 22 with AccountType

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

the class CompactRawContactsEditorView method parseRawContactDeltas.

private void parseRawContactDeltas(RawContactDeltaList rawContactDeltas) {
    // Build the kind section data list map
    vlog("parse: " + rawContactDeltas.size() + " rawContactDelta(s)");
    for (int j = 0; j < rawContactDeltas.size(); j++) {
        final RawContactDelta rawContactDelta = rawContactDeltas.get(j);
        vlog("parse: " + j + " rawContactDelta" + rawContactDelta);
        if (rawContactDelta == null || !rawContactDelta.isVisible())
            continue;
        final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
        if (accountType == null)
            continue;
        final List<DataKind> dataKinds = accountType.getSortedDataKinds();
        final int dataKindSize = dataKinds == null ? 0 : dataKinds.size();
        vlog("parse: " + dataKindSize + " dataKinds(s)");
        for (int i = 0; i < dataKindSize; i++) {
            final DataKind dataKind = dataKinds.get(i);
            if (dataKind == null || !dataKind.editable) {
                vlog("parse: " + i + " " + dataKind.mimeType + " dropped read-only");
                continue;
            }
            final String mimeType = dataKind.mimeType;
            // Skip psuedo mime types
            if (DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME.equals(mimeType) || DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)) {
                vlog("parse: " + i + " " + dataKind.mimeType + " dropped pseudo type");
                continue;
            }
            final KindSectionDataList kindSectionDataList = getOrCreateKindSectionDataList(mimeType);
            final KindSectionData kindSectionData = new KindSectionData(accountType, dataKind, rawContactDelta);
            kindSectionDataList.add(kindSectionData);
            vlog("parse: " + i + " " + dataKind.mimeType + " " + kindSectionData.getValuesDeltas().size() + " value(s) " + kindSectionData.getNonEmptyValuesDeltas().size() + " non-empty value(s) " + kindSectionData.getVisibleValuesDeltas().size() + " visible value(s)");
        }
    }
}
Also used : DataKind(com.android.contacts.common.model.dataitem.DataKind) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 23 with AccountType

use of com.android.contacts.common.model.account.AccountType 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 24 with AccountType

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

the class ContactEditorBaseFragment method createContact.

/**
 * Shows account creation screen associated with a given account.
 *
 * @param account may be null to signal a device-local contact should be created.
 */
protected void createContact(AccountWithDataSet account) {
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
    final AccountType accountType = accountTypes.getAccountTypeForAccount(account);
    if (accountType.getCreateContactActivityClassName() != null) {
        if (mListener != null) {
            mListener.onCustomCreateContactActivityRequested(account, mIntentExtras);
        }
    } else {
        setStateForNewContact(account, accountType, isEditingUserProfile());
    }
}
Also used : AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType) SimAccountType(com.android.contacts.common.model.account.SimAccountType)

Example 25 with AccountType

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

Aggregations

AccountType (com.android.contacts.common.model.account.AccountType)34 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)13 Intent (android.content.Intent)7 RawContactDelta (com.android.contacts.common.model.RawContactDelta)7 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)7 Uri (android.net.Uri)6 ValuesDelta (com.android.contacts.common.model.ValuesDelta)6 GoogleAccountType (com.android.contacts.common.model.account.GoogleAccountType)6 View (android.view.View)4 TextView (android.widget.TextView)4 RawContact (com.android.contacts.common.model.RawContact)4 AccountTypeWithDataSet (com.android.contacts.common.model.account.AccountTypeWithDataSet)4 ExchangeAccountType (com.android.contacts.common.model.account.ExchangeAccountType)4 ExternalAccountType (com.android.contacts.common.model.account.ExternalAccountType)4 FallbackAccountType (com.android.contacts.common.model.account.FallbackAccountType)4 SamsungAccountType (com.android.contacts.common.model.account.SamsungAccountType)4 ArrayMap (android.util.ArrayMap)3 OnClickListener (android.view.View.OnClickListener)3 ImageView (android.widget.ImageView)3 DataKind (com.android.contacts.common.model.dataitem.DataKind)3