From c0c1af1ccaf11856fa765f98e5d4ad8e0fb4ab0c Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 20 Sep 2019 23:53:07 +0200 Subject: added overlay to avatar in EditAccountActivity in addition to #390 --- .../pixart/messenger/persistance/FileBackend.java | 33 +- .../pixart/messenger/ui/EditAccountActivity.java | 4 +- .../pixart/messenger/ui/util/AvatarWorkerTask.java | 22 +- src/main/res/drawable-hdpi/pencil_overlay.png | Bin 0 -> 1199 bytes src/main/res/drawable-mdpi/pencil_overlay.png | Bin 0 -> 1873 bytes src/main/res/drawable-xhdpi/pencil_overlay.png | Bin 0 -> 3465 bytes src/main/res/drawable-xxhdpi/pencil_overlay.png | Bin 0 -> 2119 bytes src/main/res/drawable-xxxhdpi/pencil_overlay.png | Bin 0 -> 9724 bytes src/main/res/layout/activity_edit_account.xml | 444 +++++++++++---------- src/main/res/values/strings.xml | 1 + 10 files changed, 276 insertions(+), 228 deletions(-) create mode 100644 src/main/res/drawable-hdpi/pencil_overlay.png create mode 100644 src/main/res/drawable-mdpi/pencil_overlay.png create mode 100644 src/main/res/drawable-xhdpi/pencil_overlay.png create mode 100644 src/main/res/drawable-xxhdpi/pencil_overlay.png create mode 100644 src/main/res/drawable-xxxhdpi/pencil_overlay.png (limited to 'src/main') 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 + android:layout_marginStart="6dp" + android:layout_marginLeft="6dp" + android:visibility="gone"> - + + - - - + android:text="@string/your_name" + android:textAppearance="@style/TextAppearance.Conversations.Caption" /> - + + + - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/list_padding" + android:layout_marginBottom="@dimen/list_padding" + android:text="@string/this_device" + android:textAppearance="@style/TextAppearance.Conversations.Title" /> - + + tools:ignore="UselessParent"> + android:ellipsize="end" + android:singleLine="true" + android:text="@string/server_info_session_established" + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> - - - - - + android:layout_gravity="end" + android:paddingStart="4dp" + android:paddingLeft="4dp" + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + - - - + - + android:layout_height="8dp" /> - + + + android:layout_alignParentEnd="true" + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:alpha="1.0" + android:background="?attr/selectableItemBackgroundBorderless" + android:padding="@dimen/image_button_padding" + android:src="?attr/icon_remove" + android:visibility="visible" /> + + + android:textAppearance="@style/TextAppearance.Conversations.Fingerprint" /> - + android:text="@string/openpgp_key_id" + android:textAppearance="@style/TextAppearance.Conversations.Caption" /> + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 420b13b2f..47dfc1b9b 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -940,4 +940,5 @@ Your status Replace YouTube links with Invidious Invidious is a privacy friendly alternative to YouTube + This device -- cgit v1.2.3