Added photo and name to new call log.
For now I am just using the "cached" columns in the system call log since they seem to be reliable and rewriting the code that writes them would be a large project that can be done independently at any time in the future.
I am just using ContactPhotoManager to set the photo, which means that photos and letter tiles work. However, I am not currently determing the contact type (voicemail, business, etc). That will come in a future CL.
Screenshot: https://screenshot.googleplex.com/oziuL6BtqFH
Bug: 34672501
Test: unit, view holder screeshot test will come when UI more complete
PiperOrigin-RevId: 166769376
Change-Id: Ice884c021d9a561c59f1d04f5d60ce37cf3837e6
diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java
index 78c329a..e1ec0f6 100644
--- a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java
+++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java
@@ -40,11 +40,12 @@
.append(AnnotatedCallLog.TIMESTAMP + " integer, ")
.append(AnnotatedCallLog.NAME + " string, ")
.append(AnnotatedCallLog.FORMATTED_NUMBER + " string, ")
- .append(AnnotatedCallLog.NEW + " integer, ")
- .append(AnnotatedCallLog.TYPE + " integer, ")
- .append(AnnotatedCallLog.CONTACT_PHOTO_URI + " string, ")
+ .append(AnnotatedCallLog.PHOTO_URI + " string, ")
+ .append(AnnotatedCallLog.PHOTO_ID + " integer, ")
+ .append(AnnotatedCallLog.LOOKUP_URI + " string, ")
.append(AnnotatedCallLog.NUMBER_TYPE_LABEL + " string, ")
.append(AnnotatedCallLog.IS_READ + " integer, ")
+ .append(AnnotatedCallLog.NEW + " integer, ")
.append(AnnotatedCallLog.GEOCODED_LOCATION + " string, ")
.append(AnnotatedCallLog.PHONE_ACCOUNT_LABEL + " string, ")
.append(AnnotatedCallLog.PHONE_ACCOUNT_COLOR + " integer, ")
@@ -52,7 +53,8 @@
.append(AnnotatedCallLog.IS_BUSINESS + " integer, ")
.append(AnnotatedCallLog.IS_VOICEMAIL + " integer, ")
// Columns only in AnnotatedCallLog
- .append(AnnotatedCallLog.NUMBER + " blob")
+ .append(AnnotatedCallLog.NUMBER + " blob, ")
+ .append(AnnotatedCallLog.TYPE + " integer")
.append(");")
.toString();
diff --git a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java
index be891c5..25950f6 100644
--- a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java
+++ b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java
@@ -42,8 +42,7 @@
String TIMESTAMP = "timestamp";
/**
- * Name of the caller if available. This could be a name from a local contact or caller ID data
- * source, for example.
+ * Copied from {@link android.provider.CallLog.Calls#CACHED_NAME}.
*
* <p>This is exactly how it should appear to the user. If the user's locale or name display
* preferences change, this column should be rewritten.
@@ -60,14 +59,25 @@
String FORMATTED_NUMBER = "formatted_number";
/**
- * Local photo URI for the contact associated with the phone number, if it exists.
- *
- * <p>Photos currently only come from local contacts database and not caller ID sources. If
- * there is no photo for a contact then an appropriate letter tile should be drawn.
+ * Copied from {@link android.provider.CallLog.Calls#CACHED_PHOTO_URI}.
*
* <p>TYPE: TEXT
*/
- String CONTACT_PHOTO_URI = "contact_photo_uri";
+ String PHOTO_URI = "photo_uri";
+
+ /**
+ * Copied from {@link android.provider.CallLog.Calls#CACHED_PHOTO_ID}.
+ *
+ * <p>Type: INTEGER (long)
+ */
+ String PHOTO_ID = "photo_id";
+
+ /**
+ * Copied from {@link android.provider.CallLog.Calls#CACHED_LOOKUP_URI}.
+ *
+ * <p>TYPE: TEXT
+ */
+ String LOOKUP_URI = "lookup_uri";
// TODO(zachh): If we need to support photos other than local contacts', add a (blob?) column.
@@ -144,7 +154,9 @@
TIMESTAMP,
NAME,
FORMATTED_NUMBER,
- CONTACT_PHOTO_URI,
+ PHOTO_URI,
+ PHOTO_ID,
+ LOOKUP_URI,
NUMBER_TYPE_LABEL,
IS_READ,
NEW,
diff --git a/java/com/android/dialer/calllog/datasources/contacts/ContactsDataSource.java b/java/com/android/dialer/calllog/datasources/contacts/ContactsDataSource.java
index 8090cbc..f0384b0 100644
--- a/java/com/android/dialer/calllog/datasources/contacts/ContactsDataSource.java
+++ b/java/com/android/dialer/calllog/datasources/contacts/ContactsDataSource.java
@@ -20,10 +20,8 @@
import android.content.Context;
import android.support.annotation.MainThread;
import android.support.annotation.WorkerThread;
-import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog;
import com.android.dialer.calllog.datasources.CallLogDataSource;
import com.android.dialer.calllog.datasources.CallLogMutations;
-import com.android.dialer.calllog.datasources.util.RowCombiner;
import com.android.dialer.common.Assert;
import java.util.List;
import javax.inject.Inject;
@@ -50,9 +48,6 @@
CallLogMutations mutations) {
Assert.isWorkerThread();
// TODO(zachh): Implementation.
- for (ContentValues contentValues : mutations.getInserts().values()) {
- contentValues.put(AnnotatedCallLog.NAME, "Placeholder name");
- }
}
@Override
@@ -63,9 +58,7 @@
@Override
public ContentValues coalesce(List<ContentValues> individualRowsSortedByTimestampDesc) {
// TODO(zachh): Implementation.
- return new RowCombiner(individualRowsSortedByTimestampDesc)
- .useSingleValueString(AnnotatedCallLog.NAME)
- .combine();
+ return new ContentValues();
}
@MainThread
diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
index 9d77505..1bdbb8a 100644
--- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
+++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
@@ -158,8 +158,12 @@
.useMostRecentLong(AnnotatedCallLog.TIMESTAMP)
.useMostRecentLong(AnnotatedCallLog.NEW)
.useMostRecentString(AnnotatedCallLog.NUMBER_TYPE_LABEL)
- .useMostRecentString(AnnotatedCallLog.GEOCODED_LOCATION)
+ .useMostRecentString(AnnotatedCallLog.NAME)
.useMostRecentString(AnnotatedCallLog.FORMATTED_NUMBER)
+ .useMostRecentString(AnnotatedCallLog.PHOTO_URI)
+ .useMostRecentLong(AnnotatedCallLog.PHOTO_ID)
+ .useMostRecentString(AnnotatedCallLog.LOOKUP_URI)
+ .useMostRecentString(AnnotatedCallLog.GEOCODED_LOCATION)
.useSingleValueString(AnnotatedCallLog.PHONE_ACCOUNT_LABEL)
.useSingleValueLong(AnnotatedCallLog.PHONE_ACCOUNT_COLOR)
.combine();
@@ -198,7 +202,11 @@
Calls.NUMBER,
Calls.TYPE,
Calls.COUNTRY_ISO,
+ Calls.CACHED_NAME,
Calls.CACHED_FORMATTED_NUMBER,
+ Calls.CACHED_PHOTO_URI,
+ Calls.CACHED_PHOTO_ID,
+ Calls.CACHED_LOOKUP_URI,
Calls.CACHED_NUMBER_TYPE,
Calls.CACHED_NUMBER_LABEL,
Calls.IS_READ,
@@ -229,8 +237,12 @@
int numberColumn = cursor.getColumnIndexOrThrow(Calls.NUMBER);
int typeColumn = cursor.getColumnIndexOrThrow(Calls.TYPE);
int countryIsoColumn = cursor.getColumnIndexOrThrow(Calls.COUNTRY_ISO);
+ int cachedNameColumn = cursor.getColumnIndexOrThrow(Calls.CACHED_NAME);
int cachedFormattedNumberColumn =
cursor.getColumnIndexOrThrow(Calls.CACHED_FORMATTED_NUMBER);
+ int cachedPhotoUriColumn = cursor.getColumnIndexOrThrow(Calls.CACHED_PHOTO_URI);
+ int cachedPhotoIdColumn = cursor.getColumnIndexOrThrow(Calls.CACHED_PHOTO_ID);
+ int cachedLookupUriColumn = cursor.getColumnIndexOrThrow(Calls.CACHED_LOOKUP_URI);
int cachedNumberTypeColumn = cursor.getColumnIndexOrThrow(Calls.CACHED_NUMBER_TYPE);
int cachedNumberLabelColumn = cursor.getColumnIndexOrThrow(Calls.CACHED_NUMBER_LABEL);
int isReadColumn = cursor.getColumnIndexOrThrow(Calls.IS_READ);
@@ -250,7 +262,11 @@
String numberAsStr = cursor.getString(numberColumn);
long type = cursor.getInt(typeColumn);
String countryIso = cursor.getString(countryIsoColumn);
+ String cachedName = cursor.getString(cachedNameColumn);
String formattedNumber = cursor.getString(cachedFormattedNumberColumn);
+ String cachedPhotoUri = cursor.getString(cachedPhotoUriColumn);
+ long cachedPhotoId = cursor.getLong(cachedPhotoIdColumn);
+ String cachedLookupUri = cursor.getString(cachedLookupUriColumn);
int cachedNumberType = cursor.getInt(cachedNumberTypeColumn);
String cachedNumberLabel = cursor.getString(cachedNumberLabelColumn);
int isRead = cursor.getInt(isReadColumn);
@@ -271,7 +287,11 @@
}
contentValues.put(AnnotatedCallLog.TYPE, type);
+ contentValues.put(AnnotatedCallLog.NAME, cachedName);
contentValues.put(AnnotatedCallLog.FORMATTED_NUMBER, formattedNumber);
+ contentValues.put(AnnotatedCallLog.PHOTO_URI, cachedPhotoUri);
+ contentValues.put(AnnotatedCallLog.PHOTO_ID, cachedPhotoId);
+ contentValues.put(AnnotatedCallLog.LOOKUP_URI, cachedLookupUri);
// Phone.getTypeLabel returns "Custom" if given (0, null) which is not of any use. Just
// omit setting the label if there's no information for it.
diff --git a/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java b/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java
index 0dacece..d893383 100644
--- a/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java
+++ b/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java
@@ -35,18 +35,20 @@
private static final int TIMESTAMP = 1;
private static final int NAME = 2;
private static final int FORMATTED_NUMBER = 3;
- private static final int CONTACT_PHOTO_URI = 4;
- private static final int NUMBER_TYPE_LABEL = 5;
- private static final int IS_READ = 6;
- private static final int NEW = 7;
- private static final int GEOCODED_LOCATION = 8;
- private static final int PHONE_ACCOUNT_LABEL = 9;
- private static final int PHONE_ACCOUNT_COLOR = 10;
- private static final int FEATURES = 11;
- private static final int IS_BUSINESS = 12;
- private static final int IS_VOICEMAIL = 13;
- private static final int NUMBER_CALLS = 14;
- private static final int CALL_TYPES = 15;
+ private static final int PHOTO_URI = 4;
+ private static final int PHOTO_ID = 5;
+ private static final int LOOKUP_URI = 6;
+ private static final int NUMBER_TYPE_LABEL = 7;
+ private static final int IS_READ = 8;
+ private static final int NEW = 9;
+ private static final int GEOCODED_LOCATION = 10;
+ private static final int PHONE_ACCOUNT_LABEL = 11;
+ private static final int PHONE_ACCOUNT_COLOR = 12;
+ private static final int FEATURES = 13;
+ private static final int IS_BUSINESS = 14;
+ private static final int IS_VOICEMAIL = 15;
+ private static final int NUMBER_CALLS = 16;
+ private static final int CALL_TYPES = 17;
/** Convenience class for accessing values using an abbreviated syntax. */
static final class Row {
@@ -68,8 +70,20 @@
return cursor.getString(NAME);
}
- String contactPhotoUri() {
- return cursor.getString(CONTACT_PHOTO_URI);
+ String formattedNumber() {
+ return cursor.getString(FORMATTED_NUMBER);
+ }
+
+ String photoUri() {
+ return cursor.getString(PHOTO_URI);
+ }
+
+ long photoId() {
+ return cursor.getLong(PHOTO_ID);
+ }
+
+ String lookupUri() {
+ return cursor.getString(LOOKUP_URI);
}
String numberTypeLabel() {
@@ -113,10 +127,6 @@
return cursor.getInt(NUMBER_CALLS);
}
- String formattedNumber() {
- return cursor.getString(FORMATTED_NUMBER);
- }
-
@NonNull
CallTypes callTypes() {
try {
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
index 58c98f6..e198a38 100644
--- a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
+++ b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.database.Cursor;
+import android.net.Uri;
import android.provider.CallLog.Calls;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
@@ -61,8 +62,6 @@
CoalescedAnnotatedCallLogCursorLoader.Row row =
new CoalescedAnnotatedCallLogCursorLoader.Row(cursor);
- // TODO(zachh): Use name for primary text if available.
- // TODO(zachh): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers.
// TODO(zachh): Handle RTL properly.
primaryTextView.setText(buildPrimaryText(row));
secondaryTextView.setText(buildSecondaryText(row));
@@ -74,18 +73,22 @@
secondaryTextView.setTextAppearance(R.style.secondary_textview_new_call);
}
- setPhoto();
+ setPhoto(row);
setPrimaryCallTypes(row);
setSecondaryCallTypes(row);
setPhoneAccounts(row);
}
private String buildPrimaryText(CoalescedAnnotatedCallLogCursorLoader.Row row) {
- StringBuilder primaryText =
- new StringBuilder(
- TextUtils.isEmpty(row.formattedNumber())
- ? context.getText(R.string.new_call_log_unknown)
- : row.formattedNumber());
+ StringBuilder primaryText = new StringBuilder();
+ if (!TextUtils.isEmpty(row.name())) {
+ primaryText.append(row.name());
+ } else if (!TextUtils.isEmpty(row.formattedNumber())) {
+ primaryText.append(row.formattedNumber());
+ } else {
+ // TODO(zachh): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers.
+ primaryText.append(context.getText(R.string.new_call_log_unknown));
+ }
if (row.numberCalls() > 1) {
primaryText.append(String.format(Locale.getDefault(), " (%d)", row.numberCalls()));
}
@@ -134,11 +137,16 @@
return secondaryText.toString();
}
- private void setPhoto() {
- // TODO(zachh): Set photo/icon appropriately. (This just uses the anonymous avatar.)
+ private void setPhoto(Row row) {
+ // TODO(zachh): Set the contact type.
ContactPhotoManager.getInstance(context)
.loadDialerThumbnailOrPhoto(
- quickContactBadge, null, 0, null, null, LetterTileDrawable.TYPE_DEFAULT);
+ quickContactBadge,
+ row.lookupUri() == null ? null : Uri.parse(row.lookupUri()),
+ row.photoId(),
+ row.photoUri() == null ? null : Uri.parse(row.photoUri()),
+ row.name(),
+ LetterTileDrawable.TYPE_DEFAULT);
}
private void setPrimaryCallTypes(Row row) {