summaryrefslogtreecommitdiff
path: root/src/com/android/dialer/calllog
diff options
context:
space:
mode:
authorTa-wei Yen <twyen@google.com>2016-03-07 15:29:13 -0800
committerTa-wei Yen <twyen@google.com>2016-03-07 15:29:13 -0800
commitbcb15f99dff4e01343bb7470135f5392a65a01f4 (patch)
tree9b082d6cc0cd3e6f60e1270331d5a65fc4f03982 /src/com/android/dialer/calllog
parent40026e882fa3e5bdc897606e4cb96ed6ac1bfbb9 (diff)
Add contact photo for missed call notifications
+ ContactPhotoLoader to create the appropriate icon from a ContactInfo - NameLookupQuery in CallLogNotificationsHelper#getContactInfo To show a photo the name is not enough. Full query need to be made to retrieve the photoUri. + class Assert in util + Gradle directory setup for dialer tests (Note: this is just for project setup in Android Studio, tests are still not runnable in gradle) Bug:27276108 Change-Id: I0ed2147f2bb60454fe5a5ad6c25fe99727441880
Diffstat (limited to 'src/com/android/dialer/calllog')
-rw-r--r--src/com/android/dialer/calllog/CallLogNotificationsHelper.java24
-rw-r--r--src/com/android/dialer/calllog/MissedCallNotifier.java14
2 files changed, 18 insertions, 20 deletions
diff --git a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
index 6abf241b4..189263199 100644
--- a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
+++ b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
@@ -16,9 +16,7 @@
package com.android.dialer.calllog;
-import static android.Manifest.permission.READ_CALL_LOG;
-import static android.Manifest.permission.READ_CONTACTS;
-
+import android.Manifest;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
@@ -111,7 +109,7 @@ public class CallLogNotificationsHelper {
/**
* Given a number and number information (presentation and country ISO), get
* {@link ContactInfo}. If the name is empty but we have a special presentation, display that.
- * Otherwise attempt to look it up in the database or the cache.
+ * Otherwise attempt to look it up in the cache.
* If that fails, fall back to displaying the number.
*/
public @NonNull ContactInfo getContactInfo(@Nullable String number, int numberPresentation,
@@ -136,13 +134,7 @@ public class CallLogNotificationsHelper {
return contactInfo;
}
- // 2. Personal ContactsProvider phonelookup query.
- contactInfo.name = mNameLookupQuery.query(number);
- if (!TextUtils.isEmpty(contactInfo.name)) {
- return contactInfo;
- }
-
- // 3. Look it up in the cache.
+ // 2. Look it up in the cache.
ContactInfo cachedContactInfo = mContactInfoHelper.lookupNumber(number, countryIso);
if (cachedContactInfo != null && !TextUtils.isEmpty(cachedContactInfo.name)) {
@@ -150,13 +142,13 @@ public class CallLogNotificationsHelper {
}
if (!TextUtils.isEmpty(contactInfo.formattedNumber)) {
- // 4. If we cannot lookup the contact, use the formatted number instead.
+ // 3. If we cannot lookup the contact, use the formatted number instead.
contactInfo.name = contactInfo.formattedNumber;
} else if (!TextUtils.isEmpty(number)) {
- // 5. If number can't be formatted, use number.
+ // 4. If number can't be formatted, use number.
contactInfo.name = number;
} else {
- // 6. Otherwise, it's unknown number.
+ // 5. Otherwise, it's unknown number.
contactInfo.name = mContext.getResources().getString(R.string.unknown);
}
return contactInfo;
@@ -259,7 +251,7 @@ public class CallLogNotificationsHelper {
@Override
@Nullable
public List<NewCall> query(int type) {
- if (!PermissionsUtil.hasPermission(mContext, READ_CALL_LOG)) {
+ if (!PermissionsUtil.hasPermission(mContext, Manifest.permission.READ_CALL_LOG)) {
Log.w(TAG, "No READ_CALL_LOG permission, returning null for calls lookup.");
return null;
}
@@ -338,7 +330,7 @@ public class CallLogNotificationsHelper {
@Override
@Nullable
public String query(@Nullable String number) {
- if (!PermissionsUtil.hasPermission(mContext, READ_CONTACTS)) {
+ if (!PermissionsUtil.hasPermission(mContext, Manifest.permission.READ_CONTACTS)) {
Log.w(TAG, "No READ_CONTACTS permission, returning null for name lookup.");
return null;
}
diff --git a/src/com/android/dialer/calllog/MissedCallNotifier.java b/src/com/android/dialer/calllog/MissedCallNotifier.java
index a9dfd442f..c422dd58d 100644
--- a/src/com/android/dialer/calllog/MissedCallNotifier.java
+++ b/src/com/android/dialer/calllog/MissedCallNotifier.java
@@ -21,6 +21,7 @@ import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.provider.CallLog.Calls;
import android.text.TextUtils;
@@ -28,13 +29,14 @@ import android.util.Log;
import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.util.PhoneNumberHelper;
-import com.android.dialer.calllog.CallLogNotificationsHelper.NewCall;
import com.android.dialer.DialtactsActivity;
+import com.android.dialer.R;
+import com.android.dialer.calllog.CallLogNotificationsHelper.NewCall;
+import com.android.dialer.contactinfo.ContactPhotoLoader;
import com.android.dialer.list.ListsFragment;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.util.IntentUtil;
import com.android.dialer.util.IntentUtil.CallIntentBuilder;
-import com.android.dialer.R;
import java.util.List;
@@ -94,6 +96,7 @@ public class MissedCallNotifier {
NewCall newestCall = useCallLog ? newCalls.get(0) : null;
long timeMs = useCallLog ? newestCall.dateMs : System.currentTimeMillis();
+ Notification.Builder builder = new Notification.Builder(mContext);
// Display the first line of the notification:
// 1 missed call: <caller name || handle>
// More than 1 missed call: <number of calls> + "missed calls"
@@ -110,6 +113,11 @@ public class MissedCallNotifier {
: R.string.notification_missedCallTitle;
expandedText = contactInfo.name;
+ ContactPhotoLoader loader = new ContactPhotoLoader(mContext, contactInfo);
+ Bitmap photoIcon = loader.loadPhotoIcon();
+ if (photoIcon != null) {
+ builder.setLargeIcon(photoIcon);
+ }
} else {
titleResId = R.string.notification_missedCallsTitle;
expandedText =
@@ -132,7 +140,6 @@ public class MissedCallNotifier {
.setDeleteIntent(createClearMissedCallsPendingIntent());
// Create the notification suitable for display when sensitive information is showing.
- Notification.Builder builder = new Notification.Builder(mContext);
builder.setSmallIcon(android.R.drawable.stat_notify_missed_call)
.setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
.setContentTitle(mContext.getText(titleResId))
@@ -161,7 +168,6 @@ public class MissedCallNotifier {
createSendSmsFromNotificationPendingIntent(number));
}
}
- //TODO: add photo
}
Notification notification = builder.build();