From f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sun, 10 Jul 2011 19:31:02 -0700 Subject: [PATCH] Add KeyEventHandler interface This change also revert KeyboardView to non-abstract class. Bug: 4768084 Change-Id: I827defb58bfb28b345464f6a89aa4438e41cf1e2 --- .../AccessibleKeyboardViewProxy.java | 6 ++-- .../inputmethod/keyboard/KeyboardView.java | 22 +----------- .../keyboard/LatinKeyboardBaseView.java | 12 +++++-- .../inputmethod/keyboard/PointerTracker.java | 35 ++++++++++++++++--- .../inputmethod/keyboard/PopupPanel.java | 2 +- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index de1e3963d..8ca834148 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -29,7 +29,7 @@ import com.android.inputmethod.compat.AccessibilityEventCompatUtils; import com.android.inputmethod.compat.MotionEventCompatUtils; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; -import com.android.inputmethod.keyboard.KeyboardView; +import com.android.inputmethod.keyboard.LatinKeyboardBaseView; import com.android.inputmethod.keyboard.PointerTracker; public class AccessibleKeyboardViewProxy { @@ -40,7 +40,7 @@ public class AccessibleKeyboardViewProxy { private static final long DELAY_KEY_PRESS = 10; private int mScaledEdgeSlop; - private KeyboardView mView; + private LatinKeyboardBaseView mView; private AccessibleKeyboardActionListener mListener; private FlickGestureDetector mGestureDetector; @@ -57,7 +57,7 @@ public class AccessibleKeyboardViewProxy { return sInstance; } - public static void setView(KeyboardView view) { + public static void setView(LatinKeyboardBaseView view) { sInstance.mView = view; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 56e4dc871..e31aa8478 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -38,7 +38,6 @@ import android.view.ViewGroup; import android.widget.TextView; import com.android.inputmethod.compat.FrameLayoutCompatUtils; -import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; @@ -73,7 +72,7 @@ import java.util.HashMap; * @attr ref R.styleable#KeyboardView_shadowColor * @attr ref R.styleable#KeyboardView_shadowRadius */ -public abstract class KeyboardView extends View implements PointerTracker.DrawingProxy { +public class KeyboardView extends View implements PointerTracker.DrawingProxy { private static final boolean DEBUG_KEYBOARD_GRID = false; // Miscellaneous constants @@ -918,23 +917,4 @@ public abstract class KeyboardView extends View implements PointerTracker.Drawin super.onDetachedFromWindow(); closing(); } - - /** - * Get KeyDetector object that is used for the Keyboard of this KeyboardView. - * @return the KeyDetector object that is used for the Keyboard - */ - public abstract KeyDetector getKeyDetector(); - - /** - * Get KeyboardActionListener object that is used to register key code and so on. - * @return the KeyboardActionListner for this KeyboardView - */ - public abstract KeyboardActionListener getKeyboardActionListener(); - - /** - * Get TimerProxy object that handles key repeat and long press timer event for the Keyboard - * of this KeyboardView. - * @return the TimerProxy object that handles key repeat and long press timer event. - */ - public abstract TimerProxy getTimerProxy(); } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 318e454d3..c4e37ff87 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -33,6 +33,7 @@ import android.widget.PopupWindow; import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; +import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; @@ -49,7 +50,7 @@ import java.util.WeakHashMap; * @attr ref R.styleable#KeyboardView_verticalCorrection * @attr ref R.styleable#KeyboardView_popupLayout */ -public class LatinKeyboardBaseView extends KeyboardView { +public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler { private static final String TAG = LatinKeyboardBaseView.class.getSimpleName(); private static final boolean ENABLE_CAPSLOCK_BY_LONGPRESS = true; @@ -277,6 +278,11 @@ public class LatinKeyboardBaseView extends KeyboardView { return mKeyDetector; } + @Override + public DrawingProxy getDrawingProxy() { + return this; + } + @Override public TimerProxy getTimerProxy() { return mKeyTimerHandler; @@ -589,11 +595,11 @@ public class LatinKeyboardBaseView extends KeyboardView { } private static void processMotionEvent(PointerTracker tracker, int action, int x, int y, - long eventTime, KeyboardView keyboardView) { + long eventTime, PointerTracker.KeyEventHandler handler) { switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: - tracker.onDownEvent(x, y, eventTime, keyboardView); + tracker.onDownEvent(x, y, eventTime, handler); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 95574258e..29a575ad0 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -36,6 +36,33 @@ public class PointerTracker { private static final boolean DEBUG_LISTENER = false; private static boolean DEBUG_MODE = LatinImeLogger.sDBG; + public interface KeyEventHandler { + /** + * Get KeyDetector object that is used for this PointerTracker. + * @return the KeyDetector object that is used for this PointerTracker + */ + public KeyDetector getKeyDetector(); + + /** + * Get KeyboardActionListener object that is used to register key code and so on. + * @return the KeyboardActionListner for this PointerTracker + */ + public KeyboardActionListener getKeyboardActionListener(); + + /** + * Get DrawingProxy object that is used for this PointerTracker. + * @return the DrawingProxy object that is used for this PointerTracker + */ + public DrawingProxy getDrawingProxy(); + + /** + * Get TimerProxy object that handles key repeat and long press timer event for this + * PointerTracker. + * @return the TimerProxy object that handles key repeat and long press timer event. + */ + public TimerProxy getTimerProxy(); + } + public interface DrawingProxy { public void invalidateKey(Key key); public void showKeyPreview(int keyIndex, PointerTracker tracker); @@ -329,13 +356,13 @@ public class PointerTracker { return onMoveKeyInternal(x, y); } - public void onDownEvent(int x, int y, long eventTime, KeyboardView keyboardView) { + public void onDownEvent(int x, int y, long eventTime, KeyEventHandler handler) { if (DEBUG_EVENT) printTouchEvent("onDownEvent:", x, y, eventTime); - mDrawingProxy = keyboardView; - setKeyboardActionListener(keyboardView.getKeyboardActionListener()); - setKeyDetectorInner(keyboardView.getKeyDetector()); + mDrawingProxy = handler.getDrawingProxy(); + setKeyboardActionListener(handler.getKeyboardActionListener()); + setKeyDetectorInner(handler.getKeyDetector()); // Naive up-to-down noise filter. final long deltaT = eventTime - mUpTime; if (deltaT < mTouchNoiseThresholdMillis) { diff --git a/java/src/com/android/inputmethod/keyboard/PopupPanel.java b/java/src/com/android/inputmethod/keyboard/PopupPanel.java index 386e11f2c..2d9130fcb 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupPanel.java +++ b/java/src/com/android/inputmethod/keyboard/PopupPanel.java @@ -19,7 +19,7 @@ package com.android.inputmethod.keyboard; import android.view.MotionEvent; import android.widget.PopupWindow; -public interface PopupPanel { +public interface PopupPanel extends PointerTracker.KeyEventHandler { /** * Show popup panel. * @param parentKeyboardView the parent KeyboardView that has the parent key.