diff options
| author | Ken Wakasa <kwakasa@google.com> | 2011-06-25 03:54:11 +0900 |
|---|---|---|
| committer | Ken Wakasa <kwakasa@google.com> | 2011-06-26 00:14:40 +0900 |
| commit | 4f0d290c5d112ebac434bd8de4635f7d42ea2df0 (patch) | |
| tree | 04e25e7f7605dd0860147fc0c169ccc381b1881f /java/src/com/android/inputmethod/keyboard/KeyboardView.java | |
| parent | e7de39ac424356311ffde20f26c0517f241e2ba0 (diff) | |
Avoid memory leak by by non-static Handler inner classes
bug: 4901934
Change-Id: I870ab2e621ef3640a84468f09c074cdd726dc963
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/KeyboardView.java')
| -rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardView.java | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 9dc019c61..6a60a9ddf 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -30,7 +30,6 @@ import android.graphics.Rect; import android.graphics.Region.Op; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.util.Log; @@ -53,6 +52,7 @@ import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.keyboard.internal.SwipeTracker; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import java.util.ArrayList; import java.util.HashMap; @@ -193,9 +193,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private static final String KEY_LABEL_REFERENCE_CHAR = "M"; private final int mKeyLabelHorizontalPadding; - private final UIHandler mHandler = new UIHandler(); + private final UIHandler mHandler = new UIHandler(this); - class UIHandler extends Handler { + public static class UIHandler extends StaticInnerHandlerWrapper<KeyboardView> { private static final int MSG_SHOW_KEY_PREVIEW = 1; private static final int MSG_DISMISS_KEY_PREVIEW = 2; private static final int MSG_REPEAT_KEY = 3; @@ -205,34 +205,40 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private boolean mInKeyRepeat; + public UIHandler(KeyboardView outerInstance) { + super(outerInstance); + } + @Override public void handleMessage(Message msg) { + final KeyboardView keyboardView = getOuterInstance(); final PointerTracker tracker = (PointerTracker) msg.obj; switch (msg.what) { case MSG_SHOW_KEY_PREVIEW: - showKey(msg.arg1, tracker); + keyboardView.showKey(msg.arg1, tracker); break; case MSG_DISMISS_KEY_PREVIEW: - mPreviewText.setVisibility(View.INVISIBLE); + keyboardView.mPreviewText.setVisibility(View.INVISIBLE); break; case MSG_REPEAT_KEY: tracker.onRepeatKey(msg.arg1); - startKeyRepeatTimer(mKeyRepeatInterval, msg.arg1, tracker); + startKeyRepeatTimer(keyboardView.mKeyRepeatInterval, msg.arg1, tracker); break; case MSG_LONGPRESS_KEY: - openMiniKeyboardIfRequired(msg.arg1, tracker); + keyboardView.openMiniKeyboardIfRequired(msg.arg1, tracker); break; case MSG_LONGPRESS_SHIFT_KEY: - onLongPressShiftKey(tracker); + keyboardView.onLongPressShiftKey(tracker); break; } } public void showKeyPreview(long delay, int keyIndex, PointerTracker tracker) { + final KeyboardView keyboardView = getOuterInstance(); removeMessages(MSG_SHOW_KEY_PREVIEW); - if (mPreviewText.getVisibility() == VISIBLE || delay == 0) { + if (keyboardView.mPreviewText.getVisibility() == VISIBLE || delay == 0) { // Show right away, if it's already visible and finger is moving around - showKey(keyIndex, tracker); + keyboardView.showKey(keyIndex, tracker); } else { sendMessageDelayed( obtainMessage(MSG_SHOW_KEY_PREVIEW, keyIndex, 0, tracker), delay); |
