aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2013-10-09 18:54:57 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-10-09 18:54:57 -0700
commit383da922a64e33d72907ead6ac8771ad3b98856a (patch)
treec9b10b4ab8a7595a596253d04ee209a4bbcab006 /java/src
parentd439ee371d9765ef5a89b4a766844f2b6965d908 (diff)
parent664f11f2ffee2cfefe12a98bde79673abf909148 (diff)
downloadlatinime-383da922a64e33d72907ead6ac8771ad3b98856a.tar.gz
latinime-383da922a64e33d72907ead6ac8771ad3b98856a.tar.xz
latinime-383da922a64e33d72907ead6ac8771ad3b98856a.zip
am 664f11f2: am 0b288985: Merge "Fix emoji recent key behavior"
* commit '664f11f2ffee2cfefe12a98bde79673abf909148': Fix emoji recent key behavior
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java20
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/DynamicGridKeyboard.java21
2 files changed, 38 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java b/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java
index eb48d01f6..db7c845bc 100644
--- a/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java
@@ -580,10 +580,18 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
}
private void setCurrentCategoryId(final int categoryId, final boolean force) {
- if (mEmojiCategory.getCurrentCategoryId() == categoryId && !force) {
+ final int oldCategoryId = mEmojiCategory.getCurrentCategoryId();
+ if (oldCategoryId == categoryId && !force) {
return;
}
+ if (oldCategoryId == CATEGORY_ID_RECENTS) {
+ // Needs to save pending updates for recent keys when we get out of the recents
+ // category because we don't want to move the recent emojis around while the user
+ // is in the recents category.
+ mEmojiKeyboardAdapter.flushPendingRecentKeys();
+ }
+
mEmojiCategory.setCurrentCategoryId(categoryId);
final int newTabId = mEmojiCategory.getTabIdFromCategoryId(categoryId);
final int newCategoryPageId = mEmojiCategory.getPageIdFromCategoryId(categoryId);
@@ -612,8 +620,18 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
mRecentsKeyboard = mEmojiCategory.getKeyboard(CATEGORY_ID_RECENTS, 0);
}
+ public void flushPendingRecentKeys() {
+ mRecentsKeyboard.flushPendingRecentKeys();
+ final KeyboardView recentKeyboardView =
+ mActiveKeyboardView.get(mEmojiCategory.getRecentTabId());
+ if (recentKeyboardView != null) {
+ recentKeyboardView.invalidateAllKeys();
+ }
+ }
+
public void addRecentKey(final Key key) {
if (mEmojiCategory.isInRecentTab()) {
+ mRecentsKeyboard.addPendingKey(key);
return;
}
mRecentsKeyboard.addKeyFirst(key);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/DynamicGridKeyboard.java b/java/src/com/android/inputmethod/keyboard/internal/DynamicGridKeyboard.java
index 0dd71e2ec..587f95a39 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/DynamicGridKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/DynamicGridKeyboard.java
@@ -39,6 +39,7 @@ public class DynamicGridKeyboard extends Keyboard {
private static final String TAG = DynamicGridKeyboard.class.getSimpleName();
private static final int TEMPLATE_KEY_CODE_0 = 0x30;
private static final int TEMPLATE_KEY_CODE_1 = 0x31;
+ private final Object mLock = new Object();
private final SharedPreferences mPrefs;
private final int mLeftPadding;
@@ -48,6 +49,7 @@ public class DynamicGridKeyboard extends Keyboard {
private final int mMaxKeyCount;
private final boolean mIsRecents;
private final ArrayDeque<GridKey> mGridKeys = CollectionUtils.newArrayDeque();
+ private final ArrayDeque<Key> mPendingKeys = CollectionUtils.newArrayDeque();
private Key[] mCachedGridKeys;
@@ -74,6 +76,21 @@ public class DynamicGridKeyboard extends Keyboard {
throw new RuntimeException("Can't find template key: code=" + code);
}
+ public void addPendingKey(final Key usedKey) {
+ synchronized (mLock) {
+ mPendingKeys.addLast(usedKey);
+ }
+ }
+
+ public void flushPendingRecentKeys() {
+ synchronized (mLock) {
+ while (!mPendingKeys.isEmpty()) {
+ addKey(mPendingKeys.pollFirst(), true);
+ }
+ saveRecentKeys();
+ }
+ }
+
public void addKeyFirst(final Key usedKey) {
addKey(usedKey, true);
if (mIsRecents) {
@@ -89,7 +106,7 @@ public class DynamicGridKeyboard extends Keyboard {
if (usedKey == null) {
return;
}
- synchronized (mGridKeys) {
+ synchronized (mLock) {
mCachedGridKeys = null;
final GridKey key = new GridKey(usedKey);
while (mGridKeys.remove(key)) {
@@ -167,7 +184,7 @@ public class DynamicGridKeyboard extends Keyboard {
@Override
public Key[] getKeys() {
- synchronized (mGridKeys) {
+ synchronized (mLock) {
if (mCachedGridKeys != null) {
return mCachedGridKeys;
}