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);
}
}
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);
}
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;
}
}
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;
}
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));
}
Aggregations