am 18ffeaba: Use interfaces instead of MainKeyboardView class

* commit '18ffeaba16abdc4da5492f18a829308937cd9a0a':
  Use interfaces instead of MainKeyboardView class
main
Tadashi G. Takaoka 2013-11-28 19:27:28 -08:00 committed by Android Git Automerger
commit 2459b1a794
3 changed files with 63 additions and 38 deletions

View File

@ -50,15 +50,15 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.annotations.ExternallyReferenced; import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.DrawingHandler;
import com.android.inputmethod.keyboard.internal.GestureFloatingPreviewText; import com.android.inputmethod.keyboard.internal.GestureFloatingPreviewText;
import com.android.inputmethod.keyboard.internal.GestureTrailsPreview; import com.android.inputmethod.keyboard.internal.GestureTrailsPreview;
import com.android.inputmethod.keyboard.internal.KeyDrawParams; import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams; import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.keyboard.internal.MainKeyboardViewDrawingHandler;
import com.android.inputmethod.keyboard.internal.MainKeyboardViewTimerHandler;
import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper; import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview; import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview;
import com.android.inputmethod.keyboard.internal.TimerHandler;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -120,7 +120,8 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration * @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
*/ */
public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler, public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler,
PointerTracker.DrawingProxy, MoreKeysPanel.Controller { PointerTracker.DrawingProxy, MoreKeysPanel.Controller, DrawingHandler.Callbacks,
TimerHandler.Callbacks {
private static final String TAG = MainKeyboardView.class.getSimpleName(); private static final String TAG = MainKeyboardView.class.getSimpleName();
/** Listener for {@link KeyboardActionListener}. */ /** Listener for {@link KeyboardActionListener}. */
@ -196,14 +197,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// TODO: Make this parameter customizable by user via settings. // TODO: Make this parameter customizable by user via settings.
private int mGestureFloatingPreviewTextLingerTimeout; private int mGestureFloatingPreviewTextLingerTimeout;
private KeyDetector mKeyDetector; private final KeyDetector mKeyDetector;
private final NonDistinctMultitouchHelper mNonDistinctMultitouchHelper; private final NonDistinctMultitouchHelper mNonDistinctMultitouchHelper;
private final MainKeyboardViewTimerHandler mKeyTimerHandler; private final TimerHandler mKeyTimerHandler;
private final int mLanguageOnSpacebarHorizontalMargin; private final int mLanguageOnSpacebarHorizontalMargin;
private final MainKeyboardViewDrawingHandler mDrawingHandler = private final DrawingHandler mDrawingHandler =
new MainKeyboardViewDrawingHandler(this); new DrawingHandler(this);
public MainKeyboardView(final Context context, final AttributeSet attrs) { public MainKeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.mainKeyboardViewStyle); this(context, attrs, R.attr.mainKeyboardViewStyle);
@ -256,7 +257,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f); R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
mKeyDetector = new KeyDetector( mKeyDetector = new KeyDetector(
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier); keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
mKeyTimerHandler = new MainKeyboardViewTimerHandler(this, mainKeyboardViewAttr); final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
final int gestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
mKeyTimerHandler = new TimerHandler(
this, ignoreAltCodeKeyTimeout, gestureRecognitionUpdateTime);
mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset( mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
R.styleable.MainKeyboardView_keyPreviewOffset, 0); R.styleable.MainKeyboardView_keyPreviewOffset, 0);
mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize( mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
@ -344,11 +350,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
animatorToStart.setCurrentPlayTime(startTime); animatorToStart.setCurrentPlayTime(startTime);
} }
// Implements {@link TimerHander.Callbacks} method.
@Override
public void startWhileTypingFadeinAnimation() { public void startWhileTypingFadeinAnimation() {
cancelAndStartAnimators( cancelAndStartAnimators(
mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator); mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator);
} }
@Override
public void startWhileTypingFadeoutAnimation() { public void startWhileTypingFadeoutAnimation() {
cancelAndStartAnimators( cancelAndStartAnimators(
mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator); mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator);
@ -521,6 +530,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return previewTextView; return previewTextView;
} }
// Implements {@link DrawingHandler.Callbacks} method.
@Override
public void dismissAllKeyPreviews() { public void dismissAllKeyPreviews() {
for (final Key key : new HashSet<Key>(mShowingKeyPreviewTextViews.keySet())) { for (final Key key : new HashSet<Key>(mShowingKeyPreviewTextViews.keySet())) {
dismissKeyPreviewWithoutDelay(key); dismissKeyPreviewWithoutDelay(key);
@ -714,7 +725,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return zoomOutAnimation; return zoomOutAnimation;
} }
// Implements {@link TimerHandler.Callbacks} method.
// TODO: Take this method out of this class. // TODO: Take this method out of this class.
@Override
public void dismissKeyPreviewWithoutDelay(final Key key) { public void dismissKeyPreviewWithoutDelay(final Key key) {
if (key == null) { if (key == null) {
return; return;
@ -773,6 +786,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mGestureTrailsPreview.setPreviewEnabled(isGestureTrailEnabled); mGestureTrailsPreview.setPreviewEnabled(isGestureTrailEnabled);
} }
// Implements {@link DrawingHandler.Callbacks} method.
@Override
public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) { public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords); mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
@ -848,10 +863,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return moreKeysKeyboardView; return moreKeysKeyboardView;
} }
// Implements {@link TimerHandler.Callbacks} method.
/** /**
* Called when a key is long pressed. * Called when a key is long pressed.
* @param tracker the pointer tracker which pressed the parent key * @param tracker the pointer tracker which pressed the parent key
*/ */
@Override
public void onLongPress(final PointerTracker tracker) { public void onLongPress(final PointerTracker tracker) {
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
return; return;

View File

@ -19,30 +19,37 @@ package com.android.inputmethod.keyboard.internal;
import android.os.Message; 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.internal.DrawingHandler.Callbacks;
import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper<MainKeyboardView> { // TODO: Separate this class into KeyPreviewHandler and BatchInputPreviewHandler or so.
public class DrawingHandler extends LeakGuardHandlerWrapper<Callbacks> {
public interface Callbacks {
public void dismissKeyPreviewWithoutDelay(Key key);
public void dismissAllKeyPreviews();
public void showGestureFloatingPreviewText(SuggestedWords suggestedWords);
}
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 ownerInstance) { public DrawingHandler(final Callbacks ownerInstance) {
super(ownerInstance); super(ownerInstance);
} }
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final MainKeyboardView mainKeyboardView = getOwnerInstance(); final Callbacks callbacks = getOwnerInstance();
if (mainKeyboardView == null) { if (callbacks == null) {
return; return;
} }
switch (msg.what) { switch (msg.what) {
case MSG_DISMISS_KEY_PREVIEW: case MSG_DISMISS_KEY_PREVIEW:
mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj); callbacks.dismissKeyPreviewWithoutDelay((Key)msg.obj);
break; break;
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY); callbacks.showGestureFloatingPreviewText(SuggestedWords.EMPTY);
break; break;
} }
} }
@ -53,11 +60,11 @@ public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper<Main
private void cancelAllDismissKeyPreviews() { private void cancelAllDismissKeyPreviews() {
removeMessages(MSG_DISMISS_KEY_PREVIEW); removeMessages(MSG_DISMISS_KEY_PREVIEW);
final MainKeyboardView mainKeyboardView = getOwnerInstance(); final Callbacks callbacks = getOwnerInstance();
if (mainKeyboardView == null) { if (callbacks == null) {
return; return;
} }
mainKeyboardView.dismissAllKeyPreviews(); callbacks.dismissAllKeyPreviews();
} }
public void dismissGestureFloatingPreviewText(final long delay) { public void dismissGestureFloatingPreviewText(final long delay) {

View File

@ -16,21 +16,25 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.content.res.TypedArray;
import android.os.Message; import android.os.Message;
import android.os.SystemClock; import android.os.SystemClock;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.TimerHandler.Callbacks;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper<MainKeyboardView> // TODO: Separate this class into KeyTimerHandler and BatchInputTimerHandler or so.
implements TimerProxy { public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> implements TimerProxy {
public interface Callbacks {
public void startWhileTypingFadeinAnimation();
public void startWhileTypingFadeoutAnimation();
public void onLongPress(PointerTracker tracker);
}
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;
private static final int MSG_LONGPRESS_KEY = 2; private static final int MSG_LONGPRESS_KEY = 2;
@ -40,32 +44,29 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper<
private final int mIgnoreAltCodeKeyTimeout; private final int mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime; private final int mGestureRecognitionUpdateTime;
public MainKeyboardViewTimerHandler(final MainKeyboardView ownerInstance, public TimerHandler(final Callbacks ownerInstance, final int ignoreAltCodeKeyTimeout,
final TypedArray mainKeyboardViewAttr) { final int gestureRecognitionUpdateTime) {
super(ownerInstance); super(ownerInstance);
mIgnoreAltCodeKeyTimeout = ignoreAltCodeKeyTimeout;
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( mGestureRecognitionUpdateTime = gestureRecognitionUpdateTime;
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
} }
@Override @Override
public void handleMessage(final Message msg) { public void handleMessage(final Message msg) {
final MainKeyboardView mainKeyboardView = getOwnerInstance(); final Callbacks callbacks = getOwnerInstance();
if (mainKeyboardView == null) { if (callbacks == 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:
mainKeyboardView.startWhileTypingFadeinAnimation(); callbacks.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:
mainKeyboardView.onLongPress(tracker); callbacks.onLongPress(tracker);
break; break;
case MSG_UPDATE_BATCH_INPUT: case MSG_UPDATE_BATCH_INPUT:
tracker.updateBatchInputByTimer(SystemClock.uptimeMillis()); tracker.updateBatchInputByTimer(SystemClock.uptimeMillis());
@ -114,8 +115,8 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper<
final boolean isTyping = isTypingState(); final boolean isTyping = isTypingState();
removeMessages(MSG_TYPING_STATE_EXPIRED); removeMessages(MSG_TYPING_STATE_EXPIRED);
final MainKeyboardView mainKeyboardView = getOwnerInstance(); final Callbacks callbacks = getOwnerInstance();
if (mainKeyboardView == null) { if (callbacks == null) {
return; return;
} }
@ -123,7 +124,7 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper<
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) {
mainKeyboardView.startWhileTypingFadeinAnimation(); callbacks.startWhileTypingFadeinAnimation();
} }
return; return;
} }
@ -133,7 +134,7 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper<
if (isTyping) { if (isTyping) {
return; return;
} }
mainKeyboardView.startWhileTypingFadeoutAnimation(); callbacks.startWhileTypingFadeoutAnimation();
} }
@Override @Override