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