FileDocCategorySizeDatePackage
AttachImage.javaAPI DocAndroid 1.5 API3818Wed May 06 22:42:44 BST 2009com.android.contacts

AttachImage

public class AttachImage extends android.app.Activity
Provides an external interface for other applications to attach images to contacts. It will first present a contact picker and then run the image that is handed to it through the cropper to make the image the proper size and give the user a chance to use the face detector.

Fields Summary
private static final int
REQUEST_PICK_CONTACT
private static final int
REQUEST_CROP_PHOTO
private static final String
CONTACT_URI_KEY
android.net.Uri
mContactUri
Constructors Summary
public AttachImage()


      

    
Methods Summary
protected voidonActivityResult(int requestCode, int resultCode, android.content.Intent result)

        if (resultCode != RESULT_OK) {
            finish();
            return;
        }

        if (requestCode == REQUEST_PICK_CONTACT) {
            mContactUri = result.getData();
            // A contact was picked. Launch the cropper to get face detection, the right size, etc.
            // TODO: get these values from constants somewhere
            Intent myIntent = getIntent();
            Intent intent = new Intent("com.android.camera.action.CROP", myIntent.getData());
            if (myIntent.getStringExtra("mimeType") != null) {
                intent.setDataAndType(myIntent.getData(), myIntent.getStringExtra("mimeType"));
            }
            intent.putExtra("crop", "true");
            intent.putExtra("aspectX", 1);
            intent.putExtra("aspectY", 1);
            intent.putExtra("outputX", 96);
            intent.putExtra("outputY", 96);
            intent.putExtra("return-data", true);
            startActivityForResult(intent, REQUEST_CROP_PHOTO);
        } else if (requestCode == REQUEST_CROP_PHOTO) {
            final Bundle extras = result.getExtras();
            if (extras != null) {
                Bitmap photo = extras.getParcelable("data");
                if (photo != null) {
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);
                    Contacts.People.setPhotoData(getContentResolver(), mContactUri,
                            stream.toByteArray());
                }
            }
            finish();
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        if (icicle != null) {
            mContactUri = icicle.getParcelable(CONTACT_URI_KEY);
        } else {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType(People.CONTENT_ITEM_TYPE);
            startActivityForResult(intent, REQUEST_PICK_CONTACT);
        }
    
protected voidonSaveInstanceState(android.os.Bundle outState)

        super.onSaveInstanceState(outState);

        if (mContactUri != null) {
            outState.putParcelable(CONTACT_URI_KEY, mContactUri);
        }