avoid bundled source selection that comes with ImageCropper on Android 10
This commit is contained in:
parent
d729a11d26
commit
e64a7c7a45
2 changed files with 40 additions and 21 deletions
|
@ -51,6 +51,8 @@ import de.pixart.messenger.ui.interfaces.OnAvatarPublication;
|
|||
import de.pixart.messenger.ui.util.PendingItem;
|
||||
import me.drakeet.support.toast.ToastCompat;
|
||||
|
||||
import static de.pixart.messenger.ui.PublishProfilePictureActivity.REQUEST_CHOOSE_PICTURE;
|
||||
|
||||
public class PublishGroupChatProfilePictureActivity extends XmppActivity implements OnAvatarPublication {
|
||||
|
||||
private final PendingItem<String> pendingConversationUuid = new PendingItem<>();
|
||||
|
@ -96,7 +98,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) {
|
||||
|
@ -116,7 +118,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) {
|
||||
|
@ -128,17 +130,13 @@ public class PublishGroupChatProfilePictureActivity extends XmppActivity impleme
|
|||
ToastCompat.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
|
||||
public void onAvatarPublicationSucceeded() {
|
||||
runOnUiThread(() -> {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package de.pixart.messenger.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.util.Log;
|
||||
import android.view.View;
|
||||
|
@ -28,6 +30,8 @@ import me.drakeet.support.toast.ToastCompat;
|
|||
|
||||
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;
|
||||
|
@ -108,7 +112,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");
|
||||
|
@ -141,15 +145,28 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
ToastCompat.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() {
|
||||
CropImage.activity()
|
||||
.setOutputCompressFormat(Bitmap.CompressFormat.PNG)
|
||||
.setAspectRatio(1, 1)
|
||||
.setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE)
|
||||
.start(this);
|
||||
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(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,10 +200,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;
|
||||
}
|
||||
|
||||
|
@ -196,6 +210,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;
|
||||
|
|
Reference in a new issue