use of com.android.contacts.common.model.AccountTypeManager 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.AccountTypeManager in project packages_apps_Contacts by AOKP.
the class ContactEditorBaseFragment method rebindEditorsForNewContact.
/**
* Removes a current editor ({@link #mState}) and rebinds new editor for a new account.
* Some of old data are reused with new restriction enforced by the new account.
*
* @param oldState Old data being edited.
* @param oldAccount Old account associated with oldState.
* @param newAccount New account to be used.
*/
protected void rebindEditorsForNewContact(RawContactDelta oldState, AccountWithDataSet oldAccount, AccountWithDataSet newAccount) {
AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
AccountType oldAccountType = accountTypes.getAccountTypeForAccount(oldAccount);
AccountType newAccountType = accountTypes.getAccountTypeForAccount(newAccount);
if (newAccountType.getCreateContactActivityClassName() != null) {
Log.w(TAG, "external activity called in rebind situation");
if (mListener != null) {
mListener.onCustomCreateContactActivityRequested(newAccount, mIntentExtras);
}
} else {
mExistingContactDataReady = false;
mNewContactDataReady = false;
mState = new RawContactDeltaList();
setStateForNewContact(newAccount, newAccountType, oldState, oldAccountType, isEditingUserProfile());
if (mIsEdit) {
setStateForExistingContact(mReadOnlyDisplayName, isEditingUserProfile(), mRawContacts);
}
}
}
use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.
the class GroupDetailFragment method updateAccountType.
/**
* Once the account type, group source action, and group source URI have been determined
* (based on the result from the {@link Loader}), then we can display this to the user in 1 of
* 2 ways depending on screen size and orientation: either as a button in the action bar or as
* a button in a static header on the page.
* We also use isGroupMembershipEditable() of accountType to determine whether or not we should
* display the Edit option in the Actionbar.
*/
private void updateAccountType(final String accountTypeString, final String dataSet) {
final AccountTypeManager manager = AccountTypeManager.getInstance(getActivity());
final AccountType accountType = manager.getAccountType(accountTypeString, dataSet);
mIsMembershipEditable = accountType.isGroupMembershipEditable();
// else to be done by this {@link Fragment}.
if (mShowGroupActionInActionBar) {
mListener.onAccountTypeUpdated(accountTypeString, dataSet);
return;
}
// verify that there is a valid action.
if (!TextUtils.isEmpty(accountType.getViewGroupActivity())) {
if (mGroupSourceView == null) {
mGroupSourceView = GroupDetailDisplayUtils.getNewGroupSourceView(mContext);
// the view there.
if (mGroupSourceViewContainer != null) {
mGroupSourceViewContainer.addView(mGroupSourceView);
}
}
// Rebind the data since this action can change if the loader returns updated data
mGroupSourceView.setVisibility(View.VISIBLE);
GroupDetailDisplayUtils.bindGroupSourceView(mContext, mGroupSourceView, accountTypeString, dataSet);
mGroupSourceView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI, mGroupId);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setClassName(accountType.syncAdapterPackageName, accountType.getViewGroupActivity());
try {
ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "startActivity() failed: " + e);
Toast.makeText(getActivity(), R.string.missing_app, Toast.LENGTH_SHORT).show();
}
}
});
} else if (mGroupSourceView != null) {
mGroupSourceView.setVisibility(View.GONE);
}
}
use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.
the class AggregationSuggestionView method canEditSuggestedContact.
/**
* Returns true if the suggested contact can be edited.
*/
private boolean canEditSuggestedContact() {
if (!mNewContact) {
return false;
}
AccountTypeManager accountTypes = AccountTypeManager.getInstance(getContext());
for (RawContact rawContact : mRawContacts) {
String accountType = rawContact.accountType;
String dataSet = rawContact.dataSet;
if (accountType == null) {
return true;
}
AccountType type = accountTypes.getAccountType(accountType, dataSet);
if (type.areContactsWritable()) {
return true;
}
}
return false;
}
use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.
the class InvisibleContactUtil method addToDefaultGroup.
public static void addToDefaultGroup(Contact contactData, Context context) {
final long defaultGroupId = getDefaultGroupId(contactData.getGroupMetaData());
// but let's be safe here
if (defaultGroupId == -1)
return;
// add the group membership to the current state
final RawContactDeltaList contactDeltaList = contactData.createRawContactDeltaList();
final RawContactDelta rawContactEntityDelta = contactDeltaList.get(0);
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context);
final AccountType type = rawContactEntityDelta.getAccountType(accountTypes);
final DataKind groupMembershipKind = type.getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE);
final ValuesDelta entry = RawContactModifier.insertChild(rawContactEntityDelta, groupMembershipKind);
if (entry == null)
return;
entry.setGroupRowId(defaultGroupId);
// and fire off the intent. we don't need a callback, as the database listener
// should update the ui
final Intent intent = ContactSaveService.createSaveContactIntent(context, contactDeltaList, "", 0, false, QuickContactActivity.class, Intent.ACTION_VIEW, null, /* joinContactIdExtraKey =*/
null, /* joinContactId =*/
null);
ContactSaveService.startService(context, intent);
}
Aggregations