From ccc86630a25704ac726c8aa0cf0d008a29d4259f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 29 Nov 2013 11:50:00 +0900 Subject: [PATCH] Rename StaticInnerHandlerWrapper to LeakGuardHandlerWrapper Change-Id: I024f0ee9c7f7718afc8a4ca0c6c49f2e88b035ad --- .../internal/GestureTrailsPreview.java | 14 ++++++----- .../MainKeyboardViewDrawingHandler.java | 20 +++++++++------ .../MainKeyboardViewTimerHandler.java | 25 +++++++++++-------- .../android/inputmethod/latin/LatinIME.java | 22 ++++++++-------- .../latin/setup/SetupWizardActivity.java | 10 ++++---- ...pper.java => LeakGuardHandlerWrapper.java} | 20 +++++++-------- 6 files changed, 60 insertions(+), 51 deletions(-) rename java/src/com/android/inputmethod/latin/utils/{StaticInnerHandlerWrapper.java => LeakGuardHandlerWrapper.java} (60%) diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java index 19e995548..8b413e5e2 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java @@ -31,7 +31,7 @@ import android.view.View; import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.internal.GestureTrail.Params; import com.android.inputmethod.latin.utils.CollectionUtils; -import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; /** * Draw gesture trail preview graphics during gesture. @@ -52,21 +52,23 @@ public final class GestureTrailsPreview extends AbstractDrawingPreview { private final DrawingHandler mDrawingHandler; private static final class DrawingHandler - extends StaticInnerHandlerWrapper { + extends LeakGuardHandlerWrapper { private static final int MSG_UPDATE_GESTURE_TRAIL = 0; private final Params mGestureTrailParams; - public DrawingHandler(final GestureTrailsPreview outerInstance, + public DrawingHandler(final GestureTrailsPreview ownerInstance, final Params gestureTrailParams) { - super(outerInstance); + super(ownerInstance); mGestureTrailParams = gestureTrailParams; } @Override public void handleMessage(final Message msg) { - final GestureTrailsPreview preview = getOuterInstance(); - if (preview == null) return; + final GestureTrailsPreview preview = getOwnerInstance(); + if (preview == null) { + return; + } switch (msg.what) { case MSG_UPDATE_GESTURE_TRAIL: preview.getDrawingView().invalidate(); diff --git a/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java b/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java index 53845534e..fb1f78901 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java +++ b/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java @@ -21,20 +21,22 @@ import android.os.Message; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.latin.SuggestedWords; -import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; -public class MainKeyboardViewDrawingHandler extends StaticInnerHandlerWrapper { +public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper { private static final int MSG_DISMISS_KEY_PREVIEW = 0; private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; - public MainKeyboardViewDrawingHandler(final MainKeyboardView outerInstance) { - super(outerInstance); + public MainKeyboardViewDrawingHandler(final MainKeyboardView ownerInstance) { + super(ownerInstance); } @Override public void handleMessage(final Message msg) { - final MainKeyboardView mainKeyboardView = getOuterInstance(); - if (mainKeyboardView == null) return; + final MainKeyboardView mainKeyboardView = getOwnerInstance(); + if (mainKeyboardView == null) { + return; + } switch (msg.what) { case MSG_DISMISS_KEY_PREVIEW: mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj); @@ -51,8 +53,10 @@ public class MainKeyboardViewDrawingHandler extends StaticInnerHandlerWrapper +public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper implements TimerProxy { private static final int MSG_TYPING_STATE_EXPIRED = 0; private static final int MSG_REPEAT_KEY = 1; @@ -40,9 +40,9 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe private final int mIgnoreAltCodeKeyTimeout; private final int mGestureRecognitionUpdateTime; - public MainKeyboardViewTimerHandler(final MainKeyboardView outerInstance, + public MainKeyboardViewTimerHandler(final MainKeyboardView ownerInstance, final TypedArray mainKeyboardViewAttr) { - super(outerInstance); + super(ownerInstance); mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0); @@ -52,20 +52,20 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe @Override public void handleMessage(final Message msg) { - final MainKeyboardView keyboardView = getOuterInstance(); - if (keyboardView == null) { + final MainKeyboardView mainKeyboardView = getOwnerInstance(); + if (mainKeyboardView == null) { return; } final PointerTracker tracker = (PointerTracker) msg.obj; switch (msg.what) { case MSG_TYPING_STATE_EXPIRED: - keyboardView.startWhileTypingFadeinAnimation(); + mainKeyboardView.startWhileTypingFadeinAnimation(); break; case MSG_REPEAT_KEY: tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */); break; case MSG_LONGPRESS_KEY: - keyboardView.onLongPress(tracker); + mainKeyboardView.onLongPress(tracker); break; case MSG_UPDATE_BATCH_INPUT: tracker.updateBatchInputByTimer(SystemClock.uptimeMillis()); @@ -114,13 +114,16 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe final boolean isTyping = isTypingState(); removeMessages(MSG_TYPING_STATE_EXPIRED); - final MainKeyboardView keyboardView = getOuterInstance(); + final MainKeyboardView mainKeyboardView = getOwnerInstance(); + if (mainKeyboardView == null) { + return; + } // When user hits the space or the enter key, just cancel the while-typing timer. final int typedCode = typedKey.getCode(); if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) { if (isTyping) { - keyboardView.startWhileTypingFadeinAnimation(); + mainKeyboardView.startWhileTypingFadeinAnimation(); } return; } @@ -130,7 +133,7 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe if (isTyping) { return; } - keyboardView.startWhileTypingFadeoutAnimation(); + mainKeyboardView.startWhileTypingFadeoutAnimation(); } @Override diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6445b61ca..87eed3bc9 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -97,8 +97,8 @@ import com.android.inputmethod.latin.utils.InputTypeUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.JniUtils; import com.android.inputmethod.latin.utils.LatinImeLoggerUtils; +import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; import com.android.inputmethod.latin.utils.RecapitalizeStatus; -import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask; import com.android.inputmethod.latin.utils.TextRange; @@ -224,7 +224,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public final UIHandler mHandler = new UIHandler(this); private InputUpdater mInputUpdater; - public static final class UIHandler extends StaticInnerHandlerWrapper { + public static final class UIHandler extends LeakGuardHandlerWrapper { private static final int MSG_UPDATE_SHIFT_STATE = 0; private static final int MSG_PENDING_IMS_CALLBACK = 1; private static final int MSG_UPDATE_SUGGESTION_STRIP = 2; @@ -247,12 +247,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private long mDoubleSpacePeriodTimeout; private long mDoubleSpacePeriodTimerStart; - public UIHandler(final LatinIME outerInstance) { - super(outerInstance); + public UIHandler(final LatinIME ownerInstance) { + super(ownerInstance); } public void onCreate() { - final Resources res = getOuterInstance().getResources(); + final Resources res = getOwnerInstance().getResources(); mDelayUpdateSuggestions = res.getInteger(R.integer.config_delay_update_suggestions); mDelayUpdateShiftState = @@ -263,7 +263,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void handleMessage(final Message msg) { - final LatinIME latinIme = getOuterInstance(); + final LatinIME latinIme = getOwnerInstance(); final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; switch (msg.what) { case MSG_UPDATE_SUGGESTION_STRIP: @@ -407,7 +407,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen removeMessages(MSG_PENDING_IMS_CALLBACK); resetPendingImsCallback(); mIsOrientationChanging = true; - final LatinIME latinIme = getOuterInstance(); + final LatinIME latinIme = getOwnerInstance(); if (latinIme.isInputViewShown()) { latinIme.mKeyboardSwitcher.saveKeyboardState(); } @@ -440,7 +440,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mIsOrientationChanging = false; mPendingSuccessiveImsCallback = true; } - final LatinIME latinIme = getOuterInstance(); + final LatinIME latinIme = getOwnerInstance(); executePendingImsCallback(latinIme, editorInfo, restarting); latinIme.onStartInputInternal(editorInfo, restarting); } @@ -459,7 +459,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK), PENDING_IMS_CALLBACK_DURATION); } - final LatinIME latinIme = getOuterInstance(); + final LatinIME latinIme = getOwnerInstance(); executePendingImsCallback(latinIme, editorInfo, restarting); latinIme.onStartInputViewInternal(editorInfo, restarting); mAppliedEditorInfo = editorInfo; @@ -471,7 +471,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Typically this is the first onFinishInputView after orientation changed. mHasPendingFinishInputView = true; } else { - final LatinIME latinIme = getOuterInstance(); + final LatinIME latinIme = getOwnerInstance(); latinIme.onFinishInputViewInternal(finishingInput); mAppliedEditorInfo = null; } @@ -482,7 +482,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Typically this is the first onFinishInput after orientation changed. mHasPendingFinishInput = true; } else { - final LatinIME latinIme = getOuterInstance(); + final LatinIME latinIme = getOwnerInstance(); executePendingImsCallback(latinIme, null, false); latinIme.onFinishInputInternal(); } diff --git a/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java index c4a813c24..5072fabd6 100644 --- a/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java +++ b/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java @@ -38,7 +38,7 @@ import com.android.inputmethod.compat.ViewCompatUtils; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.settings.SettingsActivity; import com.android.inputmethod.latin.utils.CollectionUtils; -import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; import java.util.ArrayList; @@ -74,21 +74,21 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL private SettingsPoolingHandler mHandler; private static final class SettingsPoolingHandler - extends StaticInnerHandlerWrapper { + extends LeakGuardHandlerWrapper { private static final int MSG_POLLING_IME_SETTINGS = 0; private static final long IME_SETTINGS_POLLING_INTERVAL = 200; private final InputMethodManager mImmInHandler; - public SettingsPoolingHandler(final SetupWizardActivity outerInstance, + public SettingsPoolingHandler(final SetupWizardActivity ownerInstance, final InputMethodManager imm) { - super(outerInstance); + super(ownerInstance); mImmInHandler = imm; } @Override public void handleMessage(final Message msg) { - final SetupWizardActivity setupWizardActivity = getOuterInstance(); + final SetupWizardActivity setupWizardActivity = getOwnerInstance(); if (setupWizardActivity == null) { return; } diff --git a/java/src/com/android/inputmethod/latin/utils/StaticInnerHandlerWrapper.java b/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java similarity index 60% rename from java/src/com/android/inputmethod/latin/utils/StaticInnerHandlerWrapper.java rename to java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java index 44e5d17b4..8469c87b0 100644 --- a/java/src/com/android/inputmethod/latin/utils/StaticInnerHandlerWrapper.java +++ b/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java @@ -21,22 +21,22 @@ import android.os.Looper; import java.lang.ref.WeakReference; -public class StaticInnerHandlerWrapper extends Handler { - private final WeakReference mOuterInstanceRef; +public class LeakGuardHandlerWrapper extends Handler { + private final WeakReference mOwnerInstanceRef; - public StaticInnerHandlerWrapper(final T outerInstance) { - this(outerInstance, Looper.myLooper()); + public LeakGuardHandlerWrapper(final T ownerInstance) { + this(ownerInstance, Looper.myLooper()); } - public StaticInnerHandlerWrapper(final T outerInstance, final Looper looper) { + public LeakGuardHandlerWrapper(final T ownerInstance, final Looper looper) { super(looper); - if (outerInstance == null) { - throw new NullPointerException("outerInstance is null"); + if (ownerInstance == null) { + throw new NullPointerException("ownerInstance is null"); } - mOuterInstanceRef = new WeakReference(outerInstance); + mOwnerInstanceRef = new WeakReference(ownerInstance); } - public T getOuterInstance() { - return mOuterInstanceRef.get(); + public T getOwnerInstance() { + return mOwnerInstanceRef.get(); } }