Search in sources :

Example 1 with Crop

use of com.soundcloud.android.crop.Crop in project Signal-Android by WhisperSystems.

the class GroupCreateActivity method onActivityResult.

@Override
public void onActivityResult(int reqCode, int resultCode, final Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
    if (data == null || resultCode != Activity.RESULT_OK)
        return;
    switch(reqCode) {
        case PICK_CONTACT:
            List<String> selected = data.getStringArrayListExtra("contacts");
            for (String contact : selected) {
                final Recipient recipient = RecipientFactory.getRecipientsFromString(this, contact, false).getPrimaryRecipient();
                if (recipient != null)
                    addSelectedContacts(recipient);
            }
            break;
        case Crop.REQUEST_PICK:
            new Crop(data.getData()).output(outputFile).asSquare().start(this);
            break;
        case Crop.REQUEST_CROP:
            Glide.with(this).load(Crop.getOutput(data)).asBitmap().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(AVATAR_SIZE, AVATAR_SIZE).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    setAvatar(Crop.getOutput(data), resource);
                }
            });
    }
}
Also used : Crop(com.soundcloud.android.crop.Crop) Bitmap(android.graphics.Bitmap) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Uri(android.net.Uri) File(java.io.File)

Example 2 with Crop

use of com.soundcloud.android.crop.Crop in project Signal-Android by signalapp.

the class CreateProfileActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
        case REQUEST_CODE_AVATAR:
            if (resultCode == Activity.RESULT_OK) {
                Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
                Uri inputFile = (data != null ? data.getData() : null);
                if (inputFile == null && captureFile != null) {
                    inputFile = Uri.fromFile(captureFile);
                }
                if (data != null && data.getBooleanExtra("delete", false)) {
                    avatarBytes = null;
                    avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(this, getResources().getColor(R.color.grey_400)));
                } else {
                    new Crop(inputFile).output(outputFile).asSquare().start(this);
                }
            }
            break;
        case Crop.REQUEST_CROP:
            if (resultCode == Activity.RESULT_OK) {
                new AsyncTask<Void, Void, byte[]>() {

                    @Override
                    protected byte[] doInBackground(Void... params) {
                        try {
                            return BitmapUtil.createScaledBytes(CreateProfileActivity.this, Crop.getOutput(data), new ProfileMediaConstraints());
                        } catch (BitmapDecodingException e) {
                            Log.w(TAG, e);
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(byte[] result) {
                        if (result != null) {
                            avatarBytes = result;
                            GlideApp.with(CreateProfileActivity.this).load(avatarBytes).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).circleCrop().into(avatar);
                        } else {
                            Toast.makeText(CreateProfileActivity.this, R.string.CreateProfileActivity_error_setting_profile_photo, Toast.LENGTH_LONG).show();
                        }
                    }
                }.execute();
            }
            break;
    }
}
Also used : Crop(com.soundcloud.android.crop.Crop) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) ProfileMediaConstraints(org.thoughtcrime.securesms.profiles.ProfileMediaConstraints) Uri(android.net.Uri) File(java.io.File) BitmapDecodingException(org.thoughtcrime.securesms.util.BitmapDecodingException)

Example 3 with Crop

use of com.soundcloud.android.crop.Crop in project Signal-Android by signalapp.

the class GroupCreateActivity method onActivityResult.

@Override
public void onActivityResult(int reqCode, int resultCode, final Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
    if (data == null || resultCode != Activity.RESULT_OK)
        return;
    switch(reqCode) {
        case PICK_CONTACT:
            List<String> selected = data.getStringArrayListExtra("contacts");
            for (String contact : selected) {
                Address address = Address.fromExternal(this, contact);
                Recipient recipient = Recipient.from(this, address, false);
                addSelectedContacts(recipient);
            }
            break;
        case Crop.REQUEST_PICK:
            new Crop(data.getData()).output(outputFile).asSquare().start(this);
            break;
        case Crop.REQUEST_CROP:
            GlideApp.with(this).asBitmap().load(Crop.getOutput(data)).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(AVATAR_SIZE, AVATAR_SIZE).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
                    setAvatar(Crop.getOutput(data), resource);
                }
            });
    }
}
Also used : Crop(com.soundcloud.android.crop.Crop) Bitmap(android.graphics.Bitmap) Address(org.thoughtcrime.securesms.database.Address) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Uri(android.net.Uri) File(java.io.File)

Aggregations

Uri (android.net.Uri)3 Crop (com.soundcloud.android.crop.Crop)3 File (java.io.File)3 Bitmap (android.graphics.Bitmap)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 ResourceContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto)1 Address (org.thoughtcrime.securesms.database.Address)1 ProfileMediaConstraints (org.thoughtcrime.securesms.profiles.ProfileMediaConstraints)1 BitmapDecodingException (org.thoughtcrime.securesms.util.BitmapDecodingException)1