aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java33
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/AvatarWorkerTask.java22
3 files changed, 51 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index e30cb028c..274b84c08 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -13,6 +13,7 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
import android.media.MediaMetadataRetriever;
import android.media.MediaScannerConnection;
import android.net.Uri;
@@ -21,8 +22,6 @@ import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.provider.OpenableColumns;
-import androidx.annotation.RequiresApi;
-import androidx.core.content.FileProvider;
import android.system.Os;
import android.system.StructStat;
import android.util.Base64;
@@ -30,6 +29,9 @@ import android.util.Base64OutputStream;
import android.util.Log;
import android.util.LruCache;
+import androidx.annotation.RequiresApi;
+import androidx.core.content.FileProvider;
+
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
@@ -677,7 +679,7 @@ public class FileBackend {
}
}
- private void drawOverlay(Bitmap bitmap, int resource, float factor) {
+ public void drawOverlay(final Bitmap bitmap, final int resource, final float factor) {
Bitmap overlay = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), resource);
Canvas canvas = new Canvas(bitmap);
float targetSize = Math.min(canvas.getWidth(), canvas.getHeight()) * factor;
@@ -688,6 +690,31 @@ public class FileBackend {
canvas.drawBitmap(overlay, null, dst, createAntiAliasingPaint());
}
+ public void drawOverlayFromDrawable(final Drawable drawable, final int resource, final float factor) {
+ Bitmap overlay = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), resource);
+ Bitmap original = drawableToBitmap(drawable);
+ Canvas canvas = new Canvas(original);
+ float targetSize = Math.min(canvas.getWidth(), canvas.getHeight()) * factor;
+ Log.d(Config.LOGTAG, "target size overlay: " + targetSize + " overlay bitmap size was " + overlay.getHeight());
+ float left = (canvas.getWidth() - targetSize) / 2.0f;
+ float top = (canvas.getHeight() - targetSize) / 2.0f;
+ RectF dst = new RectF(left, top, left + targetSize - 1, top + targetSize - 1);
+ canvas.drawBitmap(overlay, null, dst, createAntiAliasingPaint());
+ }
+
+ private static Bitmap drawableToBitmap(Drawable drawable) {
+ Bitmap bitmap = null;
+ if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
+ bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
+ } else {
+ bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+ }
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+ return bitmap;
+ }
+
private static Paint createAntiAliasingPaint() {
Paint paint = new Paint();
paint.setAntiAlias(true);
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 8d5712bf5..f3488a3fc 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -671,7 +671,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
private void refreshAvatar() {
- AvatarWorkerTask.loadAvatar(mAccount, binding.avater, R.dimen.avatar_on_details_screen_size);
+ AvatarWorkerTask.loadAvatar(mAccount, binding.avater, R.dimen.avatar_on_details_screen_size, true);
}
@Override
@@ -1154,7 +1154,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (!mInitMode) {
binding.avater.setVisibility(View.VISIBLE);
- AvatarWorkerTask.loadAvatar(mAccount, binding.avater, R.dimen.avatar_on_details_screen_size);
+ refreshAvatar();
this.binding.accountJid.setEnabled(false);
} else {
binding.avater.setVisibility(View.GONE);
diff --git a/src/main/java/de/pixart/messenger/ui/util/AvatarWorkerTask.java b/src/main/java/de/pixart/messenger/ui/util/AvatarWorkerTask.java
index 54cb3c2a1..738f387de 100644
--- a/src/main/java/de/pixart/messenger/ui/util/AvatarWorkerTask.java
+++ b/src/main/java/de/pixart/messenger/ui/util/AvatarWorkerTask.java
@@ -4,6 +4,7 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
import android.os.AsyncTask;
import androidx.annotation.DimenRes;
import android.widget.ImageView;
@@ -11,6 +12,7 @@ import android.widget.ImageView;
import java.lang.ref.WeakReference;
import java.util.concurrent.RejectedExecutionException;
+import de.pixart.messenger.R;
import de.pixart.messenger.services.AvatarService;
import de.pixart.messenger.ui.XmppActivity;
@@ -72,22 +74,36 @@ public class AvatarWorkerTask extends AsyncTask<AvatarService.Avatarable, Void,
}
public static void loadAvatar(final AvatarService.Avatarable avatarable, final ImageView imageView, final @DimenRes int size) {
+ loadAvatar(avatarable, imageView, size, false);
+ }
+
+ public static void loadAvatar(final AvatarService.Avatarable avatarable, final ImageView imageView, final @DimenRes int size, final boolean overlay) {
if (cancelPotentialWork(avatarable, imageView)) {
final XmppActivity activity = XmppActivity.find(imageView);
if (activity == null) {
return;
}
- final Bitmap bm = activity.avatarService().get(avatarable, (int) activity.getResources().getDimension(size), true);
+ final Bitmap bm = activity.avatarService().get(avatarable, (int) activity.getResources().getDimension(size), false);
if (bm != null) {
cancelPotentialWork(avatarable, imageView);
- imageView.setImageBitmap(bm);
+ if (overlay) {
+ activity.xmppConnectionService.fileBackend.drawOverlay(bm, R.drawable.pencil_overlay, 1.0f);
+ imageView.setImageBitmap(bm);
+ } else {
+ imageView.setImageBitmap(bm);
+ }
imageView.setBackgroundColor(0x00000000);
} else {
imageView.setBackgroundColor(avatarable.getAvatarBackgroundColor());
imageView.setImageDrawable(null);
final AvatarWorkerTask task = new AvatarWorkerTask(imageView, size);
final AsyncDrawable asyncDrawable = new AsyncDrawable(activity.getResources(), null, task);
- imageView.setImageDrawable(asyncDrawable);
+ if (overlay) {
+ activity.xmppConnectionService.fileBackend.drawOverlayFromDrawable(asyncDrawable, R.drawable.pencil_overlay, 1.0f);
+ imageView.setImageDrawable(asyncDrawable);
+ } else {
+ imageView.setImageDrawable(asyncDrawable);
+ }
try {
task.execute(avatarable);
} catch (final RejectedExecutionException ignored) {