mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-26 23:25:20 +03:00
parent
e42a41f87a
commit
cc96878d52
4 changed files with 7 additions and 74 deletions
|
@ -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<Mention
|
|||
new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
|
||||
item.getId(), item.getLabel(), conversationUser, item.getSource(),
|
||||
R.xml.chip_text_entry, emojiEditText),
|
||||
DynamicDrawableSpan.ALIGN_BASELINE,
|
||||
BetterImageSpan.ALIGN_CENTER,
|
||||
item.getId(), item.getLabel());
|
||||
editable.setSpan(mentionChipSpan, start, start + item.getLabel().length(),
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
|
|
@ -48,6 +48,7 @@ import androidx.annotation.*;
|
|||
import androidx.appcompat.widget.AppCompatDrawableManager;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.emoji.text.EmojiSpan;
|
||||
import com.facebook.common.executors.UiThreadImmediateExecutorService;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
|
@ -63,6 +64,7 @@ import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
|
|||
import com.facebook.imagepipeline.postprocessors.RoundPostprocessor;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.facebook.widget.text.span.BetterImageSpan;
|
||||
import com.google.android.material.chip.ChipDrawable;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
|
@ -321,7 +323,7 @@ public class DisplayUtils {
|
|||
lastStartIndex = end;
|
||||
mentionChipSpan = new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
|
||||
id, label, conversationUser, type, chipXmlRes, null),
|
||||
DynamicDrawableSpan.ALIGN_BASELINE, id,
|
||||
BetterImageSpan.ALIGN_CENTER, id,
|
||||
label);
|
||||
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if ("user".equals(type) && !conversationUser.getUserId().equals(id)) {
|
||||
|
|
|
@ -22,12 +22,13 @@ package com.nextcloud.talk.utils.text;
|
|||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.widget.text.span.BetterImageSpan;
|
||||
import lombok.Data;
|
||||
|
||||
public class Spans {
|
||||
|
||||
@Data
|
||||
public static class MentionChipSpan extends TextAlignedImageSpan {
|
||||
public static class MentionChipSpan extends BetterImageSpan {
|
||||
String id;
|
||||
String label;
|
||||
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue