From 18ffeaba16abdc4da5492f18a829308937cd9a0a Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 29 Nov 2013 10:08:02 +0900 Subject: [PATCH] Use interfaces instead of MainKeyboardView class Change-Id: I760b107d804fc84153f08667f20061fedd308841 --- .../keyboard/MainKeyboardView.java | 33 +++++++++++---- ...rawingHandler.java => DrawingHandler.java} | 27 +++++++----- ...iewTimerHandler.java => TimerHandler.java} | 41 ++++++++++--------- 3 files changed, 63 insertions(+), 38 deletions(-) rename java/src/com/android/inputmethod/keyboard/internal/{MainKeyboardViewDrawingHandler.java => DrawingHandler.java} (67%) rename java/src/com/android/inputmethod/keyboard/internal/{MainKeyboardViewTimerHandler.java => TimerHandler.java} (82%) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index f7c54c74b..e4051e887 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -50,15 +50,15 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.annotations.ExternallyReferenced; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; 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.GestureTrailsPreview; import com.android.inputmethod.keyboard.internal.KeyDrawParams; 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.PreviewPlacerView; 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.LatinImeLogger; import com.android.inputmethod.latin.R; @@ -120,7 +120,8 @@ import java.util.WeakHashMap; * @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration */ 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(); /** 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. private int mGestureFloatingPreviewTextLingerTimeout; - private KeyDetector mKeyDetector; + private final KeyDetector mKeyDetector; private final NonDistinctMultitouchHelper mNonDistinctMultitouchHelper; - private final MainKeyboardViewTimerHandler mKeyTimerHandler; + private final TimerHandler mKeyTimerHandler; private final int mLanguageOnSpacebarHorizontalMargin; - private final MainKeyboardViewDrawingHandler mDrawingHandler = - new MainKeyboardViewDrawingHandler(this); + private final DrawingHandler mDrawingHandler = + new DrawingHandler(this); public MainKeyboardView(final Context context, final AttributeSet attrs) { this(context, attrs, R.attr.mainKeyboardViewStyle); @@ -256,7 +257,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f); mKeyDetector = new KeyDetector( 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( R.styleable.MainKeyboardView_keyPreviewOffset, 0); mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize( @@ -344,11 +350,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack animatorToStart.setCurrentPlayTime(startTime); } + // Implements {@link TimerHander.Callbacks} method. + @Override public void startWhileTypingFadeinAnimation() { cancelAndStartAnimators( mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator); } + @Override public void startWhileTypingFadeoutAnimation() { cancelAndStartAnimators( mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator); @@ -521,6 +530,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return previewTextView; } + // Implements {@link DrawingHandler.Callbacks} method. + @Override public void dismissAllKeyPreviews() { for (final Key key : new HashSet(mShowingKeyPreviewTextViews.keySet())) { dismissKeyPreviewWithoutDelay(key); @@ -714,7 +725,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return zoomOutAnimation; } + // Implements {@link TimerHandler.Callbacks} method. // TODO: Take this method out of this class. + @Override public void dismissKeyPreviewWithoutDelay(final Key key) { if (key == null) { return; @@ -773,6 +786,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mGestureTrailsPreview.setPreviewEnabled(isGestureTrailEnabled); } + // Implements {@link DrawingHandler.Callbacks} method. + @Override public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) { locatePreviewPlacerView(); mGestureFloatingPreviewText.setSuggetedWords(suggestedWords); @@ -848,10 +863,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return moreKeysKeyboardView; } + // Implements {@link TimerHandler.Callbacks} method. /** * Called when a key is long pressed. * @param tracker the pointer tracker which pressed the parent key */ + @Override public void onLongPress(final PointerTracker tracker) { if (isShowingMoreKeysPanel()) { return; diff --git a/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java b/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java similarity index 67% rename from java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java rename to java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java index fb1f78901..df82becae 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java +++ b/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java @@ -19,30 +19,37 @@ package com.android.inputmethod.keyboard.internal; import android.os.Message; 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.utils.LeakGuardHandlerWrapper; -public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper { +// TODO: Separate this class into KeyPreviewHandler and BatchInputPreviewHandler or so. +public class DrawingHandler extends LeakGuardHandlerWrapper { + 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_GESTURE_FLOATING_PREVIEW_TEXT = 1; - public MainKeyboardViewDrawingHandler(final MainKeyboardView ownerInstance) { + public DrawingHandler(final Callbacks ownerInstance) { super(ownerInstance); } @Override public void handleMessage(final Message msg) { - final MainKeyboardView mainKeyboardView = getOwnerInstance(); - if (mainKeyboardView == null) { + final Callbacks callbacks = getOwnerInstance(); + if (callbacks == null) { return; } switch (msg.what) { case MSG_DISMISS_KEY_PREVIEW: - mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj); + callbacks.dismissKeyPreviewWithoutDelay((Key)msg.obj); break; case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: - mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY); + callbacks.showGestureFloatingPreviewText(SuggestedWords.EMPTY); break; } } @@ -53,11 +60,11 @@ public class MainKeyboardViewDrawingHandler extends LeakGuardHandlerWrapper
- implements TimerProxy { +// TODO: Separate this class into KeyTimerHandler and BatchInputTimerHandler or so. +public final class TimerHandler extends LeakGuardHandlerWrapper 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_REPEAT_KEY = 1; 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 mGestureRecognitionUpdateTime; - public MainKeyboardViewTimerHandler(final MainKeyboardView ownerInstance, - final TypedArray mainKeyboardViewAttr) { + public TimerHandler(final Callbacks ownerInstance, final int ignoreAltCodeKeyTimeout, + final int gestureRecognitionUpdateTime) { super(ownerInstance); - - mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( - R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0); - mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt( - R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0); + mIgnoreAltCodeKeyTimeout = ignoreAltCodeKeyTimeout; + mGestureRecognitionUpdateTime = gestureRecognitionUpdateTime; } @Override public void handleMessage(final Message msg) { - final MainKeyboardView mainKeyboardView = getOwnerInstance(); - if (mainKeyboardView == null) { + final Callbacks callbacks = getOwnerInstance(); + if (callbacks == null) { return; } final PointerTracker tracker = (PointerTracker) msg.obj; switch (msg.what) { case MSG_TYPING_STATE_EXPIRED: - mainKeyboardView.startWhileTypingFadeinAnimation(); + callbacks.startWhileTypingFadeinAnimation(); break; case MSG_REPEAT_KEY: tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */); break; case MSG_LONGPRESS_KEY: - mainKeyboardView.onLongPress(tracker); + callbacks.onLongPress(tracker); break; case MSG_UPDATE_BATCH_INPUT: tracker.updateBatchInputByTimer(SystemClock.uptimeMillis()); @@ -114,8 +115,8 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper< final boolean isTyping = isTypingState(); removeMessages(MSG_TYPING_STATE_EXPIRED); - final MainKeyboardView mainKeyboardView = getOwnerInstance(); - if (mainKeyboardView == null) { + final Callbacks callbacks = getOwnerInstance(); + if (callbacks == null) { return; } @@ -123,7 +124,7 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper< final int typedCode = typedKey.getCode(); if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) { if (isTyping) { - mainKeyboardView.startWhileTypingFadeinAnimation(); + callbacks.startWhileTypingFadeinAnimation(); } return; } @@ -133,7 +134,7 @@ public final class MainKeyboardViewTimerHandler extends LeakGuardHandlerWrapper< if (isTyping) { return; } - mainKeyboardView.startWhileTypingFadeoutAnimation(); + callbacks.startWhileTypingFadeoutAnimation(); } @Override