1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Simplify and improve message view header layout.

The star was displayed partially off-screen before.
This commit is contained in:
Danny Baumann 2013-02-04 13:23:44 +01:00
parent a8917d60c9
commit f51f675021
2 changed files with 147 additions and 224 deletions

View File

@ -2,177 +2,129 @@
<com.fsck.k9.view.MessageHeader
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_container"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Message header area -->
<TableLayout
android:id="@+id/top_container"
android:layout_width="fill_parent"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="1"
android:background="@color/message_view_header_background">
<TableRow>
<!-- Color chip -->
<View
android:id="@+id/chip"
android:layout_marginRight="6dip"
android:layout_width="6dip"
android:layout_height="fill_parent"/>
android:layout_height="match_parent"
android:layout_marginRight="6dip"/>
<LinearLayout
android:paddingTop="2dip"
android:layout_column="1"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Subject -->
<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/state_container"
android:maxLines="3"
android:ellipsize="end"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<!-- From -->
<LinearLayout
android:id="@+id/from_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/subject"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/state_container"
android:paddingRight="6dip"
android:singleLine="true"
android:ellipsize="end"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
<!-- To -->
<LinearLayout
android:id="@+id/to_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="true">
<TextView
android:id="@+id/to_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:text="@string/message_to_label"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="?android:attr/textColorSecondary"/>
<TextView
android:id="@+id/to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/from"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/state_container"
android:maxLines="2"
android:ellipsize="end"
android:textSize="10sp"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
<!-- CC -->
<LinearLayout
android:id="@+id/cc_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="true">
<TextView
android:id="@+id/cc_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:text="@string/message_view_cc_label"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="?android:attr/textColorSecondary"/>
<TextView
android:id="@+id/cc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/to"
android:layout_alignParentLeft="true"
android:maxLines="2"
android:ellipsize="end"
android:textSize="10sp"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</LinearLayout>
<!-- Date/Time + Icons -->
<LinearLayout
android:id="@+id/topright_container"
android:layout_marginTop="6dip"
android:layout_marginRight="6dip"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_gravity="right">
<LinearLayout
android:id="@+id/date_time_container"
android:orientation="vertical"
android:id="@+id/state_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:paddingRight="5dip"
android:gravity="right"
>
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:orientation="vertical">
<!-- Date -->
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:singleLine="true"
android:ellipsize="none"
android:textSize="10sp"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<!-- Time -->
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:layout_gravity="right"
android:singleLine="true"
android:ellipsize="none"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
<!-- State icons -->
<LinearLayout
android:id="@+id/icons_container"
android:orientation="horizontal"
android:id="@+id/icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right">
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"
android:layout_gravity="center_vertical|right"
android:orientation="horizontal">
<View
android:id="@+id/answered"
@ -180,98 +132,67 @@
android:layout_height="22sp"
android:paddingRight="4dip"
android:background="@drawable/ic_email_answered_small"/>
<View
android:id="@+id/forwarded"
android:layout_width="22sp"
android:layout_height="22sp"
android:paddingRight="4dip"
android:background="@drawable/ic_email_forwarded_small"/>
<CheckBox
android:id="@+id/flagged"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:button="@drawable/star"
/>
android:button="@drawable/star"/>
</LinearLayout>
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/additional_headers_row">
<!-- Color chip 2 -->
<View
android:id="@+id/chip2"
android:layout_marginRight="6dip"
android:layout_width="6dip"
android:layout_height="fill_parent"/>
<!-- Additional headers -->
<TextView
android:layout_span="2"
android:id="@+id/additional_headers_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:singleLine="false"
android:ellipsize="none"
android:textSize="10sp"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
</TableLayout>
<!-- Separator -->
<!-- This layout has an explicit height because otherwise there will be strange
display issues when the additional headers are shown. -->
<LinearLayout
android:id="@+id/show_additional_headers_area"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="21dp"
android:focusable="true"
android:clickable="true"
android:background="@drawable/message_view_header_background">
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="20dp">
<!-- Color chip 3 -->
<View
android:id="@+id/chip3"
android:layout_marginRight="6dip"
android:layout_width="6dip"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"/>
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Show more/less indicator -->
<ImageView
android:id="@+id/show_additional_headers_icon"
android:src="@drawable/show_more"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginRight="12dp"/>
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:paddingRight="12dp"
android:scaleType="fitEnd"/>
<TextView
android:id="@+id/additional_headers_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/show_additional_headers_icon"
android:layout_marginRight="10dp"
android:singleLine="false"
android:ellipsize="none"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@drawable/divider_horizontal_email" />
</LinearLayout>
</LinearLayout>
<View
android:layout_height="1dip"
android:layout_width="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@id/additional_headers_view"
android:background="@drawable/divider_horizontal_email" />
<!-- Button area -->
<LinearLayout
android:layout_width="fill_parent"

View File

@ -6,6 +6,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log;
import android.util.AttributeSet;
@ -16,7 +17,6 @@ import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.fsck.k9.FontSizes;
@ -50,12 +50,8 @@ public class MessageHeader extends ScrollView implements OnClickListener {
private DateFormat mTimeFormat;
private View mChip;
private View mChip2;
private View mChip3;
private CheckBox mFlagged;
private int defaultSubjectColor;
private LinearLayout mToContainerView;
private LinearLayout mCcContainerView;
private TextView mAdditionalHeadersView;
private View mAnsweredIcon;
private View mForwardedIcon;
@ -96,13 +92,9 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mFromView = (TextView) findViewById(R.id.from);
mToView = (TextView) findViewById(R.id.to);
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);
mChip3 = findViewById(R.id.chip3);
mDateView = (TextView) findViewById(R.id.date);
mTimeView = (TextView) findViewById(R.id.time);
mFlagged = (CheckBox) findViewById(R.id.flagged);
@ -121,11 +113,8 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mFromView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewSender());
mToView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo());
mCcView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC());
((TextView) findViewById(R.id.to_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo());
((TextView) findViewById(R.id.cc_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC());
findViewById(R.id.show_additional_headers_area).setOnClickListener(this);
findViewById(R.id.additional_headers_row).setOnClickListener(this);
mShowAdditionalHeadersIcon.setOnClickListener(this);
mFromView.setOnClickListener(this);
mToView.setOnClickListener(this);
mCcView.setOnClickListener(this);
@ -134,8 +123,7 @@ public class MessageHeader extends ScrollView implements OnClickListener {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.additional_headers_row:
case R.id.show_additional_headers_area: {
case R.id.show_additional_headers_icon: {
onShowAdditionalHeaders();
break;
}
@ -256,10 +244,8 @@ public class MessageHeader extends ScrollView implements OnClickListener {
mDateView.setVisibility(View.GONE);
}
mTimeView.setText(time);
mToContainerView.setVisibility((to != null && to.length() > 0) ? View.VISIBLE : View.GONE);
mToView.setText(to);
mCcContainerView.setVisibility((cc != null && cc.length() > 0) ? View.VISIBLE : View.GONE);
mCcView.setText(cc);
updateAddressField(mToView, to, R.string.message_to_label);
updateAddressField(mCcView, cc, R.string.message_view_cc_label);
mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
mFlagged.setChecked(message.isSet(Flag.FLAGGED));
@ -268,10 +254,6 @@ public class MessageHeader extends ScrollView implements OnClickListener {
int chipColorAlpha = (!message.isSet(Flag.SEEN)) ? 255 : 127;
mChip.setBackgroundColor(chipColor);
mChip.getBackground().setAlpha(chipColorAlpha);
mChip2.setBackgroundColor(chipColor);
mChip2.getBackground().setAlpha(chipColorAlpha);
mChip3.setBackgroundColor(chipColor);
mChip3.getBackground().setAlpha(chipColorAlpha);
setVisibility(View.VISIBLE);
@ -299,6 +281,26 @@ public class MessageHeader extends ScrollView implements OnClickListener {
layoutChanged();
}
private static final StyleSpan sBoldSpan = new StyleSpan(Typeface.BOLD);
private void updateAddressField(TextView v, CharSequence address, int prefixId) {
if (TextUtils.isEmpty(address)) {
v.setVisibility(View.GONE);
return;
}
final SpannableStringBuilder text = new SpannableStringBuilder();
final String prefix = mContext.getString(prefixId);
text.append(prefix);
text.append(" ");
text.append(address);
text.setSpan(sBoldSpan, 0, prefix.length(), 0);
v.setText(text);
v.setVisibility(View.VISIBLE);
}
/**
* Expand or collapse a TextView by removing or adding the 2 lines limitation
*/