Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package androidx.emoji.util;
     18 
     19 import androidx.annotation.NonNull;
     20 
     21 public class Emoji {
     22 
     23     public static final int CHAR_KEYCAP = 0x20E3;
     24     public static final int CHAR_DIGIT = 0x0039;
     25     public static final int CHAR_ZWJ = 0x200D;
     26     public static final int CHAR_VS_EMOJI = 0xFE0f;
     27     public static final int CHAR_VS_TEXT = 0xFE0E;
     28     public static final int CHAR_FITZPATRICK = 0x1F3FE;
     29     public static final int CHAR_FITZPATRICK_TYPE_1 = 0x1F3fB;
     30     public static final int CHAR_DEFAULT_TEXT_STYLE = 0x26F9;
     31     public static final int CHAR_DEFAULT_EMOJI_STYLE = 0x1f3A2;
     32     public static final int CHAR_FEMALE_SIGN = 0x2640;
     33     public static final int CHAR_MAN = 0x1F468;
     34     public static final int CHAR_HEART = 0x2764;
     35     public static final int CHAR_KISS = 0x1F48B;
     36     public static final int CHAR_REGIONAL_SYMBOL = 0x1F1E8;
     37     public static final int CHAR_ASTERISK = 0x002A;
     38 
     39     public static final EmojiMapping EMOJI_SINGLE_CODEPOINT = new EmojiMapping(
     40             new int[]{CHAR_DEFAULT_EMOJI_STYLE}, 0xF01B4);
     41 
     42     public static final EmojiMapping EMOJI_WITH_ZWJ = new EmojiMapping(
     43             new int[]{CHAR_MAN, CHAR_ZWJ, CHAR_HEART, CHAR_VS_EMOJI, CHAR_ZWJ, CHAR_KISS, CHAR_ZWJ,
     44                     CHAR_MAN}, 0xF051F);
     45 
     46     public static final EmojiMapping EMOJI_GENDER = new EmojiMapping(new int[]{
     47             CHAR_DEFAULT_TEXT_STYLE, CHAR_VS_EMOJI, CHAR_ZWJ, CHAR_FEMALE_SIGN}, 0xF0950);
     48 
     49     public static final EmojiMapping EMOJI_FLAG = new EmojiMapping(
     50             new int[]{CHAR_REGIONAL_SYMBOL, CHAR_REGIONAL_SYMBOL}, 0xF03A0);
     51 
     52     public static final EmojiMapping EMOJI_GENDER_WITHOUT_VS = new EmojiMapping(
     53             new int[]{CHAR_DEFAULT_TEXT_STYLE, CHAR_ZWJ, CHAR_FEMALE_SIGN}, 0xF0950);
     54 
     55     public static final EmojiMapping DEFAULT_TEXT_STYLE = new EmojiMapping(
     56             new int[]{CHAR_DEFAULT_TEXT_STYLE, CHAR_VS_EMOJI}, 0xF04C6);
     57 
     58     public static final EmojiMapping EMOJI_REGIONAL_SYMBOL = new EmojiMapping(
     59             new int[]{CHAR_REGIONAL_SYMBOL}, 0xF0025);
     60 
     61     public static final EmojiMapping EMOJI_UNKNOWN_FLAG = new EmojiMapping(
     62             new int[]{0x1F1FA, 0x1F1F3}, 0xF0599);
     63 
     64     public static final EmojiMapping EMOJI_DIGIT_ES = new EmojiMapping(
     65             new int[]{CHAR_DIGIT, CHAR_VS_EMOJI}, 0xF0340);
     66 
     67     public static final EmojiMapping EMOJI_DIGIT_KEYCAP = new EmojiMapping(
     68             new int[]{CHAR_DIGIT, CHAR_KEYCAP}, 0xF0377);
     69 
     70     public static final EmojiMapping EMOJI_DIGIT_ES_KEYCAP = new EmojiMapping(
     71             new int[]{CHAR_DIGIT, CHAR_VS_EMOJI, CHAR_KEYCAP}, 0xF0377);
     72 
     73     public static final EmojiMapping EMOJI_ASTERISK_KEYCAP = new EmojiMapping(
     74             new int[]{CHAR_ASTERISK, CHAR_VS_EMOJI, CHAR_KEYCAP}, 0xF051D);
     75 
     76     public static final EmojiMapping EMOJI_SKIN_MODIFIER = new EmojiMapping(
     77             new int[]{CHAR_MAN, CHAR_FITZPATRICK}, 0xF0603);
     78 
     79     public static final EmojiMapping EMOJI_SKIN_MODIFIER_TYPE_ONE = new EmojiMapping(
     80             new int[]{CHAR_MAN, CHAR_FITZPATRICK_TYPE_1}, 0xF0606);
     81 
     82     public static final EmojiMapping EMOJI_SKIN_MODIFIER_WITH_VS = new EmojiMapping(
     83             new int[]{CHAR_MAN, CHAR_VS_EMOJI, CHAR_FITZPATRICK_TYPE_1}, 0xF0606);
     84 
     85     public static class EmojiMapping {
     86         private final int[] mCodepoints;
     87         private final int mId;
     88 
     89         private EmojiMapping(@NonNull final int[] codepoints, final int id) {
     90             mCodepoints = codepoints;
     91             mId = id;
     92         }
     93 
     94         public final int[] codepoints() {
     95             return mCodepoints;
     96         }
     97 
     98         public final int id() {
     99             return mId;
    100         }
    101 
    102         public final int charCount() {
    103             int count = 0;
    104             for (int i = 0; i < mCodepoints.length; i++) {
    105                 count += Character.charCount(mCodepoints[i]);
    106             }
    107             return count;
    108         }
    109     }
    110 }
    111