Merge "Decorate PeopleSpaceTile with background chars."
This commit is contained in:
committed by
Android (Google) Code Review
commit
b910c7dab0
@@ -18,89 +18,175 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:background="@drawable/people_space_tile_view_card"
|
||||
android:id="@+id/item"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="6dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:gravity="top"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/person_icon"
|
||||
android:layout_width="34dp"
|
||||
android:layout_height="34dp" />
|
||||
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start">
|
||||
<TextView
|
||||
android:id="@+id/punctuation1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:maxLines="1"
|
||||
android:alpha="0.2"
|
||||
android:rotation="350" />
|
||||
<TextView
|
||||
android:id="@+id/punctuation2"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:maxLines="1"
|
||||
android:alpha="0.2"
|
||||
android:rotation="5" />
|
||||
<TextView
|
||||
android:id="@+id/punctuation3"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="25dp"
|
||||
android:maxLines="1"
|
||||
android:alpha="0.2"
|
||||
android:rotation="355"/>
|
||||
<TextView
|
||||
android:id="@+id/punctuation4"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="-5dp"
|
||||
android:layout_marginStart="25dp"
|
||||
android:maxLines="1"
|
||||
android:alpha="0.2"
|
||||
android:rotation="10" />
|
||||
<TextView
|
||||
android:id="@+id/punctuation5"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="25dp"
|
||||
android:maxLines="1"
|
||||
android:alpha="0.2"
|
||||
android:rotation="15" />
|
||||
<TextView
|
||||
android:id="@+id/punctuation6"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="-5dp"
|
||||
android:layout_marginStart="25dp"
|
||||
android:maxLines="1"
|
||||
android:alpha="0.2"
|
||||
android:rotation="345" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/item"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="6dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:background="@drawable/people_space_rounded_border"
|
||||
android:layout_marginStart="-5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/package_icon"
|
||||
android:layout_width="6dp"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:layout_marginStart="1dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:layout_marginTop="1dp"
|
||||
android:layout_height="6dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="6dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:gravity="top"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="14sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ImageView
|
||||
android:id="@+id/person_icon"
|
||||
android:layout_width="34dp"
|
||||
android:layout_height="34dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:background="@drawable/people_space_rounded_border"
|
||||
android:layout_marginStart="-5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/package_icon"
|
||||
android:layout_width="6dp"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:layout_marginStart="1dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:layout_marginTop="1dp"
|
||||
android:layout_height="6dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="6dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="14sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="10sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:background="@drawable/people_space_content_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:id="@+id/content"
|
||||
android:paddingVertical="3dp"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="10sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:textSize="14sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end" />
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:background="@drawable/people_space_content_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:paddingVertical="3dp"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
|
||||
android:textSize="14sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end" />
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
@@ -64,6 +64,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;
|
||||
|
||||
@@ -77,6 +79,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,
|
||||
@@ -267,7 +274,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);
|
||||
}
|
||||
@@ -306,6 +315,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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user