Search in sources :

Example 1 with AccountTypeManager

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();
        }
    });
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) AdapterView(android.widget.AdapterView) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Uri(android.net.Uri) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 2 with AccountTypeManager

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

Example 3 with AccountTypeManager

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);
    }
}
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 4 with AccountTypeManager

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;
}
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 5 with AccountTypeManager

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

AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)15 AccountType (com.android.contacts.common.model.account.AccountType)13 Uri (android.net.Uri)6 RawContactDelta (com.android.contacts.common.model.RawContactDelta)5 Intent (android.content.Intent)4 View (android.view.View)3 TextView (android.widget.TextView)3 RawContactDeltaList (com.android.contacts.common.model.RawContactDeltaList)3 ValuesDelta (com.android.contacts.common.model.ValuesDelta)3 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)3 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 SimAccountType (com.android.contacts.common.model.account.SimAccountType)2 Activity (android.app.Activity)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentProviderResult (android.content.ContentProviderResult)1 ContentResolver (android.content.ContentResolver)1 OperationApplicationException (android.content.OperationApplicationException)1 Cursor (android.database.Cursor)1