am 4905d832: Merge "Release and register current key when emoji palette is hidden"

* commit '4905d83270720ce9b9121595277dae6ba8102f16':
  Release and register current key when emoji palette is hidden
main
Tadashi G. Takaoka 2014-05-25 13:11:51 +00:00 committed by Android Git Automerger
commit de471d02c7
3 changed files with 18 additions and 9 deletions

View File

@ -102,7 +102,7 @@ final class EmojiPageKeyboardView extends KeyboardView implements
}
final Key key = getKey(e);
if (key != null && key != mCurrentKey) {
releaseCurrentKey();
releaseCurrentKey(false /* withKeyRegistering */);
}
return true;
}
@ -119,7 +119,7 @@ final class EmojiPageKeyboardView extends KeyboardView implements
return mKeyDetector.detectHitKey(x, y);
}
public void releaseCurrentKey() {
public void releaseCurrentKey(final boolean withKeyRegistering) {
mHandler.removeCallbacks(mPendingKeyDown);
mPendingKeyDown = null;
final Key currentKey = mCurrentKey;
@ -128,13 +128,16 @@ final class EmojiPageKeyboardView extends KeyboardView implements
}
currentKey.onReleased();
invalidateKey(currentKey);
if (withKeyRegistering) {
mListener.onReleaseKey(currentKey);
}
mCurrentKey = null;
}
@Override
public boolean onDown(final MotionEvent e) {
final Key key = getKey(e);
releaseCurrentKey();
releaseCurrentKey(false /* withKeyRegistering */);
mCurrentKey = key;
if (key == null) {
return false;
@ -163,7 +166,7 @@ final class EmojiPageKeyboardView extends KeyboardView implements
final Key key = getKey(e);
final Runnable pendingKeyDown = mPendingKeyDown;
final Key currentKey = mCurrentKey;
releaseCurrentKey();
releaseCurrentKey(false /* withKeyRegistering */);
if (key == null) {
return false;
}
@ -189,14 +192,14 @@ final class EmojiPageKeyboardView extends KeyboardView implements
@Override
public boolean onScroll(final MotionEvent e1, final MotionEvent e2, final float distanceX,
final float distanceY) {
releaseCurrentKey();
releaseCurrentKey(false /* withKeyRegistering */);
return false;
}
@Override
public boolean onFling(final MotionEvent e1, final MotionEvent e2, final float velocityX,
final float velocityY) {
releaseCurrentKey();
releaseCurrentKey(false /* withKeyRegistering */);
return false;
}

View File

@ -68,13 +68,18 @@ final class EmojiPalettesAdapter extends PagerAdapter {
}
public void onPageScrolled() {
releaseCurrentKey(false /* withKeyRegistering */);
}
public void releaseCurrentKey(final boolean withKeyRegistering) {
// Make sure the delayed key-down event (highlight effect and haptic feedback) will be
// canceled.
final EmojiPageKeyboardView currentKeyboardView =
mActiveKeyboardViews.get(mActivePosition);
if (currentKeyboardView != null) {
currentKeyboardView.releaseCurrentKey();
if (currentKeyboardView == null) {
return;
}
currentKeyboardView.releaseCurrentKey(withKeyRegistering);
}
@Override
@ -90,7 +95,7 @@ final class EmojiPalettesAdapter extends PagerAdapter {
}
final EmojiPageKeyboardView oldKeyboardView = mActiveKeyboardViews.get(mActivePosition);
if (oldKeyboardView != null) {
oldKeyboardView.releaseCurrentKey();
oldKeyboardView.releaseCurrentKey(false /* withKeyRegistering */);
oldKeyboardView.deallocateMemory();
}
mActivePosition = position;

View File

@ -380,6 +380,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
}
public void stopEmojiPalettes() {
mEmojiPalettesAdapter.releaseCurrentKey(true /* withKeyRegistering */);
mEmojiPalettesAdapter.flushPendingRecentKeys();
mEmojiPager.setAdapter(null);
}