Update the formatting of call log entries.
Use the three line style that is also used in the details view, in fact,
reuse the helper class and layout from that class.
Fix a few cases that were correctly handled by the call log list but not
by the details view.
Change-Id: I32e6516a571d6e3d95b5f0e414a4fc711cb6a51b
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index 5a795e2..a1d2bb7 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -304,8 +304,8 @@
setListAdapter(adapter);
}
mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews,
- new PhoneCallDetails(numberText, callType, date, nameText, numberType,
- numberLabel), false);
+ new PhoneCallDetails(mNumber, numberText, callType, date, nameText,
+ numberType, numberLabel), false);
loadContactPhotos(photoId);
} else {
diff --git a/src/com/android/contacts/PhoneCallDetails.java b/src/com/android/contacts/PhoneCallDetails.java
index 8ed6bee..c5c37df 100644
--- a/src/com/android/contacts/PhoneCallDetails.java
+++ b/src/com/android/contacts/PhoneCallDetails.java
@@ -25,6 +25,8 @@
public class PhoneCallDetails {
/** The number of the other party involved in the call. */
public final CharSequence number;
+ /** The formatted version of {@link #number}. */
+ public final CharSequence formattedNumber;
/** The type of call, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}. */
public final int callType;
/** The date of the call, in milliseconds since the epoch. */
@@ -37,14 +39,16 @@
public final CharSequence numberLabel;
/** Create the details for a call with a number not associated with a contact. */
- public PhoneCallDetails(CharSequence number, int callType, long date) {
- this(number, callType, date, "", 0, "");
+ public PhoneCallDetails(CharSequence number, CharSequence formattedNumber, int callType,
+ long date) {
+ this(number, formattedNumber, callType, date, "", 0, "");
}
/** Create the details for a call with a number associated with a contact. */
- public PhoneCallDetails(CharSequence number, int callType, long date, CharSequence name,
- int numberType, CharSequence numberLabel) {
+ public PhoneCallDetails(CharSequence number, CharSequence formattedNumber, int callType,
+ long date, CharSequence name, int numberType, CharSequence numberLabel) {
this.number = number;
+ this.formattedNumber = formattedNumber;
this.callType = callType;
this.date = date;
this.name = name;
diff --git a/src/com/android/contacts/PhoneCallDetailsHelper.java b/src/com/android/contacts/PhoneCallDetailsHelper.java
index b52dacb..4605799 100644
--- a/src/com/android/contacts/PhoneCallDetailsHelper.java
+++ b/src/com/android/contacts/PhoneCallDetailsHelper.java
@@ -162,11 +162,11 @@
final CharSequence nameText;
final CharSequence numberText;
if (TextUtils.isEmpty(details.name)) {
- nameText = getDisplayNumber(details.number);
+ nameText = getDisplayNumber(details.number, details.formattedNumber);
numberText = "";
} else {
nameText = details.name;
- CharSequence displayNumber = getDisplayNumber(details.number);
+ CharSequence displayNumber = getDisplayNumber(details.number, details.formattedNumber);
if (details.callType != 0 && numberFormattedLabel != null) {
numberText = FormatUtils.applyStyleToSpan(Typeface.BOLD,
numberFormattedLabel + " " + displayNumber, 0,
@@ -191,7 +191,7 @@
}
}
- private CharSequence getDisplayNumber(CharSequence number) {
+ private CharSequence getDisplayNumber(CharSequence number, CharSequence formattedNumber) {
if (TextUtils.isEmpty(number)) {
return "";
}
@@ -207,7 +207,11 @@
if (PhoneNumberUtils.extractNetworkPortion(number.toString()).equals(mVoicemailNumber)) {
return mResources.getString(R.string.voicemail);
}
- return number;
+ if (TextUtils.isEmpty(formattedNumber)) {
+ return number;
+ } else {
+ return formattedNumber;
+ }
}
public void setCurrentTimeForTest(long currentTimeMillis) {
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 79ddd7b..331bb1f 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -20,6 +20,8 @@
import com.android.contacts.CallDetailActivity;
import com.android.contacts.ContactPhotoManager;
import com.android.contacts.ContactsUtils;
+import com.android.contacts.PhoneCallDetails;
+import com.android.contacts.PhoneCallDetailsHelper;
import com.android.contacts.R;
import com.android.contacts.activities.DialtactsActivity.ViewPagerVisibilityListener;
import com.android.contacts.util.ExpirableCache;
@@ -64,10 +66,8 @@
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
-import android.widget.ImageView;
import android.widget.ListView;
import android.widget.QuickContactBadge;
-import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.LinkedList;
@@ -265,23 +265,25 @@
mRequests = new LinkedList<CallerInfoQuery>();
mPreDrawListener = null;
- Drawable drawableIncoming = getResources().getDrawable(
+ Drawable incomingDrawable = getResources().getDrawable(
R.drawable.ic_call_log_list_incoming_call);
- Drawable drawableOutgoing = getResources().getDrawable(
+ Drawable outgoingDrawable = getResources().getDrawable(
R.drawable.ic_call_log_list_outgoing_call);
- Drawable drawableMissed = getResources().getDrawable(
+ Drawable missedDrawable = getResources().getDrawable(
R.drawable.ic_call_log_list_missed_call);
- Drawable drawableVoicemail = getResources().getDrawable(
+ Drawable voicemailDrawable = getResources().getDrawable(
R.drawable.ic_call_log_list_voicemail);
- Drawable drawableCall = getResources().getDrawable(
+ Drawable callDrawable = getResources().getDrawable(
R.drawable.ic_call_log_list_action_call);
- Drawable drawablePlay = getResources().getDrawable(
+ Drawable playDrawable = getResources().getDrawable(
R.drawable.ic_call_log_list_action_play);
mContactPhotoManager = ContactPhotoManager.getInstance(getActivity());
- mCallLogViewsHelper = new CallLogListItemHelper(getResources(), mVoiceMailNumber,
- drawableIncoming, drawableOutgoing, drawableMissed, drawableVoicemail,
- drawableCall, drawablePlay);
+ PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
+ getActivity(), getResources(), mVoiceMailNumber, incomingDrawable,
+ outgoingDrawable, missedDrawable, voicemailDrawable);
+ mCallLogViewsHelper = new CallLogListItemHelper(phoneCallDetailsHelper, callDrawable,
+ playDrawable);
}
/**
@@ -651,27 +653,15 @@
int groupIndicator = expanded
? com.android.internal.R.drawable.expander_ic_maximized
: com.android.internal.R.drawable.expander_ic_minimized;
- views.groupIndicator.setImageResource(groupIndicator);
- views.groupSize.setText("(" + groupSize + ")");
bindView(context, view, cursor);
}
private void findAndCacheViews(View view) {
-
- // Get the views to bind to
- CallLogListItemViews views = new CallLogListItemViews();
- views.line1View = (TextView) view.findViewById(R.id.line1);
- views.labelView = (TextView) view.findViewById(R.id.label);
- views.numberView = (TextView) view.findViewById(R.id.number);
- views.dateView = (TextView) view.findViewById(R.id.date);
- views.iconView = (ImageView) view.findViewById(R.id.call_type_icon);
- views.callView = (ImageView) view.findViewById(R.id.call_icon);
+ // Get the views to bind to.
+ CallLogListItemViews views = CallLogListItemViews.fromView(view);
if (views.callView != null) {
views.callView.setOnClickListener(this);
}
- views.groupIndicator = (ImageView) view.findViewById(R.id.groupIndicator);
- views.groupSize = (TextView) view.findViewById(R.id.groupSize);
- views.photoView = (QuickContactBadge) view.findViewById(R.id.contact_photo);
view.setTag(views);
}
@@ -679,6 +669,8 @@
final CallLogListItemViews views = (CallLogListItemViews) view.getTag();
String number = c.getString(CallLogQuery.NUMBER);
+ long date = c.getLong(CallLogQuery.DATE);
+ int callType = c.getInt(CallLogQuery.CALL_TYPE);
final String formattedNumber;
String callerName = c.getString(CallLogQuery.CALLER_NAME);
int callerNumberType = c.getInt(CallLogQuery.CALLER_NUMBERTYPE);
@@ -760,18 +752,14 @@
views.callView.setVisibility(View.VISIBLE);
}
- if (!TextUtils.isEmpty(name)) {
- mCallLogViewsHelper.setContactNameLabelAndNumber(views, name, number, ntype, label,
- formattedNumber);
+ final PhoneCallDetails details;
+ if (TextUtils.isEmpty(name)) {
+ details = new PhoneCallDetails(number, formattedNumber, callType, date);
} else {
- // TODO: Do we need to format the number again? Is formattedNumber already storing
- // this value?
- mCallLogViewsHelper.setContactNumberOnly(views, number,
- formatPhoneNumber(number, null, countryIso));
+ details = new PhoneCallDetails(number, formattedNumber, callType, date, name,
+ ntype, label);
}
- mCallLogViewsHelper.setDate(views, c.getLong(CallLogQuery.DATE),
- System.currentTimeMillis());
- mCallLogViewsHelper.setCallType(views, c.getInt(CallLogQuery.CALL_TYPE));
+ mCallLogViewsHelper.setPhoneCallDetails(views, details , true);
if (views.photoView != null) {
bindQuickContact(views.photoView, photoId, contactId, lookupKey);
}
diff --git a/src/com/android/contacts/calllog/CallLogListItemHelper.java b/src/com/android/contacts/calllog/CallLogListItemHelper.java
index 56399c0..462b0b3 100644
--- a/src/com/android/contacts/calllog/CallLogListItemHelper.java
+++ b/src/com/android/contacts/calllog/CallLogListItemHelper.java
@@ -16,220 +16,63 @@
package com.android.contacts.calllog;
-import com.android.contacts.R;
+import com.android.contacts.PhoneCallDetails;
+import com.android.contacts.PhoneCallDetailsHelper;
import com.android.internal.telephony.CallerInfo;
-import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.provider.CallLog.Calls;
-import android.provider.ContactsContract.CommonDataKinds.Phone;
-import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
-import android.text.format.DateUtils;
import android.view.View;
-import android.view.ViewGroup;
/**
* Helper class to fill in the views of a call log entry.
*/
/*package*/ class CallLogListItemHelper {
- /** The resources used to look up strings. */
- private final Resources mResources;
- /** The voicemail number. */
- private final String mVoiceMailNumber;
- /** Icon for incoming calls. */
- private final Drawable mDrawableIncoming;
- /** Icon for outgoing calls. */
- private final Drawable mDrawableOutgoing;
- /** Icon for missed calls. */
- private final Drawable mDrawableMissed;
- /** Icon for voicemails. */
- private final Drawable mDrawableVoicemail;
+ /** Helper for populating the details of a phone call. */
+ private final PhoneCallDetailsHelper mPhoneCallDetailsHelper;
/** Icon for the call action. */
- private final Drawable mDrawableCall;
+ private final Drawable mCallDrawable;
/** Icon for the play action. */
- private final Drawable mDrawablePlay;
+ private final Drawable mPlayDrawable;
/**
* Creates a new helper instance.
*
- * @param resources used to look up strings
- * @param voicemailNumber the voicemail number, used to determine if a call was to voicemail
- * @param drawableIncoming the icon drawn besides an incoming call entry
- * @param drawableOutgoing the icon drawn besides an outgoing call entry
- * @param drawableMissed the icon drawn besides a missed call entry
+ * @param phoneCallDetailsHelper used to set the details of a phone call
+ * @param callDrawable used to render the call button, for calling back a person
+ * @param playDrawable used to render the play button, for playing a voicemail
*/
- public CallLogListItemHelper(Resources resources, String voicemailNumber,
- Drawable drawableIncoming, Drawable drawableOutgoing, Drawable drawableMissed,
- Drawable drawableVoicemail, Drawable drawableCall, Drawable drawablePlay) {
- mResources = resources;
- mVoiceMailNumber = voicemailNumber;
- mDrawableIncoming = drawableIncoming;
- mDrawableOutgoing = drawableOutgoing;
- mDrawableMissed = drawableMissed;
- mDrawableVoicemail = drawableVoicemail;
- mDrawableCall = drawableCall;
- mDrawablePlay = drawablePlay;
+ public CallLogListItemHelper(PhoneCallDetailsHelper phoneCallDetailsHelper,
+ Drawable callDrawable, Drawable playDrawable) {
+ mPhoneCallDetailsHelper = phoneCallDetailsHelper;
+ mCallDrawable = callDrawable;
+ mPlayDrawable = playDrawable;
}
/**
* Sets the name, label, and number for a contact.
*
* @param views the views to populate
- * @param name the name of the contact
- * @param number the number of the contact
- * @param numberType the type of the number as it appears in the contact, e.g.,
- * {@link Phone#TYPE_HOME}
- * @param label the label of the number, only used if numberType is {@link Phone#TYPE_CUSTOM}
- * @param formattedNumber the formatted version of the number above
+ * @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
*/
- public void setContactNameLabelAndNumber(CallLogListItemViews views, String name, String number,
- int numberType, String label, String formattedNumber) {
- views.line1View.setText(name);
- views.labelView.setVisibility(View.VISIBLE);
-
- // "type" and "label" are currently unused for SIP addresses.
- CharSequence numberLabel = null;
- if (!PhoneNumberUtils.isUriNumber(number)) {
- numberLabel = Phone.getTypeLabel(mResources, numberType, label);
- }
- views.numberView.setVisibility(View.VISIBLE);
- views.numberView.setText(formattedNumber);
- if (!TextUtils.isEmpty(numberLabel)) {
- views.labelView.setText(numberLabel);
- views.labelView.setVisibility(View.VISIBLE);
-
- // Zero out the numberView's left margin (see below)
- ViewGroup.MarginLayoutParams numberLP =
- (ViewGroup.MarginLayoutParams) views.numberView.getLayoutParams();
- numberLP.leftMargin = 0;
- views.numberView.setLayoutParams(numberLP);
- } else {
- // There's nothing to display in views.labelView, so hide it.
- // We can't set it to View.GONE, since it's the anchor for
- // numberView in the RelativeLayout, so make it INVISIBLE.
- // Also, we need to manually *subtract* some left margin from
- // numberView to compensate for the right margin built in to
- // labelView (otherwise the number will be indented by a very
- // slight amount).
- // TODO: a cleaner fix would be to contain both the label and
- // number inside a LinearLayout, and then set labelView *and*
- // its padding to GONE when there's no label to display.
- views.labelView.setText(null);
- views.labelView.setVisibility(View.INVISIBLE);
-
- ViewGroup.MarginLayoutParams labelLP =
- (ViewGroup.MarginLayoutParams) views.labelView.getLayoutParams();
- ViewGroup.MarginLayoutParams numberLP =
- (ViewGroup.MarginLayoutParams) views.numberView.getLayoutParams();
- // Equivalent to setting android:layout_marginLeft in XML
- numberLP.leftMargin = -labelLP.rightMargin;
- views.numberView.setLayoutParams(numberLP);
- }
- }
-
- /**
- * Sets the number in a call log entry.
- * <p>
- * To be used if we do not have a contact with this number.
- *
- * @param views the views to populate
- * @param number the number of the contact
- * @param formattedNumber the formatted version of the number above
- */
- public void setContactNumberOnly(final CallLogListItemViews views, String number,
- String formattedNumber) {
- if (number.equals(CallerInfo.UNKNOWN_NUMBER)) {
- number = mResources.getString(R.string.unknown);
- if (views.callView != null) {
- views.callView.setVisibility(View.INVISIBLE);
- }
- } else if (number.equals(CallerInfo.PRIVATE_NUMBER)) {
- number = mResources.getString(R.string.private_num);
- if (views.callView != null) {
- views.callView.setVisibility(View.INVISIBLE);
- }
- } else if (number.equals(CallerInfo.PAYPHONE_NUMBER)) {
- number = mResources.getString(R.string.payphone);
- if (views.callView != null) {
- views.callView.setVisibility(View.INVISIBLE);
- }
- } else if (PhoneNumberUtils.extractNetworkPortion(number)
- .equals(mVoiceMailNumber)) {
- number = mResources.getString(R.string.voicemail);
- } else {
- // Just a phone number, so use the formatted version of the number.
- number = formattedNumber;
- }
-
- views.line1View.setText(number);
- views.numberView.setVisibility(View.GONE);
- views.labelView.setVisibility(View.GONE);
- }
-
- /**
- * Sets the date in the views.
- *
- * @param views the views to populate
- * @param date the date of the call log entry
- * @param now the current time relative to which the date should be formatted
- */
- public void setDate(final CallLogListItemViews views, long date, long now) {
- views.dateView.setText(
- DateUtils.getRelativeTimeSpanString(
- date, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));
- }
-
- /**
- * Sets the type of the call in the views.
- *
- * @param views the views to populate
- * @param type the type of call log entry, e.g., {@link Calls#INCOMING_TYPE}
- */
- public void setCallType(final CallLogListItemViews views, int type) {
- if (views.iconView != null) {
- // Set the call type icon.
- Drawable drawable = null;
- switch (type) {
- case Calls.INCOMING_TYPE:
- drawable = mDrawableIncoming;
- break;
-
- case Calls.OUTGOING_TYPE:
- drawable = mDrawableOutgoing;
- break;
-
- case Calls.MISSED_TYPE:
- drawable = mDrawableMissed;
- break;
-
- case Calls.VOICEMAIL_TYPE:
- drawable = mDrawableVoicemail;
- break;
-
- default:
- throw new IllegalArgumentException("invalid call type: " + type);
- }
- views.iconView.setImageDrawable(drawable);
- }
+ public void setPhoneCallDetails(CallLogListItemViews views, PhoneCallDetails details,
+ boolean useIcons) {
+ mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details, useIcons);
if (views.callView != null) {
- // Set the action icon.
- Drawable drawable = null;
- switch (type) {
- case Calls.INCOMING_TYPE:
- case Calls.OUTGOING_TYPE:
- case Calls.MISSED_TYPE:
- drawable = mDrawableCall;
- break;
-
- case Calls.VOICEMAIL_TYPE:
- drawable = mDrawablePlay;
- break;
-
- default:
- throw new IllegalArgumentException("invalid call type: " + type);
- }
- views.callView.setImageDrawable(drawable);
+ views.callView.setImageDrawable(
+ details.callType == Calls.VOICEMAIL_TYPE ? mPlayDrawable : mCallDrawable);
+ views.callView.setVisibility(
+ canPlaceCallsTo(details.number) ? View.VISIBLE : View.INVISIBLE);
}
}
+
+ /** Returns true if it is possible to place a call to the given number. */
+ public boolean canPlaceCallsTo(CharSequence number) {
+ return !(TextUtils.isEmpty(number)
+ || number.equals(CallerInfo.UNKNOWN_NUMBER)
+ || number.equals(CallerInfo.PRIVATE_NUMBER)
+ || number.equals(CallerInfo.PAYPHONE_NUMBER));
+ }
}
diff --git a/src/com/android/contacts/calllog/CallLogListItemViews.java b/src/com/android/contacts/calllog/CallLogListItemViews.java
index 7264c96..0cf15cc 100644
--- a/src/com/android/contacts/calllog/CallLogListItemViews.java
+++ b/src/com/android/contacts/calllog/CallLogListItemViews.java
@@ -16,37 +16,39 @@
package com.android.contacts.calllog;
+import com.android.contacts.PhoneCallDetailsViews;
+import com.android.contacts.R;
+
+import android.view.View;
import android.widget.ImageView;
import android.widget.QuickContactBadge;
-import android.widget.TextView;
/**
* Simple value object containing the various views within a call log entry.
*/
public final class CallLogListItemViews {
- /** The first line in the call log entry, containing either the name or the number. */
- public TextView line1View;
- /** The label associated with the phone number. */
- public TextView labelView;
- /**
- * The number the call was from or to.
- * <p>
- * Only filled in if the number is not already in the first line, i.e., {@link #line1View}.
- */
- public TextView numberView;
- /** The date of the call. */
- public TextView dateView;
- /** The icon indicating the type of call. */
- public ImageView iconView;
- /** The icon used to place a call to the contact. Only present for non-group entries. */
- public ImageView callView;
- /** The icon used to expand and collapse an entry. Only present for group entries. */
- public ImageView groupIndicator;
- /**
- * The text view containing the number of items in the group. Only present for group
- * entries.
- */
- public TextView groupSize;
/** The quick contact badge for the contact. Only present for group and stand alone entries. */
- public QuickContactBadge photoView;
+ public final QuickContactBadge photoView;
+ /** The main action button on the entry. */
+ public final ImageView callView;
+ /** The details of the phone call. */
+ public final PhoneCallDetailsViews phoneCallDetailsViews;
+
+ private CallLogListItemViews(QuickContactBadge photoView, ImageView callView,
+ PhoneCallDetailsViews phoneCallDetailsViews) {
+ this.photoView = photoView;
+ this.callView = callView;
+ this.phoneCallDetailsViews = phoneCallDetailsViews;
+ }
+
+ public static CallLogListItemViews fromView(View view) {
+ return new CallLogListItemViews((QuickContactBadge) view.findViewById(R.id.contact_photo),
+ (ImageView) view.findViewById(R.id.call_icon),
+ PhoneCallDetailsViews.fromView(view));
+ }
+
+ public static CallLogListItemViews createForTest(QuickContactBadge photoView,
+ ImageView callView, PhoneCallDetailsViews phoneCallDetailsViews) {
+ return new CallLogListItemViews(photoView, callView, phoneCallDetailsViews);
+ }
}