am ccc86630: Rename StaticInnerHandlerWrapper to LeakGuardHandlerWrapper

* commit 'ccc86630a25704ac726c8aa0cf0d008a29d4259f':
  Rename StaticInnerHandlerWrapper to LeakGuardHandlerWrapper
main
Tadashi G. Takaoka 2013-11-28 19:24:12 -08:00 committed by Android Git Automerger
commit accbd1fc8a
6 changed files with 60 additions and 51 deletions

View File

@ -31,7 +31,7 @@ import android.view.View;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.internal.GestureTrail.Params; import com.android.inputmethod.keyboard.internal.GestureTrail.Params;
import com.android.inputmethod.latin.utils.CollectionUtils; 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. * Draw gesture trail preview graphics during gesture.
@ -52,21 +52,23 @@ public final class GestureTrailsPreview extends AbstractDrawingPreview {
private final DrawingHandler mDrawingHandler; private final DrawingHandler mDrawingHandler;
private static final class DrawingHandler private static final class DrawingHandler
extends StaticInnerHandlerWrapper<GestureTrailsPreview> { extends LeakGuardHandlerWrapper<GestureTrailsPreview> {
private static final int MSG_UPDATE_GESTURE_TRAIL = 0; private static final int MSG_UPDATE_GESTURE_TRAIL = 0;
private final Params mGestureTrailParams; private final Params mGestureTrailParams;
public DrawingHandler(final GestureTrailsPreview outerInstance, public DrawingHandler(final GestureTrailsPreview ownerInstance,
final Params gestureTrailParams) { final Params gestureTrailParams) {
super(outerInstance); super(ownerInstance);
mGestureTrailParams = gestureTrailParams; mGestureTrailParams = gestureTrailParams;
} }
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final GestureTrailsPreview preview = getOuterInstance(); final GestureTrailsPreview preview = getOwnerInstance();
if (preview == null) return; if (preview == null) {
return;
}
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_GESTURE_TRAIL: case MSG_UPDATE_GESTURE_TRAIL:
preview.getDrawingView().invalidate(); preview.getDrawingView().invalidate();

View File

@ -21,20 +21,22 @@ import android.os.Message;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.SuggestedWords; 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<MainKeyboardView> { public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper<MainKeyboardView> {
private static final int MSG_DISMISS_KEY_PREVIEW = 0; private static final int MSG_DISMISS_KEY_PREVIEW = 0;
private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
public MainKeyboardViewDrawingHandler(final MainKeyboardView outerInstance) { public MainKeyboardViewDrawingHandler(final MainKeyboardView ownerInstance) {
super(outerInstance); super(ownerInstance);
} }
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final MainKeyboardView mainKeyboardView = getOuterInstance(); final MainKeyboardView mainKeyboardView = getOwnerInstance();
if (mainKeyboardView == null) return; if (mainKeyboardView == null) {
return;
}
switch (msg.what) { switch (msg.what) {
case MSG_DISMISS_KEY_PREVIEW: case MSG_DISMISS_KEY_PREVIEW:
mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj); mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj);
@ -51,8 +53,10 @@ public class MainKeyboardViewDrawingHandler extends StaticInnerHandlerWrapper<Ma
private void cancelAllDismissKeyPreviews() { private void cancelAllDismissKeyPreviews() {
removeMessages(MSG_DISMISS_KEY_PREVIEW); removeMessages(MSG_DISMISS_KEY_PREVIEW);
final MainKeyboardView mainKeyboardView = getOuterInstance(); final MainKeyboardView mainKeyboardView = getOwnerInstance();
if (mainKeyboardView == null) return; if (mainKeyboardView == null) {
return;
}
mainKeyboardView.dismissAllKeyPreviews(); mainKeyboardView.dismissAllKeyPreviews();
} }

View File

@ -27,9 +27,9 @@ import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrapper<MainKeyboardView> public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper<MainKeyboardView>
implements TimerProxy { implements TimerProxy {
private static final int MSG_TYPING_STATE_EXPIRED = 0; private static final int MSG_TYPING_STATE_EXPIRED = 0;
private static final int MSG_REPEAT_KEY = 1; 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 mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime; private final int mGestureRecognitionUpdateTime;
public MainKeyboardViewTimerHandler(final MainKeyboardView outerInstance, public MainKeyboardViewTimerHandler(final MainKeyboardView ownerInstance,
final TypedArray mainKeyboardViewAttr) { final TypedArray mainKeyboardViewAttr) {
super(outerInstance); super(ownerInstance);
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0); R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
@ -52,20 +52,20 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final MainKeyboardView keyboardView = getOuterInstance(); final MainKeyboardView mainKeyboardView = getOwnerInstance();
if (keyboardView == null) { if (mainKeyboardView == null) {
return; return;
} }
final PointerTracker tracker = (PointerTracker) msg.obj; final PointerTracker tracker = (PointerTracker) msg.obj;
switch (msg.what) { switch (msg.what) {
case MSG_TYPING_STATE_EXPIRED: case MSG_TYPING_STATE_EXPIRED:
keyboardView.startWhileTypingFadeinAnimation(); mainKeyboardView.startWhileTypingFadeinAnimation();
break; break;
case MSG_REPEAT_KEY: case MSG_REPEAT_KEY:
tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */); tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */);
break; break;
case MSG_LONGPRESS_KEY: case MSG_LONGPRESS_KEY:
keyboardView.onLongPress(tracker); mainKeyboardView.onLongPress(tracker);
break; break;
case MSG_UPDATE_BATCH_INPUT: case MSG_UPDATE_BATCH_INPUT:
tracker.updateBatchInputByTimer(SystemClock.uptimeMillis()); tracker.updateBatchInputByTimer(SystemClock.uptimeMillis());
@ -114,13 +114,16 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe
final boolean isTyping = isTypingState(); final boolean isTyping = isTypingState();
removeMessages(MSG_TYPING_STATE_EXPIRED); 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. // When user hits the space or the enter key, just cancel the while-typing timer.
final int typedCode = typedKey.getCode(); final int typedCode = typedKey.getCode();
if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) { if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) {
if (isTyping) { if (isTyping) {
keyboardView.startWhileTypingFadeinAnimation(); mainKeyboardView.startWhileTypingFadeinAnimation();
} }
return; return;
} }
@ -130,7 +133,7 @@ public final class MainKeyboardViewTimerHandler extends StaticInnerHandlerWrappe
if (isTyping) { if (isTyping) {
return; return;
} }
keyboardView.startWhileTypingFadeoutAnimation(); mainKeyboardView.startWhileTypingFadeoutAnimation();
} }
@Override @Override

View File

@ -97,8 +97,8 @@ import com.android.inputmethod.latin.utils.InputTypeUtils;
import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.IntentUtils;
import com.android.inputmethod.latin.utils.JniUtils; import com.android.inputmethod.latin.utils.JniUtils;
import com.android.inputmethod.latin.utils.LatinImeLoggerUtils; 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.RecapitalizeStatus;
import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask; import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
import com.android.inputmethod.latin.utils.TextRange; 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); public final UIHandler mHandler = new UIHandler(this);
private InputUpdater mInputUpdater; private InputUpdater mInputUpdater;
public static final class UIHandler extends StaticInnerHandlerWrapper<LatinIME> { public static final class UIHandler extends LeakGuardHandlerWrapper<LatinIME> {
private static final int MSG_UPDATE_SHIFT_STATE = 0; private static final int MSG_UPDATE_SHIFT_STATE = 0;
private static final int MSG_PENDING_IMS_CALLBACK = 1; private static final int MSG_PENDING_IMS_CALLBACK = 1;
private static final int MSG_UPDATE_SUGGESTION_STRIP = 2; 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 mDoubleSpacePeriodTimeout;
private long mDoubleSpacePeriodTimerStart; private long mDoubleSpacePeriodTimerStart;
public UIHandler(final LatinIME outerInstance) { public UIHandler(final LatinIME ownerInstance) {
super(outerInstance); super(ownerInstance);
} }
public void onCreate() { public void onCreate() {
final Resources res = getOuterInstance().getResources(); final Resources res = getOwnerInstance().getResources();
mDelayUpdateSuggestions = mDelayUpdateSuggestions =
res.getInteger(R.integer.config_delay_update_suggestions); res.getInteger(R.integer.config_delay_update_suggestions);
mDelayUpdateShiftState = mDelayUpdateShiftState =
@ -263,7 +263,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOwnerInstance();
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_SUGGESTION_STRIP: case MSG_UPDATE_SUGGESTION_STRIP:
@ -407,7 +407,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
removeMessages(MSG_PENDING_IMS_CALLBACK); removeMessages(MSG_PENDING_IMS_CALLBACK);
resetPendingImsCallback(); resetPendingImsCallback();
mIsOrientationChanging = true; mIsOrientationChanging = true;
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOwnerInstance();
if (latinIme.isInputViewShown()) { if (latinIme.isInputViewShown()) {
latinIme.mKeyboardSwitcher.saveKeyboardState(); latinIme.mKeyboardSwitcher.saveKeyboardState();
} }
@ -440,7 +440,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mIsOrientationChanging = false; mIsOrientationChanging = false;
mPendingSuccessiveImsCallback = true; mPendingSuccessiveImsCallback = true;
} }
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOwnerInstance();
executePendingImsCallback(latinIme, editorInfo, restarting); executePendingImsCallback(latinIme, editorInfo, restarting);
latinIme.onStartInputInternal(editorInfo, restarting); latinIme.onStartInputInternal(editorInfo, restarting);
} }
@ -459,7 +459,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK), sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK),
PENDING_IMS_CALLBACK_DURATION); PENDING_IMS_CALLBACK_DURATION);
} }
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOwnerInstance();
executePendingImsCallback(latinIme, editorInfo, restarting); executePendingImsCallback(latinIme, editorInfo, restarting);
latinIme.onStartInputViewInternal(editorInfo, restarting); latinIme.onStartInputViewInternal(editorInfo, restarting);
mAppliedEditorInfo = editorInfo; mAppliedEditorInfo = editorInfo;
@ -471,7 +471,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Typically this is the first onFinishInputView after orientation changed. // Typically this is the first onFinishInputView after orientation changed.
mHasPendingFinishInputView = true; mHasPendingFinishInputView = true;
} else { } else {
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOwnerInstance();
latinIme.onFinishInputViewInternal(finishingInput); latinIme.onFinishInputViewInternal(finishingInput);
mAppliedEditorInfo = null; mAppliedEditorInfo = null;
} }
@ -482,7 +482,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Typically this is the first onFinishInput after orientation changed. // Typically this is the first onFinishInput after orientation changed.
mHasPendingFinishInput = true; mHasPendingFinishInput = true;
} else { } else {
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOwnerInstance();
executePendingImsCallback(latinIme, null, false); executePendingImsCallback(latinIme, null, false);
latinIme.onFinishInputInternal(); latinIme.onFinishInputInternal();
} }

View File

@ -38,7 +38,7 @@ import com.android.inputmethod.compat.ViewCompatUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.settings.SettingsActivity; import com.android.inputmethod.latin.settings.SettingsActivity;
import com.android.inputmethod.latin.utils.CollectionUtils; 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; import java.util.ArrayList;
@ -74,21 +74,21 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
private SettingsPoolingHandler mHandler; private SettingsPoolingHandler mHandler;
private static final class SettingsPoolingHandler private static final class SettingsPoolingHandler
extends StaticInnerHandlerWrapper<SetupWizardActivity> { extends LeakGuardHandlerWrapper<SetupWizardActivity> {
private static final int MSG_POLLING_IME_SETTINGS = 0; private static final int MSG_POLLING_IME_SETTINGS = 0;
private static final long IME_SETTINGS_POLLING_INTERVAL = 200; private static final long IME_SETTINGS_POLLING_INTERVAL = 200;
private final InputMethodManager mImmInHandler; private final InputMethodManager mImmInHandler;
public SettingsPoolingHandler(final SetupWizardActivity outerInstance, public SettingsPoolingHandler(final SetupWizardActivity ownerInstance,
final InputMethodManager imm) { final InputMethodManager imm) {
super(outerInstance); super(ownerInstance);
mImmInHandler = imm; mImmInHandler = imm;
} }
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final SetupWizardActivity setupWizardActivity = getOuterInstance(); final SetupWizardActivity setupWizardActivity = getOwnerInstance();
if (setupWizardActivity == null) { if (setupWizardActivity == null) {
return; return;
} }

View File

@ -21,22 +21,22 @@ import android.os.Looper;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public class StaticInnerHandlerWrapper<T> extends Handler { public class LeakGuardHandlerWrapper<T> extends Handler {
private final WeakReference<T> mOuterInstanceRef; private final WeakReference<T> mOwnerInstanceRef;
public StaticInnerHandlerWrapper(final T outerInstance) { public LeakGuardHandlerWrapper(final T ownerInstance) {
this(outerInstance, Looper.myLooper()); this(ownerInstance, Looper.myLooper());
} }
public StaticInnerHandlerWrapper(final T outerInstance, final Looper looper) { public LeakGuardHandlerWrapper(final T ownerInstance, final Looper looper) {
super(looper); super(looper);
if (outerInstance == null) { if (ownerInstance == null) {
throw new NullPointerException("outerInstance is null"); throw new NullPointerException("ownerInstance is null");
} }
mOuterInstanceRef = new WeakReference<T>(outerInstance); mOwnerInstanceRef = new WeakReference<T>(ownerInstance);
} }
public T getOuterInstance() { public T getOwnerInstance() {
return mOuterInstanceRef.get(); return mOwnerInstanceRef.get();
} }
} }