Search in sources :

Example 11 with AccountTypeManager

use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.

the class ContactEditorFragment method bindEditors.

@Override
protected void bindEditors() {
    // if mState is null
    if (mState.isEmpty()) {
        return;
    }
    // blank form.  When the data is not ready, skip. This method will be called multiple times.
    if ((mIsEdit && !mExistingContactDataReady) || (mHasNewContact && !mNewContactDataReady)) {
        return;
    }
    // Sort the editors
    Collections.sort(mState, mComparator);
    // Remove any existing editors and rebuild any visible
    mContent.removeAllViews();
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
    int numRawContacts = mState.size();
    for (int i = 0; i < numRawContacts; i++) {
        // TODO ensure proper ordering of entities in the list
        final RawContactDelta rawContactDelta = mState.get(i);
        if (!rawContactDelta.isVisible())
            continue;
        final AccountType type = rawContactDelta.getAccountType(accountTypes);
        final long rawContactId = rawContactDelta.getRawContactId();
        if (mRawContactIdToDisplayAlone != -1 && mRawContactIdToDisplayAlone != rawContactId) {
            continue;
        }
        final BaseRawContactEditorView editor;
        if (!type.areContactsWritable()) {
            editor = (BaseRawContactEditorView) inflater.inflate(R.layout.raw_contact_readonly_editor_view, mContent, false);
        } else {
            editor = (RawContactEditorView) inflater.inflate(R.layout.raw_contact_editor_view, mContent, false);
        }
        editor.setListener(this);
        final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(mContext).getAccounts(true);
        if (mHasNewContact && !mNewLocalProfile && accounts.size() > 1) {
            addAccountSwitcher(mState.get(0), editor);
        }
        editor.setEnabled(isEnabled());
        if (mRawContactIdToDisplayAlone != -1) {
            editor.setCollapsed(false);
        } else if (mExpandedEditors.containsKey(rawContactId)) {
            editor.setCollapsed(mExpandedEditors.get(rawContactId));
        } else {
            // By default, only the first editor will be expanded.
            editor.setCollapsed(i != 0);
        }
        mContent.addView(editor);
        editor.setState(rawContactDelta, type, mViewIdGenerator, isEditingUserProfile());
        if (mRawContactIdToDisplayAlone != -1) {
            editor.setCollapsible(false);
        } else {
            editor.setCollapsible(numRawContacts > 1);
        }
        // Set up the photo handler.
        bindPhotoHandler(editor, type, mState);
        // If a new photo was chosen but not yet saved, we need to update the UI to
        // reflect this.
        final Uri photoUri = updatedPhotoUriForRawContact(rawContactId);
        if (photoUri != null)
            editor.setFullSizedPhoto(photoUri);
        if (editor instanceof RawContactEditorView) {
            final Activity activity = getActivity();
            final RawContactEditorView rawContactEditor = (RawContactEditorView) editor;
            final ValuesDelta nameValuesDelta = rawContactEditor.getNameEditor().getValues();
            final EditorListener structuredNameListener = new EditorListener() {

                @Override
                public void onRequest(int request) {
                    // Make sure the activity is running
                    if (activity.isFinishing()) {
                        return;
                    }
                    if (!isEditingUserProfile()) {
                        if (request == EditorListener.FIELD_CHANGED) {
                            if (!nameValuesDelta.isSuperPrimary()) {
                                unsetSuperPrimaryForAllNameEditors();
                                nameValuesDelta.setSuperPrimary(true);
                            }
                            acquireAggregationSuggestions(activity, rawContactEditor.getNameEditor().getRawContactId(), rawContactEditor.getNameEditor().getValues());
                        } else if (request == EditorListener.FIELD_TURNED_EMPTY) {
                            if (nameValuesDelta.isSuperPrimary()) {
                                nameValuesDelta.setSuperPrimary(false);
                            }
                        }
                    }
                }

                @Override
                public void onDeleteRequested(Editor removedEditor) {
                }
            };
            final StructuredNameEditorView nameEditor = rawContactEditor.getNameEditor();
            nameEditor.setEditorListener(structuredNameListener);
            rawContactEditor.setAutoAddToDefaultGroup(mAutoAddToDefaultGroup);
            if (!isEditingUserProfile() && isAggregationSuggestionRawContactId(rawContactId)) {
                acquireAggregationSuggestions(activity, rawContactEditor.getNameEditor().getRawContactId(), rawContactEditor.getNameEditor().getValues());
            }
        }
    }
    setGroupMetaData();
    // Show editor now that we've loaded state
    mContent.setVisibility(View.VISIBLE);
    // Refresh Action Bar as the visibility of the join command
    // Activity can be null if we have been detached from the Activity
    invalidateOptionsMenu();
    updatedExpandedEditorsMap();
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) ContactEditorActivity(com.android.contacts.activities.ContactEditorActivity) Activity(android.app.Activity) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType) Uri(android.net.Uri) LayoutInflater(android.view.LayoutInflater) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) ContactEditor(com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor) EditorListener(com.android.contacts.editor.Editor.EditorListener)

Example 12 with AccountTypeManager

use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.

the class RawContactDeltaComparator method compare.

@Override
public int compare(RawContactDelta one, RawContactDelta two) {
    // Check direct equality
    if (one.equals(two)) {
        return 0;
    }
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
    String accountType1 = one.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
    String dataSet1 = one.getValues().getAsString(RawContacts.DATA_SET);
    final AccountType type1 = accountTypes.getAccountType(accountType1, dataSet1);
    String accountType2 = two.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
    String dataSet2 = two.getValues().getAsString(RawContacts.DATA_SET);
    final AccountType type2 = accountTypes.getAccountType(accountType2, dataSet2);
    // Check read-only. Sort read/write before read-only.
    if (!type1.areContactsWritable() && type2.areContactsWritable()) {
        return 1;
    } else if (type1.areContactsWritable() && !type2.areContactsWritable()) {
        return -1;
    }
    // Check account type. Sort Google before non-Google.
    boolean skipAccountTypeCheck = false;
    boolean isGoogleAccount1 = type1 instanceof GoogleAccountType;
    boolean isGoogleAccount2 = type2 instanceof GoogleAccountType;
    if (isGoogleAccount1 && !isGoogleAccount2) {
        return -1;
    } else if (!isGoogleAccount1 && isGoogleAccount2) {
        return 1;
    } else if (isGoogleAccount1 && isGoogleAccount2) {
        skipAccountTypeCheck = true;
    }
    int value;
    if (!skipAccountTypeCheck) {
        // Sort accounts with type before accounts without types.
        if (type1.accountType != null && type2.accountType == null) {
            return -1;
        } else if (type1.accountType == null && type2.accountType != null) {
            return 1;
        }
        if (type1.accountType != null && type2.accountType != null) {
            value = type1.accountType.compareTo(type2.accountType);
            if (value != 0) {
                return value;
            }
        }
        // those without.
        if (type1.dataSet != null && type2.dataSet == null) {
            return -1;
        } else if (type1.dataSet == null && type2.dataSet != null) {
            return 1;
        }
        if (type1.dataSet != null && type2.dataSet != null) {
            value = type1.dataSet.compareTo(type2.dataSet);
            if (value != 0) {
                return value;
            }
        }
    }
    // Check account name
    String oneAccount = one.getAccountName();
    if (oneAccount == null) {
        oneAccount = "";
    }
    String twoAccount = two.getAccountName();
    if (twoAccount == null) {
        twoAccount = "";
    }
    value = oneAccount.compareTo(twoAccount);
    if (value != 0) {
        return value;
    }
    // Both are in the same account, fall back to contact ID
    Long oneId = one.getRawContactId();
    Long twoId = two.getRawContactId();
    if (oneId == null && twoId == null) {
        return 0;
    } else if (oneId == null) {
        return -1;
    } else if (twoId == null) {
        return 1;
    }
    return Long.compare(oneId, twoId);
}
Also used : AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType) AccountType(com.android.contacts.common.model.account.AccountType) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType)

Example 13 with AccountTypeManager

use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.

the class GroupDetailDisplayUtils method bindGroupSourceView.

public static void bindGroupSourceView(Context context, View view, String accountTypeString, String dataSet) {
    AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(context);
    AccountType accountType = accountTypeManager.getAccountType(accountTypeString, dataSet);
    TextView label = (TextView) view.findViewById(android.R.id.title);
    if (label == null) {
        throw new IllegalStateException("Group source view must contain a TextView with id" + "android.R.id.label");
    }
    label.setText(accountType.getViewGroupLabel(context));
    ImageView accountIcon = (ImageView) view.findViewById(android.R.id.icon);
    if (accountIcon == null) {
        throw new IllegalStateException("Group source view must contain an ImageView with id" + "android.R.id.icon");
    }
    accountIcon.setImageDrawable(accountType.getDisplayIcon(context));
}
Also used : TextView(android.widget.TextView) ImageView(android.widget.ImageView) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType)

Example 14 with AccountTypeManager

use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.

the class ContactDeletionInteraction method onLoadFinished.

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (mDialog != null) {
        mDialog.dismiss();
        mDialog = null;
    }
    if (!mActive) {
        return;
    }
    if (cursor == null || cursor.isClosed()) {
        Log.e(TAG, "Failed to load contacts");
        return;
    }
    long contactId = 0;
    String lookupKey = null;
    // This cursor may contain duplicate raw contacts, so we need to de-dupe them first
    HashSet<Long> readOnlyRawContacts = Sets.newHashSet();
    HashSet<Long> writableRawContacts = Sets.newHashSet();
    AccountTypeManager accountTypes = AccountTypeManager.getInstance(getActivity());
    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        final long rawContactId = cursor.getLong(COLUMN_INDEX_RAW_CONTACT_ID);
        final String accountType = cursor.getString(COLUMN_INDEX_ACCOUNT_TYPE);
        final String dataSet = cursor.getString(COLUMN_INDEX_DATA_SET);
        contactId = cursor.getLong(COLUMN_INDEX_CONTACT_ID);
        lookupKey = cursor.getString(COLUMN_INDEX_LOOKUP_KEY);
        AccountType type = accountTypes.getAccountType(accountType, dataSet);
        boolean writable = type == null || type.areContactsWritable();
        if (writable) {
            writableRawContacts.add(rawContactId);
        } else {
            readOnlyRawContacts.add(rawContactId);
        }
    }
    if (TextUtils.isEmpty(lookupKey)) {
        Log.e(TAG, "Failed to find contact lookup key");
        getActivity().finish();
        return;
    }
    int readOnlyCount = readOnlyRawContacts.size();
    int writableCount = writableRawContacts.size();
    int positiveButtonId = android.R.string.ok;
    if (readOnlyCount > 0 && writableCount > 0) {
        mMessageId = R.string.readOnlyContactDeleteConfirmation;
    } else if (readOnlyCount > 0 && writableCount == 0) {
        mMessageId = R.string.readOnlyContactWarning;
        positiveButtonId = R.string.readOnlyContactWarning_positive_button;
    } else if (readOnlyCount == 0 && writableCount > 1) {
        mMessageId = R.string.multipleContactDeleteConfirmation;
        positiveButtonId = R.string.deleteConfirmation_positive_button;
    } else {
        mMessageId = R.string.deleteConfirmation;
        positiveButtonId = R.string.deleteConfirmation_positive_button;
    }
    final Uri contactUri = Contacts.getLookupUri(contactId, lookupKey);
    showDialog(mMessageId, positiveButtonId, contactUri);
    // We don't want onLoadFinished() calls any more, which may come when the database is
    // updating.
    getLoaderManager().destroyLoader(R.id.dialog_delete_contact_loader_id);
}
Also used : AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType) Uri(android.net.Uri)

Example 15 with AccountTypeManager

use of com.android.contacts.common.model.AccountTypeManager in project packages_apps_Contacts by AOKP.

the class ContactMultiDeletionInteraction method onLoadFinished.

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (mDialog != null) {
        mDialog.dismiss();
        mDialog = null;
    }
    if (!mIsLoaderActive) {
        return;
    }
    if (cursor == null || cursor.isClosed()) {
        Log.e(TAG, "Failed to load contacts");
        return;
    }
    // This cursor may contain duplicate raw contacts, so we need to de-dupe them first
    final HashSet<Long> readOnlyRawContacts = Sets.newHashSet();
    final HashSet<Long> writableRawContacts = Sets.newHashSet();
    final HashSet<Long> contactIds = Sets.newHashSet();
    AccountTypeManager accountTypes = AccountTypeManager.getInstance(getActivity());
    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        final long rawContactId = cursor.getLong(COLUMN_INDEX_RAW_CONTACT_ID);
        final String accountType = cursor.getString(COLUMN_INDEX_ACCOUNT_TYPE);
        final String dataSet = cursor.getString(COLUMN_INDEX_DATA_SET);
        final long contactId = cursor.getLong(COLUMN_INDEX_CONTACT_ID);
        contactIds.add(contactId);
        final AccountType type = accountTypes.getAccountType(accountType, dataSet);
        boolean writable = type == null || type.areContactsWritable();
        if (writable) {
            writableRawContacts.add(rawContactId);
        } else {
            readOnlyRawContacts.add(rawContactId);
        }
    }
    final int readOnlyCount = readOnlyRawContacts.size();
    final int writableCount = writableRawContacts.size();
    final int messageId;
    int positiveButtonId = android.R.string.ok;
    if (readOnlyCount > 0 && writableCount > 0) {
        messageId = R.string.batch_delete_multiple_accounts_confirmation;
    } else if (readOnlyCount > 0 && writableCount == 0) {
        messageId = R.string.batch_delete_read_only_contact_confirmation;
        positiveButtonId = R.string.readOnlyContactWarning_positive_button;
    } else if (writableCount == 1) {
        messageId = R.string.single_delete_confirmation;
        positiveButtonId = R.string.deleteConfirmation_positive_button;
    } else {
        messageId = R.string.batch_delete_confirmation;
        positiveButtonId = R.string.deleteConfirmation_positive_button;
    }
    // Convert set of contact ids into a format that is easily parcellable and iterated upon
    // for the sake of ContactSaveService.
    final Long[] contactIdObjectArray = contactIds.toArray(new Long[contactIds.size()]);
    final long[] contactIdArray = new long[contactIds.size()];
    for (int i = 0; i < contactIds.size(); i++) {
        contactIdArray[i] = contactIdObjectArray[i];
    }
    showDialog(messageId, positiveButtonId, contactIdArray);
    // We don't want onLoadFinished() calls any more, which may come when the database is
    // updating.
    getLoaderManager().destroyLoader(R.id.dialog_delete_multiple_contact_loader_id);
}
Also used : AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) 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