diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java | 18 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java | 43 |
2 files changed, 40 insertions, 21 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java index 9c70640c3..fc0d34beb 100644 --- a/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java +++ b/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java @@ -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(() -> { diff --git a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java index f505bd3a3..0c634d8f3 100644 --- a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java +++ b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java @@ -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; |