use of com.android.contacts.common.model.account.AccountType 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.account.AccountType in project packages_apps_Contacts by AOKP.
the class PhotoSelectionHandler method getDeltaForAttachingPhotoToContact.
/**
* Utility method to retrieve the entity delta for attaching the given bitmap to the contact.
* This will attach the photo to the first contact-writable account that provided data to the
* contact. It is the caller's responsibility to apply the delta.
* @return An entity delta list that can be applied to associate the bitmap with the contact,
* or null if the photo could not be parsed or none of the accounts associated with the
* contact are writable.
*/
public RawContactDeltaList getDeltaForAttachingPhotoToContact() {
// Find the first writable entity.
int writableEntityIndex = getWritableEntityIndex();
if (writableEntityIndex != -1) {
// We are guaranteed to have contact data if we have a writable entity index.
final RawContactDelta delta = mState.get(writableEntityIndex);
// Need to find the right account so that EntityModifier knows which fields to add
final ContentValues entityValues = delta.getValues().getCompleteValues();
final String type = entityValues.getAsString(RawContacts.ACCOUNT_TYPE);
final String dataSet = entityValues.getAsString(RawContacts.DATA_SET);
final AccountType accountType = AccountTypeManager.getInstance(mContext).getAccountType(type, dataSet);
final ValuesDelta child = RawContactModifier.ensureKindExists(delta, accountType, Photo.CONTENT_ITEM_TYPE);
child.setFromTemplate(false);
child.setSuperPrimary(true);
return mState;
}
return null;
}
use of com.android.contacts.common.model.account.AccountType 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.account.AccountType in project packages_apps_Contacts by AOKP.
the class AttachPhotoActivity method saveToContact.
private void saveToContact(Contact contact, RawContactDeltaList deltaList, RawContactDelta raw) {
// Create a scaled, compressed bitmap to add to the entity-delta list.
final int size = ContactsUtils.getThumbnailSize(this);
Bitmap bitmap;
try {
bitmap = ContactPhotoUtils.getBitmapFromUri(this, mCroppedPhotoUri);
} catch (FileNotFoundException e) {
Log.w(TAG, "Could not find bitmap");
finish();
return;
}
if (bitmap == null) {
Log.w(TAG, "Could not decode bitmap");
finish();
return;
}
final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, size, size, false);
final byte[] compressed = ContactPhotoUtils.compressBitmap(scaled);
if (compressed == null) {
Log.w(TAG, "could not create scaled and compressed Bitmap");
finish();
return;
}
// Add compressed bitmap to entity-delta... this allows us to save to
// a new contact; otherwise the entity-delta-list would be empty, and
// the ContactSaveService would not create the new contact, and the
// full-res photo would fail to be saved to the non-existent contact.
AccountType account = raw.getRawContactAccountType(this);
ValuesDelta values = RawContactModifier.ensureKindExists(raw, account, Photo.CONTENT_ITEM_TYPE);
if (values == null) {
Log.w(TAG, "cannot attach photo to this account type");
finish();
return;
}
values.setPhoto(compressed);
// Finally, invoke the ContactSaveService.
Log.v(TAG, "all prerequisites met, about to save photo to contact");
Intent intent = ContactSaveService.createSaveContactIntent(this, deltaList, "", 0, contact.isUserProfile(), null, null, raw.getRawContactId() != null ? raw.getRawContactId() : -1, mCroppedPhotoUri);
ContactSaveService.startService(this, intent);
finish();
}
use of com.android.contacts.common.model.account.AccountType 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