Use a single text view for count and date of calls.
This further reduces the number of views needed to render the call log.
At the same time, fix a few minor issues that are needed for pixel
perfect UI:
- Do not show the text when the item is new.
- Instead, for new items, highlight the date in the color associated
with the item (blue for voicemail, red for missed calls).
- Do not put a separating slash between the count and the date.
Bug: 5099652
Change-Id: I18b71463e7398f00f0fe8fecbeb334b67d618312
diff --git a/src/com/android/contacts/PhoneCallDetailsHelper.java b/src/com/android/contacts/PhoneCallDetailsHelper.java
index 08e6a56..3101aee 100644
--- a/src/com/android/contacts/PhoneCallDetailsHelper.java
+++ b/src/com/android/contacts/PhoneCallDetailsHelper.java
@@ -24,9 +24,12 @@
import android.graphics.Typeface;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telephony.PhoneNumberUtils;
+import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.StyleSpan;
import android.view.View;
import android.widget.TextView;
@@ -60,43 +63,36 @@
/** Fills the call details views with content. */
public void setPhoneCallDetails(PhoneCallDetailsViews views, PhoneCallDetails details,
- boolean useIcons, boolean isHighlighted) {
- if (useIcons) {
- views.callTypeIcons.clear();
- int count = details.callTypes.length;
- for (int index = 0; index < count && index < MAX_CALL_TYPE_ICONS; ++index) {
- views.callTypeIcons.add(details.callTypes[index]);
- }
- views.callTypeIcons.setVisibility(View.VISIBLE);
- if (count > MAX_CALL_TYPE_ICONS) {
- views.callTypeText.setVisibility(View.VISIBLE);
- views.callTypeSeparator.setVisibility(View.VISIBLE);
- views.callTypeText.setText(
- mResources.getString(R.string.call_log_item_count, count));
- } else {
- views.callTypeText.setVisibility(View.GONE);
- views.callTypeSeparator.setVisibility(View.GONE);
- }
- } else {
- // Use the name of the first call type.
- // TODO: We should update this to handle the text for multiple calls as well.
- int callType = details.callTypes[0];
- views.callTypeText.setText(
- isHighlighted ? mCallTypeHelper.getHighlightedCallTypeText(callType)
- : mCallTypeHelper.getCallTypeText(callType));
- views.callTypeIcons.clear();
-
- views.callTypeText.setVisibility(View.VISIBLE);
- views.callTypeSeparator.setVisibility(View.VISIBLE);
- views.callTypeIcons.setVisibility(View.GONE);
+ boolean isHighlighted) {
+ // Display up to a given number of icons.
+ views.callTypeIcons.clear();
+ int count = details.callTypes.length;
+ for (int index = 0; index < count && index < MAX_CALL_TYPE_ICONS; ++index) {
+ views.callTypeIcons.add(details.callTypes[index]);
}
+ views.callTypeIcons.setVisibility(View.VISIBLE);
- CharSequence shortDateText =
+ // Show the total call count only if there are more than the maximum number of icons.
+ final Integer callCount;
+ if (count > MAX_CALL_TYPE_ICONS) {
+ callCount = count;
+ } else {
+ callCount = null;
+ }
+ // The color to highlight the count and date in, if any. This is based on the first call.
+ Integer highlightColor =
+ isHighlighted ? mCallTypeHelper.getHighlightedColor(details.callTypes[0]) : null;
+
+ // The date of this call, relative to the current time.
+ CharSequence dateText =
DateUtils.getRelativeTimeSpanString(details.date,
getCurrentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
+ // Set the call count and date.
+ setCallCountAndDate(views, callCount, dateText, highlightColor);
+
CharSequence numberFormattedLabel = null;
// Only show a label if the number is shown and it is not a SIP address.
if (!TextUtils.isEmpty(details.number)
@@ -130,7 +126,6 @@
}
}
- views.dateView.setText(shortDateText);
views.nameView.setText(nameText);
views.numberView.setText(numberText);
}
@@ -165,4 +160,36 @@
return mCurrentTimeMillisForTest;
}
}
+
+ /** Sets the call count and date. */
+ private void setCallCountAndDate(PhoneCallDetailsViews views, Integer callCount,
+ CharSequence dateText, Integer highlightColor) {
+ // Combine the count (if present) and the date.
+ final CharSequence text;
+ if (callCount != null) {
+ text = mResources.getString(
+ R.string.call_log_item_count_and_date, callCount.intValue(), dateText);
+ } else {
+ text = dateText;
+ }
+
+ // Apply the highlight color if present.
+ final CharSequence formattedText;
+ if (highlightColor != null) {
+ formattedText = addBoldAndColor(text, highlightColor);
+ } else {
+ formattedText = text;
+ }
+
+ views.callTypeAndDate.setText(formattedText);
+ }
+
+ /** Creates a SpannableString for the given text which is bold and in the given color. */
+ private CharSequence addBoldAndColor(CharSequence text, int color) {
+ int flags = Spanned.SPAN_INCLUSIVE_INCLUSIVE;
+ SpannableString result = new SpannableString(text);
+ result.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), flags);
+ result.setSpan(new ForegroundColorSpan(color), 0, text.length(), flags);
+ return result;
+ }
}
diff --git a/src/com/android/contacts/PhoneCallDetailsViews.java b/src/com/android/contacts/PhoneCallDetailsViews.java
index c07e337..fa06879 100644
--- a/src/com/android/contacts/PhoneCallDetailsViews.java
+++ b/src/com/android/contacts/PhoneCallDetailsViews.java
@@ -29,20 +29,15 @@
public final TextView nameView;
public final View callTypeView;
public final CallTypeIconsView callTypeIcons;
- public final TextView callTypeText;
- public final View callTypeSeparator;
- public final TextView dateView;
+ public final TextView callTypeAndDate;
public final TextView numberView;
private PhoneCallDetailsViews(TextView nameView, View callTypeView,
- CallTypeIconsView callTypeIcons, TextView callTypeText, View callTypeSeparator,
- TextView dateView, TextView numberView) {
+ CallTypeIconsView callTypeIcons, TextView callTypeAndDate, TextView numberView) {
this.nameView = nameView;
this.callTypeView = callTypeView;
this.callTypeIcons = callTypeIcons;
- this.callTypeText = callTypeText;
- this.callTypeSeparator = callTypeSeparator;
- this.dateView = dateView;
+ this.callTypeAndDate = callTypeAndDate;
this.numberView = numberView;
}
@@ -57,9 +52,7 @@
return new PhoneCallDetailsViews((TextView) view.findViewById(R.id.name),
view.findViewById(R.id.call_type),
(CallTypeIconsView) view.findViewById(R.id.call_type_icons),
- (TextView) view.findViewById(R.id.call_type_name),
- view.findViewById(R.id.call_type_separator),
- (TextView) view.findViewById(R.id.date),
+ (TextView) view.findViewById(R.id.call_count_and_date),
(TextView) view.findViewById(R.id.number));
}
@@ -69,8 +62,6 @@
new View(context),
new CallTypeIconsView(context),
new TextView(context),
- new View(context),
- new TextView(context),
new TextView(context));
}
}
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 63b41af..ae70c0b 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -39,7 +39,6 @@
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
-import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -760,11 +759,9 @@
}
final boolean isNew = CallLogQuery.isNewSection(c);
- // Use icons for old items, but text for new ones.
- final boolean useIcons = !isNew;
// New items also use the highlighted version of the text.
final boolean isHighlighted = isNew;
- mCallLogViewsHelper.setPhoneCallDetails(views, details, useIcons, isHighlighted);
+ mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted);
setPhoto(views, thumbnailUri, personId, lookupKey);
// Listen for the first draw
diff --git a/src/com/android/contacts/calllog/CallLogListItemHelper.java b/src/com/android/contacts/calllog/CallLogListItemHelper.java
index a448399..a973d49 100644
--- a/src/com/android/contacts/calllog/CallLogListItemHelper.java
+++ b/src/com/android/contacts/calllog/CallLogListItemHelper.java
@@ -48,12 +48,11 @@
*
* @param views the views to populate
* @param details the details of a phone call needed to fill in the data
- * @param useIcons whether to use icons to show the type of the call
* @param isHighlighted whether to use the highlight text for the call
*/
public void setPhoneCallDetails(CallLogListItemViews views, PhoneCallDetails details,
- boolean useIcons, boolean isHighlighted) {
- mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details, useIcons,
+ boolean isHighlighted) {
+ mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details,
isHighlighted);
boolean canCall = mPhoneNumberHelper.canPlaceCallsTo(details.number);
boolean canPlay = details.callTypes[0] == Calls.VOICEMAIL_TYPE;
diff --git a/src/com/android/contacts/calllog/CallTypeHelper.java b/src/com/android/contacts/calllog/CallTypeHelper.java
index d27d4f9..d5d1068 100644
--- a/src/com/android/contacts/calllog/CallTypeHelper.java
+++ b/src/com/android/contacts/calllog/CallTypeHelper.java
@@ -19,12 +19,7 @@
import com.android.contacts.R;
import android.content.res.Resources;
-import android.graphics.Typeface;
import android.provider.CallLog.Calls;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.style.ForegroundColorSpan;
-import android.text.style.StyleSpan;
/**
* Helper class to perform operations related to call types.
@@ -38,10 +33,10 @@
private final CharSequence mMissedName;
/** Name used to identify voicemail calls. */
private final CharSequence mVoicemailName;
- /** Name used to identify new missed calls. */
- private final CharSequence mNewMissedName;
- /** Name used to identify new voicemail calls. */
- private final CharSequence mNewVoicemailName;
+ /** Color used to identify new missed calls. */
+ private final int mNewMissedColor;
+ /** Color used to identify new voicemail calls. */
+ private final int mNewVoicemailColor;
public CallTypeHelper(Resources resources) {
// Cache these values so that we do not need to look them up each time.
@@ -49,10 +44,8 @@
mOutgoingName = resources.getString(R.string.type_outgoing);
mMissedName = resources.getString(R.string.type_missed);
mVoicemailName = resources.getString(R.string.type_voicemail);
- mNewMissedName = addBoldAndColor(mMissedName,
- resources.getColor(R.color.call_log_missed_call_highlight_color));
- mNewVoicemailName = addBoldAndColor(mVoicemailName,
- resources.getColor(R.color.call_log_voicemail_highlight_color));
+ mNewMissedColor = resources.getColor(R.color.call_log_missed_call_highlight_color);
+ mNewVoicemailColor = resources.getColor(R.color.call_log_voicemail_highlight_color);
}
/** Returns the text used to represent the given call type. */
@@ -75,34 +68,25 @@
}
}
- /** Returns the text used to represent the given call type. */
- public CharSequence getHighlightedCallTypeText(int callType) {
+ /** Returns the color used to highlight the given call type, null if not highlight is needed. */
+ public Integer getHighlightedColor(int callType) {
switch (callType) {
case Calls.INCOMING_TYPE:
// New incoming calls are not highlighted.
- return mIncomingName;
+ return null;
case Calls.OUTGOING_TYPE:
// New outgoing calls are not highlighted.
- return mOutgoingName;
+ return null;
case Calls.MISSED_TYPE:
- return mNewMissedName;
+ return mNewMissedColor;
case Calls.VOICEMAIL_TYPE:
- return mNewVoicemailName;
+ return mNewVoicemailColor;
default:
throw new IllegalArgumentException("invalid call type: " + callType);
}
}
-
- /** Creates a SpannableString for the given text which is bold and in the given color. */
- private CharSequence addBoldAndColor(CharSequence text, int color) {
- int flags = Spanned.SPAN_INCLUSIVE_INCLUSIVE;
- SpannableString result = new SpannableString(text);
- result.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), flags);
- result.setSpan(new ForegroundColorSpan(color), 0, text.length(), flags);
- return result;
- }
}