mirror of
https://github.com/moparisthebest/k-9
synced 2024-08-13 17:03:48 -04:00
8d4a82ba0e
- Android does not support ellipsize in combination with maxlines for TextViews. This caused getEllipsisCount() in MessageTitleView to always fail, and the full subject was never shown in the regular headers area when needed. To work around that, check for ourselves whether the text is longer than 2, and ellipsize manually. - Clicking the star button on a message caused the subject line to re-appear, even if it fits in the action bar title without being cut off. This was caused by MessageHeader.populate(), which always set the subject to visible. As a workaround: Only set subject to visible in case populate() actually shows a new message. - delete res/layout/actionbar_message_view.xml, its already present in the actionbar_custom.xml
67 lines
2.2 KiB
Java
67 lines
2.2 KiB
Java
package com.fsck.k9.view;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Canvas;
|
|
import android.util.AttributeSet;
|
|
import android.widget.TextView;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
public class MessageTitleView extends TextView {
|
|
private static final int MAX_LINES = 2;
|
|
private static final String ELLIPSIS = "\u2026";
|
|
|
|
private MessageHeader mHeader;
|
|
private boolean mNeedEllipsizeCheck = true;
|
|
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
protected void onTextChanged(CharSequence text, int start,
|
|
int lengthBefore, int lengthAfter) {
|
|
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
|
mNeedEllipsizeCheck = true;
|
|
}
|
|
/**
|
|
* Check to see if we need to hide the subject line in {@link MessageHeader} or not.
|
|
*/
|
|
@Override
|
|
public void onDraw(Canvas canvas) {
|
|
/*
|
|
* 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;
|
|
}
|
|
}
|
|
super.onDraw(canvas);
|
|
}
|
|
|
|
public void setMessageHeader(final MessageHeader header) {
|
|
mHeader = header;
|
|
}
|
|
}
|