summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ang Li <ihcinihsdk@google.com> 2023-10-16 20:33:07 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-10-16 20:33:07 +0000
commit281c3994ce759fb18d092f8a961316ab6e349c8c (patch)
tree29c8ed95c3e4edc37687a92221b2a561f9f7df2a
parentfb7046244b127b446d5f5bc714879aa57eec4071 (diff)
parent929d298d7a387b443d4abd5142a8465b9596dc84 (diff)
Merge "Extract variables related to Emoji to a separate class." into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java77
1 files changed, 40 insertions, 37 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java b/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java
index 733383e344b8..58c4f0d029c7 100644
--- a/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java
@@ -96,6 +96,44 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+/** Variables and functions that is related to Emoji. */
+class EmojiHelper {
+ static final CharSequence EMOJI_CAKE = "\ud83c\udf82";
+
+ // This regex can be used to match Unicode emoji characters and character sequences. It's from
+ // the official Unicode site (https://unicode.org/reports/tr51/#EBNF_and_Regex) with minor
+ // changes to fit our needs. It should be updated once new emoji categories are added.
+ //
+ // Emoji categories that can be matched by this regex:
+ // - Country flags. "\p{RI}\p{RI}" matches country flags since they always consist of 2 Unicode
+ // scalars.
+ // - Single-Character Emoji. "\p{Emoji}" matches Single-Character Emojis.
+ // - Emoji with modifiers. E.g. Emojis with different skin tones. "\p{Emoji}\p{EMod}" matches
+ // them.
+ // - Emoji Presentation. Those are characters which can normally be drawn as either text or as
+ // Emoji. "\p{Emoji}\x{FE0F}" matches them.
+ // - Emoji Keycap. E.g. Emojis for number 0 to 9. "\p{Emoji}\x{FE0F}\x{20E3}" matches them.
+ // - Emoji tag sequence. "\p{Emoji}[\x{E0020}-\x{E007E}]+\x{E007F}" matches them.
+ // - Emoji Zero-Width Joiner (ZWJ) Sequence. A ZWJ emoji is actually multiple emojis joined by
+ // the jointer "0x200D".
+ //
+ // Note: since "\p{Emoji}" also matches some ASCII characters like digits 0-9, we use
+ // "\p{Emoji}&&\p{So}" to exclude them. This is the change we made from the official emoji
+ // regex.
+ private static final String UNICODE_EMOJI_REGEX =
+ "\\p{RI}\\p{RI}|"
+ + "("
+ + "\\p{Emoji}(\\p{EMod}|\\x{FE0F}\\x{20E3}?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})"
+ + "|[\\p{Emoji}&&\\p{So}]"
+ + ")"
+ + "("
+ + "\\x{200D}"
+ + "\\p{Emoji}(\\p{EMod}|\\x{FE0F}\\x{20E3}?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})"
+ + "?)*";
+
+ static final Pattern EMOJI_PATTERN = Pattern.compile(UNICODE_EMOJI_REGEX);
+}
+
/** Functions that help creating the People tile layouts. */
public class PeopleTileViewHelper {
/** Turns on debugging information about People Space. */
@@ -125,8 +163,6 @@ public class PeopleTileViewHelper {
private static final int MESSAGES_COUNT_OVERFLOW = 6;
- private static final CharSequence EMOJI_CAKE = "\ud83c\udf82";
-
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("[!?][!?]+");
@@ -134,39 +170,6 @@ public class PeopleTileViewHelper {
static final String BRIEF_PAUSE_ON_TALKBACK = "\n\n";
- // This regex can be used to match Unicode emoji characters and character sequences. It's from
- // the official Unicode site (https://unicode.org/reports/tr51/#EBNF_and_Regex) with minor
- // changes to fit our needs. It should be updated once new emoji categories are added.
- //
- // Emoji categories that can be matched by this regex:
- // - Country flags. "\p{RI}\p{RI}" matches country flags since they always consist of 2 Unicode
- // scalars.
- // - Single-Character Emoji. "\p{Emoji}" matches Single-Character Emojis.
- // - Emoji with modifiers. E.g. Emojis with different skin tones. "\p{Emoji}\p{EMod}" matches
- // them.
- // - Emoji Presentation. Those are characters which can normally be drawn as either text or as
- // Emoji. "\p{Emoji}\x{FE0F}" matches them.
- // - Emoji Keycap. E.g. Emojis for number 0 to 9. "\p{Emoji}\x{FE0F}\x{20E3}" matches them.
- // - Emoji tag sequence. "\p{Emoji}[\x{E0020}-\x{E007E}]+\x{E007F}" matches them.
- // - Emoji Zero-Width Joiner (ZWJ) Sequence. A ZWJ emoji is actually multiple emojis joined by
- // the jointer "0x200D".
- //
- // Note: since "\p{Emoji}" also matches some ASCII characters like digits 0-9, we use
- // "\p{Emoji}&&\p{So}" to exclude them. This is the change we made from the official emoji
- // regex.
- private static final String UNICODE_EMOJI_REGEX =
- "\\p{RI}\\p{RI}|"
- + "("
- + "\\p{Emoji}(\\p{EMod}|\\x{FE0F}\\x{20E3}?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})"
- + "|[\\p{Emoji}&&\\p{So}]"
- + ")"
- + "("
- + "\\x{200D}"
- + "\\p{Emoji}(\\p{EMod}|\\x{FE0F}\\x{20E3}?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})"
- + "?)*";
-
- private static final Pattern EMOJI_PATTERN = Pattern.compile(UNICODE_EMOJI_REGEX);
-
public static final String EMPTY_STRING = "";
private int mMediumVerticalPadding;
@@ -831,7 +834,7 @@ public class PeopleTileViewHelper {
if (status.getActivity() == ACTIVITY_BIRTHDAY
|| status.getActivity() == ACTIVITY_UPCOMING_BIRTHDAY) {
- setEmojiBackground(views, EMOJI_CAKE);
+ setEmojiBackground(views, EmojiHelper.EMOJI_CAKE);
}
Icon statusIcon = status.getIcon();
@@ -1072,7 +1075,7 @@ public class PeopleTileViewHelper {
/** Returns emoji if {@code message} has two of the same emoji in sequence. */
@VisibleForTesting
CharSequence getDoubleEmoji(CharSequence message) {
- Matcher unicodeEmojiMatcher = EMOJI_PATTERN.matcher(message);
+ Matcher unicodeEmojiMatcher = EmojiHelper.EMOJI_PATTERN.matcher(message);
// Stores the start and end indices of each matched emoji.
List<Pair<Integer, Integer>> emojiIndices = new ArrayList<>();
// Stores each emoji text.