diff options
author | Justin Klaassen <justinklaassen@google.com> | 2017-09-15 17:58:39 -0400 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2017-09-15 17:58:39 -0400 |
commit | 10d07c88d69cc64f73a069163e7ea5ba2519a099 (patch) | |
tree | 8dbd149eb350320a29c3d10e7ad3201de1c5cbee /android/text/Emoji.java | |
parent | 677516fb6b6f207d373984757d3d9450474b6b00 (diff) | |
download | android-28-10d07c88d69cc64f73a069163e7ea5ba2519a099.tar.gz |
Import Android SDK Platform PI [4335822]
/google/data/ro/projects/android/fetch_artifact \
--bid 4335822 \
--target sdk_phone_armv7-win_sdk \
sdk-repo-linux-sources-4335822.zip
AndroidVersion.ApiLevel has been modified to appear as 28
Change-Id: Ic8f04be005a71c2b9abeaac754d8da8d6f9a2c32
Diffstat (limited to 'android/text/Emoji.java')
-rw-r--r-- | android/text/Emoji.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/android/text/Emoji.java b/android/text/Emoji.java new file mode 100644 index 00000000..d33aad99 --- /dev/null +++ b/android/text/Emoji.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.text; + +import android.icu.lang.UCharacter; +import android.icu.lang.UProperty; + +/** + * An utility class for Emoji. + * @hide + */ +public class Emoji { + public static int COMBINING_ENCLOSING_KEYCAP = 0x20E3; + + public static int ZERO_WIDTH_JOINER = 0x200D; + + public static int VARIATION_SELECTOR_16 = 0xFE0F; + + public static int CANCEL_TAG = 0xE007F; + + /** + * Returns true if the given code point is regional indicator symbol. + */ + public static boolean isRegionalIndicatorSymbol(int codePoint) { + return 0x1F1E6 <= codePoint && codePoint <= 0x1F1FF; + } + + /** + * Returns true if the given code point is emoji modifier. + */ + public static boolean isEmojiModifier(int codePoint) { + return UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI_MODIFIER); + } + + // Returns true if the given code point is emoji modifier base. + public static boolean isEmojiModifierBase(int codePoint) { + // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to + // keep them as emoji modifier bases since there are fonts and user-generated text out there + // that treats these as potential emoji bases. + if (codePoint == 0x1F91D || codePoint == 0x1F93C) { + return true; + } + // Emoji Modifier Base characters new in Unicode emoji 5.0. + // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt + // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. + if (codePoint == 0x1F91F + || (0x1F931 <= codePoint && codePoint <= 0x1F932) + || (0x1F9D1 <= codePoint && codePoint <= 0x1F9DD)) { + return true; + } + return UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI_MODIFIER_BASE); + } + + /** + * Returns true if the character is a new emoji still not supported in our version of ICU. + */ + public static boolean isNewEmoji(int codePoint) { + // Emoji characters new in Unicode emoji 5.0. + // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt + // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. + if (codePoint < 0x1F6F7 || codePoint > 0x1F9E6) { + // Optimization for characters outside the new emoji range. + return false; + } + return (0x1F6F7 <= codePoint && codePoint <= 0x1F6F8) + || codePoint == 0x1F91F + || (0x1F928 <= codePoint && codePoint <= 0x1F92F) + || (0x1F931 <= codePoint && codePoint <= 0x1F932) + || codePoint == 0x1F94C + || (0x1F95F <= codePoint && codePoint <= 0x1F96B) + || (0x1F992 <= codePoint && codePoint <= 0x1F997) + || (0x1F9D0 <= codePoint && codePoint <= 0x1F9E6); + } + + /** + * Returns true if the character has Emoji property. + */ + public static boolean isEmoji(int codePoint) { + return isNewEmoji(codePoint) || UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI); + } + + // Returns true if the character can be a base character of COMBINING ENCLOSING KEYCAP. + public static boolean isKeycapBase(int codePoint) { + return ('0' <= codePoint && codePoint <= '9') || codePoint == '#' || codePoint == '*'; + } + + /** + * Returns true if the character can be a part of tag_spec in emoji tag sequence. + * + * Note that 0xE007F (CANCEL TAG) is not included. + */ + public static boolean isTagSpecChar(int codePoint) { + return 0xE0020 <= codePoint && codePoint <= 0xE007E; + } +} |