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;
public class ComposeText extends EmojiEditText {
private SpannableString hint;
public ComposeText(Context 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) {
super.onLayout(changed, left, top, right, bottom);
if (!TextUtils.isEmpty(getHint())) {
setHint(TextUtils.ellipsize(getHint(),
getPaint(),
getWidth() - getPaddingLeft() - getPaddingRight(),
TruncateAt.END));
if (!TextUtils.isEmpty(hint)) {
setHint(ellipsizeToWidth(hint));
}
}
private CharSequence ellipsizeToWidth(CharSequence text) {
return TextUtils.ellipsize(text,
getPaint(),
getWidth() - getPaddingLeft() - getPaddingRight(),
TruncateAt.END);
}
public void setHint(@NonNull String hint) {
SpannableString span = new SpannableString(hint);
span.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
super.setHint(span);
this.hint = new SpannableString(hint);
this.hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
super.setHint(ellipsizeToWidth(this.hint));
}
public void appendInvite(String invite) {

View File

@ -14,6 +14,7 @@ public class EmojiFilter implements InputFilter, OnGlobalLayoutListener {
public EmojiFilter(TextView view) {
this.view = view;
view.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
@Override public CharSequence filter(CharSequence source, int start, int end,
@ -25,7 +26,6 @@ public class EmojiFilter implements InputFilter, OnGlobalLayoutListener {
if (source instanceof Spanned) {
TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
}
view.getViewTreeObserver().addOnGlobalLayoutListener(this);
if (view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
return emojified;
} else {
@ -38,13 +38,6 @@ public class EmojiFilter implements InputFilter, OnGlobalLayoutListener {
@SuppressWarnings("deprecation")
@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();
}
}