Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6817946f authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 25601 into eclair

* changes:
  Fix possible race condition when switching keyboards while there are pending messages.
parents 3ecd5f43 ebe3d518
Loading
Loading
Loading
Loading
+12 −7
Original line number Original line Diff line number Diff line
@@ -408,6 +408,8 @@ public class KeyboardView extends View implements View.OnClickListener {
        if (mKeyboard != null) {
        if (mKeyboard != null) {
            showPreview(NOT_A_KEY);
            showPreview(NOT_A_KEY);
        }
        }
        // Remove any pending messages
        removeMessages();
        mKeyboard = keyboard;
        mKeyboard = keyboard;
        List<Key> keys = mKeyboard.getKeys();
        List<Key> keys = mKeyboard.getKeys();
        mKeys = keys.toArray(new Key[keys.size()]);
        mKeys = keys.toArray(new Key[keys.size()]);
@@ -828,6 +830,7 @@ public class KeyboardView extends View implements View.OnClickListener {
    private void showKey(final int keyIndex) {
    private void showKey(final int keyIndex) {
        final PopupWindow previewPopup = mPreviewPopup;
        final PopupWindow previewPopup = mPreviewPopup;
        final Key[] keys = mKeys;
        final Key[] keys = mKeys;
        if (keyIndex < 0 || keyIndex >= mKeys.length) return;
        Key key = keys[keyIndex];
        Key key = keys[keyIndex];
        if (key.icon != null) {
        if (key.icon != null) {
            mPreviewText.setCompoundDrawables(null, null, null, 
            mPreviewText.setCompoundDrawables(null, null, null, 
@@ -1145,9 +1148,7 @@ public class KeyboardView extends View implements View.OnClickListener {
                break;
                break;


            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_UP:
                mHandler.removeMessages(MSG_SHOW_PREVIEW);
                removeMessages();
                mHandler.removeMessages(MSG_REPEAT);
                mHandler.removeMessages(MSG_LONGPRESS);
                if (keyIndex == mCurrentKey) {
                if (keyIndex == mCurrentKey) {
                    mCurrentKeyTime += eventTime - mLastMoveTime;
                    mCurrentKeyTime += eventTime - mLastMoveTime;
                } else {
                } else {
@@ -1203,9 +1204,7 @@ public class KeyboardView extends View implements View.OnClickListener {
        if (mPreviewPopup.isShowing()) {
        if (mPreviewPopup.isShowing()) {
            mPreviewPopup.dismiss();
            mPreviewPopup.dismiss();
        }
        }
        mHandler.removeMessages(MSG_REPEAT);
        removeMessages();
        mHandler.removeMessages(MSG_LONGPRESS);
        mHandler.removeMessages(MSG_SHOW_PREVIEW);
        
        
        dismissPopupKeyboard();
        dismissPopupKeyboard();
        mBuffer = null;
        mBuffer = null;
@@ -1213,6 +1212,12 @@ public class KeyboardView extends View implements View.OnClickListener {
        mMiniKeyboardCache.clear();
        mMiniKeyboardCache.clear();
    }
    }


    private void removeMessages() {
        mHandler.removeMessages(MSG_REPEAT);
        mHandler.removeMessages(MSG_LONGPRESS);
        mHandler.removeMessages(MSG_SHOW_PREVIEW);
    }

    @Override
    @Override
    public void onDetachedFromWindow() {
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        super.onDetachedFromWindow();