Search in sources :

Example 1 with RawContact

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

the class ContactEditorBaseFragment method setState.

// 
// Data binding
// 
private void setState(Contact contact) {
    // If we have already loaded data, we do not want to change it here to not confuse the user
    if (!mState.isEmpty()) {
        Log.v(TAG, "Ignoring background change. This will have to be rebased later");
        return;
    }
    // See if this edit operation needs to be redirected to a custom editor
    mRawContacts = contact.getRawContacts();
    if (mRawContacts.size() == 1) {
        RawContact rawContact = mRawContacts.get(0);
        String type = rawContact.getAccountTypeString();
        String dataSet = rawContact.getDataSet();
        AccountType accountType = rawContact.getAccountType(mContext);
        if (accountType.getEditContactActivityClassName() != null && !accountType.areContactsWritable()) {
            if (mListener != null) {
                String name = rawContact.getAccountName();
                long rawContactId = rawContact.getId();
                mListener.onCustomEditContactActivityRequested(new AccountWithDataSet(name, type, dataSet), ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), mIntentExtras, true);
            }
            return;
        }
    }
    String readOnlyDisplayName = null;
    // can edit.  For the user profile case, there is already an editable contact.
    if (!contact.isUserProfile() && !contact.isWritableContact(mContext)) {
        mHasNewContact = true;
        // This is potentially an asynchronous call and will add deltas to list.
        selectAccountAndCreateContact();
        readOnlyDisplayName = contact.getDisplayName();
    } else {
        mHasNewContact = false;
    }
    // This also adds deltas to list.  If readOnlyDisplayName is null at this point it is
    // simply ignored later on by the editor.
    setStateForExistingContact(readOnlyDisplayName, contact.isUserProfile(), mRawContacts);
}
Also used : RawContact(com.android.contacts.common.model.RawContact) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AccountType(com.android.contacts.common.model.account.AccountType) SimAccountType(com.android.contacts.common.model.account.SimAccountType)

Example 2 with RawContact

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

the class ContactEditorBaseFragment method createNewRawContactDelta.

/**
 * Returns a {@link RawContactDelta} for a new contact suitable for addition into
 * {@link #mState}.
 *
 * If oldState and oldAccountType are specified, the state specified by those parameters
 * is migrated to the result {@link RawContactDelta}.
 */
private RawContactDelta createNewRawContactDelta(AccountWithDataSet account, AccountType accountType, RawContactDelta oldState, AccountType oldAccountType) {
    final RawContact rawContact = new RawContact();
    if (account != null) {
        rawContact.setAccount(account);
    } else {
        rawContact.setAccountToLocal();
    }
    final RawContactDelta result = new RawContactDelta(ValuesDelta.fromAfter(rawContact.getValues()));
    if (oldState == null) {
        // Parse any values from incoming intent
        RawContactModifier.parseExtras(mContext, accountType, result, mIntentExtras);
    } else {
        RawContactModifier.migrateStateForNewContact(mContext, oldState, result, oldAccountType, accountType);
    }
    // Ensure we have some default fields (if the account type does not support a field,
    // ensureKind will not add it, so it is safe to add e.g. Event)
    RawContactModifier.ensureKindExists(result, accountType, Phone.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, Email.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, Organization.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, Event.CONTENT_ITEM_TYPE);
    RawContactModifier.ensureKindExists(result, accountType, StructuredPostal.CONTENT_ITEM_TYPE);
    // Set the correct URI for saving the contact as a profile
    if (mNewLocalProfile) {
        result.setProfileQueryUri();
    }
    return result;
}
Also used : RawContact(com.android.contacts.common.model.RawContact) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 3 with RawContact

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

the class QuickContactActivity method hasPhoneOrEmailDate.

private boolean hasPhoneOrEmailDate(Contact contact) {
    int phoneCount = 0;
    int emailCount = 0;
    ImmutableList<RawContact> rawContacts = contact.getRawContacts();
    for (RawContact rawContact : rawContacts) {
        RawContactDelta rawContactDelta = RawContactDelta.fromBefore(rawContact);
        phoneCount += rawContactDelta.getMimeEntriesCount(Phone.CONTENT_ITEM_TYPE, true);
        emailCount += rawContactDelta.getMimeEntriesCount(Email.CONTENT_ITEM_TYPE, true);
    }
    if (phoneCount > 0 || emailCount > 0) {
        return true;
    } else {
        return false;
    }
}
Also used : RawContact(com.android.contacts.common.model.RawContact) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 4 with RawContact

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

the class QuickContactActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mContactData != null) {
        final MenuItem starredMenuItem = menu.findItem(R.id.menu_star);
        ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, mContactData.isDirectoryEntry(), mContactData.isUserProfile(), mContactData.getStarred());
        if (!simOneLoadComplete) {
            simOneLoadComplete = (MoreContactUtils.getAdnCount(this, SimContactsConstants.SLOT1) > 0) ? true : false;
        }
        if (!simTwoLoadComplete) {
            simTwoLoadComplete = (MoreContactUtils.getAdnCount(this, SimContactsConstants.SLOT2) > 0) ? true : false;
        }
        // Configure edit MenuItem
        final MenuItem editMenuItem = menu.findItem(R.id.menu_edit);
        editMenuItem.setVisible(true);
        if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) {
            editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp);
            editMenuItem.setTitle(R.string.menu_add_contact);
        } else if (isContactEditable()) {
            editMenuItem.setIcon(R.drawable.ic_create_24dp);
            editMenuItem.setTitle(R.string.menu_editContact);
        } else {
            editMenuItem.setVisible(false);
        }
        final MenuItem refreshMenuItem = menu.findItem(R.id.menu_refresh);
        refreshMenuItem.setVisible(false);
        final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete);
        deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile());
        final MenuItem shareMenuItem = menu.findItem(R.id.menu_share);
        shareMenuItem.setVisible(isContactShareable());
        final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut);
        shortcutMenuItem.setVisible(isShortcutCreatable());
        final MenuItem helpMenu = menu.findItem(R.id.menu_help);
        helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable());
        String accoutName = null;
        String accoutType = null;
        final RawContact rawContact = mContactData.getRawContacts().get(0);
        accoutName = rawContact.getAccountName();
        accoutType = rawContact.getAccountTypeString();
        final MenuItem copyToPhoneMenu = menu.findItem(R.id.menu_copy_to_phone);
        if (copyToPhoneMenu != null) {
            copyToPhoneMenu.setVisible(false);
        }
        final MenuItem copyToSim1Menu = menu.findItem(R.id.menu_copy_to_sim1);
        if (copyToSim1Menu != null) {
            copyToSim1Menu.setVisible(false);
        }
        final MenuItem copyToSim2Menu = menu.findItem(R.id.menu_copy_to_sim2);
        if (copyToSim2Menu != null) {
            copyToSim2Menu.setVisible(false);
        }
        if (!TextUtils.isEmpty(accoutType)) {
            if (SimContactsConstants.ACCOUNT_TYPE_SIM.equals(accoutType)) {
                copyToPhoneMenu.setVisible(true);
                copyToPhoneMenu.setTitle(getString(R.string.menu_copyTo, getString(R.string.phoneLabelsGroup)));
                if (tm.getPhoneCount() > 1) {
                    if (SimContactsConstants.SIM_NAME_1.equals(accoutName) && simTwoLoadComplete) {
                        copyToSim2Menu.setTitle(getString(R.string.menu_copyTo, MoreContactUtils.getAcount(QuickContactActivity.this, SimContactsConstants.SLOT2).name));
                        String customLabel = MoreContactUtils.getCustomOperatorLabel(getApplicationContext(), SimContactsConstants.SLOT2);
                        if (!TextUtils.isEmpty(customLabel)) {
                            copyToSim2Menu.setTitle(getString(R.string.menu_copyTo, customLabel));
                        }
                        copyToSim2Menu.setVisible(true);
                    }
                    if (SimContactsConstants.SIM_NAME_2.equals(accoutName) && simOneLoadComplete) {
                        copyToSim1Menu.setTitle(getString(R.string.menu_copyTo, MoreContactUtils.getAcount(QuickContactActivity.this, SimContactsConstants.SLOT1).name));
                        String customLabel = MoreContactUtils.getCustomOperatorLabel(getApplicationContext(), SimContactsConstants.SLOT1);
                        if (!TextUtils.isEmpty(customLabel)) {
                            copyToSim1Menu.setTitle(getString(R.string.menu_copyTo, customLabel));
                        }
                        copyToSim1Menu.setVisible(true);
                    }
                }
            } else if (SimContactsConstants.ACCOUNT_TYPE_PHONE.equals(accoutType)) {
                copyToPhoneMenu.setVisible(false);
                boolean hasPhoneOrEmail = hasPhoneOrEmailDate(mContactData);
                if (tm.getPhoneCount() > 1) {
                    if (hasPhoneOrEmail && simOneLoadComplete) {
                        copyToSim1Menu.setTitle(getString(R.string.menu_copyTo, MoreContactUtils.getAcount(this, SimContactsConstants.SLOT1).name));
                        String customLabel = MoreContactUtils.getCustomOperatorLabel(getApplicationContext(), SimContactsConstants.SLOT1);
                        if (!TextUtils.isEmpty(customLabel)) {
                            copyToSim1Menu.setTitle(getString(R.string.menu_copyTo, customLabel));
                        }
                        copyToSim1Menu.setVisible(true);
                    }
                    if (hasPhoneOrEmail && simTwoLoadComplete) {
                        copyToSim2Menu.setTitle(getString(R.string.menu_copyTo, MoreContactUtils.getAcount(this, SimContactsConstants.SLOT2).name));
                        String customLabel = MoreContactUtils.getCustomOperatorLabel(getApplicationContext(), SimContactsConstants.SLOT2);
                        if (!TextUtils.isEmpty(customLabel)) {
                            copyToSim2Menu.setTitle(getString(R.string.menu_copyTo, customLabel));
                        }
                        copyToSim2Menu.setVisible(true);
                    }
                } else {
                    if (hasPhoneOrEmail && simOneLoadComplete) {
                        copyToSim1Menu.setTitle(getString(R.string.menu_copyTo, SimContactsConstants.SIM_NAME));
                        copyToSim1Menu.setVisible(true);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : RawContact(com.android.contacts.common.model.RawContact) MenuItem(android.view.MenuItem) SpannableString(android.text.SpannableString)

Example 5 with RawContact

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

the class QuickContactActivity method copyToPhone.

private void copyToPhone() {
    String name = mContactData.getDisplayName();
    if (TextUtils.isEmpty(name)) {
        name = "";
    }
    String phoneNumber = "";
    StringBuilder anrNumber = new StringBuilder();
    StringBuilder email = new StringBuilder();
    // get phonenumber,email,anr from SIM contacts,then insert them to phone
    for (RawContact rawContact : mContactData.getRawContacts()) {
        for (DataItem dataItem : rawContact.getDataItems()) {
            if (dataItem.getMimeType() == null) {
                continue;
            }
            if (dataItem instanceof PhoneDataItem) {
                PhoneDataItem phoneNum = (PhoneDataItem) dataItem;
                final String number = phoneNum.getNumber();
                if (!TextUtils.isEmpty(number)) {
                    if (Phone.TYPE_MOBILE == phoneNum.getContentValues().getAsInteger(Phone.TYPE)) {
                        phoneNumber = number;
                    } else {
                        if (!TextUtils.isEmpty(anrNumber.toString())) {
                            anrNumber.append(",");
                        }
                        anrNumber.append(number);
                    }
                }
            } else if (dataItem instanceof EmailDataItem) {
                EmailDataItem emailData = (EmailDataItem) dataItem;
                final String address = emailData.getData();
                if (!TextUtils.isEmpty(address)) {
                    if (!TextUtils.isEmpty(email.toString())) {
                        email.append(",");
                    }
                    email.append(address);
                }
            }
        }
    }
    String[] value = new String[] { name, phoneNumber, email.toString(), anrNumber.toString() };
    boolean success = MoreContactUtils.insertToPhone(value, QuickContactActivity.this, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
    Toast.makeText(this, success ? R.string.copy_done : R.string.copy_failure, Toast.LENGTH_SHORT).show();
}
Also used : PhoneDataItem(com.android.contacts.common.model.dataitem.PhoneDataItem) EventDataItem(com.android.contacts.common.model.dataitem.EventDataItem) OrganizationDataItem(com.android.contacts.common.model.dataitem.OrganizationDataItem) RelationDataItem(com.android.contacts.common.model.dataitem.RelationDataItem) StructuredNameDataItem(com.android.contacts.common.model.dataitem.StructuredNameDataItem) NoteDataItem(com.android.contacts.common.model.dataitem.NoteDataItem) DataItem(com.android.contacts.common.model.dataitem.DataItem) SipAddressDataItem(com.android.contacts.common.model.dataitem.SipAddressDataItem) EmailDataItem(com.android.contacts.common.model.dataitem.EmailDataItem) NicknameDataItem(com.android.contacts.common.model.dataitem.NicknameDataItem) StructuredPostalDataItem(com.android.contacts.common.model.dataitem.StructuredPostalDataItem) WebsiteDataItem(com.android.contacts.common.model.dataitem.WebsiteDataItem) GroupMembershipDataItem(com.android.contacts.common.model.dataitem.GroupMembershipDataItem) ImDataItem(com.android.contacts.common.model.dataitem.ImDataItem) PhoneDataItem(com.android.contacts.common.model.dataitem.PhoneDataItem) RawContact(com.android.contacts.common.model.RawContact) SpannableString(android.text.SpannableString) EmailDataItem(com.android.contacts.common.model.dataitem.EmailDataItem)

Aggregations

RawContact (com.android.contacts.common.model.RawContact)13 DataItem (com.android.contacts.common.model.dataitem.DataItem)5 SpannableString (android.text.SpannableString)4 RawContactDelta (com.android.contacts.common.model.RawContactDelta)4 AccountType (com.android.contacts.common.model.account.AccountType)4 GroupMembershipDataItem (com.android.contacts.common.model.dataitem.GroupMembershipDataItem)4 OrganizationDataItem (com.android.contacts.common.model.dataitem.OrganizationDataItem)4 EmailDataItem (com.android.contacts.common.model.dataitem.EmailDataItem)3 EventDataItem (com.android.contacts.common.model.dataitem.EventDataItem)3 ImDataItem (com.android.contacts.common.model.dataitem.ImDataItem)3 NicknameDataItem (com.android.contacts.common.model.dataitem.NicknameDataItem)3 NoteDataItem (com.android.contacts.common.model.dataitem.NoteDataItem)3 PhoneDataItem (com.android.contacts.common.model.dataitem.PhoneDataItem)3 RelationDataItem (com.android.contacts.common.model.dataitem.RelationDataItem)3 SipAddressDataItem (com.android.contacts.common.model.dataitem.SipAddressDataItem)3 StructuredNameDataItem (com.android.contacts.common.model.dataitem.StructuredNameDataItem)3 StructuredPostalDataItem (com.android.contacts.common.model.dataitem.StructuredPostalDataItem)3 WebsiteDataItem (com.android.contacts.common.model.dataitem.WebsiteDataItem)3 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)2 ArrayList (java.util.ArrayList)2