mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch '884-emoji-text-view-layout-bug' into 'master'
Remove ellipsizing support from EmojiTextView Closes #884 See merge request !533
This commit is contained in:
@@ -1,29 +1,21 @@
|
||||
package org.thoughtcrime.securesms.components.emoji;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Paint.FontMetricsInt;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static android.text.TextUtils.TruncateAt.END;
|
||||
import static android.view.View.MeasureSpec.AT_MOST;
|
||||
import static android.view.View.MeasureSpec.EXACTLY;
|
||||
import static android.widget.TextView.BufferType.SPANNABLE;
|
||||
|
||||
@UiThread
|
||||
public class EmojiTextView extends TextView {
|
||||
|
||||
private CharSequence source;
|
||||
private boolean needsEllipsizing;
|
||||
public class EmojiTextView extends AppCompatTextView {
|
||||
|
||||
public EmojiTextView(Context context) {
|
||||
this(context, null);
|
||||
@@ -42,13 +34,9 @@ public class EmojiTextView extends TextView {
|
||||
|
||||
@Override
|
||||
public void setText(@Nullable CharSequence text, BufferType type) {
|
||||
source = EmojiProvider.getInstance(getContext()).emojify(text, this);
|
||||
|
||||
setTextEllipsized(source);
|
||||
}
|
||||
|
||||
private void setTextEllipsized(final @Nullable CharSequence source) {
|
||||
super.setText(needsEllipsizing ? ellipsize(source) : source, SPANNABLE);
|
||||
CharSequence source =
|
||||
EmojiProvider.getInstance(getContext()).emojify(text, this);
|
||||
super.setText(source, SPANNABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,26 +45,6 @@ public class EmojiTextView extends TextView {
|
||||
else super.invalidateDrawable(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int size = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int mode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
if (getEllipsize() == END &&
|
||||
!TextUtils.isEmpty(source) &&
|
||||
(mode == AT_MOST || mode == EXACTLY) &&
|
||||
getPaint().breakText(source, 0, source.length() - 1, true, size,
|
||||
null) != source.length()) {
|
||||
needsEllipsizing = true;
|
||||
FontMetricsInt font = getPaint().getFontMetricsInt();
|
||||
int height = Math.abs(font.top - font.bottom);
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(size, EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(height, EXACTLY));
|
||||
} else {
|
||||
needsEllipsizing = false;
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right,
|
||||
int bottom) {
|
||||
@@ -89,20 +57,6 @@ public class EmojiTextView extends TextView {
|
||||
if (size > drawingCacheSize) {
|
||||
setLayerType(LAYER_TYPE_NONE, null);
|
||||
}
|
||||
|
||||
if (changed) setTextEllipsized(source);
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CharSequence ellipsize(@Nullable CharSequence text) {
|
||||
if (TextUtils.isEmpty(text) || getWidth() == 0 ||
|
||||
getEllipsize() != END) {
|
||||
return text;
|
||||
} else {
|
||||
return TextUtils.ellipsize(text, getPaint(),
|
||||
getWidth() - getPaddingRight() - getPaddingLeft(), END);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user