fix hint not ellipsizing

Closes #3672
// FREEBIE
This commit is contained in:
Jake McGinty 2015-07-16 11:53:57 -07:00 committed by Moxie Marlinspike
parent b0f7df93a4
commit 534ac22fd2

View File

@ -6,6 +6,7 @@ import android.support.v7.widget.AppCompatEditText;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -24,6 +25,16 @@ public class ComposeText extends EmojiEditText {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
} }
@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));
}
}
public void setHint(@NonNull String hint) { public void setHint(@NonNull String hint) {
SpannableString span = new SpannableString(hint); SpannableString span = new SpannableString(hint);
span.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); span.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);