1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

Show the subject line in the MessageHeader if the ActionBar title was truncated.

This commit is contained in:
Andrew Chen 2012-09-07 20:33:53 -07:00
parent 20b155ec8b
commit 9fbb2b4836
9 changed files with 170 additions and 4 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.fsck.k9.view.MessageTitleView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textSize="16sp"
android:includeFontPadding="false"
/>
</LinearLayout>

View File

@ -34,7 +34,18 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Subject is shown on the actionbar -->
<!-- Subject -->
<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:ellipsize="end"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"/>
<!-- From -->
<LinearLayout

View File

@ -121,6 +121,14 @@
android:entryValues="@array/font_values"
android:dialogTitle="@string/font_size_message_view_cc" />
<ListPreference
android:persistent="false"
android:key="message_view_subject_font"
android:title="@string/font_size_message_view_subject"
android:entries="@array/font_entries"
android:entryValues="@array/font_values"
android:dialogTitle="@string/font_size_message_view_subject" />
<ListPreference
android:persistent="false"
android:key="message_view_time_font"

View File

@ -101,6 +101,11 @@ public class FontSizes {
*/
private int messageViewAdditionalHeaders;
/**
* Font size of the message subject in the message view activity.
*/
private int messageViewSubject;
/**
* Font size of the message time in the message view activity.
*/
@ -143,6 +148,7 @@ public class FontSizes {
messageViewTo = FONT_12SP;
messageViewCC = FONT_12SP;
messageViewAdditionalHeaders = FONT_12SP;
messageViewSubject = FONT_12SP;
messageViewTime = FONT_10SP;
messageViewDate = FONT_10SP;
@ -170,6 +176,7 @@ public class FontSizes {
editor.putInt(MESSAGE_VIEW_TO, messageViewTo);
editor.putInt(MESSAGE_VIEW_CC, messageViewCC);
editor.putInt(MESSAGE_VIEW_ADDITIONAL_HEADERS, messageViewAdditionalHeaders);
editor.putInt(MESSAGE_VIEW_SUBJECT, messageViewSubject);
editor.putInt(MESSAGE_VIEW_TIME, messageViewTime);
editor.putInt(MESSAGE_VIEW_DATE, messageViewDate);
editor.putInt(MESSAGE_VIEW_CONTENT, getMessageViewContentAsInt());
@ -198,6 +205,7 @@ public class FontSizes {
messageViewTo = prefs.getInt(MESSAGE_VIEW_TO, messageViewTo);
messageViewCC = prefs.getInt(MESSAGE_VIEW_CC, messageViewCC);
messageViewAdditionalHeaders = prefs.getInt(MESSAGE_VIEW_ADDITIONAL_HEADERS, messageViewAdditionalHeaders);
messageViewSubject = prefs.getInt(MESSAGE_VIEW_SUBJECT, messageViewSubject);
messageViewTime = prefs.getInt(MESSAGE_VIEW_TIME, messageViewTime);
messageViewDate = prefs.getInt(MESSAGE_VIEW_DATE, messageViewDate);
setMessageViewContent(prefs.getInt(MESSAGE_VIEW_CONTENT, 3));
@ -301,6 +309,14 @@ public class FontSizes {
this.messageViewAdditionalHeaders = messageViewAdditionalHeaders;
}
public int getMessageViewSubject() {
return messageViewSubject;
}
public void setMessageViewSubject(int messageViewSubject) {
this.messageViewSubject = messageViewSubject;
}
public int getMessageViewTime() {
return messageViewTime;
}

View File

@ -20,6 +20,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
@ -40,6 +41,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalMessage;
import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.view.AttachmentView;
import com.fsck.k9.view.AttachmentView.AttachmentFileDownloadCallback;
import com.fsck.k9.view.MessageTitleView;
import com.fsck.k9.view.SingleMessageView;
public class MessageView extends K9Activity implements OnClickListener {
@ -52,6 +54,7 @@ public class MessageView extends K9Activity implements OnClickListener {
private static final int ACTIVITY_CHOOSE_DIRECTORY = 3;
private SingleMessageView mMessageView;
private MessageTitleView mTitleView;
private PgpData mPgpData;
private Menu mMenu;
@ -311,8 +314,6 @@ public class MessageView extends K9Activity implements OnClickListener {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.message_view);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mMessageView = (SingleMessageView) findViewById(R.id.message_view);
//set a callback for the attachment view. With this callback the attachmentview
@ -344,6 +345,8 @@ public class MessageView extends K9Activity implements OnClickListener {
mMessageView.initialize(this);
initializeActionBar();
setTitle("");
final Intent intent = getIntent();
@ -415,6 +418,18 @@ public class MessageView extends K9Activity implements OnClickListener {
mMessageView.updateCryptoLayout(mAccount.getCryptoProvider(), mPgpData, mMessage);
}
private void initializeActionBar() {
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar_message_view);
final View customView = actionBar.getCustomView();
mTitleView = (MessageTitleView) customView.findViewById(android.R.id.title);
mTitleView.setMessageHeader(mMessageView.getMessageHeaderView());
}
private void displayMessage(MessageReference ref) {
mMessageReference = ref;
if (K9.DEBUG)
@ -1082,4 +1097,14 @@ public class MessageView extends K9Activity implements OnClickListener {
Log.e(K9.LOG_TAG, "displayMessageBody failed", e);
}
}
/**
* Set the title of the view. Since we're using a custom ActionBar view, the normal setTitle() doesn't do what we
* think. This version sets the text value into the proper ActionBar title view.
* @param title Title to set.
*/
@Override
public void setTitle(CharSequence title) {
mTitleView.setText(title);
}
}

View File

@ -1,4 +1,3 @@
package com.fsck.k9.activity.setup;
import android.content.Context;
@ -32,6 +31,7 @@ public class FontSizeSettings extends K9PreferenceActivity {
private static final String PREFERENCE_MESSAGE_VIEW_TO_FONT = "message_view_to_font";
private static final String PREFERENCE_MESSAGE_VIEW_CC_FONT = "message_view_cc_font";
private static final String PREFERENCE_MESSAGE_VIEW_ADDITIONAL_HEADERS_FONT = "message_view_additional_headers_font";
private static final String PREFERENCE_MESSAGE_VIEW_SUBJECT_FONT = "message_view_subject_font";
private static final String PREFERENCE_MESSAGE_VIEW_TIME_FONT = "message_view_time_font";
private static final String PREFERENCE_MESSAGE_VIEW_DATE_FONT = "message_view_date_font";
private static final String PREFERENCE_MESSAGE_VIEW_CONTENT_FONT = "message_view_content_font";
@ -49,6 +49,7 @@ public class FontSizeSettings extends K9PreferenceActivity {
private ListPreference mMessageViewTo;
private ListPreference mMessageViewCC;
private ListPreference mMessageViewAdditionalHeaders;
private ListPreference mMessageViewSubject;
private ListPreference mMessageViewTime;
private ListPreference mMessageViewDate;
private ListPreference mMessageViewContent;
@ -111,6 +112,9 @@ public class FontSizeSettings extends K9PreferenceActivity {
mMessageViewAdditionalHeaders = setupListPreference(
PREFERENCE_MESSAGE_VIEW_ADDITIONAL_HEADERS_FONT,
Integer.toString(fontSizes.getMessageViewAdditionalHeaders()));
mMessageViewSubject = setupListPreference(
PREFERENCE_MESSAGE_VIEW_SUBJECT_FONT,
Integer.toString(fontSizes.getMessageViewSubject()));
mMessageViewTime = setupListPreference(
PREFERENCE_MESSAGE_VIEW_TIME_FONT,
Integer.toString(fontSizes.getMessageViewTime()));
@ -148,6 +152,7 @@ public class FontSizeSettings extends K9PreferenceActivity {
fontSizes.setMessageViewTo(Integer.parseInt(mMessageViewTo.getValue()));
fontSizes.setMessageViewCC(Integer.parseInt(mMessageViewCC.getValue()));
fontSizes.setMessageViewAdditionalHeaders(Integer.parseInt(mMessageViewAdditionalHeaders.getValue()));
fontSizes.setMessageViewSubject(Integer.parseInt(mMessageViewSubject.getValue()));
fontSizes.setMessageViewTime(Integer.parseInt(mMessageViewTime.getValue()));
fontSizes.setMessageViewDate(Integer.parseInt(mMessageViewDate.getValue()));
fontSizes.setMessageViewContent(Integer.parseInt(mMessageViewContent.getValue()));

View File

@ -25,6 +25,7 @@ import com.fsck.k9.R;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.Account;
import com.fsck.k9.helper.DateFormatter;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Message;
@ -44,6 +45,7 @@ public class MessageHeader extends ScrollView implements OnClickListener {
private TextView mTimeView;
private TextView mToView;
private TextView mCcView;
private TextView mSubjectView;
private DateFormat mDateFormat;
private DateFormat mTimeFormat;
@ -51,6 +53,7 @@ public class MessageHeader extends ScrollView implements OnClickListener {
private View mChip2;
private View mChip3;
private CheckBox mFlagged;
private int defaultSubjectColor;
private LinearLayout mToContainerView;
private LinearLayout mCcContainerView;
private TextView mAdditionalHeadersView;
@ -95,6 +98,7 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mCcView = (TextView) findViewById(R.id.cc);
mToContainerView = (LinearLayout) findViewById(R.id.to_container);
mCcContainerView = (LinearLayout) findViewById(R.id.cc_container);
mSubjectView = (TextView) findViewById(R.id.subject);
mAdditionalHeadersView = (TextView) findViewById(R.id.additional_headers_view);
mChip = findViewById(R.id.chip);
mChip2 = findViewById(R.id.chip2);
@ -104,6 +108,8 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mFlagged = (CheckBox) findViewById(R.id.flagged);
mShowAdditionalHeadersIcon = (ImageView) findViewById(R.id.show_additional_headers_icon);
defaultSubjectColor = mSubjectView.getCurrentTextColor();
mSubjectView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewSubject());
mTimeView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTime());
mDateView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewDate());
mAdditionalHeadersView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewAdditionalHeaders());
@ -233,6 +239,13 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mAccount = account;
initializeLayout();
final String subject = message.getSubject();
if (StringUtils.isNullOrEmpty(subject)) {
mSubjectView.setText(mContext.getText(R.string.general_no_subject));
} else {
mSubjectView.setText(subject);
}
mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);
mFromView.setText(from);
@ -417,4 +430,11 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mOnLayoutChangedListener.onLayoutChanged();
}
}
/**
* The subject line defaults to GONE. Make it visible.
*/
public void showSubjectLine() {
mSubjectView.setVisibility(VISIBLE);
}
}

View File

@ -0,0 +1,55 @@
package com.fsck.k9.view;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.TextView;
import com.fsck.k9.K9;
/**
* This {@link TextView} is used in the title of the {@link com.fsck.k9.activity.MessageView} ActionBar.
* It'll un-hide the subject line {@link MessageHeader} if it doesn't fit in the ActionBar's title area.
*/
public class MessageTitleView extends TextView {
private static final String LOG_PREFIX = "MessageTitleView: ";
private MessageHeader mHeader;
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);
}
/**
* Check to see if we need to unhide the subject line in the MessageHeader or not.
* @param canvas Canvas to draw on.
*/
@Override
public void onDraw(Canvas canvas) {
if(mHeader != null && getLayout() != null) {
if(getLayout().getEllipsisCount(1) > 0) {
if(K9.DEBUG) {
Log.d(K9.LOG_TAG, LOG_PREFIX +
"Subject was truncated; enabling the subject line in the message header.");
}
mHeader.showSubjectLine();
} else {
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, LOG_PREFIX + "Subject was fully shown in ActionBar.");
}
}
}
super.onDraw(canvas);
}
public void setMessageHeader(final MessageHeader header) {
this.mHeader = header;
}
}

View File

@ -495,6 +495,15 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
mShowAttachmentsAction.setVisibility(show ? View.VISIBLE : View.GONE);
}
/**
* Fetch the message header view. This is not the same as the message headers; this is the View shown at the top
* of messages.
* @return MessageHeader View.
*/
public MessageHeader getMessageHeaderView() {
return mHeaderContainer;
}
public void setHeaders(final Message message, Account account) {
try {
mHeaderContainer.populate(message, account);