From 60c72b45e851d8b4380675f7e5c70a9f7fd49763 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 22 May 2024 15:08:40 -0500 Subject: [PATCH] Animted emoji working now --- .../com/cheogram/android/InlineImageSpan.java | 26 ++++++++++++++++--- .../services/XmppConnectionService.java | 5 ---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/cheogram/java/com/cheogram/android/InlineImageSpan.java b/src/cheogram/java/com/cheogram/android/InlineImageSpan.java index 82fcff5667eeda95ca9c589729e1c258580c1a13..9c3d6831d9613837b134d49c620dd4a6eb821d95 100644 --- a/src/cheogram/java/com/cheogram/android/InlineImageSpan.java +++ b/src/cheogram/java/com/cheogram/android/InlineImageSpan.java @@ -1,5 +1,6 @@ package com.cheogram.android; +import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.drawable.AnimatedImageDrawable; import android.graphics.drawable.Drawable; @@ -25,9 +26,8 @@ public class InlineImageSpan extends ImageSpan { paint.getFontMetricsInt(mTmpFontMetrics); final int fontHeight = Math.abs(mTmpFontMetrics.descent - mTmpFontMetrics.ascent); float mRatio = fontHeight * 1.0f / dHeight; - int mHeight = (short) (dHeight * mRatio); - int mWidth = (short) (dWidth * mRatio); - getDrawable().setBounds(0, 0, mWidth, mHeight); + int mWidth = (int) (dWidth * mRatio); + getDrawable().setBounds(0, 0, (int) dWidth, (int) dHeight); if (fm != null) { fm.ascent = mTmpFontMetrics.ascent; fm.descent = mTmpFontMetrics.descent; @@ -36,4 +36,24 @@ public class InlineImageSpan extends ImageSpan { } return mWidth; } + + @Override + public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { + paint.getFontMetricsInt(mTmpFontMetrics); + final int fontHeight = Math.abs(mTmpFontMetrics.descent - mTmpFontMetrics.ascent); + float mRatio = fontHeight * 1.0f / dHeight; + + Drawable b = getDrawable(); + canvas.save(); + + int transY = 0; + if (mVerticalAlignment == ALIGN_BASELINE) { + transY -= paint.getFontMetricsInt().descent; + } + + canvas.translate(x, transY); + canvas.scale(mRatio, mRatio); + b.draw(canvas); + canvas.restore(); + } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 79fcb7eba8cad4d98133a2fbbac0ce39a81237da..12277db1ae2cdf1ff46e0e7c30a27347561ab6e3 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -817,11 +817,6 @@ public class XmppConnectionService extends Service { if (file.isFile() && file.canRead()) { DownloadableFile df = new DownloadableFile(file.getAbsolutePath()); Drawable icon = fileBackend.getThumbnail(df, getResources(), (int) (getResources().getDisplayMetrics().density * 288), false); - if (Build.VERSION.SDK_INT >= 28 && icon instanceof AnimatedImageDrawable) { - // Animated drawable not working in spans for me yet - // https://stackoverflow.com/questions/76870075/using-animatedimagedrawable-inside-imagespan-renders-wrong-size - continue; - } final String filename = Files.getNameWithoutExtension(df.getName()); Cid[] cids = fileBackend.calculateCids(new FileInputStream(df)); for (Cid cid : cids) {