Animted emoji working now

Stephen Paul Weber created

Change summary

src/cheogram/java/com/cheogram/android/InlineImageSpan.java              | 26 
src/main/java/eu/siacs/conversations/services/XmppConnectionService.java |  5 
2 files changed, 23 insertions(+), 8 deletions(-)

Detailed changes

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();
+	}
 }

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) {