mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
use image editor for avatar selection when possible
also update old android-crop dependency
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ dependencies {
|
||||
annotationProcessor 'androidx.annotation:annotation:1.5.0'
|
||||
implementation 'com.makeramen:roundedimageview:2.1.0' // crops the avatars to circles
|
||||
implementation 'com.pnikosis:materialish-progress:1.5' // used only in the "Progress Wheel" in Share Activity.
|
||||
implementation 'com.soundcloud.android:android-crop:0.9.10@aar' // used in Group Select Avatar, should be unified with profile
|
||||
implementation 'com.soundcloud.android:android-crop:1.0.1@aar' // used for profile and group avatar selection in Android SDK<19
|
||||
implementation 'com.nineoldandroids:library:2.4.0' // DEPRECATED! Used to slide in the half-camera.
|
||||
implementation 'mobi.upod:time-duration-picker:1.1.3' // Used to pick the time for inactivity.
|
||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' // number of unread messages,
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
@@ -164,24 +165,27 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (resultCode != Activity.RESULT_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_AVATAR:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Uri inputFile = (data != null ? data.getData() : null);
|
||||
onFileSelected(inputFile);
|
||||
}
|
||||
Uri inputFile = (data != null ? data.getData() : null);
|
||||
onFileSelected(inputFile);
|
||||
break;
|
||||
|
||||
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
|
||||
setAvatarView(data.getData());
|
||||
break;
|
||||
|
||||
case Crop.REQUEST_CROP:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
setAvatarView(data);
|
||||
}
|
||||
setAvatarView(Crop.getOutput(data));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setAvatarView(Intent data) {
|
||||
final Uri output = Crop.getOutput(data);
|
||||
private void setAvatarView(Uri output) {
|
||||
final ProfileMediaConstraints constraints = new ProfileMediaConstraints();
|
||||
GlideApp.with(this)
|
||||
.asBitmap()
|
||||
@@ -207,12 +211,11 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
}
|
||||
|
||||
private void onFileSelected(Uri inputFile) {
|
||||
Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
|
||||
if (inputFile == null) {
|
||||
inputFile = attachmentManager.getImageCaptureUri();
|
||||
}
|
||||
|
||||
new Crop(inputFile).output(outputFile).asSquare().start(this);
|
||||
AvatarHelper.cropAvatar(this, inputFile);
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.qr.QrShowActivity;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.SelectedRecipientsAdapter;
|
||||
@@ -465,15 +466,20 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
break;
|
||||
|
||||
case Crop.REQUEST_PICK:
|
||||
new Crop(data.getData()).output(outputFile).asSquare().start(this);
|
||||
Crop.of(data.getData(), outputFile).asSquare().start(this);
|
||||
break;
|
||||
|
||||
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
|
||||
setAvatarView(data.getData());
|
||||
break;
|
||||
|
||||
case Crop.REQUEST_CROP:
|
||||
setAvatarView(data);
|
||||
setAvatarView(Crop.getOutput(data));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setAvatarView(Intent data) {
|
||||
final Uri output = Crop.getOutput(data);
|
||||
private void setAvatarView(Uri output) {
|
||||
GlideApp.with(this)
|
||||
.asBitmap()
|
||||
.load(output)
|
||||
@@ -611,11 +617,10 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void onFileSelected(Uri inputFile) {
|
||||
Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
|
||||
if (inputFile == null) {
|
||||
inputFile = attachmentManager.getImageCaptureUri();
|
||||
}
|
||||
|
||||
new Crop(inputFile).output(outputFile).asSquare().start(this);
|
||||
AvatarHelper.cropAvatar(this, inputFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package org.thoughtcrime.securesms.profiles;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.soundcloud.android.crop.Crop;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -55,4 +61,17 @@ public class AvatarHelper {
|
||||
avatar.delete(); // ..., now we can delete it.
|
||||
}
|
||||
}
|
||||
|
||||
public static void cropAvatar(Activity context, Uri imageUri) {
|
||||
if (Build.VERSION.SDK_INT >= 19) { // Image editor requires Android 4.4 KitKat or newer.
|
||||
Intent intent = new Intent(context, ScribbleActivity.class);
|
||||
intent.setData(imageUri);
|
||||
intent.putExtra(ScribbleActivity.CROP_AVATAR, true);
|
||||
context.startActivityForResult(intent, ScribbleActivity.SCRIBBLE_REQUEST_CODE);
|
||||
} else {
|
||||
Uri outputFile = Uri.fromFile(new File(context.getCacheDir(), "cropped"));
|
||||
Crop.of(imageUri, outputFile).asSquare().start(context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
@@ -79,12 +82,14 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
private Uri imageUri;
|
||||
private ImageEditorHud imageEditorHud;
|
||||
private ImageEditorView imageEditorView;
|
||||
private boolean cropAvatar;
|
||||
|
||||
public static ImageEditorFragment newInstance(@NonNull Uri imageUri) {
|
||||
public static ImageEditorFragment newInstance(@NonNull Uri imageUri, boolean cropAvatar) {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(KEY_IMAGE_URI, imageUri);
|
||||
|
||||
ImageEditorFragment fragment = new ImageEditorFragment();
|
||||
fragment.cropAvatar = cropAvatar;
|
||||
fragment.setArguments(args);
|
||||
fragment.setUri(imageUri);
|
||||
return fragment;
|
||||
@@ -133,7 +138,7 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
}
|
||||
|
||||
if (editorModel == null) {
|
||||
editorModel = new EditorModel();
|
||||
editorModel = cropAvatar? EditorModel.createForCircleEditing() : new EditorModel();
|
||||
EditorElement image = new EditorElement(new UriGlideRenderer(imageUri, true, imageMaxWidth, imageMaxHeight));
|
||||
image.getFlags().setSelectable(false).persist();
|
||||
editorModel.addElement(image);
|
||||
@@ -142,6 +147,9 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
imageEditorView.setModel(editorModel);
|
||||
|
||||
refreshUniqueColors();
|
||||
if (cropAvatar) {
|
||||
imageEditorHud.setMode(ImageEditorHud.Mode.CROP);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -257,7 +265,23 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
baos = null;
|
||||
bitmap = null;
|
||||
|
||||
Uri uri = provider.create(activity, data, MediaUtil.IMAGE_JPEG, null);
|
||||
Uri uri = null;
|
||||
if (cropAvatar) {
|
||||
File file = new File(activity.getCacheDir(), "cropped");
|
||||
try {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
stream.write(data);
|
||||
stream.flush();
|
||||
stream.close();
|
||||
uri = Uri.fromFile(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
uri = provider.create(activity, data, MediaUtil.IMAGE_JPEG, null);
|
||||
}
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setData(uri);
|
||||
activity.setResult(RESULT_OK, intent);
|
||||
|
||||
@@ -7,12 +7,14 @@ import org.thoughtcrime.securesms.R;
|
||||
|
||||
public class ScribbleActivity extends PassphraseRequiredActionBarActivity {
|
||||
public static final int SCRIBBLE_REQUEST_CODE = 31424;
|
||||
public static final String CROP_AVATAR = "crop_avatar";
|
||||
ImageEditorFragment imageEditorFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState, boolean ready) {
|
||||
setContentView(R.layout.scribble_activity);
|
||||
imageEditorFragment = initFragment(R.id.scribble_container, ImageEditorFragment.newInstance(getIntent().getData()));
|
||||
boolean cropAvatar = getIntent().getBooleanExtra(CROP_AVATAR, false);
|
||||
imageEditorFragment = initFragment(R.id.scribble_container, ImageEditorFragment.newInstance(getIntent().getData(), cropAvatar));
|
||||
}
|
||||
|
||||
/* @Override
|
||||
|
||||
Reference in New Issue
Block a user