avoid bundled source selection that comes with ImageCropper on Android 10
This commit is contained in:
parent
7b5d0e034e
commit
b2e9a954ab
|
@ -49,6 +49,8 @@ import eu.siacs.conversations.entities.Conversation;
|
|||
import eu.siacs.conversations.ui.interfaces.OnAvatarPublication;
|
||||
import eu.siacs.conversations.ui.util.PendingItem;
|
||||
|
||||
import static eu.siacs.conversations.ui.PublishProfilePictureActivity.REQUEST_CHOOSE_PICTURE;
|
||||
|
||||
public class PublishGroupChatProfilePictureActivity extends XmppActivity implements OnAvatarPublication {
|
||||
private final PendingItem<String> pendingConversationUuid = new PendingItem<>();
|
||||
private ActivityPublishProfilePictureBinding binding;
|
||||
|
@ -93,7 +95,7 @@ public class PublishGroupChatProfilePictureActivity extends XmppActivity impleme
|
|||
configureActionBar(getSupportActionBar());
|
||||
this.binding.cancelButton.setOnClickListener((v) -> this.finish());
|
||||
this.binding.secondaryHint.setVisibility(View.GONE);
|
||||
this.binding.accountImage.setOnClickListener((v) -> this.chooseAvatar());
|
||||
this.binding.accountImage.setOnClickListener((v) -> PublishProfilePictureActivity.chooseAvatar(this));
|
||||
Intent intent = getIntent();
|
||||
String uuid = intent == null ? null : intent.getStringExtra("uuid");
|
||||
if (uuid != null) {
|
||||
|
@ -113,7 +115,7 @@ public class PublishGroupChatProfilePictureActivity extends XmppActivity impleme
|
|||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
|
||||
CropImage.ActivityResult result = CropImage.getActivityResult(data);
|
||||
final CropImage.ActivityResult result = CropImage.getActivityResult(data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
this.uri = result.getUri();
|
||||
if (xmppConnectionServiceBound) {
|
||||
|
@ -125,15 +127,11 @@ public class PublishGroupChatProfilePictureActivity extends XmppActivity impleme
|
|||
Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
} else if (requestCode == REQUEST_CHOOSE_PICTURE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
PublishProfilePictureActivity.cropUri(this, data.getData());
|
||||
}
|
||||
}
|
||||
|
||||
private void chooseAvatar() {
|
||||
CropImage.activity()
|
||||
.setOutputCompressFormat(Bitmap.CompressFormat.PNG)
|
||||
.setAspectRatio(1, 1)
|
||||
.setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE)
|
||||
.start(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.util.Log;
|
||||
|
@ -26,6 +28,8 @@ import eu.siacs.conversations.utils.PhoneHelper;
|
|||
|
||||
public class PublishProfilePictureActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate, OnAvatarPublication {
|
||||
|
||||
public static final int REQUEST_CHOOSE_PICTURE = 0x1337;
|
||||
|
||||
private ImageView avatar;
|
||||
private TextView hintOrWarning;
|
||||
private TextView secondaryHint;
|
||||
|
@ -106,7 +110,7 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
}
|
||||
finish();
|
||||
});
|
||||
this.avatar.setOnClickListener(v -> chooseAvatar());
|
||||
this.avatar.setOnClickListener(v -> chooseAvatar(this));
|
||||
this.defaultUri = PhoneHelper.getProfilePictureUri(getApplicationContext());
|
||||
if (savedInstanceState != null) {
|
||||
this.avatarUri = savedInstanceState.getParcelable("uri");
|
||||
|
@ -139,15 +143,28 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
} else if (requestCode == REQUEST_CHOOSE_PICTURE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
cropUri(this, data.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chooseAvatar() {
|
||||
public static void chooseAvatar(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("image/*");
|
||||
activity.startActivityForResult(
|
||||
Intent.createChooser(intent, activity.getString(R.string.attach_choose_picture)),
|
||||
REQUEST_CHOOSE_PICTURE
|
||||
);
|
||||
} else {
|
||||
CropImage.activity()
|
||||
.setOutputCompressFormat(Bitmap.CompressFormat.PNG)
|
||||
.setAspectRatio(1, 1)
|
||||
.setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE)
|
||||
.start(this);
|
||||
.start(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,10 +198,7 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
final Uri uri = intent != null ? intent.getData() : null;
|
||||
|
||||
if (uri != null && handledExternalUri.compareAndSet(false,true)) {
|
||||
CropImage.activity(uri).setOutputCompressFormat(Bitmap.CompressFormat.PNG)
|
||||
.setAspectRatio(1, 1)
|
||||
.setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE)
|
||||
.start(this);
|
||||
cropUri(this, uri);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -194,6 +208,13 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
configureActionBar(getSupportActionBar(), !this.mInitialAccountSetup && !handledExternalUri.get());
|
||||
}
|
||||
|
||||
public static void cropUri(final Activity activity, final Uri uri) {
|
||||
CropImage.activity(uri).setOutputCompressFormat(Bitmap.CompressFormat.PNG)
|
||||
.setAspectRatio(1, 1)
|
||||
.setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE)
|
||||
.start(activity);
|
||||
}
|
||||
|
||||
protected void loadImageIntoPreview(Uri uri) {
|
||||
|
||||
Bitmap bm = null;
|
||||
|
|
Loading…
Reference in New Issue