diff --git a/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java b/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java index e3a0d4f1b..aef43a89c 100644 --- a/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java +++ b/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java @@ -24,6 +24,7 @@ import android.content.Context; import android.text.Editable; import android.text.Spanned; import android.text.style.DynamicDrawableSpan; +import com.facebook.widget.text.span.BetterImageSpan; import com.nextcloud.talk.R; import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.mention.Mention; @@ -57,7 +58,7 @@ public class MentionAutocompleteCallback implements AutocompleteCallback - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Taken and adapter from - */ - -package com.nextcloud.talk.utils.text; - -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.text.style.ImageSpan; -import androidx.annotation.NonNull; - -public class TextAlignedImageSpan extends ImageSpan { - public TextAlignedImageSpan(@NonNull Drawable drawable, int verticalAlignment) { - super(drawable, verticalAlignment); - } - - public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, - Paint.FontMetricsInt fontMetricsInt) { - Drawable drawable = getDrawable(); - Rect drawableBounds = drawable.getBounds(); - - if (fontMetricsInt != null) { - Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt(); - int fontHeight = fmPaint.bottom - fmPaint.top; - int drHeight = drawableBounds.bottom - drawableBounds.top; - - int top = drHeight / 2 - fontHeight / 4; - int bottom = drHeight / 2 + fontHeight / 4; - - fontMetricsInt.ascent = -bottom; - fontMetricsInt.top = -bottom; - fontMetricsInt.bottom = top; - fontMetricsInt.descent = top; - } - - return drawableBounds.right; - } - - @Override - public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, - float x, int top, int y, int bottom, @NonNull Paint paint) { - Drawable drawable = getDrawable(); - canvas.save(); - int transY; - transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top; - canvas.translate(x, transY); - drawable.draw(canvas); - canvas.restore(); - } - -}