Search in sources :

Example 6 with AccountWithDataSet

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

the class ContactEditorAccountsChangedActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SUBACTIVITY_ADD_NEW_ACCOUNT) {
        // the user.
        if (resultCode != RESULT_OK) {
            return;
        }
        // Subactivity was successful, so pass the result back and finish the activity.
        AccountWithDataSet account = mEditorUtils.getCreatedAccount(resultCode, data);
        if (account == null) {
            setResult(resultCode);
            finish();
            return;
        }
        saveAccountAndReturnResult(account);
    }
}
Also used : AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet)

Example 7 with AccountWithDataSet

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

the class AttachPhotoActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
    if (requestCode == REQUEST_PICK_DEFAULT_ACCOUNT_FOR_NEW_CONTACT) {
        // Bail if the account selector was not successful.
        if (resultCode != Activity.RESULT_OK) {
            Log.w(TAG, "account selector was not successful");
            finish();
            return;
        }
        // If there's an account specified, use it.
        if (result != null) {
            AccountWithDataSet account = result.getParcelableExtra(Intents.Insert.EXTRA_ACCOUNT);
            if (account != null) {
                createNewRawContact(account);
                return;
            }
        }
        // If there isn't an account specified, then the user opted to keep the contact local.
        createNewRawContact(null);
    } else if (requestCode == REQUEST_PICK_CONTACT) {
        if (resultCode != RESULT_OK) {
            finish();
            return;
        }
        // A contact was picked. Launch the cropper to get face detection, the right size, etc.
        // TODO: get these values from constants somewhere
        final Intent myIntent = getIntent();
        final Uri inputUri = myIntent.getData();
        // TODO: With b/10837468 fixed should be able to avoid this copy.
        if (!ContactPhotoUtils.savePhotoFromUriToUri(this, inputUri, mTempPhotoUri, false)) {
            finish();
            return;
        }
        final Intent intent = new Intent("com.android.camera.action.CROP", mTempPhotoUri);
        if (myIntent.getStringExtra("mimeType") != null) {
            intent.setDataAndType(mTempPhotoUri, myIntent.getStringExtra("mimeType"));
        }
        ContactPhotoUtils.addPhotoPickerExtras(intent, mCroppedPhotoUri);
        ContactPhotoUtils.addCropExtras(intent, mPhotoDim != 0 ? mPhotoDim : mDefaultPhotoDim);
        if (!hasIntentHandler(intent)) {
            // No activity supports the crop action. So skip cropping and set the photo
            // without performing any cropping.
            mCroppedPhotoUri = mTempPhotoUri;
            mContactUri = result.getData();
            loadContact(mContactUri, new Listener() {

                @Override
                public void onContactLoaded(Contact contact) {
                    saveContact(contact);
                }
            });
            return;
        }
        try {
            startActivityForResult(intent, REQUEST_CROP_PHOTO);
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(this, R.string.missing_app, Toast.LENGTH_SHORT).show();
            return;
        }
        mContactUri = result.getData();
    } else if (requestCode == REQUEST_CROP_PHOTO) {
        // Delete the temporary photo from cache now that we have a cropped version.
        // We should do this even if the crop failed and we eventually bail
        getContentResolver().delete(mTempPhotoUri, null, null);
        if (resultCode != RESULT_OK) {
            finish();
            return;
        }
        loadContact(mContactUri, new Listener() {

            @Override
            public void onContactLoaded(Contact contact) {
                saveContact(contact);
            }
        });
    }
}
Also used : OnLoadCompleteListener(android.content.Loader.OnLoadCompleteListener) ActivityNotFoundException(android.content.ActivityNotFoundException) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) Intent(android.content.Intent) Uri(android.net.Uri) Contact(com.android.contacts.common.model.Contact)

Example 8 with AccountWithDataSet

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

the class PeopleActivityTest method setUp.

@Override
public void setUp() {
    mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
    mContactsProvider = mContext.getContactsProvider();
    // The ContactsApplication performs this getType query to warm up the provider - see
    // ContactsApplication#DelayedInitialization.doInBackground
    mContactsProvider.expectTypeQuery(ContentUris.withAppendedId(Contacts.CONTENT_URI, 1), Contacts.CONTENT_ITEM_TYPE);
    mSettingsProvider = mContext.getSettingsProvider();
    InjectedServices services = new InjectedServices();
    services.setContentResolver(mContext.getContentResolver());
    services.setSharedPreferences(new MockSharedPreferences());
    ContactPhotoManager.injectContactPhotoManagerForTesting(new MockContactPhotoManager());
    AccountType accountType = new BaseAccountType() {

        @Override
        public boolean areContactsWritable() {
            return false;
        }
    };
    accountType.accountType = TEST_ACCOUNT_TYPE;
    AccountWithDataSet account = new AccountWithDataSet(TEST_ACCOUNT, TEST_ACCOUNT_TYPE, null);
    ContactsApplication.injectServices(services);
    final MockAccountTypeManager mockManager = new MockAccountTypeManager(new AccountType[] { accountType }, new AccountWithDataSet[] { account });
    AccountTypeManager.setInstanceForTest(mockManager);
}
Also used : InjectedServices(com.android.contacts.common.testing.InjectedServices) BaseAccountType(com.android.contacts.common.model.account.BaseAccountType) MockContactPhotoManager(com.android.contacts.common.test.mocks.MockContactPhotoManager) MockAccountTypeManager(com.android.contacts.common.test.mocks.MockAccountTypeManager) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) MockSharedPreferences(com.android.contacts.common.test.mocks.MockSharedPreferences) 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 9 with AccountWithDataSet

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

the class ContactEditorUtilsTest method setUp.

@Override
protected void setUp() throws Exception {
    // Initialize with 0 types, 0 accounts.
    mAccountTypes = new MockAccountTypeManager(new AccountType[] {}, new AccountWithDataSet[] {});
    mTarget = new ContactEditorUtils(getContext(), mAccountTypes);
    // Clear the preferences.
    mTarget.cleanupForTest();
}
Also used : MockAccountTypeManager(com.android.contacts.common.test.mocks.MockAccountTypeManager) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AccountType(com.android.contacts.common.model.account.AccountType)

Example 10 with AccountWithDataSet

use of com.android.contacts.common.model.account.AccountWithDataSet in project android_packages_apps_Dialer by LineageOS.

the class AccountTypeManagerImpl method loadAccountsInBackground.

/**
 * Loads account list and corresponding account types (potentially with data sets). Always called
 * on a background thread.
 */
protected void loadAccountsInBackground() {
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground start");
    }
    TimingLogger timings = new TimingLogger(TAG, "loadAccountsInBackground");
    final long startTime = SystemClock.currentThreadTimeMillis();
    final long startTimeWall = SystemClock.elapsedRealtime();
    // Account types, keyed off the account type and data set concatenation.
    final Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet = new ArrayMap<>();
    // The same AccountTypes, but keyed off {@link RawContacts#ACCOUNT_TYPE}.  Since there can
    // be multiple account types (with different data sets) for the same type of account, each
    // type string may have multiple AccountType entries.
    final Map<String, List<AccountType>> accountTypesByType = new ArrayMap<>();
    final List<AccountWithDataSet> allAccounts = new ArrayList<>();
    final List<AccountWithDataSet> contactWritableAccounts = new ArrayList<>();
    final List<AccountWithDataSet> groupWritableAccounts = new ArrayList<>();
    final Set<String> extensionPackages = new HashSet<>();
    final AccountManager am = mAccountManager;
    final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
    final AuthenticatorDescription[] auths = am.getAuthenticatorTypes();
    // First process sync adapters to find any that provide contact data.
    for (SyncAdapterType sync : syncs) {
        if (!ContactsContract.AUTHORITY.equals(sync.authority)) {
            // Skip sync adapters that don't provide contact data.
            continue;
        }
        // Look for the formatting details provided by each sync
        // adapter, using the authenticator to find general resources.
        final String type = sync.accountType;
        final AuthenticatorDescription auth = findAuthenticator(auths, type);
        if (auth == null) {
            Log.w(TAG, "No authenticator found for type=" + type + ", ignoring it.");
            continue;
        }
        AccountType accountType;
        if (GoogleAccountType.ACCOUNT_TYPE.equals(type)) {
            accountType = new GoogleAccountType(mContext, auth.packageName);
        } else if (ExchangeAccountType.isExchangeType(type)) {
            accountType = new ExchangeAccountType(mContext, auth.packageName, type);
        } else if (SamsungAccountType.isSamsungAccountType(mContext, type, auth.packageName)) {
            accountType = new SamsungAccountType(mContext, auth.packageName, type);
        } else {
            Log.d(TAG, "Registering external account type=" + type + ", packageName=" + auth.packageName);
            accountType = new ExternalAccountType(mContext, auth.packageName, false);
        }
        if (!accountType.isInitialized()) {
            if (accountType.isEmbedded()) {
                throw new IllegalStateException("Problem initializing embedded type " + accountType.getClass().getCanonicalName());
            } else {
                // Skip external account types that couldn't be initialized.
                continue;
            }
        }
        accountType.accountType = auth.type;
        accountType.titleRes = auth.labelId;
        accountType.iconRes = auth.iconId;
        addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
        // Check to see if the account type knows of any other non-sync-adapter packages
        // that may provide other data sets of contact data.
        extensionPackages.addAll(accountType.getExtensionPackageNames());
    }
    // If any extension packages were specified, process them as well.
    if (!extensionPackages.isEmpty()) {
        Log.d(TAG, "Registering " + extensionPackages.size() + " extension packages");
        for (String extensionPackage : extensionPackages) {
            ExternalAccountType accountType = new ExternalAccountType(mContext, extensionPackage, true);
            if (!accountType.isInitialized()) {
                // Skip external account types that couldn't be initialized.
                continue;
            }
            if (!accountType.hasContactsMetadata()) {
                Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " it doesn't have the CONTACTS_STRUCTURE metadata");
                continue;
            }
            if (TextUtils.isEmpty(accountType.accountType)) {
                Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " the CONTACTS_STRUCTURE metadata doesn't have the accountType" + " attribute");
                continue;
            }
            Log.d(TAG, "Registering extension package account type=" + accountType.accountType + ", dataSet=" + accountType.dataSet + ", packageName=" + extensionPackage);
            addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
        }
    }
    timings.addSplit("Loaded account types");
    // Map in accounts to associate the account names with each account type entry.
    Account[] accounts = mAccountManager.getAccounts();
    for (Account account : accounts) {
        boolean syncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0;
        if (syncable) {
            List<AccountType> accountTypes = accountTypesByType.get(account.type);
            if (accountTypes != null) {
                // authenticated by this account.
                for (AccountType accountType : accountTypes) {
                    AccountWithDataSet accountWithDataSet = new AccountWithDataSet(account.name, account.type, accountType.dataSet);
                    allAccounts.add(accountWithDataSet);
                    if (accountType.areContactsWritable()) {
                        contactWritableAccounts.add(accountWithDataSet);
                    }
                    if (accountType.isGroupMembershipEditable()) {
                        groupWritableAccounts.add(accountWithDataSet);
                    }
                }
            }
        }
    }
    Collections.sort(allAccounts, ACCOUNT_COMPARATOR);
    Collections.sort(contactWritableAccounts, ACCOUNT_COMPARATOR);
    Collections.sort(groupWritableAccounts, ACCOUNT_COMPARATOR);
    timings.addSplit("Loaded accounts");
    synchronized (this) {
        mAccountTypesWithDataSets = accountTypesByTypeAndDataSet;
        mAccounts = allAccounts;
        mContactWritableAccounts = contactWritableAccounts;
        mGroupWritableAccounts = groupWritableAccounts;
        mInvitableAccountTypes = findAllInvitableAccountTypes(mContext, allAccounts, accountTypesByTypeAndDataSet);
    }
    timings.dumpToLog();
    final long endTimeWall = SystemClock.elapsedRealtime();
    final long endTime = SystemClock.currentThreadTimeMillis();
    Log.i(TAG, "Loaded meta-data for " + mAccountTypesWithDataSets.size() + " account types, " + mAccounts.size() + " accounts in " + (endTimeWall - startTimeWall) + "ms(wall) " + (endTime - startTime) + "ms(cpu)");
    if (mInitializationLatch != null) {
        mInitializationLatch.countDown();
        mInitializationLatch = null;
    }
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground finish");
    }
    // Check filter validity since filter may become obsolete after account update. It must be
    // done from UI thread.
    mMainThreadHandler.post(mCheckFilterValidityRunnable);
}
Also used : Account(android.accounts.Account) ArrayList(java.util.ArrayList) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType) ExchangeAccountType(com.android.contacts.common.model.account.ExchangeAccountType) SamsungAccountType(com.android.contacts.common.model.account.SamsungAccountType) AuthenticatorDescription(android.accounts.AuthenticatorDescription) TimingLogger(android.util.TimingLogger) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AccountTypeWithDataSet(com.android.contacts.common.model.account.AccountTypeWithDataSet) ArrayMap(android.util.ArrayMap) ExternalAccountType(com.android.contacts.common.model.account.ExternalAccountType) SyncAdapterType(android.content.SyncAdapterType) AccountType(com.android.contacts.common.model.account.AccountType) FallbackAccountType(com.android.contacts.common.model.account.FallbackAccountType) ExchangeAccountType(com.android.contacts.common.model.account.ExchangeAccountType) SamsungAccountType(com.android.contacts.common.model.account.SamsungAccountType) ExternalAccountType(com.android.contacts.common.model.account.ExternalAccountType) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType) AccountManager(android.accounts.AccountManager)

Aggregations

AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)24 AccountType (com.android.contacts.common.model.account.AccountType)7 Intent (android.content.Intent)4 Activity (android.app.Activity)3 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)3 RawContactDelta (com.android.contacts.common.model.RawContactDelta)3 AccountsListAdapter (com.android.contacts.common.util.AccountsListAdapter)3 Account (android.accounts.Account)2 Uri (android.net.Uri)2 ArrayMap (android.util.ArrayMap)2 ListPopupWindow (android.widget.ListPopupWindow)2 TextView (android.widget.TextView)2 RawContact (com.android.contacts.common.model.RawContact)2 ValuesDelta (com.android.contacts.common.model.ValuesDelta)2 AccountTypeWithDataSet (com.android.contacts.common.model.account.AccountTypeWithDataSet)2 ExchangeAccountType (com.android.contacts.common.model.account.ExchangeAccountType)2 ExternalAccountType (com.android.contacts.common.model.account.ExternalAccountType)2 FallbackAccountType (com.android.contacts.common.model.account.FallbackAccountType)2