Rename StaticInnerHandlerWrapper to LeakGuardHandlerWrapper

Change-Id: I024f0ee9c7f7718afc8a4ca0c6c49f2e88b035ad
This commit is contained in:
Tadashi G. Takaoka 2013-11-29 11:50:00 +09:00
parent ebd5541edf
commit ccc86630a2
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.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<GestureTrailsPreview> {
extends LeakGuardHandlerWrapper<GestureTrailsPreview> {
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();

View file

@ -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<MainKeyboardView> {
public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper<MainKeyboardView> {
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<Ma
private void cancelAllDismissKeyPreviews() {
removeMessages(MSG_DISMISS_KEY_PREVIEW);
final MainKeyboardView mainKeyboardView = getOuterInstance();
if (mainKeyboardView == null) return;
final MainKeyboardView mainKeyboardView = getOwnerInstance();
if (mainKeyboardView == null) {
return;
}
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.latin.Constants;
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 {
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

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.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<LatinIME> {
public static final class UIHandler extends LeakGuardHandlerWrapper<LatinIME> {
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();
}

View file

@ -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<SetupWizardActivity> {
extends LeakGuardHandlerWrapper<SetupWizardActivity> {
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;
}

View file

@ -21,22 +21,22 @@ import android.os.Looper;
import java.lang.ref.WeakReference;
public class StaticInnerHandlerWrapper<T> extends Handler {
private final WeakReference<T> mOuterInstanceRef;
public class LeakGuardHandlerWrapper<T> extends Handler {
private final WeakReference<T> 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<T>(outerInstance);
mOwnerInstanceRef = new WeakReference<T>(ownerInstance);
}
public T getOuterInstance() {
return mOuterInstanceRef.get();
public T getOwnerInstance() {
return mOwnerInstanceRef.get();
}
}