Search in sources :

Example 6 with AccountType

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);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType) ContactTileView(com.android.contacts.common.list.ContactTileView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) Uri(android.net.Uri)

Example 7 with AccountType

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;
}
Also used : ContentValues(android.content.ContentValues) ValuesDelta(com.android.contacts.common.model.ValuesDelta) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 8 with AccountType

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;
}
Also used : RawContact(com.android.contacts.editor.AggregationSuggestionEngine.RawContact) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType)

Example 9 with AccountType

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();
}
Also used : Bitmap(android.graphics.Bitmap) ValuesDelta(com.android.contacts.common.model.ValuesDelta) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) AccountType(com.android.contacts.common.model.account.AccountType)

Example 10 with AccountType

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);
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind) RawContactDeltaList(com.android.contacts.common.model.RawContactDeltaList) Intent(android.content.Intent) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Aggregations

AccountType (com.android.contacts.common.model.account.AccountType)34 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)13 Intent (android.content.Intent)7 RawContactDelta (com.android.contacts.common.model.RawContactDelta)7 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)7 Uri (android.net.Uri)6 ValuesDelta (com.android.contacts.common.model.ValuesDelta)6 GoogleAccountType (com.android.contacts.common.model.account.GoogleAccountType)6 View (android.view.View)4 TextView (android.widget.TextView)4 RawContact (com.android.contacts.common.model.RawContact)4 AccountTypeWithDataSet (com.android.contacts.common.model.account.AccountTypeWithDataSet)4 ExchangeAccountType (com.android.contacts.common.model.account.ExchangeAccountType)4 ExternalAccountType (com.android.contacts.common.model.account.ExternalAccountType)4 FallbackAccountType (com.android.contacts.common.model.account.FallbackAccountType)4 SamsungAccountType (com.android.contacts.common.model.account.SamsungAccountType)4 ArrayMap (android.util.ArrayMap)3 OnClickListener (android.view.View.OnClickListener)3 ImageView (android.widget.ImageView)3 DataKind (com.android.contacts.common.model.dataitem.DataKind)3