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/res/layout/call_detail.xml b/res/layout/call_detail.xml
index 1fe6faa..6a03493 100644
--- a/res/layout/call_detail.xml
+++ b/res/layout/call_detail.xml
@@ -52,7 +52,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/contact_background"
- android:background="?attr/call_detail_primary_background_color"
+ android:background="?attr/call_log_primary_background_color"
/>
<LinearLayout
android:layout_width="match_parent"
@@ -96,14 +96,14 @@
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingLeft="80dp"
- android:background="?attr/call_detail_secondary_background_color"
+ android:background="?attr/call_log_secondary_background_color"
>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
- android:textColor="?attr/call_detail_secondary_text_color"
+ android:textColor="?attr/call_log_secondary_text_color"
/>
<TextView
android:id="@+id/duration"
@@ -112,7 +112,7 @@
android:layout_alignParentLeft="true"
android:layout_below="@id/time"
android:layout_alignLeft="@id/time"
- android:textColor="?attr/call_detail_secondary_text_color"
+ android:textColor="?attr/call_log_secondary_text_color"
/>
<ImageView
android:id="@+id/delete"
diff --git a/res/layout/call_log_contact_photo.xml b/res/layout/call_log_contact_photo.xml
index 178c45b..552e9ca 100644
--- a/res/layout/call_log_contact_photo.xml
+++ b/res/layout/call_log_contact_photo.xml
@@ -2,9 +2,9 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<QuickContactBadge
android:id="@+id/contact_photo"
- android:layout_width="?attr/call_log_contact_photo_size"
- android:layout_height="?attr/call_log_contact_photo_size"
- android:layout_margin="?attr/call_log_contact_photo_margin"
+ android:layout_width="?attr/call_log_list_contact_photo_size"
+ android:layout_height="?attr/call_log_list_contact_photo_size"
+ android:layout_margin="?attr/call_log_list_contact_photo_margin"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
/>
diff --git a/res/layout/call_log_list_group_item.xml b/res/layout/call_log_list_group_item.xml
index 352d7ec..57465a6 100644
--- a/res/layout/call_log_list_group_item.xml
+++ b/res/layout/call_log_list_group_item.xml
@@ -21,75 +21,5 @@
<include layout="@layout/call_log_contact_photo"/>
<include layout="@layout/call_log_action_group"/>
-
- <TextView android:id="@+id/date"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@id/divider"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="8dip"
- android:layout_marginLeft="10dip"
-
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:singleLine="true"
- />
-
- <TextView android:id="@+id/label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- android:layout_marginLeft="86dip"
- android:layout_marginRight="5dip"
- android:layout_alignBaseline="@id/date"
-
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textStyle="bold"
- />
-
- <TextView android:id="@+id/number"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/label"
- android:layout_toLeftOf="@id/date"
- android:layout_alignBaseline="@id/label"
- android:layout_alignWithParentIfMissing="true"
-
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- />
-
- <TextView android:id="@+id/groupSize"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_toLeftOf="@id/divider"
- android:layout_above="@id/date"
- android:layout_alignWithParentIfMissing="true"
- android:layout_marginBottom="-10dip"
-
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:singleLine="true"
- android:gravity="center_vertical"
- />
-
- <TextView android:id="@+id/line1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_toLeftOf="@+id/groupSize"
- android:layout_above="@id/date"
- android:layout_alignWithParentIfMissing="true"
- android:layout_marginLeft="86dip"
- android:layout_marginBottom="-10dip"
-
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:singleLine="true"
- android:ellipsize="marquee"
- android:gravity="center_vertical"
- />
+ <include layout="@layout/call_log_list_item_layout" />
</RelativeLayout>
diff --git a/res/layout/call_log_list_item_layout.xml b/res/layout/call_log_list_item_layout.xml
index 2128a79..8ea2bf7 100644
--- a/res/layout/call_log_list_item_layout.xml
+++ b/res/layout/call_log_list_item_layout.xml
@@ -15,69 +15,12 @@
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
-
- <ImageView android:id="@+id/call_type_icon"
+ <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:layout_marginLeft="54dip"
- />
-
- <TextView android:id="@+id/date"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@id/divider"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="8dip"
- android:layout_marginLeft="10dip"
-
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:singleLine="true"
- />
-
- <TextView android:id="@+id/label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- android:layout_marginLeft="86dip"
- android:layout_marginRight="5dip"
- android:layout_alignBaseline="@id/date"
-
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textStyle="bold"
- />
-
- <TextView android:id="@+id/number"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/label"
- android:layout_toLeftOf="@id/date"
- android:layout_alignBaseline="@id/label"
- android:layout_alignWithParentIfMissing="true"
-
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- />
-
- <TextView android:id="@+id/line1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
+ android:layout_toRightOf="@id/contact_photo"
android:layout_alignParentTop="true"
- android:layout_toLeftOf="@id/divider"
- android:layout_above="@id/date"
- android:layout_alignWithParentIfMissing="true"
- android:layout_marginLeft="86dip"
- android:layout_marginBottom="-10dip"
-
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:singleLine="true"
- android:ellipsize="marquee"
- android:gravity="center_vertical"
- />
+ >
+ <include layout="@layout/call_log_phone_call_details"/>
+ </RelativeLayout>
</merge>
diff --git a/res/layout/call_log_phone_call_details.xml b/res/layout/call_log_phone_call_details.xml
index 5d167f1..f22efba 100644
--- a/res/layout/call_log_phone_call_details.xml
+++ b/res/layout/call_log_phone_call_details.xml
@@ -32,15 +32,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?attr/call_detail_primary_text_color"
+ android:textColor="?attr/call_log_primary_text_color"
/>
<TextView
android:id="@+id/call_type_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginLeft="?attr/call_detail_date_margin"
+ android:layout_marginLeft="?attr/call_log_date_margin"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?attr/call_detail_primary_text_color"
+ android:textColor="?attr/call_log_primary_text_color"
android:text="@string/call_log_type_date_separator"
/>
</LinearLayout>
@@ -49,9 +49,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?attr/call_detail_primary_text_color"
+ android:textColor="?attr/call_log_primary_text_color"
android:layout_toRightOf="@id/call_type"
- android:layout_marginLeft="?attr/call_detail_date_margin"
+ android:layout_marginLeft="?attr/call_log_date_margin"
android:layout_alignParentBottom="true"
/>
<TextView
@@ -59,7 +59,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?attr/call_detail_primary_text_color"
+ android:textColor="?attr/call_log_primary_text_color"
android:layout_alignParentLeft="true"
android:layout_above="@id/call_type"
/>
@@ -68,7 +68,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
- android:textColor="?attr/call_detail_primary_text_color"
+ android:textColor="?attr/call_log_primary_text_color"
android:layout_alignParentLeft="true"
android:layout_above="@id/number"
android:paddingBottom="2dp"
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 914532c..e4b7a86 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -36,10 +36,16 @@
<item name="list_item_header_text_color">#ffcccccc</item>
<item name="list_item_header_text_size">14sp</item>
<item name="contact_filter_popup_width">320dip</item>
- <!-- CallLogActivity -->
- <item name="call_log_contact_photo_size">50dip</item>
- <item name="call_log_contact_photo_margin">5dip</item>
+ <!-- CallLogList -->
+ <item name="call_log_list_contact_photo_size">50dip</item>
+ <item name="call_log_list_contact_photo_margin">5dip</item>
<item name="call_log_list_item_height">60dip</item>
+ <!-- CallLog -->
+ <item name="call_log_date_margin">5dip</item>
+ <item name="call_log_primary_text_color">#FFFFFF</item>
+ <item name="call_log_primary_background_color">#000000</item>
+ <item name="call_log_secondary_text_color">#FFFFFF</item>
+ <item name="call_log_secondary_background_color">#333333</item>
</style>
<style name="CallDetailActivityTheme" parent="android:Theme.Holo">
@@ -51,11 +57,12 @@
<item name="call_detail_action_bar_height">60dip</item>
<item name="call_detail_action_icon_size">60dip</item>
<item name="call_detail_contact_background_overlay_alpha">0.25</item>
- <item name="call_detail_primary_text_color">#FFFFFF</item>
- <item name="call_detail_date_margin">5dip</item>
- <item name="call_detail_primary_background_color">#000000</item>
- <item name="call_detail_secondary_text_color">#FFFFFF</item>
- <item name="call_detail_secondary_background_color">#333333</item>
+ <!-- CallLog -->
+ <item name="call_log_date_margin">5dip</item>
+ <item name="call_log_primary_text_color">#FFFFFF</item>
+ <item name="call_log_primary_background_color">#000000</item>
+ <item name="call_log_secondary_text_color">#FFFFFF</item>
+ <item name="call_log_secondary_background_color">#333333</item>
</style>
<style name="ContactDetailActivityTheme" parent="android:Theme.Holo.Light">
@@ -138,16 +145,19 @@
<attr name="call_detail_contact_photo_size" format="dimension" />
<attr name="call_detail_action_icon_size" format="dimension" />
<attr name="call_detail_action_bar_height" format="dimension" />
- <attr name="call_detail_primary_text_color" format="color" />
- <attr name="call_detail_primary_background_color" format="color" />
- <attr name="call_detail_secondary_text_color" format="color" />
- <attr name="call_detail_secondary_background_color" format="color" />
- <attr name="call_detail_date_margin" format="dimension" />
</declare-styleable>
- <declare-styleable name="CallLogActivity">
- <attr name="call_log_contact_photo_size" format="dimension" />
- <attr name="call_log_contact_photo_margin" format="dimension" />
+ <declare-styleable name="CallLog">
+ <attr name="call_log_primary_text_color" format="color" />
+ <attr name="call_log_primary_background_color" format="color" />
+ <attr name="call_log_secondary_text_color" format="color" />
+ <attr name="call_log_secondary_background_color" format="color" />
+ <attr name="call_log_date_margin" format="dimension" />
+ </declare-styleable>
+
+ <declare-styleable name="CallLogList">
+ <attr name="call_log_list_contact_photo_size" format="dimension" />
+ <attr name="call_log_list_contact_photo_margin" format="dimension" />
<attr name="call_log_list_item_height" format="dimension" />
</declare-styleable>
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);
+ }
}
diff --git a/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java b/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java
index 37e16a3..8b8baae 100644
--- a/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java
+++ b/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java
@@ -42,7 +42,9 @@
/** The date of the call log entry. */
private static final long TEST_DATE = 1300000000;
/** The number of the caller/callee in the log entry. */
- private static final String TEST_NUMBER = "1-412-555-5555";
+ private static final String TEST_NUMBER = "14125555555";
+ /** The formatted version of {@link #TEST_NUMBER}. */
+ private static final String TEST_FORMATTED_NUMBER = "1-412-255-5555";
/** A drawable to be used for incoming calls. */
private static final Drawable TEST_INCOMING_DRAWABLE = new ColorDrawable(Color.BLACK);
/** A drawable to be used for outgoing calls. */
@@ -77,27 +79,27 @@
}
public void testSetPhoneCallDetails_Unknown() {
- setPhoneCallDetailsWithNumber(CallerInfo.UNKNOWN_NUMBER);
+ setPhoneCallDetailsWithNumber(CallerInfo.UNKNOWN_NUMBER, CallerInfo.UNKNOWN_NUMBER);
assertNameEqualsResource(R.string.unknown);
}
public void testSetPhoneCallDetails_Private() {
- setPhoneCallDetailsWithNumber(CallerInfo.PRIVATE_NUMBER);
+ setPhoneCallDetailsWithNumber(CallerInfo.PRIVATE_NUMBER, CallerInfo.PRIVATE_NUMBER);
assertNameEqualsResource(R.string.private_num);
}
public void testSetPhoneCallDetails_Payphone() {
- setPhoneCallDetailsWithNumber(CallerInfo.PAYPHONE_NUMBER);
+ setPhoneCallDetailsWithNumber(CallerInfo.PAYPHONE_NUMBER, CallerInfo.PAYPHONE_NUMBER);
assertNameEqualsResource(R.string.payphone);
}
public void testSetPhoneCallDetails_Voicemail() {
- setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER);
+ setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER, TEST_VOICEMAIL_NUMBER);
assertNameEqualsResource(R.string.voicemail);
}
public void testSetPhoneCallDetails_Normal() {
- setPhoneCallDetailsWithNumber("1-412-555-1212");
+ setPhoneCallDetailsWithNumber("14125551212", "1-412-555-1212");
assertNameEquals("1-412-555-1212");
}
@@ -199,22 +201,23 @@
}
/** Sets the phone call details with default values and the given number. */
- private void setPhoneCallDetailsWithNumber(String number) {
+ private void setPhoneCallDetailsWithNumber(String number, String formattedNumber) {
mHelper.setPhoneCallDetails(mViews,
- new PhoneCallDetails(number, Calls.INCOMING_TYPE, TEST_DATE),
+ new PhoneCallDetails(number, formattedNumber, Calls.INCOMING_TYPE, TEST_DATE),
false);
}
/** Sets the phone call details with default values and the given date. */
private void setPhoneCallDetailsWithDate(long date) {
mHelper.setPhoneCallDetails(mViews,
- new PhoneCallDetails(TEST_NUMBER, Calls.INCOMING_TYPE, date),
+ new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, Calls.INCOMING_TYPE, date),
false);
}
/** Sets the phone call details with default values and the given call type. */
private void setPhoneCallDetailsWithCallType(int callType, boolean useIcons) {
- mHelper.setPhoneCallDetails(mViews, new PhoneCallDetails(TEST_NUMBER, callType, TEST_DATE),
+ mHelper.setPhoneCallDetails(mViews,
+ new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, callType, TEST_DATE),
useIcons);
}
}
diff --git a/tests/src/com/android/contacts/activities/CallLogActivityTests.java b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
index 6421a9e..2eac88e 100644
--- a/tests/src/com/android/contacts/activities/CallLogActivityTests.java
+++ b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
@@ -67,9 +67,9 @@
static private final long NOW = -1L;
/** A phone number to be used in tests. */
- private static final String TEST_PHONE_NUMBER = "12125551000";
- /** The formatted version of {@link #TEST_PHONE_NUMBER}. */
- private static final String TEST_FORMATTED_PHONE_NUMBER = "1 212-555-1000";
+ private static final String TEST_NUMBER = "12125551000";
+ /** The formatted version of {@link #TEST_NUMBER}. */
+ private static final String TEST_FORMATTED_NUMBER = "1 212-555-1000";
// We get the call list activity and assign is a frame to build
// its list. mAdapter is an inner class of
@@ -185,28 +185,26 @@
@MediumTest
public void testBindView_NumberOnly() {
mCursor.moveToFirst();
- insert(TEST_PHONE_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+ insert(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
View view = mAdapter.newStandAloneView(getActivity(), mParentView);
mAdapter.bindStandAloneView(view, getActivity(), mCursor);
CallLogListItemViews views = (CallLogListItemViews) view.getTag();
- assertNameIs(views, TEST_FORMATTED_PHONE_NUMBER);
- assertNumberLabelIsGone(views);
- assertNumberIsGone(views);
+ assertNameIs(views, TEST_FORMATTED_NUMBER);
+ assertNumberAndLabelAreGone(views);
}
@MediumTest
public void testBindView_WithCachedName() {
mCursor.moveToFirst();
- insertWithCachedValues(TEST_PHONE_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
+ insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
"John Doe", Phone.TYPE_HOME, "");
View view = mAdapter.newStandAloneView(getActivity(), mParentView);
mAdapter.bindStandAloneView(view, getActivity(), mCursor);
CallLogListItemViews views = (CallLogListItemViews) view.getTag();
assertNameIs(views, "John Doe");
- assertNumberLabelIsVisible(views);
- assertNumberIs(views, TEST_FORMATTED_PHONE_NUMBER);
+ assertNumberAndLabelAre(views, TEST_FORMATTED_NUMBER, getTypeLabel(Phone.TYPE_HOME));
}
@MediumTest
@@ -219,51 +217,47 @@
CallLogListItemViews views = (CallLogListItemViews) view.getTag();
assertNameIs(views, "John Doe");
- assertNumberLabelIsInvisible(views);
- assertNumberIs(views, "sip:johndoe@gmail.com");
+ assertNumberAndLabelAre(views, "sip:johndoe@gmail.com", null);
}
@MediumTest
public void testBindView_HomeLabel() {
mCursor.moveToFirst();
- insertWithCachedValues(TEST_PHONE_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
+ insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
"John Doe", Phone.TYPE_HOME, "");
View view = mAdapter.newStandAloneView(getActivity(), mParentView);
mAdapter.bindStandAloneView(view, getActivity(), mCursor);
CallLogListItemViews views = (CallLogListItemViews) view.getTag();
assertNameIs(views, "John Doe");
- assertNumberLabelIs(views, getTypeLabel(Phone.TYPE_HOME));
- assertNumberIsVisible(views);
+ assertNumberAndLabelAre(views, TEST_FORMATTED_NUMBER, getTypeLabel(Phone.TYPE_HOME));
}
@MediumTest
public void testBindView_WorkLabel() {
mCursor.moveToFirst();
- insertWithCachedValues(TEST_PHONE_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
+ insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
"John Doe", Phone.TYPE_WORK, "");
View view = mAdapter.newStandAloneView(getActivity(), mParentView);
mAdapter.bindStandAloneView(view, getActivity(), mCursor);
CallLogListItemViews views = (CallLogListItemViews) view.getTag();
assertNameIs(views, "John Doe");
- assertNumberLabelIs(views, getTypeLabel(Phone.TYPE_WORK));
- assertNumberIsVisible(views);
+ assertNumberAndLabelAre(views, TEST_FORMATTED_NUMBER, getTypeLabel(Phone.TYPE_WORK));
}
@MediumTest
public void testBindView_CustomLabel() {
mCursor.moveToFirst();
String numberLabel = "My label";
- insertWithCachedValues(TEST_PHONE_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
+ insertWithCachedValues(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE,
"John Doe", Phone.TYPE_CUSTOM, numberLabel);
View view = mAdapter.newStandAloneView(getActivity(), mParentView);
mAdapter.bindStandAloneView(view, getActivity(), mCursor);
CallLogListItemViews views = (CallLogListItemViews) view.getTag();
assertNameIs(views, "John Doe");
- assertNumberLabelIs(views, numberLabel);
- assertNumberIsVisible(views);
+ assertNumberAndLabelAre(views, TEST_FORMATTED_NUMBER, numberLabel);
}
/** Returns the label associated with a given phone type. */
@@ -275,27 +269,6 @@
// HELPERS to check conditions on the DB/views
//
/**
- * Check the date of the current list item.
- * @param date That should be present in the call log list
- * item. Only NOW is supported.
- */
- private void checkDate(long date) {
- if (NOW == date) {
- assertEquals("0 mins ago", mItem.dateView.getText());
- }
- throw new UnsupportedOperationException();
- }
-
- /**
- * Checks the right icon is used to represent the call type
- * (missed, incoming, outgoing.) in the current item.
- */
- private void checkCallType(int type) {
- Bitmap icon = ((BitmapDrawable) mItem.iconView.getDrawable()).getBitmap();
- assertEquals(mCallTypeIcons.get(type), icon);
- }
-
- /**
* Go over all the views in the list and check that the Call
* icon's visibility matches the nature of the number.
*/
@@ -513,44 +486,25 @@
/** Asserts that the name text view is shown and contains the given text. */
private void assertNameIs(CallLogListItemViews views, String name) {
- assertEquals(View.VISIBLE, views.line1View.getVisibility());
- assertEquals(name, views.line1View.getText());
+ assertEquals(View.VISIBLE, views.phoneCallDetailsViews.nameView.getVisibility());
+ assertEquals(name, views.phoneCallDetailsViews.nameView.getText());
}
- /** Asserts that the number label text view is shown and contains the given text. */
- private void assertNumberLabelIs(CallLogListItemViews views, CharSequence numberLabel) {
- assertNumberLabelIsVisible(views);
- assertEquals(numberLabel, views.labelView.getText());
+ /** Asserts that the number and label text view contains the given text. */
+ private void assertNumberAndLabelAre(CallLogListItemViews views, CharSequence number,
+ CharSequence numberLabel) {
+ assertEquals(View.VISIBLE, views.phoneCallDetailsViews.numberView.getVisibility());
+ final CharSequence expectedText;
+ if (numberLabel == null) {
+ expectedText = number;
+ } else {
+ expectedText = numberLabel + " " + number;
+ }
+ assertEquals(expectedText, views.phoneCallDetailsViews.numberView.getText().toString());
}
- /** Asserts that the number label text view is shown. */
- private void assertNumberLabelIsVisible(CallLogListItemViews views) {
- assertEquals(View.VISIBLE, views.labelView.getVisibility());
- }
-
- /** Asserts that the number label text view is invisible. */
- private void assertNumberLabelIsInvisible(CallLogListItemViews views) {
- assertEquals(View.INVISIBLE, views.labelView.getVisibility());
- }
-
- /** Asserts that the number label text view is gone. */
- private void assertNumberLabelIsGone(CallLogListItemViews views) {
- assertEquals(View.GONE, views.labelView.getVisibility());
- }
-
- /** Asserts that the number text view is shown and contains the given text. */
- private void assertNumberIs(CallLogListItemViews views, String number) {
- assertNumberIsVisible(views);
- assertEquals(number, views.numberView.getText());
- }
-
- /** Asserts that the number text view is shown. */
- private void assertNumberIsVisible(CallLogListItemViews views) {
- assertEquals(View.VISIBLE, views.numberView.getVisibility());
- }
-
- /** Asserts that the number text view is gone. */
- private void assertNumberIsGone(CallLogListItemViews views) {
- assertEquals(View.GONE, views.numberView.getVisibility());
+ /** Asserts that the number and label text view is gone. */
+ private void assertNumberAndLabelAreGone(CallLogListItemViews views) {
+ assertEquals(View.GONE, views.phoneCallDetailsViews.numberView.getVisibility());
}
}
diff --git a/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java
index a33b710..2665c13 100644
--- a/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java
+++ b/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java
@@ -16,8 +16,9 @@
package com.android.contacts.calllog;
-import com.android.contacts.R;
-import com.android.contacts.util.LocaleTestUtils;
+import com.android.contacts.PhoneCallDetails;
+import com.android.contacts.PhoneCallDetailsHelper;
+import com.android.contacts.PhoneCallDetailsViews;
import com.android.internal.telephony.CallerInfo;
import android.content.Context;
@@ -28,15 +29,20 @@
import android.test.AndroidTestCase;
import android.view.View;
import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.QuickContactBadge;
import android.widget.TextView;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-
/**
* Unit tests for {@link CallLogListItemHelper}.
*/
public class CallLogListItemHelperTest extends AndroidTestCase {
+ /** A test phone number for phone calls. */
+ private static final String TEST_NUMBER = "14125555555";
+ /** The formatted version of {@link #TEST_NUMBER}. */
+ private static final String TEST_FORMATTED_NUMBER = "1-412-255-5555";
+ /** A test date value for phone calls. */
+ private static final long TEST_DATE = 1300000000;
/** A test voicemail number. */
private static final String TEST_VOICEMAIL_NUMBER = "123";
/** A drawable to be used for incoming calls. */
@@ -62,17 +68,15 @@
protected void setUp() throws Exception {
super.setUp();
Context context = getContext();
- mHelper = new CallLogListItemHelper(context.getResources(), TEST_VOICEMAIL_NUMBER,
- TEST_INCOMING_DRAWABLE, TEST_OUTGOING_DRAWABLE, TEST_MISSED_DRAWABLE,
- TEST_VOICEMAIL_DRAWABLE, TEST_CALL_DRAWABLE, TEST_PLAY_DRAWABLE);
- mViews = new CallLogListItemViews();
- // Only set the views that are needed in the tests.
- mViews.iconView = new ImageView(context);
- mViews.dateView = new TextView(context);
- mViews.callView = new ImageView(context);
- mViews.line1View = new TextView(context);
- mViews.labelView = new TextView(context);
- mViews.numberView = new TextView(context);
+ PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(context,
+ context.getResources(), TEST_VOICEMAIL_NUMBER, TEST_INCOMING_DRAWABLE,
+ TEST_OUTGOING_DRAWABLE, TEST_MISSED_DRAWABLE, TEST_VOICEMAIL_DRAWABLE);
+ mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, TEST_CALL_DRAWABLE,
+ TEST_PLAY_DRAWABLE);
+ mViews = CallLogListItemViews.createForTest(new QuickContactBadge(context),
+ new ImageView(context), PhoneCallDetailsViews.createForTest(new TextView(context),
+ new LinearLayout(context), new TextView(context), new TextView(context),
+ new TextView(context), new TextView(context)));
}
@Override
@@ -83,69 +87,48 @@
}
public void testSetContactNumberOnly() {
- mHelper.setContactNumberOnly(mViews, "12125551234", "1-212-555-1234");
- assertEquals("1-212-555-1234", mViews.line1View.getText());
- assertEquals(View.GONE, mViews.labelView.getVisibility());
- assertEquals(View.GONE, mViews.numberView.getVisibility());
+ setPhoneCallDetailsWithNumber("12125551234", "1-212-555-1234");
assertEquals(View.VISIBLE, mViews.callView.getVisibility());
+ assertEquals(TEST_CALL_DRAWABLE, mViews.callView.getDrawable());
}
public void testSetContactNumberOnly_Unknown() {
- mHelper.setContactNumberOnly(mViews, CallerInfo.UNKNOWN_NUMBER, "");
- assertEquals(getContext().getString(R.string.unknown), mViews.line1View.getText());
- assertEquals(View.GONE, mViews.labelView.getVisibility());
- assertEquals(View.GONE, mViews.numberView.getVisibility());
+ setPhoneCallDetailsWithNumber(CallerInfo.UNKNOWN_NUMBER, CallerInfo.UNKNOWN_NUMBER);
assertEquals(View.INVISIBLE, mViews.callView.getVisibility());
}
public void testSetContactNumberOnly_Private() {
- mHelper.setContactNumberOnly(mViews, CallerInfo.PRIVATE_NUMBER, "");
- assertEquals(getContext().getString(R.string.private_num), mViews.line1View.getText());
- assertEquals(View.GONE, mViews.labelView.getVisibility());
- assertEquals(View.GONE, mViews.numberView.getVisibility());
+ setPhoneCallDetailsWithNumber(CallerInfo.PRIVATE_NUMBER, CallerInfo.PRIVATE_NUMBER);
assertEquals(View.INVISIBLE, mViews.callView.getVisibility());
}
public void testSetContactNumberOnly_Payphone() {
- mHelper.setContactNumberOnly(mViews, CallerInfo.PAYPHONE_NUMBER, "");
- assertEquals(getContext().getString(R.string.payphone), mViews.line1View.getText());
- assertEquals(View.GONE, mViews.labelView.getVisibility());
- assertEquals(View.GONE, mViews.numberView.getVisibility());
+ setPhoneCallDetailsWithNumber(CallerInfo.PAYPHONE_NUMBER, CallerInfo.PAYPHONE_NUMBER);
assertEquals(View.INVISIBLE, mViews.callView.getVisibility());
}
- public void testSetContactNumberOnly_Voicemail() {
- mHelper.setContactNumberOnly(mViews, TEST_VOICEMAIL_NUMBER, "");
- assertEquals(getContext().getString(R.string.voicemail), mViews.line1View.getText());
- assertEquals(View.GONE, mViews.labelView.getVisibility());
- assertEquals(View.GONE, mViews.numberView.getVisibility());
+ public void testSetContactNumberOnly_VoicemailNumber() {
+ setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER, TEST_VOICEMAIL_NUMBER);
assertEquals(View.VISIBLE, mViews.callView.getVisibility());
+ assertEquals(TEST_CALL_DRAWABLE, mViews.callView.getDrawable());
}
- public void testSetDate() {
- // This test requires the locale to be set to US.
- LocaleTestUtils localeTestUtils = new LocaleTestUtils(getContext());
- localeTestUtils.setLocale(Locale.US);
- try {
- mHelper.setDate(mViews,
- new GregorianCalendar(2011, 5, 1, 12, 0, 0).getTimeInMillis(),
- new GregorianCalendar(2011, 5, 1, 13, 0, 0).getTimeInMillis());
- assertEquals("1 hour ago", mViews.dateView.getText());
- mHelper.setDate(mViews,
- new GregorianCalendar(2010, 5, 1, 12, 0, 0).getTimeInMillis(),
- new GregorianCalendar(2011, 5, 1, 13, 0, 0).getTimeInMillis());
- assertEquals("June 1, 2010", mViews.dateView.getText());
- } finally {
- localeTestUtils.restoreLocale();
- }
+ public void testSetContactNumberOnly_Voicemail() {
+ setPhoneCallDetailsWithType(Calls.VOICEMAIL_TYPE);
+ assertEquals(View.VISIBLE, mViews.callView.getVisibility());
+ assertEquals(TEST_PLAY_DRAWABLE, mViews.callView.getDrawable());
}
- public void testSetCallType_Icon() {
- mHelper.setCallType(mViews, Calls.INCOMING_TYPE);
- assertEquals(TEST_INCOMING_DRAWABLE, mViews.iconView.getDrawable());
- mHelper.setCallType(mViews, Calls.OUTGOING_TYPE);
- assertEquals(TEST_OUTGOING_DRAWABLE, mViews.iconView.getDrawable());
- mHelper.setCallType(mViews, Calls.MISSED_TYPE);
- assertEquals(TEST_MISSED_DRAWABLE, mViews.iconView.getDrawable());
+ /** Sets the details of a phone call using the specified phone number. */
+ private void setPhoneCallDetailsWithNumber(String number, String formattedNumber) {
+ mHelper.setPhoneCallDetails(mViews,
+ new PhoneCallDetails(number, formattedNumber, Calls.INCOMING_TYPE, TEST_DATE),
+ true);
+ }
+
+ /** Sets the details of a phone call using the specified call type. */
+ private void setPhoneCallDetailsWithType(int type) {
+ mHelper.setPhoneCallDetails(mViews,
+ new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, type, TEST_DATE), true);
}
}