Merge "Fixes play button for voicemails in call log."
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 3f3fd8d..27dbe9c 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -230,8 +230,7 @@
/** Adapter class to fill in data for the Call Log */
public final class CallLogAdapter extends GroupingListAdapter
- implements Runnable, ViewTreeObserver.OnPreDrawListener, View.OnClickListener,
- GroupCreator {
+ implements Runnable, ViewTreeObserver.OnPreDrawListener, GroupCreator {
/** The time in millis to delay starting the thread processing requests. */
private static final int START_PROCESSING_REQUESTS_DELAY_MILLIS = 1000;
@@ -272,13 +271,15 @@
/** Can be set to true by tests to disable processing of requests. */
private volatile boolean mRequestProcessingDisabled = false;
- @Override
- public void onClick(View view) {
- IntentProvider intentProvider = (IntentProvider) view.getTag();
- if (intentProvider != null) {
- startActivity(intentProvider.getIntent(CallLogFragment.this.getActivity()));
+ private final View.OnClickListener mCallPlayOnClickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ IntentProvider intentProvider = (IntentProvider) view.getTag();
+ if (intentProvider != null) {
+ startActivity(intentProvider.getIntent(CallLogFragment.this.getActivity()));
+ }
}
- }
+ };
@Override
public boolean onPreDraw() {
@@ -655,7 +656,8 @@
private void findAndCacheViews(View view) {
// Get the views to bind to.
CallLogListItemViews views = CallLogListItemViews.fromView(view);
- views.callView.setOnClickListener(this);
+ views.callView.setOnClickListener(mCallPlayOnClickListener);
+ views.playView.setOnClickListener(mCallPlayOnClickListener);
// Do nothing when a plain photo is clicked. Without this, the list item will fire.
views.plainPhotoView.setOnClickListener(null);
view.setTag(views);
@@ -699,14 +701,17 @@
if (callType == Calls.VOICEMAIL_TYPE) {
String voicemailUri = c.getString(CallLogQuery.VOICEMAIL_URI);
final long rowId = c.getLong(CallLogQuery.ID);
- views.callView.setTag(
+ views.playView.setTag(
IntentProvider.getPlayVoicemailIntentProvider(rowId, voicemailUri));
+ views.callView.setTag(null);
} else if (!TextUtils.isEmpty(number)) {
// Store away the number so we can call it directly if you click on the call icon.
views.callView.setTag(IntentProvider.getReturnCallIntentProvider(number));
+ views.playView.setTag(null);
} else {
// No action enabled.
views.callView.setTag(null);
+ views.playView.setTag(null);
}
// Lookup contacts with this number
diff --git a/tests/src/com/android/contacts/activities/CallLogActivityTests.java b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
index b642ffe..c186106 100644
--- a/tests/src/com/android/contacts/activities/CallLogActivityTests.java
+++ b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
@@ -16,13 +16,18 @@
package com.android.contacts.activities;
+import com.android.contacts.CallDetailActivity;
import com.android.contacts.R;
import com.android.contacts.calllog.CallLogFragment;
import com.android.contacts.calllog.CallLogFragment.CallLogQuery;
import com.android.contacts.calllog.CallLogFragment.ContactInfo;
import com.android.contacts.calllog.CallLogListItemViews;
+import com.android.contacts.calllog.IntentProvider;
import com.android.internal.telephony.CallerInfo;
+import android.content.ComponentName;
+import android.content.ContentUris;
+import android.content.Intent;
import android.content.res.Resources;
import android.database.MatrixCursor;
import android.graphics.Bitmap;
@@ -30,6 +35,7 @@
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.VoicemailContract;
import android.telephony.PhoneNumberUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
@@ -291,6 +297,47 @@
assertEquals(View.VISIBLE, views.plainPhotoView.getVisibility());
}
+ @MediumTest
+ public void testBindView_CallButton() {
+ mCursor.moveToFirst();
+ insert(TEST_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+ View view = mAdapter.newStandAloneView(getActivity(), mParentView);
+ mAdapter.bindStandAloneView(view, getActivity(), mCursor);
+
+ CallLogListItemViews views = (CallLogListItemViews) view.getTag();
+ IntentProvider intentProvider = (IntentProvider) views.callView.getTag();
+ Intent intent = intentProvider.getIntent(mActivity);
+ // Starts a call.
+ assertEquals(Intent.ACTION_CALL_PRIVILEGED, intent.getAction());
+ // To the entry's number.
+ assertEquals(Uri.parse("tel:" + TEST_NUMBER), intent.getData());
+ }
+
+ @MediumTest
+ public void testBindView_PlayButton() {
+ mCursor.moveToFirst();
+ insertVoicemail(TEST_NUMBER, NOW, 0);
+ View view = mAdapter.newStandAloneView(getActivity(), mParentView);
+ mAdapter.bindStandAloneView(view, getActivity(), mCursor);
+
+ CallLogListItemViews views = (CallLogListItemViews) view.getTag();
+ IntentProvider intentProvider = (IntentProvider) views.playView.getTag();
+ Intent intent = intentProvider.getIntent(mActivity);
+ // Starts the call detail activity.
+ assertEquals(new ComponentName(mActivity, CallDetailActivity.class),
+ intent.getComponent());
+ // With the given entry.
+ assertEquals(ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, 1),
+ intent.getData());
+ // With the URI of the voicemail.
+ assertEquals(
+ ContentUris.withAppendedId(VoicemailContract.Voicemails.CONTENT_URI, 1),
+ intent.getParcelableExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI));
+ // And starts playback.
+ assertTrue(
+ intent.getBooleanExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, false));
+ }
+
/** Returns the label associated with a given phone type. */
private CharSequence getTypeLabel(int phoneType) {
return Phone.getTypeLabel(getActivity().getResources(), phoneType, "");
@@ -464,6 +511,36 @@
}
/**
+ * Insert a new voicemail entry in the test DB.
+ * @param number The phone number. For unknown and private numbers,
+ * use CallerInfo.UNKNOWN_NUMBER or CallerInfo.PRIVATE_NUMBER.
+ * @param date In millisec since epoch. Use NOW to use the current time.
+ * @param duration In seconds of the call. Use RAND_DURATION to pick a random one.
+ */
+ private void insertVoicemail(String number, long date, int duration) {
+ MatrixCursor.RowBuilder row = mCursor.newRow();
+ // Must have the same index as the row.
+ Uri voicemailUri =
+ ContentUris.withAppendedId(VoicemailContract.Voicemails.CONTENT_URI, mIndex);
+ row.add(mIndex);
+ mIndex ++;
+ row.add(number);
+ if (NOW == date) {
+ row.add(new Date().getTime());
+ } else {
+ row.add(date);
+ }
+ if (duration < 0) {
+ duration = mRnd.nextInt(10 * 60); // 0 - 10 minutes random.
+ }
+ row.add(duration); // duration
+ row.add(Calls.VOICEMAIL_TYPE); // type
+ row.add(TEST_COUNTRY_ISO); // country ISO
+ row.add(voicemailUri); // voicemail_uri
+ row.add(CallLogFragment.CallLogQuery.SECTION_OLD_ITEM); // section
+ }
+
+ /**
* Insert a new private call entry in the test DB.
* @param date In millisec since epoch. Use NOW to use the current time.
* @param duration In seconds of the call. Use RAND_DURATION to pick a random one.
@@ -482,11 +559,11 @@
}
/**
- * Insert a new voicemail call entry in the test DB.
+ * Insert a new call to voicemail entry in the test DB.
* @param date In millisec since epoch. Use NOW to use the current time.
* @param duration In seconds of the call. Use RAND_DURATION to pick a random one.
*/
- private void insertVoicemail(long date, int duration) {
+ private void insertCalltoVoicemail(long date, int duration) {
// mVoicemail may be null
if (mVoicemail != null) {
insert(mVoicemail, date, duration, Calls.OUTGOING_TYPE);
@@ -521,7 +598,7 @@
insertUnknown(NOW, RAND_DURATION);
privateOrUnknownOrVm[1] = true;
} else if (2 == type) {
- insertVoicemail(NOW, RAND_DURATION);
+ insertCalltoVoicemail(NOW, RAND_DURATION);
privateOrUnknownOrVm[2] = true;
} else {
int inout = mRnd.nextBoolean() ? Calls.OUTGOING_TYPE : Calls.INCOMING_TYPE;