aboutsummaryrefslogtreecommitdiff
path: root/NotificationShowcase/src
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-03-27 15:44:26 -0400
committerChris Wren <cwren@android.com>2014-06-02 16:12:33 -0400
commit0c599a55ac00df73a055831118a7d0c54a7c9f79 (patch)
treebc4fb34abfb98b1ea6d2e5e5a91ad0aef3ebf7ed /NotificationShowcase/src
parent9bf14882a56bfd5e0bd415993da7d37d8b5c7eb6 (diff)
downloadexperimental-0c599a55ac00df73a055831118a7d0c54a7c9f79.tar.gz
add people annotations to the showcase
Depends-On: I705be85d36c414965505e34501663e7e4cdd0120 This was dropped in a bad merge. Original-Change-Id: I06f47b975f46271eab36836efdc20ac6c30d7345 Change-Id: Ifb0e507ad227588a82e124ea0b00abb422906b2a
Diffstat (limited to 'NotificationShowcase/src')
-rw-r--r--NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java44
1 files changed, 40 insertions, 4 deletions
diff --git a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java
index 9937069..0b83fa0 100644
--- a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java
+++ b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java
@@ -20,17 +20,22 @@ import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.provider.ContactsContract;
import android.support.v4.app.NotificationCompat;
import android.text.SpannableString;
+import android.text.TextUtils;
import android.text.style.StyleSpan;
+import android.util.Log;
import android.view.View;
import java.util.ArrayList;
@@ -73,6 +78,34 @@ public class NotificationService extends IntentService {
public static Notification makeBigTextNotification(Context context, int update, int id,
long when) {
+ String personUri = null;
+ Cursor c = null;
+ try {
+ String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.LOOKUP_KEY };
+ String selections = ContactsContract.Contacts.DISPLAY_NAME + " = 'Mike Cleron'";
+ final ContentResolver contentResolver = context.getContentResolver();
+ c = contentResolver.query(ContactsContract.Contacts.CONTENT_URI,
+ projection, selections, null, null);
+ if (c != null && c.getCount() > 0) {
+ c.moveToFirst();
+ int lookupIdx = c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
+ int idIdx = c.getColumnIndex(ContactsContract.Contacts._ID);
+ String lookupKey = c.getString(lookupIdx);
+ long contactId = c.getLong(idIdx);
+ Uri lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
+ personUri = lookupUri.toString();
+ }
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+ if (TextUtils.isEmpty(personUri)) {
+ Log.w(TAG, "failed to find contact for Mike Cleron");
+ } else {
+ Log.w(TAG, "Mike Cleron is " + personUri);
+ }
+
String addendum = update > 0 ? "(updated) " : "";
String longSmsText = "Hey, looks like\nI'm getting kicked out of this conference" +
" room";
@@ -86,7 +119,7 @@ public class NotificationService extends IntentService {
}
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.bigText(addendum + longSmsText);
- NotificationCompat.Builder bigTextNotification = new NotificationCompat.Builder(context)
+ Notification bigText = new NotificationCompat.Builder(context)
.setContentTitle(addendum + "Mike Cleron")
.setContentIntent(ToastService.getPendingIntent(context, "Clicked on bigText"))
.setContentText(addendum + longSmsText)
@@ -98,8 +131,11 @@ public class NotificationService extends IntentService {
"update: " + update,
UpdateService.getPendingIntent(context, update + 1, id, when))
.setSmallIcon(R.drawable.stat_notify_talk_text)
- .setStyle(bigTextStyle);
- return bigTextNotification.build();
+ .setStyle(bigTextStyle)
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .addPerson(personUri)
+ .build();
+ return bigText;
}
public static Notification makeUploadNotification(Context context, int progress, long when) {
@@ -134,7 +170,6 @@ public class NotificationService extends IntentService {
.setContentText("Matias Duarte")
.setLargeIcon(getBitmap(this, R.drawable.matias_hed))
.setSmallIcon(R.drawable.stat_sys_phone_call)
- .setDefaults(Notification.DEFAULT_SOUND)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentIntent(fullscreenIntent)
.setFullScreenIntent(fullscreenIntent, true)
@@ -143,6 +178,7 @@ public class NotificationService extends IntentService {
.addAction(R.drawable.ic_end_call, "Ignore",
PhoneService.getPendingIntent(this, phoneId, PhoneService.ACTION_IGNORE))
.setOngoing(true)
+ .addPerson(Uri.fromParts("tel", "1 (617) 555-1212", null).toString())
.build();
mNotifications.add(phoneCall);