diff --git a/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml b/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml index 085e95540f6af..b715999b477c9 100644 --- a/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml +++ b/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml @@ -18,89 +18,175 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> - - - - + android:layout_height="match_parent" + android:gravity="start"> + + + + + + + + - - - - - - + + + + + + + + + + + + + + + - - - - - + \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java index d682379d379a1..a2c7659e40c73 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java @@ -62,6 +62,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -75,6 +77,11 @@ public class PeopleSpaceUtils { private static final int ONE_DAY = 1; public static final String OPTIONS_PEOPLE_SPACE_TILE = "options_people_space_tile"; + private static final Pattern DOUBLE_EXCLAMATION_PATTERN = Pattern.compile("[!][!]+"); + private static final Pattern DOUBLE_QUESTION_PATTERN = Pattern.compile("[?][?]+"); + private static final Pattern ANY_DOUBLE_MARK_PATTERN = Pattern.compile("[!?][!?]+"); + private static final Pattern MIXED_MARK_PATTERN = Pattern.compile("![?].*|.*[?]!"); + /** Represents whether {@link StatusBarNotification} was posted or removed. */ public enum NotificationAction { POSTED, @@ -242,7 +249,9 @@ public class PeopleSpaceUtils { views.setViewVisibility(R.id.image, View.VISIBLE); views.setViewVisibility(R.id.content, View.GONE); } else { - views.setTextViewText(R.id.content, tile.getNotificationContent()); + CharSequence content = tile.getNotificationContent(); + views = setPunctuationRemoteViewsFields(views, content); + views.setTextViewText(R.id.content, content); views.setViewVisibility(R.id.content, View.VISIBLE); views.setViewVisibility(R.id.image, View.GONE); } @@ -281,6 +290,54 @@ public class PeopleSpaceUtils { return views; } + private static RemoteViews setPunctuationRemoteViewsFields( + RemoteViews views, CharSequence content) { + String punctuation = getBackgroundTextFromMessage(content.toString()); + int visibility = View.GONE; + if (punctuation != null) { + visibility = View.VISIBLE; + } + views.setTextViewText(R.id.punctuation1, punctuation); + views.setTextViewText(R.id.punctuation2, punctuation); + views.setTextViewText(R.id.punctuation3, punctuation); + views.setTextViewText(R.id.punctuation4, punctuation); + views.setTextViewText(R.id.punctuation5, punctuation); + views.setTextViewText(R.id.punctuation6, punctuation); + + views.setViewVisibility(R.id.punctuation1, visibility); + views.setViewVisibility(R.id.punctuation2, visibility); + views.setViewVisibility(R.id.punctuation3, visibility); + views.setViewVisibility(R.id.punctuation4, visibility); + views.setViewVisibility(R.id.punctuation5, visibility); + views.setViewVisibility(R.id.punctuation6, visibility); + + return views; + } + + /** Gets character for tile background decoration based on notification content. */ + @VisibleForTesting + static String getBackgroundTextFromMessage(String message) { + if (!ANY_DOUBLE_MARK_PATTERN.matcher(message).find()) { + return null; + } + if (MIXED_MARK_PATTERN.matcher(message).find()) { + return "!?"; + } + Matcher doubleQuestionMatcher = DOUBLE_QUESTION_PATTERN.matcher(message); + if (!doubleQuestionMatcher.find()) { + return "!"; + } + Matcher doubleExclamationMatcher = DOUBLE_EXCLAMATION_PATTERN.matcher(message); + if (!doubleExclamationMatcher.find()) { + return "?"; + } + // If we have both "!!" and "??", return the one that comes first. + if (doubleQuestionMatcher.start() < doubleExclamationMatcher.start()) { + return "?"; + } + return "!"; + } + /** Gets the most recent {@link Notification.MessagingStyle.Message} from the notification. */ public static Notification.MessagingStyle.Message getLastMessagingStyleMessage( StatusBarNotification sbn) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java index e934f840169f5..2a065af2a1fd8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java @@ -123,6 +123,95 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { assertThat(lastMessage).isNull(); } + @Test + public void testGetBackgroundTextFromMessageNoPunctuation() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("test"); + + assertThat(backgroundText).isNull(); + } + + @Test + public void testGetBackgroundTextFromMessageSingleExclamation() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("test!"); + + assertThat(backgroundText).isNull(); + } + + @Test + public void testGetBackgroundTextFromMessageSingleQuestion() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("?test"); + + assertThat(backgroundText).isNull(); + } + + @Test + public void testGetBackgroundTextFromMessageSeparatedMarks() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("test! right!"); + + assertThat(backgroundText).isNull(); + } + + @Test + public void testGetBackgroundTextFromMessageDoubleExclamation() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("!!test"); + + assertThat(backgroundText).isEqualTo("!"); + } + + @Test + public void testGetBackgroundTextFromMessageDoubleQuestion() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("test??"); + + assertThat(backgroundText).isEqualTo("?"); + } + + @Test + public void testGetBackgroundTextFromMessageMixed() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage("test?!"); + + assertThat(backgroundText).isEqualTo("!?"); + } + + @Test + public void testGetBackgroundTextFromMessageMixedInTheMiddle() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage( + "test!? in the middle"); + + assertThat(backgroundText).isEqualTo("!?"); + } + + @Test + public void testGetBackgroundTextFromMessageMixedDifferentOrder() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage( + "test!? in the middle"); + + assertThat(backgroundText).isEqualTo("!?"); + } + + @Test + public void testGetBackgroundTextFromMessageMultiple() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage( + "test!?!!? in the middle"); + + assertThat(backgroundText).isEqualTo("!?"); + } + + @Test + public void testGetBackgroundTextFromMessageQuestionFirst() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage( + "test?? in the middle!!"); + + assertThat(backgroundText).isEqualTo("?"); + } + + @Test + public void testGetBackgroundTextFromMessageExclamationFirst() { + String backgroundText = PeopleSpaceUtils.getBackgroundTextFromMessage( + "test!! in the middle??"); + + assertThat(backgroundText).isEqualTo("!"); + } + @Test public void testGetLastMessagingStyleMessage() { Notification notification = new Notification.Builder(mContext, "test")