From d9449ccf3ce9e5eabb022aed6a45bba680bce115 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 21 Jan 2013 14:41:33 +0900 Subject: [PATCH] Move MoreKeysPanel.Controller implementation to MainKeyboardView Change-Id: Iffa298d51ca21a7dcd1e77c633217532d96d2cf5 --- java/res/values/attrs.xml | 5 +- java/res/values/styles.xml | 2 +- .../inputmethod/keyboard/KeyboardView.java | 46 +-------- .../keyboard/MainKeyboardView.java | 96 ++++++++++++------- .../suggestions/SuggestionStripView.java | 14 +-- 5 files changed, 75 insertions(+), 88 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 5c6d0e847..528361e68 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -67,9 +67,6 @@ - - - @@ -126,6 +123,8 @@ + + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 0bcf943e4..9bbc5f34f 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -59,7 +59,6 @@ @dimen/key_preview_height @fraction/key_preview_text_ratio @integer/config_key_preview_linger_timeout - @layout/more_keys_keyboard @dimen/keyboard_vertical_correction @color/key_text_shadow_color_default 2.75 @@ -89,6 +88,7 @@ @integer/config_long_press_key_timeout @integer/config_long_press_shift_key_timeout @integer/config_ignore_alt_code_key_timeout + @layout/more_keys_keyboard @bool/config_show_more_keys_keyboard_at_touched_point @integer/config_language_on_spacebar_final_alpha @anim/language_on_spacebar_fadeout diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 7fc68e061..5f62be827 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -60,7 +60,6 @@ import java.util.HashSet; * A view that renders a virtual {@link Keyboard}. * * @attr ref R.styleable#KeyboardView_keyBackground - * @attr ref R.styleable#KeyboardView_moreKeysLayout * @attr ref R.styleable#KeyboardView_keyPreviewLayout * @attr ref R.styleable#KeyboardView_keyPreviewOffset * @attr ref R.styleable#KeyboardView_keyPreviewHeight @@ -103,8 +102,8 @@ import java.util.HashSet; * @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintActivatedColor * @attr ref R.styleable#Keyboard_Key_keyPreviewTextColor */ -public class KeyboardView extends View implements PointerTracker.DrawingProxy, - MoreKeysPanel.Controller { +// TODO: Move PointerTracker.DrawingProxy to MainKeyboardView +public class KeyboardView extends View implements PointerTracker.DrawingProxy { private static final String TAG = KeyboardView.class.getSimpleName(); // XML attributes @@ -115,7 +114,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy, private final float mKeyShiftedLetterHintPadding; private final float mKeyTextShadowRadius; protected final float mVerticalCorrection; - protected final int mMoreKeysLayout; protected final Drawable mKeyBackground; protected final Rect mKeyBackgroundPadding = new Rect(); private final int mBackgroundDimAlpha; @@ -136,13 +134,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy, protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams(); // Preview placer view - private final PreviewPlacerView mPreviewPlacerView; + // TODO: Move PreviewPlacerView to MainKeyboardView + protected final PreviewPlacerView mPreviewPlacerView; private final int[] mOriginCoords = CoordinateUtils.newInstance(); - // More keys panel (used by both more keys keyboard and more suggestions view) - // TODO: Consider extending to support multiple more keys panels - protected MoreKeysPanel mMoreKeysPanel; - // Key preview private static final int PREVIEW_ALPHA = 240; private final int mKeyPreviewLayoutId; @@ -287,8 +282,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy, } mVerticalCorrection = keyboardViewAttr.getDimension( R.styleable.KeyboardView_verticalCorrection, 0); - mMoreKeysLayout = keyboardViewAttr.getResourceId( - R.styleable.KeyboardView_moreKeysLayout, 0); mBackgroundDimAlpha = keyboardViewAttr.getInt( R.styleable.KeyboardView_backgroundDimAlpha, 0); mGestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt( @@ -1027,42 +1020,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy, public void closing() { dismissAllKeyPreviews(); cancelAllMessages(); - onCancelMoreKeysPanel(); mInvalidateAllKeys = true; mKeyboard = null; requestLayout(); } - @Override - public void onShowMoreKeysPanel(final MoreKeysPanel panel) { - if (isShowingMoreKeysPanel()) { - onDismissMoreKeysPanel(); - } - mMoreKeysPanel = panel; - mPreviewPlacerView.addView(mMoreKeysPanel.getContainerView()); - } - - public boolean isShowingMoreKeysPanel() { - return (mMoreKeysPanel != null); - } - - @Override - public void onCancelMoreKeysPanel() { - if (isShowingMoreKeysPanel()) { - mMoreKeysPanel.dismissMoreKeysPanel(); - } - } - - @Override - public boolean onDismissMoreKeysPanel() { - if (isShowingMoreKeysPanel()) { - mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView()); - mMoreKeysPanel = null; - return true; - } - return false; - } - @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 625575d53..f8a5ea600 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -85,6 +85,7 @@ import java.util.WeakHashMap; * @attr ref R.styleable#MainKeyboardView_longPressKeyTimeout * @attr ref R.styleable#MainKeyboardView_longPressShiftKeyTimeout * @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout + * @attr ref R.styleable#MainKeyboardView_moreKeysKeyboardLayout * @attr ref R.styleable#MainKeyboardView_showMoreKeysKeyboardAtTouchPoint * @attr ref R.styleable#MainKeyboardView_gestureStaticTimeThresholdAfterFastTyping * @attr ref R.styleable#MainKeyboardView_gestureDetectFastMoveSpeedThreshold @@ -99,7 +100,7 @@ import java.util.WeakHashMap; * @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration */ public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler, - TouchScreenRegulator.ProcessMotionEvent { + MoreKeysPanel.Controller, TouchScreenRegulator.ProcessMotionEvent { private static final String TAG = MainKeyboardView.class.getSimpleName(); // TODO: Kill process when the usability study mode was changed. @@ -137,11 +138,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack // More keys keyboard private final WeakHashMap mMoreKeysPanelCache = new WeakHashMap(); + private final int mMoreKeysLayout; private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint; + // More keys panel (used by both more keys keyboard and more suggestions view) + // TODO: Consider extending to support multiple more keys panels + private MoreKeysPanel mMoreKeysPanel; private final TouchScreenRegulator mTouchScreenRegulator; - protected KeyDetector mKeyDetector; + private KeyDetector mKeyDetector; private final boolean mHasDistinctMultitouch; private int mOldPointerCount = 1; private Key mOldKey; @@ -402,38 +407,41 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack res, R.array.phantom_sudden_move_event_device_list)); PointerTracker.init(needsPhantomSuddenMoveEventHack); - final TypedArray a = context.obtainStyledAttributes( + final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes( attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView); - mAutoCorrectionSpacebarLedEnabled = a.getBoolean( + mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean( R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false); - mAutoCorrectionSpacebarLedIcon = a.getDrawable( + mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable( R.styleable.MainKeyboardView_autoCorrectionSpacebarLedIcon); - mSpacebarTextRatio = a.getFraction( + mSpacebarTextRatio = mainKeyboardViewAttr.getFraction( R.styleable.MainKeyboardView_spacebarTextRatio, 1, 1, 1.0f); - mSpacebarTextColor = a.getColor(R.styleable.MainKeyboardView_spacebarTextColor, 0); - mSpacebarTextShadowColor = a.getColor( + mSpacebarTextColor = mainKeyboardViewAttr.getColor( + R.styleable.MainKeyboardView_spacebarTextColor, 0); + mSpacebarTextShadowColor = mainKeyboardViewAttr.getColor( R.styleable.MainKeyboardView_spacebarTextShadowColor, 0); - mLanguageOnSpacebarFinalAlpha = a.getInt( + mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt( R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha, Constants.Color.ALPHA_OPAQUE); - final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId( + final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId( R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0); - final int altCodeKeyWhileTypingFadeoutAnimatorResId = a.getResourceId( + final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId( R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0); - final int altCodeKeyWhileTypingFadeinAnimatorResId = a.getResourceId( + final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId( R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0); - final float keyHysteresisDistance = a.getDimension( + final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension( R.styleable.MainKeyboardView_keyHysteresisDistance, 0); - final float keyHysteresisDistanceForSlidingModifier = a.getDimension( + final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension( R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0); mKeyDetector = new KeyDetector( keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier); - mKeyTimerHandler = new KeyTimerHandler(this, a); - mConfigShowMoreKeysKeyboardAtTouchedPoint = a.getBoolean( + mKeyTimerHandler = new KeyTimerHandler(this, mainKeyboardViewAttr); + mMoreKeysLayout = mainKeyboardViewAttr.getResourceId( + R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0); + mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean( R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false); - PointerTracker.setParameters(a); - a.recycle(); + PointerTracker.setParameters(mainKeyboardViewAttr); + mainKeyboardViewAttr.recycle(); mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator( languageOnSpacebarFadeoutAnimatorResId, this); @@ -591,8 +599,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return onLongPress(parentKey, tracker); } - // This default implementation returns a more keys panel. - protected MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) { + private MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) { if (parentKey.mMoreKeys == null) { return null; } @@ -613,14 +620,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack } /** - * Called when a key is long pressed. By default this will open more keys keyboard associated - * with this key. + * Called when a key is long pressed. * @param parentKey the key that was long pressed * @param tracker the pointer tracker which pressed the parent key * @return true if the long press is handled, false otherwise. Subclasses should call the * method on the base class if the subclass doesn't wish to handle the call. */ - protected boolean onLongPress(final Key parentKey, final PointerTracker tracker) { + private boolean onLongPress(final Key parentKey, final PointerTracker tracker) { if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.mainKeyboardView_onLongPress(); } @@ -697,6 +703,38 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return PointerTracker.isAnyInSlidingKeyInput(); } + @Override + public void onShowMoreKeysPanel(final MoreKeysPanel panel) { + if (isShowingMoreKeysPanel()) { + onDismissMoreKeysPanel(); + } + mMoreKeysPanel = panel; + mPreviewPlacerView.addView(mMoreKeysPanel.getContainerView()); + } + + public boolean isShowingMoreKeysPanel() { + return (mMoreKeysPanel != null); + } + + @Override + public void onCancelMoreKeysPanel() { + if (isShowingMoreKeysPanel()) { + mMoreKeysPanel.dismissMoreKeysPanel(); + } + PointerTracker.dismissAllMoreKeysPanels(); + } + + @Override + public boolean onDismissMoreKeysPanel() { + dimEntireKeyboard(false /* dimmed */); + if (isShowingMoreKeysPanel()) { + mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView()); + mMoreKeysPanel = null; + return true; + } + return false; + } + public int getPointerCount() { return mOldPointerCount; } @@ -853,18 +891,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mMoreKeysPanelCache.clear(); } - @Override - public void onCancelMoreKeysPanel() { - super.onCancelMoreKeysPanel(); - PointerTracker.dismissAllMoreKeysPanels(); - } - - @Override - public boolean onDismissMoreKeysPanel() { - dimEntireKeyboard(false /* dimmed */); - return super.onDismissMoreKeysPanel(); - } - /** * Receives hover events from the input framework. * diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 14bb95b3c..5b440c368 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -52,7 +52,7 @@ import android.widget.TextView; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.keyboard.KeyboardView; +import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MoreKeysPanel; import com.android.inputmethod.keyboard.ViewLayoutUtils; import com.android.inputmethod.latin.AutoCorrection; @@ -81,7 +81,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick static final boolean DBG = LatinImeLogger.sDBG; private final ViewGroup mSuggestionsStrip; - KeyboardView mKeyboardView; + MainKeyboardView mMainKeyboardView; private final View mMoreSuggestionsContainer; private final MoreSuggestionsView mMoreSuggestionsView; @@ -610,7 +610,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick */ public void setListener(final Listener listener, final View inputView) { mListener = listener; - mKeyboardView = (KeyboardView)inputView.findViewById(R.id.keyboard_view); + mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view); } public void setSuggestions(final SuggestedWords suggestedWords) { @@ -676,13 +676,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick new MoreKeysPanel.Controller() { @Override public boolean onDismissMoreKeysPanel() { - mKeyboardView.dimEntireKeyboard(false /* dimmed */); - return mKeyboardView.onDismissMoreKeysPanel(); + mMainKeyboardView.dimEntireKeyboard(false /* dimmed */); + return mMainKeyboardView.onDismissMoreKeysPanel(); } @Override public void onShowMoreKeysPanel(MoreKeysPanel panel) { - mKeyboardView.onShowMoreKeysPanel(panel); + mMainKeyboardView.onShowMoreKeysPanel(panel); } @Override @@ -728,7 +728,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING; mOriginX = mLastX; mOriginY = mLastY; - mKeyboardView.dimEntireKeyboard(true /* dimmed */); + mMainKeyboardView.dimEntireKeyboard(true /* dimmed */); for (int i = 0; i < params.mSuggestionsCountInStrip; i++) { mWords.get(i).setPressed(false); }