summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2016-02-01 19:54:33 +0000
committerVictor Chang <vichang@google.com>2016-02-04 14:45:09 +0000
commit1dbbda3b035f2e1e581bb8c403b1d351d2ccdbc9 (patch)
treedcc338ab7a444fde92e2f249add6ca34378c1317
parent44d31642d0549c56737b58c7e7a5b92b0bc5ffcd (diff)
Show work call title for missed call notification
1. return complete ContactInfo in CallLogNotificationsHelper 2. use ContactInfo.userType to decide use work call title or not BUG=26902076 Change-Id: Ic58fea1002de053ba69bc0aff06691b8a8605e64
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/dialer/calllog/CallLogNotificationsHelper.java63
-rw-r--r--src/com/android/dialer/calllog/ContactInfo.java9
-rw-r--r--src/com/android/dialer/calllog/MissedCallNotifier.java13
4 files changed, 64 insertions, 23 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7e87b2fb0..ed88b960f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -106,6 +106,8 @@
<!-- Notification strings -->
<!-- Missed call notification label, used when there's exactly one missed call -->
<string name="notification_missedCallTitle">Missed call</string>
+ <!-- Missed call notification label, used when there's exactly one missed call from work contact -->
+ <string name="notification_missedWorkCallTitle">Missed work call</string>
<!-- Missed call notification label, used when there are two or more missed calls -->
<string name="notification_missedCallsTitle">Missed calls</string>
<!-- Missed call notification message used when there are multiple missed calls -->
diff --git a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
index 64ccd5f88..6abf241b4 100644
--- a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
+++ b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
@@ -26,6 +26,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.PhoneLookup;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
@@ -104,37 +105,61 @@ public class CallLogNotificationsHelper {
*/
public String getName(@Nullable String number, int numberPresentation,
@Nullable String countryIso) {
- String name = PhoneNumberDisplayUtil.getDisplayName(
+ return getContactInfo(number, numberPresentation, countryIso).name;
+ }
+
+ /**
+ * 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.
+ * If that fails, fall back to displaying the number.
+ */
+ public @NonNull ContactInfo getContactInfo(@Nullable String number, int numberPresentation,
+ @Nullable String countryIso) {
+ if (countryIso == null) {
+ countryIso = mCurrentCountryIso;
+ }
+
+ ContactInfo contactInfo = new ContactInfo();
+ contactInfo.number = number;
+ contactInfo.formattedNumber = PhoneNumberUtils.formatNumber(number, countryIso);
+ // contactInfo.normalizedNumber is not PhoneNumberUtils.normalizeNumber. Read ContactInfo.
+ contactInfo.normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso);
+
+ // 1. Special number representation.
+ contactInfo.name = PhoneNumberDisplayUtil.getDisplayName(
mContext,
number,
numberPresentation,
false).toString();
- if (!TextUtils.isEmpty(name)) {
- return name;
+ if (!TextUtils.isEmpty(contactInfo.name)) {
+ return contactInfo;
}
- // Look it up in the database.
- name = mNameLookupQuery.query(number);
- if (!TextUtils.isEmpty(name)) {
- return name;
- }
-
- if (countryIso == null) {
- countryIso = mCurrentCountryIso;
+ // 2. Personal ContactsProvider phonelookup query.
+ contactInfo.name = mNameLookupQuery.query(number);
+ if (!TextUtils.isEmpty(contactInfo.name)) {
+ return contactInfo;
}
- // Look it up in the cache
- ContactInfo contactInfo = mContactInfoHelper.lookupNumber(number, countryIso);
+ // 3. Look it up in the cache.
+ ContactInfo cachedContactInfo = mContactInfoHelper.lookupNumber(number, countryIso);
- if (contactInfo != null && !TextUtils.isEmpty(contactInfo.name)) {
- return contactInfo.name;
+ if (cachedContactInfo != null && !TextUtils.isEmpty(cachedContactInfo.name)) {
+ return cachedContactInfo;
}
- if (!TextUtils.isEmpty(number)) {
- // If we cannot lookup the contact, use the number instead.
- return PhoneNumberUtils.formatNumber(number, countryIso);
+ if (!TextUtils.isEmpty(contactInfo.formattedNumber)) {
+ // 4. 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.
+ contactInfo.name = number;
+ } else {
+ // 6. Otherwise, it's unknown number.
+ contactInfo.name = mContext.getResources().getString(R.string.unknown);
}
- return mContext.getResources().getString(R.string.unknown);
+ return contactInfo;
}
/** Removes the missed call notifications. */
diff --git a/src/com/android/dialer/calllog/ContactInfo.java b/src/com/android/dialer/calllog/ContactInfo.java
index 40d963e4e..8fe4964bc 100644
--- a/src/com/android/dialer/calllog/ContactInfo.java
+++ b/src/com/android/dialer/calllog/ContactInfo.java
@@ -40,6 +40,15 @@ public class ContactInfo {
public String label;
public String number;
public String formattedNumber;
+ /*
+ * ContactInfo.normalizedNumber is a column value returned by PhoneLookup query. By definition,
+ * it's E164 representation.
+ * http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookupColumns.
+ * html#NORMALIZED_NUMBER.
+ *
+ * The fallback value, when PhoneLookup fails or else, should be either null or
+ * PhoneNumberUtils.formatNumberToE164.
+ */
public String normalizedNumber;
/** The photo for the contact, if available. */
public long photoId;
diff --git a/src/com/android/dialer/calllog/MissedCallNotifier.java b/src/com/android/dialer/calllog/MissedCallNotifier.java
index 8811baff8..a9dfd442f 100644
--- a/src/com/android/dialer/calllog/MissedCallNotifier.java
+++ b/src/com/android/dialer/calllog/MissedCallNotifier.java
@@ -26,6 +26,7 @@ import android.provider.CallLog.Calls;
import android.text.TextUtils;
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;
@@ -97,14 +98,18 @@ public class MissedCallNotifier {
// 1 missed call: <caller name || handle>
// More than 1 missed call: <number of calls> + "missed calls"
if (count == 1) {
- titleResId = R.string.notification_missedCallTitle;
-
//TODO: look up caller ID that is not in contacts.
- expandedText = CallLogNotificationsHelper.getInstance(mContext)
- .getName(useCallLog ? newestCall.number : number,
+ ContactInfo contactInfo = CallLogNotificationsHelper.getInstance(mContext)
+ .getContactInfo(useCallLog ? newestCall.number : number,
useCallLog ? newestCall.numberPresentation
: Calls.PRESENTATION_ALLOWED,
useCallLog ? newestCall.countryIso : null);
+
+ titleResId = contactInfo.userType == ContactsUtils.USER_TYPE_WORK
+ ? R.string.notification_missedWorkCallTitle
+ : R.string.notification_missedCallTitle;
+
+ expandedText = contactInfo.name;
} else {
titleResId = R.string.notification_missedCallsTitle;
expandedText =