From f60d09ac3086f308cafcee13ebcb94c562f9e58e Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 4 Jul 2011 20:58:58 +0900 Subject: [PATCH] Narrower KeyboardView reference This change also rename static inner class to more readable name and get rid of unnecessary object reference from PointerTracker. Bug: 4768084 Change-Id: Ie4e2b940d66b47d41efcae7eeac853cdae2e4d38 --- .../AccessibleKeyboardViewProxy.java | 6 +-- .../inputmethod/keyboard/KeyboardView.java | 22 ++++---- .../keyboard/LatinKeyboardBaseView.java | 36 +++++++------ .../inputmethod/keyboard/PointerTracker.java | 53 +++++++++---------- .../internal/MiniKeyboardBuilder.java | 6 +-- .../android/inputmethod/latin/LatinIME.java | 10 ++-- 6 files changed, 67 insertions(+), 66 deletions(-) diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 38d904a94..a87ff9891 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.LatinKeyboardBaseView; +import com.android.inputmethod.keyboard.KeyboardView; 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 LatinKeyboardBaseView mView; + private KeyboardView mView; private AccessibleKeyboardActionListener mListener; private FlickGestureDetector mGestureDetector; @@ -57,7 +57,7 @@ public class AccessibleKeyboardViewProxy { return sInstance; } - public static void setView(LatinKeyboardBaseView view) { + public static void setView(KeyboardView 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 f3e023d3e..d1345db9d 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -72,7 +72,7 @@ import java.util.HashMap; * @attr ref R.styleable#KeyboardView_shadowColor * @attr ref R.styleable#KeyboardView_shadowRadius */ -public class KeyboardView extends View implements PointerTracker.UIProxy { +public class KeyboardView extends View implements PointerTracker.DrawingProxy { private static final boolean DEBUG_KEYBOARD_GRID = false; // Miscellaneous constants @@ -123,13 +123,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private static final int MEASURESPEC_UNSPECIFIED = MeasureSpec.makeMeasureSpec( 0, MeasureSpec.UNSPECIFIED); - private final UIHandler mHandler = new UIHandler(this); + private final DrawingHandler mDrawingHandler = new DrawingHandler(this); - public static class UIHandler extends StaticInnerHandlerWrapper { + public static class DrawingHandler extends StaticInnerHandlerWrapper { private static final int MSG_SHOW_KEY_PREVIEW = 1; private static final int MSG_DISMISS_KEY_PREVIEW = 2; - public UIHandler(KeyboardView outerInstance) { + public DrawingHandler(KeyboardView outerInstance) { super(outerInstance); } @@ -365,7 +365,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { */ public void setKeyboard(Keyboard keyboard) { // Remove any pending messages, except dismissing preview - mHandler.cancelAllShowKeyPreviews(); + mDrawingHandler.cancelAllShowKeyPreviews(); mKeyboard = keyboard; LatinImeLogger.onSetKeyboard(keyboard); requestLayout(); @@ -766,13 +766,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } public void cancelAllMessages() { - mHandler.cancelAllMessages(); + mDrawingHandler.cancelAllMessages(); } @Override public void showKeyPreview(int keyIndex, PointerTracker tracker) { if (mShowKeyPreviewPopup) { - mHandler.showKeyPreview(mDelayBeforePreview, keyIndex, tracker); + mDrawingHandler.showKeyPreview(mDelayBeforePreview, keyIndex, tracker); } else if (mKeyboard.needSpacebarPreview(keyIndex)) { // Show key preview (in this case, slide language switcher) without any delay. showKey(keyIndex, tracker); @@ -781,14 +781,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { @Override public void cancelShowKeyPreview(PointerTracker tracker) { - mHandler.cancelShowKeyPreview(tracker); + mDrawingHandler.cancelShowKeyPreview(tracker); } @Override public void dismissKeyPreview(PointerTracker tracker) { if (mShowKeyPreviewPopup) { - mHandler.cancelShowKeyPreview(tracker); - mHandler.dismissKeyPreview(mDelayAfterPreview, tracker); + mDrawingHandler.cancelShowKeyPreview(tracker); + mDrawingHandler.dismissKeyPreview(mDelayAfterPreview, tracker); } else if (mKeyboard.needSpacebarPreview(KeyDetector.NOT_A_KEY)) { // Dismiss key preview (in this case, slide language switcher) without any delay. mPreviewText.setVisibility(View.INVISIBLE); @@ -821,7 +821,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { if (key == null) return; - mHandler.cancelAllDismissKeyPreviews(); + mDrawingHandler.cancelAllDismissKeyPreviews(); final KeyPreviewDrawParams params = mKeyPreviewDrawParams; final int keyDrawX = key.mX + key.mVisualInsetsLeft; final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 5ef40ecb3..c8cfb43e3 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -88,17 +88,17 @@ public class LatinKeyboardBaseView extends KeyboardView { private final int mSwipeThreshold; private final boolean mDisambiguateSwipe; - private final UIHandler mHandler = new UIHandler(this); + private final KeyTimerHandler mKeyTimerHandler = new KeyTimerHandler(this); - public static class UIHandler extends StaticInnerHandlerWrapper { - private static final int MSG_REPEAT_KEY = 3; - private static final int MSG_LONGPRESS_KEY = 4; - private static final int MSG_LONGPRESS_SHIFT_KEY = 5; - private static final int MSG_IGNORE_DOUBLE_TAP = 6; + public static class KeyTimerHandler extends StaticInnerHandlerWrapper { + private static final int MSG_REPEAT_KEY = 1; + private static final int MSG_LONGPRESS_KEY = 2; + private static final int MSG_LONGPRESS_SHIFT_KEY = 3; + private static final int MSG_IGNORE_DOUBLE_TAP = 4; private boolean mInKeyRepeat; - public UIHandler(LatinKeyboardBaseView outerInstance) { + public KeyTimerHandler(LatinKeyboardBaseView outerInstance) { super(outerInstance); } @@ -249,7 +249,7 @@ public class LatinKeyboardBaseView extends KeyboardView { // Detected a double tap on shift key. If we are in the ignoring double tap // mode, it means we have already turned off caps lock in // {@link KeyboardSwitcher#onReleaseShift} . - final boolean ignoringDoubleTap = mHandler.isIgnoringDoubleTap(); + final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap(); if (!ignoringDoubleTap) onDoubleTapShiftKey(tracker); return true; @@ -272,7 +272,7 @@ public class LatinKeyboardBaseView extends KeyboardView { public void startIgnoringDoubleTap() { if (ENABLE_CAPSLOCK_BY_DOUBLETAP) - mHandler.startIgnoringDoubleTap(); + mKeyTimerHandler.startIgnoringDoubleTap(); } public void setOnKeyboardActionListener(KeyboardActionListener listener) { @@ -303,7 +303,7 @@ public class LatinKeyboardBaseView extends KeyboardView { dismissAllKeyPreviews(); } // Remove any pending messages, except dismissing preview - mHandler.cancelKeyTimers(); + mKeyTimerHandler.cancelKeyTimers(); super.setKeyboard(keyboard); mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); @@ -349,7 +349,7 @@ public class LatinKeyboardBaseView extends KeyboardView { @Override public void cancelAllMessages() { - mHandler.cancelAllMessages(); + mKeyTimerHandler.cancelAllMessages(); super.cancelAllMessages(); } @@ -481,7 +481,8 @@ public class LatinKeyboardBaseView extends KeyboardView { // Create pointer trackers until we can get 'id+1'-th tracker, if needed. for (int i = pointers.size(); i <= id; i++) { final PointerTracker tracker = - new PointerTracker(i, this, mHandler, mKeyDetector, this); + new PointerTracker(i, getContext(), mKeyTimerHandler, mKeyDetector, this, + mHasDistinctMultitouch); if (keyboard != null) tracker.setKeyboard(keyboard, mKeyDetector); if (listener != null) @@ -506,6 +507,7 @@ public class LatinKeyboardBaseView extends KeyboardView { @Override public boolean onTouchEvent(MotionEvent me) { + final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; final int action = me.getActionMasked(); final int pointerCount = me.getPointerCount(); final int oldPointerCount = mOldPointerCount; @@ -514,7 +516,7 @@ public class LatinKeyboardBaseView extends KeyboardView { // TODO: cleanup this code into a multi-touch to single-touch event converter class? // If the device does not have distinct multi-touch support panel, ignore all multi-touch // events except a transition from/to single-touch. - if (!mHasDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) { + if (nonDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) { return true; } @@ -525,7 +527,7 @@ public class LatinKeyboardBaseView extends KeyboardView { if (mPopupMiniKeyboardPanel == null && mGestureDetector != null && mGestureDetector.onTouchEvent(me)) { dismissAllKeyPreviews(); - mHandler.cancelKeyTimers(); + mKeyTimerHandler.cancelKeyTimers(); return true; } @@ -541,12 +543,12 @@ public class LatinKeyboardBaseView extends KeyboardView { return mPopupMiniKeyboardPanel.onTouchEvent(me); } - if (mHandler.isInKeyRepeat()) { + if (mKeyTimerHandler.isInKeyRepeat()) { final PointerTracker tracker = getPointerTracker(id); // Key repeating timer will be canceled if 2 or more keys are in action, and current // event (UP or DOWN) is non-modifier key. if (pointerCount > 1 && !tracker.isModifier()) { - mHandler.cancelKeyRepeatTimer(); + mKeyTimerHandler.cancelKeyRepeatTimer(); } // Up event will pass through. } @@ -554,7 +556,7 @@ public class LatinKeyboardBaseView extends KeyboardView { // TODO: cleanup this code into a multi-touch to single-touch event converter class? // Translate mutli-touch event to single-touch events on the device that has no distinct // multi-touch panel. - if (!mHasDistinctMultitouch) { + if (nonDistinctMultitouch) { // Use only main (id=0) pointer tracker. PointerTracker tracker = getPointerTracker(0); if (pointerCount == 1 && oldPointerCount == 2) { diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index ed93978ac..4ceabff4c 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -16,12 +16,13 @@ package com.android.inputmethod.keyboard; +import android.content.Context; import android.content.res.Resources; import android.os.SystemClock; import android.util.Log; import android.view.MotionEvent; -import com.android.inputmethod.keyboard.LatinKeyboardBaseView.UIHandler; +import com.android.inputmethod.keyboard.LatinKeyboardBaseView.KeyTimerHandler; import com.android.inputmethod.keyboard.internal.PointerTrackerKeyState; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; @@ -39,7 +40,7 @@ public class PointerTracker { private static final boolean DEBUG_LISTENER = false; private static boolean DEBUG_MODE = LatinImeLogger.sDBG; - public interface UIProxy { + public interface DrawingProxy { public void invalidateKey(Key key); public void showKeyPreview(int keyIndex, PointerTracker tracker); public void cancelShowKeyPreview(PointerTracker tracker); @@ -53,9 +54,8 @@ public class PointerTracker { private final int mLongPressKeyTimeout; private final int mLongPressShiftKeyTimeout; - private final LatinKeyboardBaseView mKeyboardView; - private final UIProxy mProxy; - private final UIHandler mHandler; + private final DrawingProxy mDrawingProxy; + private final KeyTimerHandler mKeyTimerHandler; private KeyDetector mKeyDetector; private KeyboardActionListener mListener = EMPTY_LISTENER; private final KeyboardSwitcher mKeyboardSwitcher; @@ -111,19 +111,18 @@ public class PointerTracker { public void onSwipeDown() {} }; - public PointerTracker(int id, LatinKeyboardBaseView keyboardView, UIHandler handler, - KeyDetector keyDetector, UIProxy proxy) { - if (proxy == null || handler == null || keyDetector == null) + public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler, + KeyDetector keyDetector, DrawingProxy drawingProxy, boolean hasDistinctMultitouch) { + if (drawingProxy == null || keyTimerHandler == null || keyDetector == null) throw new NullPointerException(); mPointerId = id; - mKeyboardView = keyboardView; - mProxy = proxy; - mHandler = handler; + mDrawingProxy = drawingProxy; + mKeyTimerHandler = keyTimerHandler; mKeyDetector = keyDetector; mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mKeyState = new PointerTrackerKeyState(keyDetector); - mHasDistinctMultitouch = keyboardView.hasDistinctMultitouch(); - final Resources res = mKeyboardView.getResources(); + mHasDistinctMultitouch = hasDistinctMultitouch; + final Resources res = context.getResources(); mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled); mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); mLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); @@ -262,7 +261,7 @@ public class PointerTracker { final Key key = getKey(keyIndex); if (key != null) { key.onReleased(); - mProxy.invalidateKey(key); + mDrawingProxy.invalidateKey(key); } } @@ -270,7 +269,7 @@ public class PointerTracker { final Key key = getKey(keyIndex); if (key != null && key.isEnabled()) { key.onPressed(); - mProxy.invalidateKey(key); + mDrawingProxy.invalidateKey(key); } } @@ -404,7 +403,7 @@ public class PointerTracker { setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); startSlidingKeyInput(oldKey); - mHandler.cancelKeyTimers(); + mKeyTimerHandler.cancelKeyTimers(); startRepeatKey(keyIndex); if (mIsAllowedSlidingKeyInput) { // This onPress call may have changed keyboard layout. Those cases are detected @@ -462,7 +461,7 @@ public class PointerTracker { setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); startSlidingKeyInput(oldKey); - mHandler.cancelLongPressTimers(); + mKeyTimerHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { keyState.onMoveToNewKey(keyIndex, x, y); } else { @@ -503,8 +502,8 @@ public class PointerTracker { private void onUpEventInternal(int x, int y, long eventTime, boolean updateReleasedKeyGraphics) { - mHandler.cancelKeyTimers(); - mProxy.cancelShowKeyPreview(this); + mKeyTimerHandler.cancelKeyTimers(); + mDrawingProxy.cancelShowKeyPreview(this); mIsInSlidingKeyInput = false; final PointerTrackerKeyState keyState = mKeyState; final int keyX, keyY; @@ -563,8 +562,8 @@ public class PointerTracker { } private void onCancelEventInternal() { - mHandler.cancelKeyTimers(); - mProxy.cancelShowKeyPreview(this); + mKeyTimerHandler.cancelKeyTimers(); + mDrawingProxy.cancelShowKeyPreview(this); dismissKeyPreview(); setReleasedKeyGraphics(mKeyState.getKeyIndex()); mIsInSlidingKeyInput = false; @@ -575,7 +574,7 @@ public class PointerTracker { if (key != null && key.mRepeatable) { dismissKeyPreview(); onRepeatKey(keyIndex); - mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); + mKeyTimerHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); mIsRepeatableKey = true; } else { mIsRepeatableKey = false; @@ -631,26 +630,26 @@ public class PointerTracker { private void showKeyPreview(int keyIndex) { if (isKeyPreviewNotRequired(keyIndex)) return; - mProxy.showKeyPreview(keyIndex, this); + mDrawingProxy.showKeyPreview(keyIndex, this); } private void dismissKeyPreview() { - mProxy.dismissKeyPreview(this); + mDrawingProxy.dismissKeyPreview(this); } private void startLongPressTimer(int keyIndex) { Key key = getKey(keyIndex); if (key.mCode == Keyboard.CODE_SHIFT) { - mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); + mKeyTimerHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); } else if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) { // We need not start long press timer on the key which has manual temporary upper case // code defined and the keyboard is in manual temporary upper case mode. return; } else if (mKeyboardSwitcher.isInMomentarySwitchState()) { // We use longer timeout for sliding finger input started from the symbols mode key. - mHandler.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this); + mKeyTimerHandler.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this); } else { - mHandler.startLongPressTimer(mLongPressKeyTimeout, keyIndex, this); + mKeyTimerHandler.startLongPressTimer(mLongPressKeyTimeout, keyIndex, this); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java index 1885ea14e..cc89579bb 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java @@ -23,7 +23,7 @@ import android.graphics.Rect; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.LatinKeyboardBaseView; +import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.MiniKeyboard; import com.android.inputmethod.latin.R; @@ -199,7 +199,7 @@ public class MiniKeyboardBuilder { } } - public MiniKeyboardBuilder(LatinKeyboardBaseView view, int layoutTemplateResId, Key parentKey, + public MiniKeyboardBuilder(KeyboardView view, int layoutTemplateResId, Key parentKey, Keyboard parentKeyboard) { final Context context = view.getContext(); mRes = context.getResources(); @@ -223,7 +223,7 @@ public class MiniKeyboardBuilder { keyboard.setDefaultCoordX(params.getDefaultKeyCoordX() + params.mKeyWidth / 2); } - private static int getMaxKeyWidth(LatinKeyboardBaseView view, CharSequence[] popupCharacters, + private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, int minKeyWidth) { Paint paint = null; Rect bounds = null; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 4a813541d..a9f34c6c7 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -66,7 +66,7 @@ import com.android.inputmethod.deprecated.recorrection.Recorrection; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.keyboard.LatinKeyboardBaseView; +import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.LatinKeyboard; import com.android.inputmethod.keyboard.LatinKeyboardView; @@ -655,7 +655,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onWindowHidden() { super.onWindowHidden(); - LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); + KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); } @@ -668,7 +668,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging); - LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); + KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); if (mAutoDictionary != null) mAutoDictionary.flushPendingWrites(); if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites(); @@ -677,7 +677,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onFinishInputView(boolean finishingInput) { super.onFinishInputView(finishingInput); - LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); + KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.cancelAllMessages(); // Remove pending messages related to update suggestions mHandler.cancelUpdateSuggestions(); @@ -866,7 +866,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onComputeInsets(InputMethodService.Insets outInsets) { super.onComputeInsets(outInsets); - final LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); + final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView == null || mCandidateViewContainer == null) return; final int containerHeight = mCandidateViewContainer.getHeight();