Skip to content
Snippets Groups Projects
Unverified Commit 37281c6c authored by akwizgran's avatar akwizgran
Browse files

Remove ellipsizing support from EmojiTextView.

This is a workaround for a layout bug.
parent 6de539a6
No related branches found
No related tags found
No related merge requests found
package org.thoughtcrime.securesms.components.emoji; package org.thoughtcrime.securesms.components.emoji;
import android.content.Context; import android.content.Context;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import android.text.TextUtils; import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import android.widget.TextView;
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable; import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable;
import javax.annotation.Nullable; 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; import static android.widget.TextView.BufferType.SPANNABLE;
@UiThread @UiThread
public class EmojiTextView extends TextView { public class EmojiTextView extends AppCompatTextView {
private CharSequence source;
private boolean needsEllipsizing;
public EmojiTextView(Context context) { public EmojiTextView(Context context) {
this(context, null); this(context, null);
...@@ -42,13 +34,9 @@ public class EmojiTextView extends TextView { ...@@ -42,13 +34,9 @@ public class EmojiTextView extends TextView {
@Override @Override
public void setText(@Nullable CharSequence text, BufferType type) { public void setText(@Nullable CharSequence text, BufferType type) {
source = EmojiProvider.getInstance(getContext()).emojify(text, this); CharSequence source =
EmojiProvider.getInstance(getContext()).emojify(text, this);
setTextEllipsized(source); super.setText(source, SPANNABLE);
}
private void setTextEllipsized(final @Nullable CharSequence source) {
super.setText(needsEllipsizing ? ellipsize(source) : source, SPANNABLE);
} }
@Override @Override
...@@ -57,26 +45,6 @@ public class EmojiTextView extends TextView { ...@@ -57,26 +45,6 @@ public class EmojiTextView extends TextView {
else super.invalidateDrawable(drawable); 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 @Override
protected void onLayout(boolean changed, int left, int top, int right, protected void onLayout(boolean changed, int left, int top, int right,
int bottom) { int bottom) {
...@@ -89,20 +57,6 @@ public class EmojiTextView extends TextView { ...@@ -89,20 +57,6 @@ public class EmojiTextView extends TextView {
if (size > drawingCacheSize) { if (size > drawingCacheSize) {
setLayerType(LAYER_TYPE_NONE, null); setLayerType(LAYER_TYPE_NONE, null);
} }
if (changed) setTextEllipsized(source);
super.onLayout(changed, left, top, right, bottom); 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);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment