diff options
author | Christine Chen <christinech@google.com> | 2013-08-16 16:00:14 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-08-16 16:00:16 +0000 |
commit | 240dfb12d879d412f53ffb9e53bef5a2c4929c70 (patch) | |
tree | dcaeabd964e68750bf106c6c240307e947d03a00 | |
parent | 34bdf87700194c35ab8f43c001391bb2ac8bc993 (diff) | |
parent | 7030a12a15e565521ffb220c00a0251e47bd3a93 (diff) |
Merge "Change primary actions of the CallLog items." into klp-dev
6 files changed, 106 insertions, 14 deletions
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 2c81f46fe..15c9b05a6 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -178,6 +178,10 @@ public class CallLogAdapter extends GroupingListAdapter /** Can be set to true by tests to disable processing of requests. */ private volatile boolean mRequestProcessingDisabled = false; + /** True if CallLogAdapter is created from the PhoneFavoriteFragment, where the primary + * action should be set to call a number instead of opening the detail page. */ + private boolean mUseCallAsPrimaryAction = false; + /** Listener for the primary action in the list, opens the call details. */ private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() { @Override @@ -228,12 +232,13 @@ public class CallLogAdapter extends GroupingListAdapter }; public CallLogAdapter(Context context, CallFetcher callFetcher, - ContactInfoHelper contactInfoHelper) { + ContactInfoHelper contactInfoHelper, boolean useCallAsPrimaryAction) { super(context); mContext = context; mCallFetcher = callFetcher; mContactInfoHelper = contactInfoHelper; + mUseCallAsPrimaryAction = useCallAsPrimaryAction; mContactInfoCache = ExpirableCache.create(CONTACT_INFO_CACHE_SIZE); mRequests = new LinkedList<ContactInfoRequest>(); @@ -515,9 +520,15 @@ public class CallLogAdapter extends GroupingListAdapter final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c); - views.primaryActionView.setTag( - IntentProvider.getCallDetailIntentProvider( - getCursor(), c.getPosition(), c.getLong(CallLogQuery.ID), count)); + if (!mUseCallAsPrimaryAction) { + // Sets the primary action to open call detail page. + views.primaryActionView.setTag( + IntentProvider.getCallDetailIntentProvider( + getCursor(), c.getPosition(), c.getLong(CallLogQuery.ID), count)); + } else { + // Sets the primary action to call the number. + views.primaryActionView.setTag(IntentProvider.getReturnCallIntentProvider(number)); + } // Store away the voicemail information so we can play it directly. if (callType == Calls.VOICEMAIL_TYPE) { @@ -594,7 +605,8 @@ public class CallLogAdapter extends GroupingListAdapter final boolean isNew = c.getInt(CallLogQuery.IS_READ) == 0; // New items also use the highlighted version of the text. final boolean isHighlighted = isNew; - mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted); + mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted, + mUseCallAsPrimaryAction); setPhoto(views, photoId, lookupUri); // Listen for the first draw diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index a76d0c17e..7168667e7 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -237,7 +237,7 @@ public class CallLogFragment extends ListFragment updateEmptyMessage(mCallTypeFilter); String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); mAdapter = new CallLogAdapter(getActivity(), this, - new ContactInfoHelper(getActivity(), currentCountryIso)); + new ContactInfoHelper(getActivity(), currentCountryIso), false); setListAdapter(mAdapter); getListView().setItemsCanFocus(true); } diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java index 23366e469..fc26e85e2 100644 --- a/src/com/android/dialer/calllog/CallLogListItemHelper.java +++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java @@ -57,7 +57,7 @@ import com.android.dialer.R; * @param isHighlighted whether to use the highlight text for the call */ public void setPhoneCallDetails(CallLogListItemViews views, PhoneCallDetails details, - boolean isHighlighted) { + boolean isHighlighted, boolean useCallAsPrimaryAction) { mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details, isHighlighted); boolean canCall = PhoneNumberHelper.canPlaceCallsTo(details.number, @@ -67,7 +67,7 @@ import com.android.dialer.R; if (canPlay) { // Playback action takes preference. configurePlaySecondaryAction(views, isHighlighted); - } else if (canCall) { + } else if (canCall && !useCallAsPrimaryAction) { // Call is the secondary action. configureCallSecondaryAction(views, details); } else { diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java index a1406d242..875977972 100644 --- a/src/com/android/dialer/list/PhoneFavoriteFragment.java +++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java @@ -182,7 +182,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen this, 1); final String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); mCallLogAdapter = new CallLogAdapter(getActivity(), this, - new ContactInfoHelper(getActivity(), currentCountryIso)); + new ContactInfoHelper(getActivity(), currentCountryIso), true); setHasOptionsMenu(true); } diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index 6811371d4..ce862de20 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -212,7 +212,7 @@ public class CallLogAdapterTest extends AndroidTestCase { public TestCallLogAdapter(Context context, CallFetcher callFetcher, ContactInfoHelper contactInfoHelper) { - super(context, callFetcher, contactInfoHelper); + super(context, callFetcher, contactInfoHelper, false); } @Override diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index 2cc742359..1b793bc65 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -77,21 +77,42 @@ public class CallLogListItemHelperTest extends AndroidTestCase { assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility()); } + public void testSetPhoneCallDetailsInFavorites() { + setPhoneCallDetailsWithNumberInFavorites("12125551234", Calls.PRESENTATION_ALLOWED, + "1-212-555-1234"); + assertNoCallButton(); + } + public void testSetPhoneCallDetails_Unknown() { setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_UNKNOWN, ""); assertNoCallButton(); } + public void testSetPhoneCallDetailsInFavorites_Unknown() { + setPhoneCallDetailsWithNumberInFavorites("", Calls.PRESENTATION_UNKNOWN, ""); + assertNoCallButton(); + } + public void testSetPhoneCallDetails_Private() { setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_RESTRICTED, ""); assertNoCallButton(); } + public void testSetPhoneCallDetailsInFavorites_Private() { + setPhoneCallDetailsWithNumberInFavorites("", Calls.PRESENTATION_RESTRICTED, ""); + assertNoCallButton(); + } + public void testSetPhoneCallDetails_Payphone() { setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_PAYPHONE, ""); assertNoCallButton(); } + public void testSetPhoneCallDetailsInFavorites_Payphone() { + setPhoneCallDetailsWithNumberInFavorites("", Calls.PRESENTATION_PAYPHONE, ""); + assertNoCallButton(); + } + public void testSetPhoneCallDetails_VoicemailNumber() { setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_VOICEMAIL_NUMBER); @@ -114,6 +135,28 @@ public class CallLogListItemHelperTest extends AndroidTestCase { assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility()); } + public void testSetPhoneCallDetailsInFavorites_VoicemailNumber() { + setPhoneCallDetailsWithNumberInFavorites(TEST_VOICEMAIL_NUMBER, + Calls.PRESENTATION_ALLOWED, TEST_VOICEMAIL_NUMBER); + assertNoCallButton(); + } + + public void testSetPhoneCallDetailsInFavorites_ReadVoicemail() { + setPhoneCallDetailsWithTypesInFavorites(Calls.VOICEMAIL_TYPE); + assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility()); + } + + public void testSetPhoneCallDetailsInFavorites_UnreadVoicemail() { + setUnreadPhoneCallDetailsWithTypesInFavorites(Calls.VOICEMAIL_TYPE); + assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility()); + } + + public void testSetPhoneCallDetailsInFavorites_VoicemailFromUnknown() { + setPhoneCallDetailsWithNumberAndTypeInFavorites("", Calls.PRESENTATION_UNKNOWN, + "", Calls.VOICEMAIL_TYPE); + assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility()); + } + /** Asserts that the whole call area is gone. */ private void assertNoCallButton() { assertEquals(View.GONE, mViews.secondaryActionView.getVisibility()); @@ -126,6 +169,13 @@ public class CallLogListItemHelperTest extends AndroidTestCase { formattedNumber, Calls.INCOMING_TYPE); } + /** Sets the details of a phone call in the favorite screen using the specified phone number. */ + private void setPhoneCallDetailsWithNumberInFavorites(String number, + int presentation, String formattedNumber) { + setPhoneCallDetailsWithNumberAndTypeInFavorites(number, presentation, + formattedNumber, Calls.INCOMING_TYPE); + } + /** Sets the details of a phone call using the specified phone number. */ private void setPhoneCallDetailsWithNumberAndType(String number, int presentation, String formattedNumber, int callType) { @@ -133,7 +183,17 @@ public class CallLogListItemHelperTest extends AndroidTestCase { new PhoneCallDetails(number, presentation, formattedNumber, TEST_COUNTRY_ISO, TEST_GEOCODE, new int[]{ callType }, TEST_DATE, TEST_DURATION), - false); + false, false); + } + + /** Sets the details of a phone call in the favorite screen using the specified phone number. */ + private void setPhoneCallDetailsWithNumberAndTypeInFavorites(String number, + int presentation, String formattedNumber, int callType) { + mHelper.setPhoneCallDetails(mViews, + new PhoneCallDetails(number, presentation, formattedNumber, + TEST_COUNTRY_ISO, TEST_GEOCODE, + new int[]{ callType }, TEST_DATE, TEST_DURATION), + false, true); } /** Sets the details of a phone call using the specified call type. */ @@ -142,15 +202,35 @@ public class CallLogListItemHelperTest extends AndroidTestCase { new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE, types, TEST_DATE, TEST_DURATION), - false); + false, false); } - /** Sets the details of a phone call using the specified call type. */ + /** Sets the details of a phone call in the favorite screen using the specified call type. */ + private void setPhoneCallDetailsWithTypesInFavorites(int... types) { + mHelper.setPhoneCallDetails(mViews, + new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED, + TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE, + types, TEST_DATE, TEST_DURATION), + false, true); + } + + /** Sets the details of an unread phone call using the specified call type. */ private void setUnreadPhoneCallDetailsWithTypes(int... types) { mHelper.setPhoneCallDetails(mViews, new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE, types, TEST_DATE, TEST_DURATION), - true); + true, false); + } + + /** Sets the details of an unread phone call in the favorite screen using the specified call + * type. + */ + private void setUnreadPhoneCallDetailsWithTypesInFavorites(int... types) { + mHelper.setPhoneCallDetails(mViews, + new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED, + TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE, + types, TEST_DATE, TEST_DURATION), + true, true); } } |