Search in sources :

Example 26 with AccountType

use of com.android.contacts.common.model.account.AccountType 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 27 with AccountType

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

the class GroupBrowseListAdapter method bindHeaderView.

private void bindHeaderView(GroupListItem entry, GroupListItemViewCache viewCache) {
    AccountType accountType = mAccountTypeManager.getAccountType(entry.getAccountType(), entry.getDataSet());
    viewCache.accountType.setText(accountType.getDisplayLabel(mContext));
    viewCache.accountName.setText(entry.getAccountName());
}
Also used : AccountType(com.android.contacts.common.model.account.AccountType)

Example 28 with AccountType

use of com.android.contacts.common.model.account.AccountType 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 29 with AccountType

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

the class GroupEditorFragment method setupEditorForAccount.

/**
 * Sets up the editor based on the group's account name and type.
 */
private void setupEditorForAccount() {
    final AccountType accountType = getAccountType();
    final boolean editable = isGroupMembershipEditable();
    boolean isNewEditor = false;
    mMemberListAdapter.setIsGroupMembershipEditable(editable);
    // Since this method can be called multiple time, remove old editor if the editor type
    // is different from the new one and mark the editor with a tag so it can be found for
    // removal if needed
    View editorView;
    int newGroupEditorId = editable ? R.layout.group_editor_view : R.layout.external_group_editor_view;
    if (newGroupEditorId != mLastGroupEditorId) {
        View oldEditorView = mRootView.findViewWithTag(CURRENT_EDITOR_TAG);
        if (oldEditorView != null) {
            mRootView.removeView(oldEditorView);
        }
        editorView = mLayoutInflater.inflate(newGroupEditorId, mRootView, false);
        editorView.setTag(CURRENT_EDITOR_TAG);
        mAutoCompleteAdapter = null;
        mLastGroupEditorId = newGroupEditorId;
        isNewEditor = true;
    } else {
        editorView = mRootView.findViewWithTag(CURRENT_EDITOR_TAG);
        if (editorView == null) {
            throw new IllegalStateException("Group editor view not found");
        }
    }
    mGroupNameView = (TextView) editorView.findViewById(R.id.group_name);
    mAutoCompleteTextView = (AutoCompleteTextView) editorView.findViewById(R.id.add_member_field);
    mAddGroupMemberView = (ImageView) editorView.findViewById(R.id.addGroupMember);
    mListView = (ListView) editorView.findViewById(android.R.id.list);
    mListView.setAdapter(mMemberListAdapter);
    // Setup the account header, only when exists.
    if (editorView.findViewById(R.id.account_header) != null) {
        CharSequence accountTypeDisplayLabel = accountType.getDisplayLabel(mContext);
        ImageView accountIcon = (ImageView) editorView.findViewById(R.id.account_icon);
        TextView accountTypeTextView = (TextView) editorView.findViewById(R.id.account_type);
        TextView accountNameTextView = (TextView) editorView.findViewById(R.id.account_name);
        if (!TextUtils.isEmpty(mAccountName)) {
            accountNameTextView.setText(mContext.getString(R.string.from_account_format, mAccountName));
        }
        accountTypeTextView.setText(accountTypeDisplayLabel);
        accountIcon.setImageDrawable(accountType.getDisplayIcon(mContext));
    }
    // autocomplete text view.
    if (mAutoCompleteTextView != null) {
        mAutoCompleteAdapter = new SuggestedMemberListAdapter(mContext, android.R.layout.simple_dropdown_item_1line);
        mAutoCompleteTextView.setThreshold(2);
        mAutoCompleteAdapter.setContentResolver(mContentResolver);
        mAutoCompleteAdapter.setAccountType(mAccountType);
        mAutoCompleteAdapter.setAccountName(mAccountName);
        mAutoCompleteAdapter.setDataSet(mDataSet);
        mAutoCompleteTextView.setAdapter(mAutoCompleteAdapter);
        mAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SuggestedMember member = (SuggestedMember) view.getTag();
                if (member == null) {
                    // just in case
                    return;
                }
                loadMemberToAddToGroup(member.getRawContactId(), String.valueOf(member.getContactId()));
                // Update the autocomplete adapter so the contact doesn't get suggested again
                mAutoCompleteAdapter.addNewMember(member.getContactId());
                // Clear out the text field
                mAutoCompleteTextView.setText("");
            }
        });
        // Update the exempt list.  (mListToDisplay might have been restored from the saved
        // state.)
        mAutoCompleteAdapter.updateExistingMembersList(mListToDisplay);
    }
    if (mAddGroupMemberView != null) {
        mAddGroupMemberView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SimContactsConstants.ACTION_MULTI_PICK);
                intent.setType(Contacts.CONTENT_TYPE);
                intent.putExtra(SimContactsConstants.IS_CONTACT, true);
                intent.putExtra(SimContactsConstants.ACCOUNT_NAME, mAccountName);
                intent.putExtra(SimContactsConstants.ACCOUNT_TYPE, mAccountType);
                intent.putExtra(MultiPickContactActivity.ADD_MOVE_GROUP_MEMBER_KEY, MultiPickContactActivity.ACTION_ADD_GROUP_MEMBER);
                intent.putExtra(MultiPickContactActivity.KEY_GROUP_ID, mGroupId);
                startActivityForResult(intent, REQUEST_CODE_PICK_GROUP_MEM);
            }
        });
    }
    // If the group name is ready only, don't let the user focus on the field.
    mGroupNameView.setFocusable(!mGroupNameIsReadOnly);
    if (mGroupNameIsReadOnly)
        mGroupNameView.setInputType(InputType.TYPE_NULL);
    if (isNewEditor) {
        mRootView.addView(editorView);
    }
    mStatus = Status.EDITING;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SuggestedMember(com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember) Intent(android.content.Intent) AccountType(com.android.contacts.common.model.account.AccountType) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) ImageView(android.widget.ImageView)

Example 30 with AccountType

use of com.android.contacts.common.model.account.AccountType 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)

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