2012-09-07 23:33:53 -04:00
|
|
|
package com.fsck.k9.view;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
/**
|
2013-01-31 20:50:00 -05:00
|
|
|
* This {@link TextView} is used in the custom view of the {@link com.fsck.k9.activity.MessageList}
|
|
|
|
* action bar.
|
|
|
|
* It will hide the subject line in {@link MessageHeader} if the subject fits completely into the
|
|
|
|
* action bar's title view.
|
2012-09-07 23:33:53 -04:00
|
|
|
*/
|
|
|
|
public class MessageTitleView extends TextView {
|
2013-02-11 01:29:22 -05:00
|
|
|
private static final int MAX_LINES = 2;
|
|
|
|
private static final String ELLIPSIS = "\u2026";
|
|
|
|
|
2012-09-07 23:33:53 -04:00
|
|
|
private MessageHeader mHeader;
|
2013-02-11 01:29:22 -05:00
|
|
|
private boolean mNeedEllipsizeCheck = true;
|
2012-09-07 23:33:53 -04:00
|
|
|
|
|
|
|
public MessageTitleView(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageTitleView(Context context, AttributeSet attrs) {
|
|
|
|
this(context, attrs, android.R.attr.textViewStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageTitleView(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
}
|
|
|
|
|
2013-02-11 01:29:22 -05:00
|
|
|
@Override
|
|
|
|
protected void onTextChanged(CharSequence text, int start,
|
|
|
|
int lengthBefore, int lengthAfter) {
|
|
|
|
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
|
|
|
mNeedEllipsizeCheck = true;
|
|
|
|
}
|
2012-09-07 23:33:53 -04:00
|
|
|
/**
|
2013-01-31 20:50:00 -05:00
|
|
|
* Check to see if we need to hide the subject line in {@link MessageHeader} or not.
|
2012-09-07 23:33:53 -04:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onDraw(Canvas canvas) {
|
2013-02-11 01:29:22 -05:00
|
|
|
/*
|
|
|
|
* Android does not support ellipsize in combination with maxlines
|
|
|
|
* for TextViews. To work around that, check for ourselves whether
|
|
|
|
* the text is longer than MAX_LINES, and ellipsize manually.
|
|
|
|
*/
|
|
|
|
if (mNeedEllipsizeCheck) {
|
|
|
|
if (getLayout() != null && mHeader != null) {
|
|
|
|
if (getLayout().getLineCount() > MAX_LINES) {
|
|
|
|
int lineEndIndex = getLayout().getLineEnd(MAX_LINES - 1);
|
|
|
|
setText(getText().subSequence(0, lineEndIndex - 2) + ELLIPSIS);
|
|
|
|
} else {
|
|
|
|
mHeader.hideSubjectLine();
|
|
|
|
}
|
|
|
|
mNeedEllipsizeCheck = false;
|
|
|
|
}
|
2012-09-07 23:33:53 -04:00
|
|
|
}
|
|
|
|
super.onDraw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMessageHeader(final MessageHeader header) {
|
2013-01-31 20:50:00 -05:00
|
|
|
mHeader = header;
|
2012-09-07 23:33:53 -04:00
|
|
|
}
|
|
|
|
}
|