Loading core/java/android/app/people/PeopleSpaceTile.java +16 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ public class PeopleSpaceTile implements Parcelable { private boolean mIsImportantConversation; private String mNotificationKey; private CharSequence mNotificationContent; private CharSequence mNotificationSender; private String mNotificationCategory; private Uri mNotificationDataUri; private int mMessagesCount; Loading @@ -73,6 +74,7 @@ public class PeopleSpaceTile implements Parcelable { mIsImportantConversation = b.mIsImportantConversation; mNotificationKey = b.mNotificationKey; mNotificationContent = b.mNotificationContent; mNotificationSender = b.mNotificationSender; mNotificationCategory = b.mNotificationCategory; mNotificationDataUri = b.mNotificationDataUri; mMessagesCount = b.mMessagesCount; Loading Loading @@ -134,6 +136,10 @@ public class PeopleSpaceTile implements Parcelable { return mNotificationContent; } public CharSequence getNotificationSender() { return mNotificationSender; } public String getNotificationCategory() { return mNotificationCategory; } Loading Loading @@ -179,6 +185,7 @@ public class PeopleSpaceTile implements Parcelable { builder.setIsImportantConversation(mIsImportantConversation); builder.setNotificationKey(mNotificationKey); builder.setNotificationContent(mNotificationContent); builder.setNotificationSender(mNotificationSender); builder.setNotificationCategory(mNotificationCategory); builder.setNotificationDataUri(mNotificationDataUri); builder.setMessagesCount(mMessagesCount); Loading @@ -201,6 +208,7 @@ public class PeopleSpaceTile implements Parcelable { private boolean mIsImportantConversation; private String mNotificationKey; private CharSequence mNotificationContent; private CharSequence mNotificationSender; private String mNotificationCategory; private Uri mNotificationDataUri; private int mMessagesCount; Loading Loading @@ -316,6 +324,12 @@ public class PeopleSpaceTile implements Parcelable { return this; } /** Sets the associated notification's sender. */ public Builder setNotificationSender(CharSequence notificationSender) { mNotificationSender = notificationSender; return this; } /** Sets the associated notification's category. */ public Builder setNotificationCategory(String notificationCategory) { mNotificationCategory = notificationCategory; Loading Loading @@ -371,6 +385,7 @@ public class PeopleSpaceTile implements Parcelable { mIsImportantConversation = in.readBoolean(); mNotificationKey = in.readString(); mNotificationContent = in.readCharSequence(); mNotificationSender = in.readCharSequence(); mNotificationCategory = in.readString(); mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader()); mMessagesCount = in.readInt(); Loading Loading @@ -398,6 +413,7 @@ public class PeopleSpaceTile implements Parcelable { dest.writeBoolean(mIsImportantConversation); dest.writeString(mNotificationKey); dest.writeCharSequence(mNotificationContent); dest.writeCharSequence(mNotificationSender); dest.writeString(mNotificationCategory); dest.writeParcelable(mNotificationDataUri, flags); dest.writeInt(mMessagesCount); Loading core/tests/coretests/src/android/app/people/PeopleSpaceTileTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ public class PeopleSpaceTileTest { .setIsImportantConversation(true) .setStatuses(statusList).setNotificationKey("key") .setNotificationContent("content") .setNotificationSender("sender") .setNotificationDataUri(Uri.parse("data")) .setMessagesCount(2) .setIntent(new Intent()) Loading @@ -256,6 +257,7 @@ public class PeopleSpaceTileTest { assertThat(readTile.getStatuses()).isEqualTo(tile.getStatuses()); assertThat(readTile.getNotificationKey()).isEqualTo(tile.getNotificationKey()); assertThat(readTile.getNotificationContent()).isEqualTo(tile.getNotificationContent()); assertThat(readTile.getNotificationSender()).isEqualTo(tile.getNotificationSender()); assertThat(readTile.getNotificationDataUri()).isEqualTo(tile.getNotificationDataUri()); assertThat(readTile.getMessagesCount()).isEqualTo(tile.getMessagesCount()); assertThat(readTile.getIntent().toString()).isEqualTo(tile.getIntent().toString()); Loading @@ -281,6 +283,16 @@ public class PeopleSpaceTileTest { assertThat(tile.getNotificationContent()).isEqualTo("test"); } @Test public void testNotificationSender() { PeopleSpaceTile tile = new PeopleSpaceTile .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps) .setNotificationSender("test") .build(); assertThat(tile.getNotificationSender()).isEqualTo("test"); } @Test public void testNotificationDataUri() { PeopleSpaceTile tile = Loading packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java +26 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import java.util.Set; /** Helper functions to handle notifications in People Tiles. */ public class NotificationHelper { private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; private static final String TAG = "PeopleNotificationHelper"; private static final String TAG = "PeopleNotifHelper"; /** Returns the notification with highest priority to be shown in People Tiles. */ public static NotificationEntry getHighestPriorityNotification( Loading Loading @@ -209,5 +209,30 @@ public class NotificationHelper { } return null; } /** Returns whether {@code notification} is a group conversation. */ private static boolean isGroupConversation(Notification notification) { return notification.extras.getBoolean(Notification.EXTRA_IS_GROUP_CONVERSATION, false); } /** * Returns {@code message}'s sender's name if {@code notification} is from a group conversation. */ public static CharSequence getSenderIfGroupConversation(Notification notification, Notification.MessagingStyle.Message message) { if (!isGroupConversation(notification)) { if (DEBUG) { Log.d(TAG, "Notification is not from a group conversation, not checking sender."); } return null; } Person person = message.getSenderPerson(); if (person == null) { if (DEBUG) Log.d(TAG, "Notification from group conversation doesn't include sender."); return null; } if (DEBUG) Log.d(TAG, "Returning sender from group conversation notification."); return person.getName(); } } packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +4 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.people; import static com.android.systemui.people.NotificationHelper.getContactUri; import static com.android.systemui.people.NotificationHelper.getMessagingStyleMessages; import static com.android.systemui.people.NotificationHelper.getSenderIfGroupConversation; import static com.android.systemui.people.NotificationHelper.hasReadContactsPermission; import static com.android.systemui.people.NotificationHelper.isMissedCall; import static com.android.systemui.people.NotificationHelper.shouldMatchNotificationByUri; Loading Loading @@ -233,6 +234,7 @@ public class PeopleSpaceUtils { // Reset notification content. .setNotificationKey(null) .setNotificationContent(null) .setNotificationSender(null) .setNotificationDataUri(null) .setMessagesCount(0) // Reset missed calls category. Loading Loading @@ -272,12 +274,14 @@ public class PeopleSpaceUtils { Log.d(TAG, "Tile key: " + key.toString() + ". Notification message has text: " + hasMessageText); } CharSequence sender = getSenderIfGroupConversation(notification, message); return tile .toBuilder() .setNotificationKey(notificationEntry.getSbn().getKey()) .setNotificationCategory(notification.category) .setNotificationContent(content) .setNotificationSender(sender) .setNotificationDataUri(dataUri) .setMessagesCount(messagesCount) .build(); Loading packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java +14 −7 Original line number Diff line number Diff line Loading @@ -182,7 +182,7 @@ public class PeopleTileViewHelper { return createLastInteractionRemoteViews(); } private void setMaxLines(RemoteViews views) { private void setMaxLines(RemoteViews views, boolean showSender) { int textSize = mLayoutSize == LAYOUT_LARGE ? getSizeInDp( R.dimen.content_text_size_for_medium) : getSizeInDp(R.dimen.content_text_size_for_medium); Loading @@ -190,6 +190,9 @@ public class PeopleTileViewHelper { int notificationContentHeight = getContentHeightForLayout(lineHeight); int maxAdaptiveLines = Math.floorDiv(notificationContentHeight, lineHeight); int maxLines = Math.max(MIN_CONTENT_MAX_LINES, maxAdaptiveLines); // Save a line for sender's name, if present. if (showSender) maxLines--; views.setInt(R.id.text_content, "setMaxLines", maxLines); } Loading Loading @@ -353,7 +356,7 @@ public class PeopleTileViewHelper { RemoteViews views = getViewForContentLayout(); views.setViewVisibility(R.id.predefined_icon, View.VISIBLE); views.setViewVisibility(R.id.messages_count, View.GONE); setMaxLines(views); setMaxLines(views, false); views.setTextViewText(R.id.text_content, mTile.getNotificationContent()); views.setImageViewResource(R.id.predefined_icon, R.drawable.ic_phone_missed); return views; Loading @@ -361,6 +364,7 @@ public class PeopleTileViewHelper { private RemoteViews createNotificationRemoteViews() { RemoteViews views = getViewForContentLayout(); CharSequence sender = mTile.getNotificationSender(); Uri image = mTile.getNotificationDataUri(); if (image != null) { // TODO: Use NotificationInlineImageCache Loading @@ -369,7 +373,7 @@ public class PeopleTileViewHelper { views.setViewVisibility(R.id.text_content, View.GONE); views.setImageViewResource(R.id.predefined_icon, R.drawable.ic_photo_camera); } else { setMaxLines(views); setMaxLines(views, !TextUtils.isEmpty(sender)); CharSequence content = mTile.getNotificationContent(); views = setPunctuationRemoteViewsFields(views, content); views.setColorAttr(R.id.text_content, "setTextColor", android.R.attr.textColorPrimary); Loading @@ -385,9 +389,12 @@ public class PeopleTileViewHelper { views.setViewVisibility(R.id.predefined_icon, View.GONE); } } // TODO: Set subtext as Group Sender name once storing the name in PeopleSpaceTile and // subtract 1 from maxLines when present. if (!TextUtils.isEmpty(sender)) { views.setViewVisibility(R.id.subtext, View.VISIBLE); views.setTextViewText(R.id.subtext, sender); } else { views.setViewVisibility(R.id.subtext, View.GONE); } return views; } Loading Loading @@ -417,7 +424,7 @@ public class PeopleTileViewHelper { } views.setViewVisibility(R.id.predefined_icon, View.VISIBLE); views.setViewVisibility(R.id.messages_count, View.GONE); setMaxLines(views); setMaxLines(views, false); // Secondary text color for statuses. views.setColorAttr(R.id.text_content, "setTextColor", android.R.attr.textColorSecondary); views.setTextViewText(R.id.text_content, statusText); Loading Loading
core/java/android/app/people/PeopleSpaceTile.java +16 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ public class PeopleSpaceTile implements Parcelable { private boolean mIsImportantConversation; private String mNotificationKey; private CharSequence mNotificationContent; private CharSequence mNotificationSender; private String mNotificationCategory; private Uri mNotificationDataUri; private int mMessagesCount; Loading @@ -73,6 +74,7 @@ public class PeopleSpaceTile implements Parcelable { mIsImportantConversation = b.mIsImportantConversation; mNotificationKey = b.mNotificationKey; mNotificationContent = b.mNotificationContent; mNotificationSender = b.mNotificationSender; mNotificationCategory = b.mNotificationCategory; mNotificationDataUri = b.mNotificationDataUri; mMessagesCount = b.mMessagesCount; Loading Loading @@ -134,6 +136,10 @@ public class PeopleSpaceTile implements Parcelable { return mNotificationContent; } public CharSequence getNotificationSender() { return mNotificationSender; } public String getNotificationCategory() { return mNotificationCategory; } Loading Loading @@ -179,6 +185,7 @@ public class PeopleSpaceTile implements Parcelable { builder.setIsImportantConversation(mIsImportantConversation); builder.setNotificationKey(mNotificationKey); builder.setNotificationContent(mNotificationContent); builder.setNotificationSender(mNotificationSender); builder.setNotificationCategory(mNotificationCategory); builder.setNotificationDataUri(mNotificationDataUri); builder.setMessagesCount(mMessagesCount); Loading @@ -201,6 +208,7 @@ public class PeopleSpaceTile implements Parcelable { private boolean mIsImportantConversation; private String mNotificationKey; private CharSequence mNotificationContent; private CharSequence mNotificationSender; private String mNotificationCategory; private Uri mNotificationDataUri; private int mMessagesCount; Loading Loading @@ -316,6 +324,12 @@ public class PeopleSpaceTile implements Parcelable { return this; } /** Sets the associated notification's sender. */ public Builder setNotificationSender(CharSequence notificationSender) { mNotificationSender = notificationSender; return this; } /** Sets the associated notification's category. */ public Builder setNotificationCategory(String notificationCategory) { mNotificationCategory = notificationCategory; Loading Loading @@ -371,6 +385,7 @@ public class PeopleSpaceTile implements Parcelable { mIsImportantConversation = in.readBoolean(); mNotificationKey = in.readString(); mNotificationContent = in.readCharSequence(); mNotificationSender = in.readCharSequence(); mNotificationCategory = in.readString(); mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader()); mMessagesCount = in.readInt(); Loading Loading @@ -398,6 +413,7 @@ public class PeopleSpaceTile implements Parcelable { dest.writeBoolean(mIsImportantConversation); dest.writeString(mNotificationKey); dest.writeCharSequence(mNotificationContent); dest.writeCharSequence(mNotificationSender); dest.writeString(mNotificationCategory); dest.writeParcelable(mNotificationDataUri, flags); dest.writeInt(mMessagesCount); Loading
core/tests/coretests/src/android/app/people/PeopleSpaceTileTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ public class PeopleSpaceTileTest { .setIsImportantConversation(true) .setStatuses(statusList).setNotificationKey("key") .setNotificationContent("content") .setNotificationSender("sender") .setNotificationDataUri(Uri.parse("data")) .setMessagesCount(2) .setIntent(new Intent()) Loading @@ -256,6 +257,7 @@ public class PeopleSpaceTileTest { assertThat(readTile.getStatuses()).isEqualTo(tile.getStatuses()); assertThat(readTile.getNotificationKey()).isEqualTo(tile.getNotificationKey()); assertThat(readTile.getNotificationContent()).isEqualTo(tile.getNotificationContent()); assertThat(readTile.getNotificationSender()).isEqualTo(tile.getNotificationSender()); assertThat(readTile.getNotificationDataUri()).isEqualTo(tile.getNotificationDataUri()); assertThat(readTile.getMessagesCount()).isEqualTo(tile.getMessagesCount()); assertThat(readTile.getIntent().toString()).isEqualTo(tile.getIntent().toString()); Loading @@ -281,6 +283,16 @@ public class PeopleSpaceTileTest { assertThat(tile.getNotificationContent()).isEqualTo("test"); } @Test public void testNotificationSender() { PeopleSpaceTile tile = new PeopleSpaceTile .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps) .setNotificationSender("test") .build(); assertThat(tile.getNotificationSender()).isEqualTo("test"); } @Test public void testNotificationDataUri() { PeopleSpaceTile tile = Loading
packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java +26 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import java.util.Set; /** Helper functions to handle notifications in People Tiles. */ public class NotificationHelper { private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; private static final String TAG = "PeopleNotificationHelper"; private static final String TAG = "PeopleNotifHelper"; /** Returns the notification with highest priority to be shown in People Tiles. */ public static NotificationEntry getHighestPriorityNotification( Loading Loading @@ -209,5 +209,30 @@ public class NotificationHelper { } return null; } /** Returns whether {@code notification} is a group conversation. */ private static boolean isGroupConversation(Notification notification) { return notification.extras.getBoolean(Notification.EXTRA_IS_GROUP_CONVERSATION, false); } /** * Returns {@code message}'s sender's name if {@code notification} is from a group conversation. */ public static CharSequence getSenderIfGroupConversation(Notification notification, Notification.MessagingStyle.Message message) { if (!isGroupConversation(notification)) { if (DEBUG) { Log.d(TAG, "Notification is not from a group conversation, not checking sender."); } return null; } Person person = message.getSenderPerson(); if (person == null) { if (DEBUG) Log.d(TAG, "Notification from group conversation doesn't include sender."); return null; } if (DEBUG) Log.d(TAG, "Returning sender from group conversation notification."); return person.getName(); } }
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +4 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.people; import static com.android.systemui.people.NotificationHelper.getContactUri; import static com.android.systemui.people.NotificationHelper.getMessagingStyleMessages; import static com.android.systemui.people.NotificationHelper.getSenderIfGroupConversation; import static com.android.systemui.people.NotificationHelper.hasReadContactsPermission; import static com.android.systemui.people.NotificationHelper.isMissedCall; import static com.android.systemui.people.NotificationHelper.shouldMatchNotificationByUri; Loading Loading @@ -233,6 +234,7 @@ public class PeopleSpaceUtils { // Reset notification content. .setNotificationKey(null) .setNotificationContent(null) .setNotificationSender(null) .setNotificationDataUri(null) .setMessagesCount(0) // Reset missed calls category. Loading Loading @@ -272,12 +274,14 @@ public class PeopleSpaceUtils { Log.d(TAG, "Tile key: " + key.toString() + ". Notification message has text: " + hasMessageText); } CharSequence sender = getSenderIfGroupConversation(notification, message); return tile .toBuilder() .setNotificationKey(notificationEntry.getSbn().getKey()) .setNotificationCategory(notification.category) .setNotificationContent(content) .setNotificationSender(sender) .setNotificationDataUri(dataUri) .setMessagesCount(messagesCount) .build(); Loading
packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java +14 −7 Original line number Diff line number Diff line Loading @@ -182,7 +182,7 @@ public class PeopleTileViewHelper { return createLastInteractionRemoteViews(); } private void setMaxLines(RemoteViews views) { private void setMaxLines(RemoteViews views, boolean showSender) { int textSize = mLayoutSize == LAYOUT_LARGE ? getSizeInDp( R.dimen.content_text_size_for_medium) : getSizeInDp(R.dimen.content_text_size_for_medium); Loading @@ -190,6 +190,9 @@ public class PeopleTileViewHelper { int notificationContentHeight = getContentHeightForLayout(lineHeight); int maxAdaptiveLines = Math.floorDiv(notificationContentHeight, lineHeight); int maxLines = Math.max(MIN_CONTENT_MAX_LINES, maxAdaptiveLines); // Save a line for sender's name, if present. if (showSender) maxLines--; views.setInt(R.id.text_content, "setMaxLines", maxLines); } Loading Loading @@ -353,7 +356,7 @@ public class PeopleTileViewHelper { RemoteViews views = getViewForContentLayout(); views.setViewVisibility(R.id.predefined_icon, View.VISIBLE); views.setViewVisibility(R.id.messages_count, View.GONE); setMaxLines(views); setMaxLines(views, false); views.setTextViewText(R.id.text_content, mTile.getNotificationContent()); views.setImageViewResource(R.id.predefined_icon, R.drawable.ic_phone_missed); return views; Loading @@ -361,6 +364,7 @@ public class PeopleTileViewHelper { private RemoteViews createNotificationRemoteViews() { RemoteViews views = getViewForContentLayout(); CharSequence sender = mTile.getNotificationSender(); Uri image = mTile.getNotificationDataUri(); if (image != null) { // TODO: Use NotificationInlineImageCache Loading @@ -369,7 +373,7 @@ public class PeopleTileViewHelper { views.setViewVisibility(R.id.text_content, View.GONE); views.setImageViewResource(R.id.predefined_icon, R.drawable.ic_photo_camera); } else { setMaxLines(views); setMaxLines(views, !TextUtils.isEmpty(sender)); CharSequence content = mTile.getNotificationContent(); views = setPunctuationRemoteViewsFields(views, content); views.setColorAttr(R.id.text_content, "setTextColor", android.R.attr.textColorPrimary); Loading @@ -385,9 +389,12 @@ public class PeopleTileViewHelper { views.setViewVisibility(R.id.predefined_icon, View.GONE); } } // TODO: Set subtext as Group Sender name once storing the name in PeopleSpaceTile and // subtract 1 from maxLines when present. if (!TextUtils.isEmpty(sender)) { views.setViewVisibility(R.id.subtext, View.VISIBLE); views.setTextViewText(R.id.subtext, sender); } else { views.setViewVisibility(R.id.subtext, View.GONE); } return views; } Loading Loading @@ -417,7 +424,7 @@ public class PeopleTileViewHelper { } views.setViewVisibility(R.id.predefined_icon, View.VISIBLE); views.setViewVisibility(R.id.messages_count, View.GONE); setMaxLines(views); setMaxLines(views, false); // Secondary text color for statuses. views.setColorAttr(R.id.text_content, "setTextColor", android.R.attr.textColorSecondary); views.setTextViewText(R.id.text_content, statusText); Loading