From a2a057a991d825c85dd07d4d353ddbca4f9ad92d Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 8 Dec 2015 16:50:51 -0800 Subject: [PATCH] Check if last shown Emoji category ID is still valid When upgrading to a new version of APK we may find that the stored Emoji category ID is no longer applicable. For example it happened when we brought in the new Unicode 8.0 Emojis. Also restore the "Symbols" emoji category on pre-kitkat devices which was accidentally dropped when bringing in Unicode 8.0 Emojis. b/25972978 Change-Id: I91c044603b0aac8757cb8597d3af995f84b822f3 --- .../keyboard/emoji/EmojiCategory.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java index 75b7962cb..b57e483d1 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java @@ -196,6 +196,8 @@ final class EmojiCategory { addShownCategoryId(EmojiCategory.ID_FLAGS); } } + } else { + addShownCategoryId(EmojiCategory.ID_SYMBOLS); } addShownCategoryId(EmojiCategory.ID_EMOTICONS); @@ -204,9 +206,14 @@ final class EmojiCategory { recentsKbd.loadRecentKeys(mCategoryKeyboardMap.values()); mCurrentCategoryId = Settings.readLastShownEmojiCategoryId(mPrefs, defaultCategoryId); - if (mCurrentCategoryId == EmojiCategory.ID_RECENTS && + Log.i(TAG, "Last Emoji category id is " + mCurrentCategoryId); + if (!isShownCategoryId(mCurrentCategoryId)) { + Log.i(TAG, "Last emoji category " + mCurrentCategoryId + + " is invalid, starting in " + defaultCategoryId); + mCurrentCategoryId = defaultCategoryId; + } else if (mCurrentCategoryId == EmojiCategory.ID_RECENTS && recentsKbd.getSortedKeys().isEmpty()) { - Log.i(TAG, "No recent emojis found, starting in category " + mCurrentCategoryId); + Log.i(TAG, "No recent emojis found, starting in category " + defaultCategoryId); mCurrentCategoryId = defaultCategoryId; } } @@ -219,6 +226,15 @@ final class EmojiCategory { mShownCategories.add(properties); } + private boolean isShownCategoryId(final int categoryId) { + for (final CategoryProperties prop : mShownCategories) { + if (prop.mCategoryId == categoryId) { + return true; + } + } + return false; + } + public static String getCategoryName(final int categoryId, final int categoryPageId) { return sCategoryName[categoryId] + "-" + categoryPageId; }