fix layout ellipsis errors

fixes #3718
closes #3743
// FREEBIE
This commit is contained in:
Jake McGinty 2015-07-21 14:21:22 -07:00 committed by Moxie Marlinspike
parent f04281ac4a
commit 4840cdd293
2 changed files with 15 additions and 16 deletions

View File

@ -17,6 +17,8 @@ import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
public class ComposeText extends EmojiEditText { public class ComposeText extends EmojiEditText {
private SpannableString hint;
public ComposeText(Context context) { public ComposeText(Context context) {
super(context); super(context);
} }
@ -31,18 +33,22 @@ public class ComposeText extends EmojiEditText {
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (!TextUtils.isEmpty(getHint())) { if (!TextUtils.isEmpty(hint)) {
setHint(TextUtils.ellipsize(getHint(), setHint(ellipsizeToWidth(hint));
getPaint(),
getWidth() - getPaddingLeft() - getPaddingRight(),
TruncateAt.END));
} }
} }
private CharSequence ellipsizeToWidth(CharSequence text) {
return TextUtils.ellipsize(text,
getPaint(),
getWidth() - getPaddingLeft() - getPaddingRight(),
TruncateAt.END);
}
public void setHint(@NonNull String hint) { public void setHint(@NonNull String hint) {
SpannableString span = new SpannableString(hint); this.hint = new SpannableString(hint);
span.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); this.hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
super.setHint(span); super.setHint(ellipsizeToWidth(this.hint));
} }
public void appendInvite(String invite) { public void appendInvite(String invite) {

View File

@ -14,6 +14,7 @@ public class EmojiFilter implements InputFilter, OnGlobalLayoutListener {
public EmojiFilter(TextView view) { public EmojiFilter(TextView view) {
this.view = view; this.view = view;
view.getViewTreeObserver().addOnGlobalLayoutListener(this);
} }
@Override public CharSequence filter(CharSequence source, int start, int end, @Override public CharSequence filter(CharSequence source, int start, int end,
@ -25,7 +26,6 @@ public class EmojiFilter implements InputFilter, OnGlobalLayoutListener {
if (source instanceof Spanned) { if (source instanceof Spanned) {
TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0); TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
} }
view.getViewTreeObserver().addOnGlobalLayoutListener(this);
if (view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) { if (view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
return emojified; return emojified;
} else { } else {
@ -38,13 +38,6 @@ public class EmojiFilter implements InputFilter, OnGlobalLayoutListener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override public void onGlobalLayout() { @Override public void onGlobalLayout() {
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
else {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
view.invalidate(); view.invalidate();
} }
} }