diff options
author | 2015-11-09 21:30:07 +0000 | |
---|---|---|
committer | 2015-11-09 21:30:07 +0000 | |
commit | a6b06585fcbece3c20241b6e29251827e73553c6 (patch) | |
tree | c9c5316b48ad493a7f763e1bd79e0dc0ec42fa49 /java/src/com/android/inputmethod | |
parent | 9a438a325b28c8f8884737683237f829c7cb5a15 (diff) | |
parent | 9cc42549d18f1e28ffc8dae94ff36728933f53f1 (diff) | |
download | latinime-a6b06585fcbece3c20241b6e29251827e73553c6.tar.gz latinime-a6b06585fcbece3c20241b6e29251827e73553c6.tar.xz latinime-a6b06585fcbece3c20241b6e29251827e73553c6.zip |
Unicode 8.0 emoji changes to Google Keyboard.
am: 9cc42549d1
* commit '9cc42549d18f1e28ffc8dae94ff36728933f53f1':
Unicode 8.0 emoji changes to Google Keyboard.
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardId.java | 22 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java | 137 |
2 files changed, 140 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index a1f7bf0e1..7352f911b 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Android Open Source Project + * Copyright (C) 2015 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. @@ -60,6 +60,16 @@ public final class KeyboardId { public static final int ELEMENT_EMOJI_CATEGORY4 = 14; public static final int ELEMENT_EMOJI_CATEGORY5 = 15; public static final int ELEMENT_EMOJI_CATEGORY6 = 16; + public static final int ELEMENT_EMOJI_CATEGORY7 = 17; + public static final int ELEMENT_EMOJI_CATEGORY8 = 18; + public static final int ELEMENT_EMOJI_CATEGORY9 = 19; + public static final int ELEMENT_EMOJI_CATEGORY10 = 20; + public static final int ELEMENT_EMOJI_CATEGORY11 = 21; + public static final int ELEMENT_EMOJI_CATEGORY12 = 22; + public static final int ELEMENT_EMOJI_CATEGORY13 = 23; + public static final int ELEMENT_EMOJI_CATEGORY14 = 24; + public static final int ELEMENT_EMOJI_CATEGORY15 = 25; + public static final int ELEMENT_EMOJI_CATEGORY16 = 26; public final RichInputMethodSubtype mSubtype; public final int mWidth; @@ -225,6 +235,16 @@ public final class KeyboardId { case ELEMENT_EMOJI_CATEGORY4: return "emojiCategory4"; case ELEMENT_EMOJI_CATEGORY5: return "emojiCategory5"; case ELEMENT_EMOJI_CATEGORY6: return "emojiCategory6"; + case ELEMENT_EMOJI_CATEGORY7: return "emojiCategory7"; + case ELEMENT_EMOJI_CATEGORY8: return "emojiCategory8"; + case ELEMENT_EMOJI_CATEGORY9: return "emojiCategory9"; + case ELEMENT_EMOJI_CATEGORY10: return "emojiCategory10"; + case ELEMENT_EMOJI_CATEGORY11: return "emojiCategory11"; + case ELEMENT_EMOJI_CATEGORY12: return "emojiCategory12"; + case ELEMENT_EMOJI_CATEGORY13: return "emojiCategory13"; + case ELEMENT_EMOJI_CATEGORY14: return "emojiCategory14"; + case ELEMENT_EMOJI_CATEGORY15: return "emojiCategory15"; + case ELEMENT_EMOJI_CATEGORY16: return "emojiCategory16"; default: return null; } } diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java index f2f52f85b..1f4fbe521 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Android Open Source Project + * Copyright (C) 2015 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. @@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.emoji; import android.content.SharedPreferences; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Paint; import android.graphics.Rect; import android.os.Build; import android.util.Log; @@ -50,6 +51,16 @@ final class EmojiCategory { private static final int ID_PLACES = 4; private static final int ID_SYMBOLS = 5; private static final int ID_EMOTICONS = 6; + private static final int ID_FLAGS = 7; + private static final int ID_EIGHT_SMILEY_PEOPLE = 8; + private static final int ID_EIGHT_ANIMALS_NATURE = 9; + private static final int ID_EIGHT_FOOD_DRINK = 10; + private static final int ID_EIGHT_TRAVEL_PLACES = 11; + private static final int ID_EIGHT_ACTIVITY = 12; + private static final int ID_EIGHT_OBJECTS = 13; + private static final int ID_EIGHT_SYMBOLS = 14; + private static final int ID_EIGHT_FLAGS = 15; + private static final int ID_EIGHT_SMILEY_PEOPLE_BORING = 16; public final class CategoryProperties { public final int mCategoryId; @@ -67,7 +78,17 @@ final class EmojiCategory { "nature", "places", "symbols", - "emoticons" }; + "emoticons", + "flags", + "smiley & people", + "animals & nature", + "food & drink", + "travel & places", + "activity", + "objects2", + "symbols2", + "flags2", + "smiley & people2" }; private static final int[] sCategoryTabIconAttr = { R.styleable.EmojiPalettesView_iconEmojiRecentsTab, @@ -76,7 +97,17 @@ final class EmojiCategory { R.styleable.EmojiPalettesView_iconEmojiCategory3Tab, R.styleable.EmojiPalettesView_iconEmojiCategory4Tab, R.styleable.EmojiPalettesView_iconEmojiCategory5Tab, - R.styleable.EmojiPalettesView_iconEmojiCategory6Tab }; + R.styleable.EmojiPalettesView_iconEmojiCategory6Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory7Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory8Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory9Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory10Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory11Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory12Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory13Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory14Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory15Tab, + R.styleable.EmojiPalettesView_iconEmojiCategory16Tab }; private static final int[] sAccessibilityDescriptionResourceIdsForCategories = { R.string.spoken_descrption_emoji_category_recents, @@ -85,7 +116,17 @@ final class EmojiCategory { R.string.spoken_descrption_emoji_category_nature, R.string.spoken_descrption_emoji_category_places, R.string.spoken_descrption_emoji_category_symbols, - R.string.spoken_descrption_emoji_category_emoticons }; + R.string.spoken_descrption_emoji_category_emoticons, + R.string.spoken_descrption_emoji_category_flags, + R.string.spoken_descrption_emoji_category_eight_smiley_people, + R.string.spoken_descrption_emoji_category_eight_animals_nature, + R.string.spoken_descrption_emoji_category_eight_food_drink, + R.string.spoken_descrption_emoji_category_eight_travel_places, + R.string.spoken_descrption_emoji_category_eight_activity, + R.string.spoken_descrption_emoji_category_objects, + R.string.spoken_descrption_emoji_category_symbols, + R.string.spoken_descrption_emoji_category_flags, + R.string.spoken_descrption_emoji_category_eight_smiley_people }; private static final int[] sCategoryElementId = { KeyboardId.ELEMENT_EMOJI_RECENTS, @@ -94,7 +135,17 @@ final class EmojiCategory { KeyboardId.ELEMENT_EMOJI_CATEGORY3, KeyboardId.ELEMENT_EMOJI_CATEGORY4, KeyboardId.ELEMENT_EMOJI_CATEGORY5, - KeyboardId.ELEMENT_EMOJI_CATEGORY6 }; + KeyboardId.ELEMENT_EMOJI_CATEGORY6, + KeyboardId.ELEMENT_EMOJI_CATEGORY7, + KeyboardId.ELEMENT_EMOJI_CATEGORY8, + KeyboardId.ELEMENT_EMOJI_CATEGORY9, + KeyboardId.ELEMENT_EMOJI_CATEGORY10, + KeyboardId.ELEMENT_EMOJI_CATEGORY11, + KeyboardId.ELEMENT_EMOJI_CATEGORY12, + KeyboardId.ELEMENT_EMOJI_CATEGORY13, + KeyboardId.ELEMENT_EMOJI_CATEGORY14, + KeyboardId.ELEMENT_EMOJI_CATEGORY15, + KeyboardId.ELEMENT_EMOJI_CATEGORY16 }; private final SharedPreferences mPrefs; private final Resources mRes; @@ -124,17 +175,37 @@ final class EmojiCategory { int defaultCategoryId = EmojiCategory.ID_SYMBOLS; addShownCategoryId(EmojiCategory.ID_RECENTS); if (BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.KITKAT) { - defaultCategoryId = EmojiCategory.ID_PEOPLE; - addShownCategoryId(EmojiCategory.ID_PEOPLE); - addShownCategoryId(EmojiCategory.ID_OBJECTS); - addShownCategoryId(EmojiCategory.ID_NATURE); - addShownCategoryId(EmojiCategory.ID_PLACES); + if (canShowUnicodeEightEmoji()) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { + defaultCategoryId = EmojiCategory.ID_EIGHT_SMILEY_PEOPLE; + addShownCategoryId(EmojiCategory.ID_EIGHT_SMILEY_PEOPLE); + } else { + defaultCategoryId = EmojiCategory.ID_EIGHT_SMILEY_PEOPLE_BORING; + addShownCategoryId(EmojiCategory.ID_EIGHT_SMILEY_PEOPLE_BORING); + } + addShownCategoryId(EmojiCategory.ID_EIGHT_ANIMALS_NATURE); + addShownCategoryId(EmojiCategory.ID_EIGHT_FOOD_DRINK); + addShownCategoryId(EmojiCategory.ID_EIGHT_TRAVEL_PLACES); + addShownCategoryId(EmojiCategory.ID_EIGHT_ACTIVITY); + addShownCategoryId(EmojiCategory.ID_EIGHT_OBJECTS); + addShownCategoryId(EmojiCategory.ID_EIGHT_SYMBOLS); + addShownCategoryId(EmojiCategory.ID_FLAGS); // Exclude combinations without glyphs. + } else { + defaultCategoryId = EmojiCategory.ID_PEOPLE; + addShownCategoryId(EmojiCategory.ID_PEOPLE); + addShownCategoryId(EmojiCategory.ID_OBJECTS); + addShownCategoryId(EmojiCategory.ID_NATURE); + addShownCategoryId(EmojiCategory.ID_PLACES); + addShownCategoryId(EmojiCategory.ID_SYMBOLS); + if (canShowFlagEmoji()) { + addShownCategoryId(EmojiCategory.ID_FLAGS); + } + } } - addShownCategoryId(EmojiCategory.ID_SYMBOLS); addShownCategoryId(EmojiCategory.ID_EMOTICONS); DynamicGridKeyboard recentsKbd = - getKeyboard(EmojiCategory.ID_RECENTS, 0 /* cagetoryPageId */); + getKeyboard(EmojiCategory.ID_RECENTS, 0 /* categoryPageId */); recentsKbd.loadRecentKeys(mCategoryKeyboardMap.values()); mCurrentCategoryId = Settings.readLastShownEmojiCategoryId(mPrefs, defaultCategoryId); @@ -147,7 +218,7 @@ final class EmojiCategory { private void addShownCategoryId(final int categoryId) { // Load a keyboard of categoryId - getKeyboard(categoryId, 0 /* cagetoryPageId */); + getKeyboard(categoryId, 0 /* categoryPageId */); final CategoryProperties properties = new CategoryProperties(categoryId, getCategoryPageCount(categoryId)); mShownCategories.add(properties); @@ -282,16 +353,16 @@ final class EmojiCategory { public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) { synchronized (mCategoryKeyboardMap) { - final Long categotyKeyboardMapKey = getCategoryKeyboardMapKey(categoryId, id); - if (mCategoryKeyboardMap.containsKey(categotyKeyboardMapKey)) { - return mCategoryKeyboardMap.get(categotyKeyboardMapKey); + final Long categoryKeyboardMapKey = getCategoryKeyboardMapKey(categoryId, id); + if (mCategoryKeyboardMap.containsKey(categoryKeyboardMapKey)) { + return mCategoryKeyboardMap.get(categoryKeyboardMapKey); } if (categoryId == EmojiCategory.ID_RECENTS) { final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs, mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), mMaxPageKeyCount, categoryId); - mCategoryKeyboardMap.put(categotyKeyboardMapKey, kbd); + mCategoryKeyboardMap.put(categoryKeyboardMapKey, kbd); return kbd; } @@ -311,7 +382,7 @@ final class EmojiCategory { mCategoryKeyboardMap.put( getCategoryKeyboardMapKey(categoryId, pageId), tempKeyboard); } - return mCategoryKeyboardMap.get(categotyKeyboardMapKey); + return mCategoryKeyboardMap.get(categoryKeyboardMapKey); } } @@ -355,4 +426,34 @@ final class EmojiCategory { } return retval; } + + private static boolean canShowFlagEmoji() { + Paint paint = new Paint(); + String switzerland = "\uD83C\uDDE8\uD83C\uDDED"; // U+1F1E8 U+1F1ED Flag for Switzerland + try { + return paint.hasGlyph(switzerland); + } catch (NoSuchMethodError e) { + // Compare display width of single-codepoint emoji to width of flag emoji to determine + // whether flag is rendered as single glyph or two adjacent regional indicator symbols. + float flagWidth = paint.measureText(switzerland); + float standardWidth = paint.measureText("\uD83D\uDC27"); // U+1F427 Penguin + return flagWidth < standardWidth * 1.25; + // This assumes that a valid glyph for the flag emoji must be less than 1.25 times + // the width of the penguin. + } + } + + private static boolean canShowUnicodeEightEmoji() { + Paint paint = new Paint(); + String cheese = "\uD83E\uDDC0"; // U+1F9C0 Cheese wedge + try { + return paint.hasGlyph(cheese); + } catch (NoSuchMethodError e) { + float cheeseWidth = paint.measureText(cheese); + float tofuWidth = paint.measureText("\uFFFE"); + return cheeseWidth > tofuWidth; + // This assumes that a valid glyph for the cheese wedge must be greater than the width + // of the noncharacter. + } + } } |