use of com.android.dialer.app.contactinfo.ContactPhotoLoader in project android_packages_apps_Dialer by LineageOS.
the class MissedCallNotifier method updateMissedCallNotification.
/**
* Update missed call notifications from the call log. Accepts default information in case call
* log cannot be accessed.
*
* @param count the number of missed calls to display if call log cannot be accessed. May be
* {@link CallLogNotificationsService#UNKNOWN_MISSED_CALL_COUNT} if unknown.
* @param number the phone number of the most recent call to display if the call log cannot be
* accessed. May be null if unknown.
*/
@VisibleForTesting
@WorkerThread
void updateMissedCallNotification(int count, @Nullable String number) {
final int titleResId;
// The text in the notification's line 1 and 2.
CharSequence expandedText;
List<NewCall> newCalls = callLogNotificationsQueryHelper.getNewMissedCalls();
if ((newCalls != null && newCalls.isEmpty()) || count == 0) {
// No calls to notify about: clear the notification.
CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context);
cancelAllMissedCallNotifications(context);
return;
}
if (newCalls != null) {
if (count != CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT && count != newCalls.size()) {
LogUtil.w("MissedCallNotifier.updateMissedCallNotification", "Call count does not match call log count." + " count: " + count + " newCalls.size(): " + newCalls.size());
}
count = newCalls.size();
}
if (count == CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT) {
// call log, then no notification can be shown.
return;
}
Notification.Builder groupSummary = createNotificationBuilder();
boolean useCallList = newCalls != null;
if (count == 1) {
NewCall call = useCallList ? newCalls.get(0) : new NewCall(null, null, number, Calls.PRESENTATION_ALLOWED, null, null, null, null, System.currentTimeMillis());
// TODO: look up caller ID that is not in contacts.
ContactInfo contactInfo = callLogNotificationsQueryHelper.getContactInfo(call.number, call.numberPresentation, call.countryIso);
titleResId = contactInfo.userType == ContactsUtils.USER_TYPE_WORK ? R.string.notification_missedWorkCallTitle : R.string.notification_missedCallTitle;
if (TextUtils.equals(contactInfo.name, contactInfo.formattedNumber) || TextUtils.equals(contactInfo.name, contactInfo.number)) {
expandedText = PhoneNumberUtilsCompat.createTtsSpannable(BidiFormatter.getInstance().unicodeWrap(contactInfo.name, TextDirectionHeuristics.LTR));
} else {
expandedText = contactInfo.name;
}
ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo);
Bitmap photoIcon = loader.loadPhotoIcon();
if (photoIcon != null) {
groupSummary.setLargeIcon(photoIcon);
}
} else {
titleResId = R.string.notification_missedCallsTitle;
expandedText = context.getString(R.string.notification_missedCallsMsg, count);
}
// Create a public viewable version of the notification, suitable for display when sensitive
// notification content is hidden.
Notification.Builder publicSummaryBuilder = createNotificationBuilder();
publicSummaryBuilder.setContentTitle(context.getText(titleResId)).setContentIntent(createCallLogPendingIntent()).setDeleteIntent(CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context));
// Create the notification summary suitable for display when sensitive information is showing.
groupSummary.setContentTitle(context.getText(titleResId)).setContentText(expandedText).setContentIntent(createCallLogPendingIntent()).setDeleteIntent(CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context)).setGroupSummary(useCallList).setOnlyAlertOnce(useCallList).setPublicVersion(publicSummaryBuilder.build());
if (BuildCompat.isAtLeastO()) {
groupSummary.setChannelId(NotificationChannelId.MISSED_CALL);
}
Notification notification = groupSummary.build();
configureLedOnNotification(notification);
LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "adding missed call notification");
getNotificationMgr().notify(getNotificationTagForGroupSummary(), NOTIFICATION_ID, notification);
if (useCallList) {
// Do not repost active notifications to prevent erasing post call notes.
NotificationManager manager = getNotificationMgr();
Set<String> activeTags = new ArraySet<>();
for (StatusBarNotification activeNotification : manager.getActiveNotifications()) {
activeTags.add(activeNotification.getTag());
}
for (NewCall call : newCalls) {
String callTag = getNotificationTagForCall(call);
if (!activeTags.contains(callTag)) {
manager.notify(callTag, NOTIFICATION_ID, getNotificationForCall(call, null));
}
}
}
}
use of com.android.dialer.app.contactinfo.ContactPhotoLoader in project android_packages_apps_Dialer by LineageOS.
the class VisualVoicemailNotifier method createNotificationForVoicemail.
private static Notification createNotificationForVoicemail(@NonNull Context context, @NonNull NewCall voicemail, @NonNull Map<String, ContactInfo> contactInfos) {
PhoneAccountHandle handle = getAccountForCall(context, voicemail);
ContactInfo contactInfo = contactInfos.get(voicemail.number);
Notification.Builder builder = createNotificationBuilder(context).setContentTitle(context.getResources().getQuantityString(R.plurals.notification_voicemail_title, 1, 1)).setContentText(ContactDisplayUtils.getTtsSpannedPhoneNumber(context.getResources(), R.string.notification_new_voicemail_ticker, contactInfo.name)).setWhen(voicemail.dateMs).setSound(getVoicemailRingtoneUri(context, handle)).setDefaults(getNotificationDefaultFlags(context, handle));
if (voicemail.voicemailUri != null) {
builder.setDeleteIntent(CallLogNotificationsService.createMarkSingleNewVoicemailAsOldIntent(context, voicemail.voicemailUri));
}
if (BuildCompat.isAtLeastO()) {
builder.setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle));
}
ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo);
Bitmap photoIcon = loader.loadPhotoIcon();
if (photoIcon != null) {
builder.setLargeIcon(photoIcon);
}
if (!TextUtils.isEmpty(voicemail.transcription)) {
Logger.get(context).logImpression(DialerImpression.Type.VVM_NOTIFICATION_CREATED_WITH_TRANSCRIPTION);
builder.setStyle(new Notification.BigTextStyle().bigText(voicemail.transcription));
}
builder.setContentIntent(newVoicemailIntent(context, voicemail));
Logger.get(context).logImpression(DialerImpression.Type.VVM_NOTIFICATION_CREATED);
return builder.build();
}
use of com.android.dialer.app.contactinfo.ContactPhotoLoader in project android_packages_apps_Dialer by LineageOS.
the class MissedCallNotifier method getNotificationForCall.
private Notification getNotificationForCall(@NonNull NewCall call, @Nullable String postCallMessage) {
ContactInfo contactInfo = callLogNotificationsQueryHelper.getContactInfo(call.number, call.numberPresentation, call.countryIso);
// Create a public viewable version of the notification, suitable for display when sensitive
// notification content is hidden.
int titleResId = contactInfo.userType == ContactsUtils.USER_TYPE_WORK ? R.string.notification_missedWorkCallTitle : R.string.notification_missedCallTitle;
Notification.Builder publicBuilder = createNotificationBuilder(call).setContentTitle(context.getText(titleResId));
Notification.Builder builder = createNotificationBuilder(call);
CharSequence expandedText;
if (TextUtils.equals(contactInfo.name, contactInfo.formattedNumber) || TextUtils.equals(contactInfo.name, contactInfo.number)) {
expandedText = PhoneNumberUtilsCompat.createTtsSpannable(BidiFormatter.getInstance().unicodeWrap(contactInfo.name, TextDirectionHeuristics.LTR));
} else {
expandedText = contactInfo.name;
}
if (postCallMessage != null) {
expandedText = context.getString(R.string.post_call_notification_message, expandedText, postCallMessage);
}
ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo);
Bitmap photoIcon = loader.loadPhotoIcon();
if (photoIcon != null) {
builder.setLargeIcon(photoIcon);
}
// Create the notification suitable for display when sensitive information is showing.
builder.setContentTitle(context.getText(titleResId)).setContentText(expandedText).setPublicVersion(publicBuilder.build());
// Add additional actions when the user isn't locked
if (UserManagerCompat.isUserUnlocked(context)) {
if (!TextUtils.isEmpty(call.number) && !TextUtils.equals(call.number, context.getString(R.string.handle_restricted))) {
builder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.ic_phone_24dp), context.getString(R.string.notification_missedCall_call_back), createCallBackPendingIntent(call.number, call.callsUri)).build());
if (!PhoneNumberHelper.isUriNumber(call.number)) {
builder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.quantum_ic_message_white_24), context.getString(R.string.notification_missedCall_message), createSendSmsFromNotificationPendingIntent(call.number, call.callsUri)).build());
}
}
}
Notification notification = builder.build();
configureLedOnNotification(notification);
return notification;
}
Aggregations