Search in sources :

Example 1 with AccountWithDataSet

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

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

the class ContactEditorBaseFragment method setState.

// 
// Data binding
// 
private void setState(Contact contact) {
    // If we have already loaded data, we do not want to change it here to not confuse the user
    if (!mState.isEmpty()) {
        Log.v(TAG, "Ignoring background change. This will have to be rebased later");
        return;
    }
    // See if this edit operation needs to be redirected to a custom editor
    mRawContacts = contact.getRawContacts();
    if (mRawContacts.size() == 1) {
        RawContact rawContact = mRawContacts.get(0);
        String type = rawContact.getAccountTypeString();
        String dataSet = rawContact.getDataSet();
        AccountType accountType = rawContact.getAccountType(mContext);
        if (accountType.getEditContactActivityClassName() != null && !accountType.areContactsWritable()) {
            if (mListener != null) {
                String name = rawContact.getAccountName();
                long rawContactId = rawContact.getId();
                mListener.onCustomEditContactActivityRequested(new AccountWithDataSet(name, type, dataSet), ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), mIntentExtras, true);
            }
            return;
        }
    }
    String readOnlyDisplayName = null;
    // can edit.  For the user profile case, there is already an editable contact.
    if (!contact.isUserProfile() && !contact.isWritableContact(mContext)) {
        mHasNewContact = true;
        // This is potentially an asynchronous call and will add deltas to list.
        selectAccountAndCreateContact();
        readOnlyDisplayName = contact.getDisplayName();
    } else {
        mHasNewContact = false;
    }
    // This also adds deltas to list.  If readOnlyDisplayName is null at this point it is
    // simply ignored later on by the editor.
    setStateForExistingContact(readOnlyDisplayName, contact.isUserProfile(), mRawContacts);
}
Also used : RawContact(com.android.contacts.common.model.RawContact) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AccountType(com.android.contacts.common.model.account.AccountType) SimAccountType(com.android.contacts.common.model.account.SimAccountType)

Example 3 with AccountWithDataSet

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

the class ContactEditorUtils method getDefaultAccount.

/**
 * @return the default account saved with {@link #saveDefaultAndAllAccounts}.
 *
 * Note the {@code null} return value can mean either {@link #saveDefaultAndAllAccounts} has
 * never been called, or {@code null} was passed to {@link #saveDefaultAndAllAccounts} --
 * i.e. the user selected "local only".
 *
 * Also note that the returned account may have been removed already.
 */
public AccountWithDataSet getDefaultAccount() {
    AccountWithDataSet overlayDefaultAccount = getOverlayDefualtAccount();
    if (overlayDefaultAccount != null) {
        return overlayDefaultAccount;
    }
    final List<AccountWithDataSet> currentWritableAccounts = getWritableAccounts();
    if (currentWritableAccounts.size() == 1) {
        return currentWritableAccounts.get(0);
    }
    final String saved = mPrefs.getString(KEY_DEFAULT_ACCOUNT, null);
    if (TextUtils.isEmpty(saved)) {
        return null;
    }
    try {
        return AccountWithDataSet.unstringify(saved);
    } catch (IllegalArgumentException exception) {
        Log.e(TAG, "Error with retrieving default account " + exception.toString());
        // unstringify()can throw an exception if the string is not in an expected format.
        // Hence, if the preferences file is corrupt, just reset the preference values
        resetPreferenceValues();
        return null;
    }
}
Also used : AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet)

Example 4 with AccountWithDataSet

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

the class ContactEditorUtils method shouldShowAccountChangedNotification.

/**
 * @return true if the contact editor should show the "accounts changed" notification, that is:
 * - If it's the first launch.
 * - Or, if the default account has been removed.
 * (And some extra sanity check)
 *
 * Note if this method returns {@code false}, the caller can safely assume that
 * {@link #getDefaultAccount} will return a valid account.  (Either an account which still
 * exists, or {@code null} which should be interpreted as "local only".)
 */
@NeededForTesting
public boolean shouldShowAccountChangedNotification() {
    // If default account is defined, accounts change should not show.
    final AccountWithDataSet overlayDefaultAccount = getOverlayDefualtAccount();
    if (overlayDefaultAccount != null) {
        return false;
    }
    if (isFirstLaunch()) {
        return true;
    }
    final List<AccountWithDataSet> currentWritableAccounts = getWritableAccounts();
    final AccountWithDataSet defaultAccount = getDefaultAccount();
    // Does default account still exist?
    if (!isValidAccount(defaultAccount)) {
        return true;
    }
    // state after they respond to the notification.
    if ((defaultAccount == null || defaultAccount.isLocalAccount()) && currentWritableAccounts.size() > 0) {
        Log.e(TAG, "Preferences file in an inconsistent state, request that the default account" + " and current writable accounts be saved again");
        return true;
    }
    // All good.
    return false;
}
Also used : AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) NeededForTesting(com.android.contacts.common.testing.NeededForTesting)

Example 5 with AccountWithDataSet

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

the class GroupCreationDialogFragment method onCompleted.

@Override
protected void onCompleted(String groupLabel) {
    Bundle arguments = getArguments();
    String accountType = arguments.getString(ARG_ACCOUNT_TYPE);
    String accountName = arguments.getString(ARG_ACCOUNT_NAME);
    String dataSet = arguments.getString(ARG_DATA_SET);
    // popup from GroupMembershipView will not be shown.
    if (mListener != null) {
        mListener.onGroupCreated();
    }
    Activity activity = getActivity();
    activity.startService(ContactSaveService.createNewGroupIntent(activity, new AccountWithDataSet(accountName, accountType, dataSet), groupLabel, null, /* no new members to add */
    activity.getClass(), ContactEditorBaseActivity.ACTION_EDIT));
}
Also used : Bundle(android.os.Bundle) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) ContactEditorBaseActivity(com.android.contacts.activities.ContactEditorBaseActivity) Activity(android.app.Activity)

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