Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5234be96 authored by Brian Attwell's avatar Brian Attwell
Browse files

Allow setting photos in managed profile

Bug: 20628786
Change-Id: I42bc27574d40b7725e64743961c250a5682f66f7
parent 0f4582f3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -275,6 +275,9 @@
    <!-- Toast displayed when saving a contact failed. [CHAR LIMIT=NONE] -->
    <string name="contactSavedErrorToast">Couldn\'t save contact changes.</string>

    <!-- Toast displayed when saving a contact photo failed. [CHAR LIMIT=NONE] -->
    <string name="contactPhotoSavedErrorToast">Couldn\'t save contact photo changes.</string>

    <!-- Toast displayed when a group is saved [CHAR LIMIT=NONE] -->
    <string name="groupSavedToast">Group saved.</string>

+25 −4
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.ContentValues;
import android.content.Intent;
import android.content.Loader;
import android.content.Loader.OnLoadCompleteListener;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
@@ -52,6 +54,7 @@ import com.android.contacts.editor.ContactEditorUtils;
import com.android.contacts.util.ContactPhotoUtils;

import java.io.FileNotFoundException;
import java.util.List;

/**
 * Provides an external interface for other applications to attach images
@@ -167,7 +170,7 @@ public class AttachPhotoActivity extends ContactsActivity {
            final Intent myIntent = getIntent();
            final Uri inputUri = myIntent.getData();

            final Uri toCrop;

            // Save the URI into a temporary file provider URI so that
            // we can add the FLAG_GRANT_WRITE_URI_PERMISSION flag to the eventual
            // crop intent for read-only URI's.
@@ -176,14 +179,26 @@ public class AttachPhotoActivity extends ContactsActivity {
                finish();
                return;
            }
            toCrop = mTempPhotoUri;

            final Intent intent = new Intent("com.android.camera.action.CROP", toCrop);
            final Intent intent = new Intent("com.android.camera.action.CROP", mTempPhotoUri);
            if (myIntent.getStringExtra("mimeType") != null) {
                intent.setDataAndType(toCrop, myIntent.getStringExtra("mimeType"));
                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);
@@ -211,6 +226,12 @@ public class AttachPhotoActivity extends ContactsActivity {
        }
    }

    private boolean hasIntentHandler(Intent intent) {
        final List<ResolveInfo> resolveInfo = getPackageManager()
                .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return resolveInfo != null && resolveInfo.size() > 0;
    }

    // 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
+20 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.content.ActivityNotFoundException;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Photo;
@@ -46,6 +48,7 @@ import com.android.contacts.util.ContactPhotoUtils;
import com.android.contacts.util.UiClosables;

import java.io.FileNotFoundException;
import java.util.List;

/**
 * Handles displaying a photo selection popup for a given photo view and dealing with the results
@@ -237,9 +240,19 @@ public abstract class PhotoSelectionHandler implements OnClickListener {
     * Sends a newly acquired photo to Gallery for cropping
     */
    private void doCropPhoto(Uri inputUri, Uri outputUri) {
        final Intent intent = getCropImageIntent(inputUri, outputUri);
        if (!hasIntentHandler(intent)) {
            try {
                getListener().onPhotoSelected(inputUri);
            } catch (FileNotFoundException e) {
                Log.e(TAG, "Cannot save uncropped photo", e);
                Toast.makeText(mContext, R.string.contactPhotoSavedErrorToast,
                        Toast.LENGTH_LONG).show();
            }
            return;
        }
        try {
            // Launch gallery to crop the photo
            final Intent intent = getCropImageIntent(inputUri, outputUri);
            startPhotoActivity(intent, REQUEST_CROP_PHOTO, inputUri);
        } catch (Exception e) {
            Log.e(TAG, "Cannot crop image", e);
@@ -308,6 +321,12 @@ public abstract class PhotoSelectionHandler implements OnClickListener {
        return intent;
    }

    private boolean hasIntentHandler(Intent intent) {
        final List<ResolveInfo> resolveInfo = mContext.getPackageManager()
                .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return resolveInfo != null && resolveInfo.size() > 0;
    }

    /**
     * Constructs an intent for image cropping.
     */