Search in sources :

Example 1 with Contact

use of com.android.contacts.common.model.Contact in project android_packages_apps_Dialer by MoKee.

the class IntentProvider method getAddContactIntentProvider.

/**
 * Retrieves an add contact intent for the given contact and phone call details.
 */
public static IntentProvider getAddContactIntentProvider(final Uri lookupUri, final CharSequence name, final CharSequence number, final int numberType, final boolean isNewContact) {
    return new IntentProvider() {

        @Override
        public Intent getIntent(Context context) {
            Contact contactToSave = null;
            if (lookupUri != null) {
                contactToSave = ContactLoader.parseEncodedContactEntity(lookupUri);
            }
            if (contactToSave != null) {
                // Populate the intent with contact information stored in the lookup URI.
                // Note: This code mirrors code in Contacts/QuickContactsActivity.
                final Intent intent;
                if (isNewContact) {
                    intent = IntentUtil.getNewContactIntent();
                } else {
                    intent = IntentUtil.getAddToExistingContactIntent();
                }
                ArrayList<ContentValues> values = contactToSave.getContentValues();
                // or better (e.g. structured name, nickname)
                if (contactToSave.getDisplayNameSource() >= ContactsContract.DisplayNameSources.NICKNAME) {
                    intent.putExtra(ContactsContract.Intents.Insert.NAME, contactToSave.getDisplayName());
                } else if (contactToSave.getDisplayNameSource() == ContactsContract.DisplayNameSources.ORGANIZATION) {
                    // This is probably an organization. Instead of copying the organization
                    // name into a name entry, copy it into the organization entry. This
                    // way we will still consider the contact an organization.
                    final ContentValues organization = new ContentValues();
                    organization.put(ContactsContract.CommonDataKinds.Organization.COMPANY, contactToSave.getDisplayName());
                    organization.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
                    values.add(organization);
                }
                // properly
                for (ContentValues value : values) {
                    value.remove(ContactsContract.Data.LAST_TIME_USED);
                    value.remove(ContactsContract.Data.TIMES_USED);
                }
                intent.putExtra(ContactsContract.Intents.Insert.DATA, values);
                return intent;
            } else {
                // If no lookup uri is provided, rely on the available phone number and name.
                if (isNewContact) {
                    return IntentUtil.getNewContactIntent(name, number, numberType);
                } else {
                    return IntentUtil.getAddToExistingContactIntent(name, number, numberType);
                }
            }
        }
    };
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) Intent(android.content.Intent) Contact(com.android.contacts.common.model.Contact)

Example 2 with Contact

use of com.android.contacts.common.model.Contact in project android_packages_apps_Dialer by MoKee.

the class CallerInfoUtils method sendViewNotification.

/**
 * Send a notification using a {@link ContactLoader} to inform the sync adapter that we are
 * viewing a particular contact, so that it can download the high-res photo.
 */
public static void sendViewNotification(Context context, Uri contactUri) {
    final ContactLoader loader = new ContactLoader(context, contactUri, true);
    loader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact contact) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                Log.e(TAG, "Error resetting loader", e);
            }
        }
    });
    loader.startLoading();
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Example 3 with Contact

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

the class ViewNotificationService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    if (DEBUG) {
        Log.d(TAG, "onHandleIntent(). Intent: " + intent);
    }
    // We simply need to start a Loader here. When its done, it will send out the
    // View-Notification automatically.
    final ContactLoader contactLoader = new ContactLoader(this, intent.getData(), true);
    contactLoader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact data) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                Log.e(TAG, "Error reseting loader", e);
            }
            try {
                // This is not 100% accurate actually. If we get several calls quickly,
                // we might be stopping out-of-order, in which case the call with the last
                // startId will stop this service. In practice, this shouldn't be a problem,
                // as this service is supposed to be called by the Phone app which only sends
                // out the notification once per phonecall. And even if there is a problem,
                // the worst that should happen is a missing view notification
                stopSelfResult(startId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Error stopping service", e);
            }
        }
    });
    contactLoader.startLoading();
    return START_REDELIVER_INTENT;
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Example 4 with Contact

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

the class AttachPhotoActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
    if (requestCode == REQUEST_PICK_DEFAULT_ACCOUNT_FOR_NEW_CONTACT) {
        // Bail if the account selector was not successful.
        if (resultCode != Activity.RESULT_OK) {
            Log.w(TAG, "account selector was not successful");
            finish();
            return;
        }
        // If there's an account specified, use it.
        if (result != null) {
            AccountWithDataSet account = result.getParcelableExtra(Intents.Insert.EXTRA_ACCOUNT);
            if (account != null) {
                createNewRawContact(account);
                return;
            }
        }
        // If there isn't an account specified, then the user opted to keep the contact local.
        createNewRawContact(null);
    } else if (requestCode == REQUEST_PICK_CONTACT) {
        if (resultCode != RESULT_OK) {
            finish();
            return;
        }
        // A contact was picked. Launch the cropper to get face detection, the right size, etc.
        // TODO: get these values from constants somewhere
        final Intent myIntent = getIntent();
        final Uri inputUri = myIntent.getData();
        // TODO: With b/10837468 fixed should be able to avoid this copy.
        if (!ContactPhotoUtils.savePhotoFromUriToUri(this, inputUri, mTempPhotoUri, false)) {
            finish();
            return;
        }
        final Intent intent = new Intent("com.android.camera.action.CROP", mTempPhotoUri);
        if (myIntent.getStringExtra("mimeType") != null) {
            intent.setDataAndType(mTempPhotoUri, myIntent.getStringExtra("mimeType"));
        }
        ContactPhotoUtils.addPhotoPickerExtras(intent, mCroppedPhotoUri);
        ContactPhotoUtils.addCropExtras(intent, mPhotoDim != 0 ? mPhotoDim : mDefaultPhotoDim);
        if (!hasIntentHandler(intent)) {
            // No activity supports the crop action. So skip cropping and set the photo
            // without performing any cropping.
            mCroppedPhotoUri = mTempPhotoUri;
            mContactUri = result.getData();
            loadContact(mContactUri, new Listener() {

                @Override
                public void onContactLoaded(Contact contact) {
                    saveContact(contact);
                }
            });
            return;
        }
        try {
            startActivityForResult(intent, REQUEST_CROP_PHOTO);
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(this, R.string.missing_app, Toast.LENGTH_SHORT).show();
            return;
        }
        mContactUri = result.getData();
    } else if (requestCode == REQUEST_CROP_PHOTO) {
        // Delete the temporary photo from cache now that we have a cropped version.
        // We should do this even if the crop failed and we eventually bail
        getContentResolver().delete(mTempPhotoUri, null, null);
        if (resultCode != RESULT_OK) {
            finish();
            return;
        }
        loadContact(mContactUri, new Listener() {

            @Override
            public void onContactLoaded(Contact contact) {
                saveContact(contact);
            }
        });
    }
}
Also used : OnLoadCompleteListener(android.content.Loader.OnLoadCompleteListener) ActivityNotFoundException(android.content.ActivityNotFoundException) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) Intent(android.content.Intent) Uri(android.net.Uri) Contact(com.android.contacts.common.model.Contact)

Example 5 with Contact

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

the class AttachPhotoActivity method loadContact.

// TODO: consider moving this to ContactLoader, especially if we keep adding similar
// code elsewhere (ViewNotificationService is another case).  The only concern is that,
// although this is convenient, it isn't quite as robust as using LoaderManager... for
// instance, the loader doesn't persist across Activity restarts.
private void loadContact(Uri contactUri, final Listener listener) {
    final ContactLoader loader = new ContactLoader(this, contactUri, true);
    loader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact contact) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                Log.e(TAG, "Error resetting loader", e);
            }
            listener.onContactLoaded(contact);
        }
    });
    loader.startLoading();
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Aggregations

Contact (com.android.contacts.common.model.Contact)7 ContactLoader (com.android.contacts.common.model.ContactLoader)4 Intent (android.content.Intent)3 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 OnLoadCompleteListener (android.content.Loader.OnLoadCompleteListener)1 Uri (android.net.Uri)1 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)1 DialerContact (com.android.dialer.dialercontact.DialerContact)1