MainKeyboardView.java revision 4b3cae9b0cbd5bf30a1c8da383ff247f9c2afc5a
15f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka/* 25f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * Copyright (C) 2011 The Android Open Source Project 35f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * 45f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * Licensed under the Apache License, Version 2.0 (the "License"); 55f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * you may not use this file except in compliance with the License. 65f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * You may obtain a copy of the License at 75f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * 85f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * http://www.apache.org/licenses/LICENSE-2.0 95f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * 105f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * Unless required by applicable law or agreed to in writing, software 115f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * distributed under the License is distributed on an "AS IS" BASIS, 125f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * See the License for the specific language governing permissions and 145f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * limitations under the License. 155f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka */ 165f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 175f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokapackage com.android.inputmethod.keyboard; 185f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 19d7c4ba170982ddce5ac12ea92c3c3d8b53d524baTadashi G. Takaokaimport android.animation.AnimatorInflater; 2031c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaokaimport android.animation.ObjectAnimator; 215f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.content.Context; 2213ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaokaimport android.content.SharedPreferences; 235f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.content.pm.PackageManager; 2427b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaokaimport android.content.res.Resources; 254112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaokaimport android.content.res.TypedArray; 266dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaokaimport android.graphics.Canvas; 27f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaokaimport android.graphics.Color; 2822b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaokaimport android.graphics.Paint; 294112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaokaimport android.graphics.Paint.Align; 30bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaokaimport android.graphics.Typeface; 314112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaokaimport android.graphics.drawable.Drawable; 325f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.os.Message; 3372fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaokaimport android.os.SystemClock; 3413ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaokaimport android.preference.PreferenceManager; 355f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.util.AttributeSet; 36375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaokaimport android.util.DisplayMetrics; 375f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.util.Log; 38375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaokaimport android.util.SparseArray; 390e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaokaimport android.util.TypedValue; 405f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.view.LayoutInflater; 415f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.view.MotionEvent; 425f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.view.View; 435f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport android.view.ViewConfiguration; 44b8dc67466339dc14653ad634c86851025373326bTadashi G. Takaokaimport android.view.ViewGroup; 45f6972561fcb45310f18230ce217f0c6bb57e7eeeTadashi G. Takaokaimport android.view.inputmethod.InputMethodSubtype; 460e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaokaimport android.widget.TextView; 475f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 485f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport com.android.inputmethod.accessibility.AccessibilityUtils; 495f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; 5015f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaokaimport com.android.inputmethod.annotations.ExternallyReferenced; 51f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8Tadashi G. Takaokaimport com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; 522321caa1f9eb6c2d616bc36f11f5b48eebf144feTadashi G. Takaokaimport com.android.inputmethod.keyboard.PointerTracker.TimerProxy; 53fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.GestureFloatingPreviewText; 54fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.GestureTrailsPreview; 5549d8af8a4e900f3c68c333aba7fde0a11fd368b1Tadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.KeyDrawParams; 560e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams; 57375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.PreviewPlacerView; 58fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview; 59081fedc42269845a31e962b2ac1aa017b3a2efeeTadashi G. Takaokaimport com.android.inputmethod.keyboard.internal.TouchScreenRegulator; 60375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaokaimport com.android.inputmethod.latin.CollectionUtils; 614daf32b6c0358f0273a99b622a259ecdf6b44fa4Tom Ouyangimport com.android.inputmethod.latin.Constants; 62547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaokaimport com.android.inputmethod.latin.CoordinateUtils; 6313ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaokaimport com.android.inputmethod.latin.DebugSettings; 646dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaokaimport com.android.inputmethod.latin.LatinIME; 6515d4793911fa305e0a58aced925961e948582979satokimport com.android.inputmethod.latin.LatinImeLogger; 665f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport com.android.inputmethod.latin.R; 679879f65651a748e4c0a45715eb7d5663652f1127Tadashi G. Takaokaimport com.android.inputmethod.latin.ResourceUtils; 685f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport com.android.inputmethod.latin.StaticInnerHandlerWrapper; 6927b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaokaimport com.android.inputmethod.latin.StringUtils; 703bf57a5624679a20db26df912077a53b9f90ad36Tadashi G. Takaokaimport com.android.inputmethod.latin.SubtypeLocale; 71375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaokaimport com.android.inputmethod.latin.SuggestedWords; 7215d4793911fa305e0a58aced925961e948582979satokimport com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; 73c166697e3f5ec600089987dbbff0be7f3e308565Ken Wakasaimport com.android.inputmethod.latin.define.ProductionFlag; 746b966160ac8570271547bf63217efa5e228d4accKurt Partridgeimport com.android.inputmethod.research.ResearchLogger; 755f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 7627b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaokaimport java.util.Locale; 775f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaokaimport java.util.WeakHashMap; 785f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 795f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka/** 805f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * A view that is responsible for detecting key presses and touch movements. 815f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * 82dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedEnabled 83dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedIcon 84dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_spacebarTextRatio 85dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_spacebarTextColor 86dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_spacebarTextShadowColor 87dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha 88dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator 89dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator 90dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator 91dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyHysteresisDistance 92dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_touchNoiseThresholdTime 93dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_touchNoiseThresholdDistance 94dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_slidingKeyInputEnable 95dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyRepeatStartTimeout 96dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyRepeatInterval 97dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_longPressKeyTimeout 98dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_longPressShiftKeyTimeout 99dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout 100375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyPreviewLayout 1010e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyPreviewOffset 1020e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyPreviewHeight 1030e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_keyPreviewLingerTimeout 104d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_moreKeysKeyboardLayout 105f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_backgroundDimAlpha 106dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_showMoreKeysKeyboardAtTouchPoint 107375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureFloatingPreviewTextLingerTimeout 1083623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureStaticTimeThresholdAfterFastTyping 1093623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureDetectFastMoveSpeedThreshold 1103623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureDynamicThresholdDecayDuration 1113623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureDynamicTimeThresholdFrom 1123623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureDynamicTimeThresholdTo 1133623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureDynamicDistanceThresholdFrom 1143623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureDynamicDistanceThresholdTo 1153623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureSamplingMinimumDistance 1163623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureRecognitionMinimumTime 1173623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_gestureRecognitionSpeedThreshold 1183623b9767b3d5f122f574d4c4d14aa79ed305752Tadashi G. Takaoka * @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration 1195f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka */ 120a28a05e971cc242b338331a3b78276fa95188d19Tadashi G. Takaokapublic final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler, 1210e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka PointerTracker.DrawingProxy, MoreKeysPanel.Controller, 1220e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka TouchScreenRegulator.ProcessMotionEvent { 123c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka private static final String TAG = MainKeyboardView.class.getSimpleName(); 1245f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 125d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge // TODO: Kill process when the usability study mode was changed. 126d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge private static final boolean ENABLE_USABILITY_STUDY_LOG = LatinImeLogger.sUsabilityStudy; 127d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge 128bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka /** Listener for {@link KeyboardActionListener}. */ 129bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka private KeyboardActionListener mKeyboardActionListener; 130bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka 131bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka /* Space key and its icons */ 1324112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka private Key mSpaceKey; 1334112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka private Drawable mSpaceIcon; 134bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka // Stuff to draw language name on spacebar. 13531c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka private final int mLanguageOnSpacebarFinalAlpha; 13631c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator; 137bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka private boolean mNeedsToDisplayLanguage; 138fd60b2f97035382b14dce207b3613711982a613eTadashi G. Takaoka private boolean mHasMultipleEnabledIMEsOrSubtypes; 1394daf32b6c0358f0273a99b622a259ecdf6b44fa4Tom Ouyang private int mLanguageOnSpacebarAnimAlpha = Constants.Color.ALPHA_OPAQUE; 1404112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka private final float mSpacebarTextRatio; 1414112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka private float mSpacebarTextSize; 1424112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka private final int mSpacebarTextColor; 1434112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka private final int mSpacebarTextShadowColor; 144bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka // The minimum x-scale to fit the language name on spacebar. 145bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka private static final float MINIMUM_XSCALE_OF_LANGUAGE_NAME = 0.8f; 146bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka // Stuff to draw auto correction LED on spacebar. 147bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka private boolean mAutoCorrectionSpacebarLedOn; 148bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka private final boolean mAutoCorrectionSpacebarLedEnabled; 149bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka private final Drawable mAutoCorrectionSpacebarLedIcon; 150bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka private static final int SPACE_LED_LENGTH_PERCENT = 80; 15115d4793911fa305e0a58aced925961e948582979satok 15273a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka // Stuff to draw altCodeWhileTyping keys. 15331c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka private ObjectAnimator mAltCodeKeyWhileTypingFadeoutAnimator; 15431c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka private ObjectAnimator mAltCodeKeyWhileTypingFadeinAnimator; 1554daf32b6c0358f0273a99b622a259ecdf6b44fa4Tom Ouyang private int mAltCodeKeyWhileTypingAnimAlpha = Constants.Color.ALPHA_OPAQUE; 15673a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka 157375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka // Preview placer view 158375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private final PreviewPlacerView mPreviewPlacerView; 159375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private final int[] mOriginCoords = CoordinateUtils.newInstance(); 160fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka private final GestureFloatingPreviewText mGestureFloatingPreviewText; 161fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka private final GestureTrailsPreview mGestureTrailsPreview; 162fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka private final SlidingKeyInputPreview mSlidingKeyInputPreview; 163375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 1640e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // Key preview 1650e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int PREVIEW_ALPHA = 240; 166375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private final int mKeyPreviewLayoutId; 1670e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private final int mKeyPreviewOffset; 1680e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private final int mKeyPreviewHeight; 169375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private final SparseArray<TextView> mKeyPreviewTexts = CollectionUtils.newSparseArray(); 1700e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private final KeyPreviewDrawParams mKeyPreviewDrawParams = new KeyPreviewDrawParams(); 1710e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private boolean mShowKeyPreviewPopup = true; 1720e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private int mKeyPreviewLingerTimeout; 1730e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 1742affaf91a04d63e0994102299816014a8bbe11e1Tadashi G. Takaoka // More keys keyboard 175f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka private final Paint mBackgroundDimAlphaPaint = new Paint(); 176f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka private boolean mNeedsToDimEntireKeyboard; 177a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private final View mMoreKeysKeyboardContainer; 178a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private final WeakHashMap<Key, Keyboard> mMoreKeysKeyboardCache = 179a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka CollectionUtils.newWeakHashMap(); 1802affaf91a04d63e0994102299816014a8bbe11e1Tadashi G. Takaoka private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint; 181d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka // More keys panel (used by both more keys keyboard and more suggestions view) 182d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka // TODO: Consider extending to support multiple more keys panels 183d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka private MoreKeysPanel mMoreKeysPanel; 1845f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 185375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka // Gesture floating preview text 186375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka // TODO: Make this parameter customizable by user via settings. 187375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private int mGestureFloatingPreviewTextLingerTimeout; 188375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 189081fedc42269845a31e962b2ac1aa017b3a2efeeTadashi G. Takaoka private final TouchScreenRegulator mTouchScreenRegulator; 1905f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 191d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka private KeyDetector mKeyDetector; 19213ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaoka private final boolean mHasDistinctMultitouch; 1935f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka private int mOldPointerCount = 1; 194e22baaadd314c80f835e2e96fb0dfc73838ac2cdTadashi G. Takaoka private Key mOldKey; 1955f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 196160f01211d169d64102205e80e9ac8d46c7d674bTadashi G. Takaoka private final KeyTimerHandler mKeyTimerHandler; 1975f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 198a28a05e971cc242b338331a3b78276fa95188d19Tadashi G. Takaoka private static final class KeyTimerHandler extends StaticInnerHandlerWrapper<MainKeyboardView> 1992321caa1f9eb6c2d616bc36f11f5b48eebf144feTadashi G. Takaoka implements TimerProxy { 20027e48447a449d2eb534dfa2dc07060727e1a8fb0Tadashi G. Takaoka private static final int MSG_TYPING_STATE_EXPIRED = 0; 201f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka private static final int MSG_REPEAT_KEY = 1; 202f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka private static final int MSG_LONGPRESS_KEY = 2; 2030ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka private static final int MSG_DOUBLE_TAP = 3; 20472fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka private static final int MSG_UPDATE_BATCH_INPUT = 4; 2055f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 2065509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka private final int mKeyRepeatStartTimeout; 2075509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka private final int mKeyRepeatInterval; 2085509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka private final int mLongPressKeyTimeout; 2095509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka private final int mLongPressShiftKeyTimeout; 2105509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka private final int mIgnoreAltCodeKeyTimeout; 21172fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka private final int mGestureRecognitionUpdateTime; 2125f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 2135509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka public KeyTimerHandler(final MainKeyboardView outerInstance, 2145509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka final TypedArray mainKeyboardViewAttr) { 2155f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka super(outerInstance); 2165509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka 2175509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka mKeyRepeatStartTimeout = mainKeyboardViewAttr.getInt( 2185509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0); 2195509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka mKeyRepeatInterval = mainKeyboardViewAttr.getInt( 2205509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka R.styleable.MainKeyboardView_keyRepeatInterval, 0); 2215509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka mLongPressKeyTimeout = mainKeyboardViewAttr.getInt( 2225509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka R.styleable.MainKeyboardView_longPressKeyTimeout, 0); 2235509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka mLongPressShiftKeyTimeout = mainKeyboardViewAttr.getInt( 2245509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka R.styleable.MainKeyboardView_longPressShiftKeyTimeout, 0); 2255509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( 2265509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0); 22772fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt( 22872fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0); 2295f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 2305f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 2315f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka @Override 232dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void handleMessage(final Message msg) { 233c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka final MainKeyboardView keyboardView = getOuterInstance(); 2345f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final PointerTracker tracker = (PointerTracker) msg.obj; 2355f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka switch (msg.what) { 23627e48447a449d2eb534dfa2dc07060727e1a8fb0Tadashi G. Takaoka case MSG_TYPING_STATE_EXPIRED: 23727e48447a449d2eb534dfa2dc07060727e1a8fb0Tadashi G. Takaoka startWhileTypingFadeinAnimation(keyboardView); 23827e48447a449d2eb534dfa2dc07060727e1a8fb0Tadashi G. Takaoka break; 2395f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka case MSG_REPEAT_KEY: 2408a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka final Key currentKey = tracker.getKey(); 2418a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka if (currentKey != null && currentKey.mCode == msg.arg1) { 2428a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka tracker.onRegisterKey(currentKey); 2435509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka startKeyRepeatTimer(tracker, mKeyRepeatInterval); 2448a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka } 2455f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka break; 2465f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka case MSG_LONGPRESS_KEY: 247a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka if (tracker != null) { 248a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka keyboardView.onLongPress(tracker); 249a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } else { 250a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1); 251a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } 2525f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka break; 25372fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka case MSG_UPDATE_BATCH_INPUT: 25472fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka tracker.updateBatchInputByTimer(SystemClock.uptimeMillis()); 25572fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka startUpdateBatchInputTimer(tracker); 25672fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka break; 2575f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 2585f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 2595f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 260dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka private void startKeyRepeatTimer(final PointerTracker tracker, final long delay) { 2618a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka final Key key = tracker.getKey(); 26220dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (key == null) { 26320dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return; 26420dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 2658a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay); 26632c54c4dbed0b27b7177f796d90a2ebb9566c9c9Tadashi G. Takaoka } 26732c54c4dbed0b27b7177f796d90a2ebb9566c9c9Tadashi G. Takaoka 2682321caa1f9eb6c2d616bc36f11f5b48eebf144feTadashi G. Takaoka @Override 269dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void startKeyRepeatTimer(final PointerTracker tracker) { 2705509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka startKeyRepeatTimer(tracker, mKeyRepeatStartTimeout); 2715f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 2725f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 2735f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka public void cancelKeyRepeatTimer() { 2745f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka removeMessages(MSG_REPEAT_KEY); 2755f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 2765f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 2770d9d37cec2b3c4b4c3747baeb529bd2a70cbafb8Tadashi G. Takaoka // TODO: Suppress layout changes in key repeat mode 2785f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka public boolean isInKeyRepeat() { 2790d9d37cec2b3c4b4c3747baeb529bd2a70cbafb8Tadashi G. Takaoka return hasMessages(MSG_REPEAT_KEY); 2805f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 2815f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 2822321caa1f9eb6c2d616bc36f11f5b48eebf144feTadashi G. Takaoka @Override 283dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void startLongPressTimer(final int code) { 28498b5c982b93cbfc74b221af30079ecb69dd4e0a1Tadashi G. Takaoka cancelLongPressTimer(); 285a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka final int delay; 286a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka switch (code) { 287240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka case Constants.CODE_SHIFT: 2885509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka delay = mLongPressShiftKeyTimeout; 289a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka break; 290a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka default: 291a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka delay = 0; 292a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka break; 293a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } 294a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka if (delay > 0) { 295a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, code, 0), delay); 296a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } 297a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } 298a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka 299a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka @Override 300dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void startLongPressTimer(final PointerTracker tracker) { 301a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka cancelLongPressTimer(); 3027b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka if (tracker == null) { 3037b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka return; 3047b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka } 3057b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka final Key key = tracker.getKey(); 3067b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka final int delay; 3077b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka switch (key.mCode) { 308240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka case Constants.CODE_SHIFT: 3095509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka delay = mLongPressShiftKeyTimeout; 3107b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka break; 3117b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka default: 3127b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka if (KeyboardSwitcher.getInstance().isInMomentarySwitchState()) { 3137b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka // We use longer timeout for sliding finger input started from the symbols 3147b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka // mode key. 3155509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka delay = mLongPressKeyTimeout * 3; 3167b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka } else { 3175509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka delay = mLongPressKeyTimeout; 318a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } 3197b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka break; 3207b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka } 3217b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka if (delay > 0) { 3227b6afb1287fb6d5edfebed7403eb31ed23a8348dTadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay); 323a5c96f376ad57e78a88942bb618e067054ed818aTadashi G. Takaoka } 3245f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 3255f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 3262321caa1f9eb6c2d616bc36f11f5b48eebf144feTadashi G. Takaoka @Override 32798b5c982b93cbfc74b221af30079ecb69dd4e0a1Tadashi G. Takaoka public void cancelLongPressTimer() { 3285f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka removeMessages(MSG_LONGPRESS_KEY); 3295f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 3305f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 331d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka private static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel, 33245213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka final ObjectAnimator animatorToStart) { 33345213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka float startFraction = 0.0f; 33445213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka if (animatorToCancel.isStarted()) { 335b9720a55b47684589e3176434cd2b1a08942d112Tadashi G. Takaoka animatorToCancel.cancel(); 33645213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka startFraction = 1.0f - animatorToCancel.getAnimatedFraction(); 337b9720a55b47684589e3176434cd2b1a08942d112Tadashi G. Takaoka } 33845213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka final long startTime = (long)(animatorToStart.getDuration() * startFraction); 33945213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka animatorToStart.start(); 34045213ed2a6e9a940ec540ff43ded7e877cb20dc9Tadashi G. Takaoka animatorToStart.setCurrentPlayTime(startTime); 341b9720a55b47684589e3176434cd2b1a08942d112Tadashi G. Takaoka } 342b9720a55b47684589e3176434cd2b1a08942d112Tadashi G. Takaoka 343d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka private static void startWhileTypingFadeinAnimation(final MainKeyboardView keyboardView) { 344d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator, 345d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka keyboardView.mAltCodeKeyWhileTypingFadeinAnimator); 346d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka } 347d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka 348d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka private static void startWhileTypingFadeoutAnimation(final MainKeyboardView keyboardView) { 349d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeinAnimator, 350d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator); 351d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka } 352d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka 3532321caa1f9eb6c2d616bc36f11f5b48eebf144feTadashi G. Takaoka @Override 354dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void startTypingStateTimer(final Key typedKey) { 355d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) { 356d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka return; 357d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka } 358d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka 35973a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka final boolean isTyping = isTypingState(); 360f1678ba8024606349bc184cfeaead2be059f7b5bTadashi G. Takaoka removeMessages(MSG_TYPING_STATE_EXPIRED); 361d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka final MainKeyboardView keyboardView = getOuterInstance(); 362d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka 363d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka // When user hits the space or the enter key, just cancel the while-typing timer. 364d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka final int typedCode = typedKey.mCode; 365240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka if (typedCode == Constants.CODE_SPACE || typedCode == Constants.CODE_ENTER) { 366d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka startWhileTypingFadeinAnimation(keyboardView); 367d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka return; 368d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka } 369d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka 37073a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka sendMessageDelayed( 3715509798977a61dcb4a9dde9030f31bb138b71e3bTadashi G. Takaoka obtainMessage(MSG_TYPING_STATE_EXPIRED), mIgnoreAltCodeKeyTimeout); 37273a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka if (isTyping) { 37373a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka return; 37473a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka } 375d2173b5737bf791a65f6b1e2980f26ebd94369c5Tadashi G. Takaoka startWhileTypingFadeoutAnimation(keyboardView); 37693246652638f423d5220449f65495dea0639c750Tadashi G. Takaoka } 37793246652638f423d5220449f65495dea0639c750Tadashi G. Takaoka 37893246652638f423d5220449f65495dea0639c750Tadashi G. Takaoka @Override 37973a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka public boolean isTypingState() { 38073a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka return hasMessages(MSG_TYPING_STATE_EXPIRED); 38193246652638f423d5220449f65495dea0639c750Tadashi G. Takaoka } 38293246652638f423d5220449f65495dea0639c750Tadashi G. Takaoka 3839f09c6fbc81ed40a41c0a23bd5913214ec7f6a9bTadashi G. Takaoka @Override 3840ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka public void startDoubleTapTimer() { 3850ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_DOUBLE_TAP), 3865f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka ViewConfiguration.getDoubleTapTimeout()); 3875f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 3885f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 3890ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka @Override 390beb08b398fa73a26f2d42d6feec87e34a96ca2d9Tadashi G. Takaoka public void cancelDoubleTapTimer() { 391beb08b398fa73a26f2d42d6feec87e34a96ca2d9Tadashi G. Takaoka removeMessages(MSG_DOUBLE_TAP); 392beb08b398fa73a26f2d42d6feec87e34a96ca2d9Tadashi G. Takaoka } 393beb08b398fa73a26f2d42d6feec87e34a96ca2d9Tadashi G. Takaoka 394beb08b398fa73a26f2d42d6feec87e34a96ca2d9Tadashi G. Takaoka @Override 3950ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka public boolean isInDoubleTapTimeout() { 3960ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka return hasMessages(MSG_DOUBLE_TAP); 3975f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 398c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka 399c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka @Override 4000ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka public void cancelKeyTimers() { 4010ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka cancelKeyRepeatTimer(); 4020ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka cancelLongPressTimer(); 403c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka } 404c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka 40572fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka @Override 40672fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka public void startUpdateBatchInputTimer(final PointerTracker tracker) { 40772fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka if (mGestureRecognitionUpdateTime <= 0) { 40872fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka return; 40972fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka } 41072fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka removeMessages(MSG_UPDATE_BATCH_INPUT, tracker); 41172fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_UPDATE_BATCH_INPUT, tracker), 41272fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka mGestureRecognitionUpdateTime); 41372fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka } 41472fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka 41572fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka @Override 416915f348b35cb66ed9696a51c9250f9b25799fb82Tadashi G. Takaoka public void cancelUpdateBatchInputTimer(final PointerTracker tracker) { 417915f348b35cb66ed9696a51c9250f9b25799fb82Tadashi G. Takaoka removeMessages(MSG_UPDATE_BATCH_INPUT, tracker); 418915f348b35cb66ed9696a51c9250f9b25799fb82Tadashi G. Takaoka } 419915f348b35cb66ed9696a51c9250f9b25799fb82Tadashi G. Takaoka 420915f348b35cb66ed9696a51c9250f9b25799fb82Tadashi G. Takaoka @Override 4212db9e1c447a71f0aec3067697cf294f711a9e4e0Tadashi G. Takaoka public void cancelAllUpdateBatchInputTimers() { 42272fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka removeMessages(MSG_UPDATE_BATCH_INPUT); 42372fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka } 42472fd0968e5227ffc383b1f9d096872ba39cfdce8Tadashi G. Takaoka 4250ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka public void cancelAllMessages() { 4260ed2d3a4491cb0f6142975a15b653be6079b6a4eTadashi G. Takaoka cancelKeyTimers(); 4272db9e1c447a71f0aec3067697cf294f711a9e4e0Tadashi G. Takaoka cancelAllUpdateBatchInputTimers(); 428c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka } 429c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka } 430c71854a6614d1945739dcf40db61b0e887442b67Tadashi G. Takaoka 431375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private final DrawingHandler mDrawingHandler = new DrawingHandler(this); 432375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 433375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public static class DrawingHandler extends StaticInnerHandlerWrapper<MainKeyboardView> { 434375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private static final int MSG_DISMISS_KEY_PREVIEW = 0; 435375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; 436375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 437375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public DrawingHandler(final MainKeyboardView outerInstance) { 438375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka super(outerInstance); 439375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 440375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 441375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka @Override 442375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void handleMessage(final Message msg) { 443375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final MainKeyboardView mainKeyboardView = getOuterInstance(); 444375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (mainKeyboardView == null) return; 445375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final PointerTracker tracker = (PointerTracker) msg.obj; 446375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka switch (msg.what) { 447375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka case MSG_DISMISS_KEY_PREVIEW: 448375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final TextView previewText = mainKeyboardView.mKeyPreviewTexts.get( 449375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka tracker.mPointerId); 450375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (previewText != null) { 451375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka previewText.setVisibility(INVISIBLE); 452375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 453375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka break; 454375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: 455fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY); 456375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka break; 457375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 458375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 459375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 460375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void dismissKeyPreview(final long delay, final PointerTracker tracker) { 461375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay); 462375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 463375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 464375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void cancelDismissKeyPreview(final PointerTracker tracker) { 465375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker); 466375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 467375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 468375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private void cancelAllDismissKeyPreviews() { 469375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka removeMessages(MSG_DISMISS_KEY_PREVIEW); 470375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 471375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 472375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void dismissGestureFloatingPreviewText(final long delay) { 473375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay); 474375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 475375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 476375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void cancelAllMessages() { 477375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka cancelAllDismissKeyPreviews(); 478375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 479375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 480375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 481dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public MainKeyboardView(final Context context, final AttributeSet attrs) { 482c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka this(context, attrs, R.attr.mainKeyboardViewStyle); 4835f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 4845f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 485dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) { 4865f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka super(context, attrs, defStyle); 4875f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 488081fedc42269845a31e962b2ac1aa017b3a2efeeTadashi G. Takaoka mTouchScreenRegulator = new TouchScreenRegulator(context, this); 489c403a46f6d787b79768895272d53d296100677ddTadashi G. Takaoka 49013ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaoka final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 49113ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaoka final boolean forceNonDistinctMultitouch = prefs.getBoolean( 492a5ff9f0c77005769f92ca1131882bb4e3ca18980Tadashi G. Takaoka DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false); 49313ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaoka final boolean hasDistinctMultitouch = context.getPackageManager() 4945f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); 49513ae76d7a342581160c172cd21706b3d57d32dadTadashi G. Takaoka mHasDistinctMultitouch = hasDistinctMultitouch && !forceNonDistinctMultitouch; 496918e420d1becc1389b9895538eceff85fe882c99Tadashi G. Takaoka final Resources res = getResources(); 497d438fcaca2a35ace4fee5b7a469596bfe2d1b025Tadashi G. Takaoka final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( 498fa7f08b37327c825baf0a6455d6f7fdf8b37da57Tadashi G. Takaoka ResourceUtils.getDeviceOverrideValue( 499fa7f08b37327c825baf0a6455d6f7fdf8b37da57Tadashi G. Takaoka res, R.array.phantom_sudden_move_event_device_list)); 50093b5c2ce63705e7ebffd9bdb7358100e8d5b5235Tadashi G. Takaoka PointerTracker.init(needsPhantomSuddenMoveEventHack); 501fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView = new PreviewPlacerView(context, attrs); 50222b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka 503d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes( 504c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView); 505f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka final int backgroundDimAlpha = mainKeyboardViewAttr.getInt( 506f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka R.styleable.MainKeyboardView_backgroundDimAlpha, 0); 507f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka mBackgroundDimAlphaPaint.setColor(Color.BLACK); 508f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha); 509d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean( 510c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false); 511d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable( 512c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_autoCorrectionSpacebarLedIcon); 513d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mSpacebarTextRatio = mainKeyboardViewAttr.getFraction( 514ef2bfad5903fb55adca61dbea51984fbc7e4375fTadashi G. Takaoka R.styleable.MainKeyboardView_spacebarTextRatio, 1, 1, 1.0f); 515d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mSpacebarTextColor = mainKeyboardViewAttr.getColor( 516d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka R.styleable.MainKeyboardView_spacebarTextColor, 0); 517d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mSpacebarTextShadowColor = mainKeyboardViewAttr.getColor( 518c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_spacebarTextShadowColor, 0); 519d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt( 520c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha, 5214daf32b6c0358f0273a99b622a259ecdf6b44fa4Tom Ouyang Constants.Color.ALPHA_OPAQUE); 522d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId( 523c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0); 524d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId( 525c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0); 526d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId( 527c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0); 528160f01211d169d64102205e80e9ac8d46c7d674bTadashi G. Takaoka 529d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension( 530c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_keyHysteresisDistance, 0); 531d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension( 532f731eb1760a5693492a34bc11aa755053aa65c19Tadashi G. Takaoka R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0); 533f731eb1760a5693492a34bc11aa755053aa65c19Tadashi G. Takaoka mKeyDetector = new KeyDetector( 534f731eb1760a5693492a34bc11aa755053aa65c19Tadashi G. Takaoka keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier); 535d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mKeyTimerHandler = new KeyTimerHandler(this, mainKeyboardViewAttr); 5360e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset( 5370e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka R.styleable.MainKeyboardView_keyPreviewOffset, 0); 5380e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize( 5390e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka R.styleable.MainKeyboardView_keyPreviewHeight, 0); 5400e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mKeyPreviewLingerTimeout = mainKeyboardViewAttr.getInt( 5410e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0); 542375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mKeyPreviewLayoutId = mainKeyboardViewAttr.getResourceId( 543375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka R.styleable.MainKeyboardView_keyPreviewLayout, 0); 5440e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (mKeyPreviewLayoutId == 0) { 5450e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mShowKeyPreviewPopup = false; 5460e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 547a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId( 548d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0); 549d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean( 550c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false); 551375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 552375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt( 553375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0); 554d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka PointerTracker.setParameters(mainKeyboardViewAttr); 555fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka 556fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureFloatingPreviewText = new GestureFloatingPreviewText( 557fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView, mainKeyboardViewAttr); 558fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView.addPreview(mGestureFloatingPreviewText); 559fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka 560fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureTrailsPreview = new GestureTrailsPreview( 561fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView, mainKeyboardViewAttr); 562fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView.addPreview(mGestureTrailsPreview); 563fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka 564fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mSlidingKeyInputPreview = new SlidingKeyInputPreview( 565fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView, mainKeyboardViewAttr); 566fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mPreviewPlacerView.addPreview(mSlidingKeyInputPreview); 567d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mainKeyboardViewAttr.recycle(); 568160f01211d169d64102205e80e9ac8d46c7d674bTadashi G. Takaoka 569a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka mMoreKeysKeyboardContainer = LayoutInflater.from(getContext()) 570a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka .inflate(moreKeysKeyboardLayoutId, null); 57131c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator( 57231c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka languageOnSpacebarFadeoutAnimatorResId, this); 57331c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator( 57431c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka altCodeKeyWhileTypingFadeoutAnimatorResId, this); 57531c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator( 57631c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka altCodeKeyWhileTypingFadeinAnimatorResId, this); 57731c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka } 57831c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka 579dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka private ObjectAnimator loadObjectAnimator(final int resId, final Object target) { 58020dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (resId == 0) { 58120dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return null; 58220dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 58331c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka final ObjectAnimator animator = (ObjectAnimator)AnimatorInflater.loadAnimator( 58431c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka getContext(), resId); 585d7c4ba170982ddce5ac12ea92c3c3d8b53d524baTadashi G. Takaoka if (animator != null) { 58631c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka animator.setTarget(target); 58773a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka } 58831c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka return animator; 58931c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka } 59073a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka 59115f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaoka @ExternallyReferenced 59231c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka public int getLanguageOnSpacebarAnimAlpha() { 59331c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka return mLanguageOnSpacebarAnimAlpha; 594d7c4ba170982ddce5ac12ea92c3c3d8b53d524baTadashi G. Takaoka } 595d7c4ba170982ddce5ac12ea92c3c3d8b53d524baTadashi G. Takaoka 59615f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaoka @ExternallyReferenced 597dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void setLanguageOnSpacebarAnimAlpha(final int alpha) { 59831c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka mLanguageOnSpacebarAnimAlpha = alpha; 59931c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka invalidateKey(mSpaceKey); 60031c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka } 60131c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka 60215f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaoka @ExternallyReferenced 60331c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka public int getAltCodeKeyWhileTypingAnimAlpha() { 60431c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka return mAltCodeKeyWhileTypingAnimAlpha; 60531c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka } 60631c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka 60715f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaoka @ExternallyReferenced 608dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void setAltCodeKeyWhileTypingAnimAlpha(final int alpha) { 60931c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka mAltCodeKeyWhileTypingAnimAlpha = alpha; 61031c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka updateAltCodeKeyWhileTyping(); 6115f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 6125f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 613dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void setKeyboardActionListener(final KeyboardActionListener listener) { 6145f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka mKeyboardActionListener = listener; 6155c73ed628b22fdfa59585803ee86e383c579a7d4Tadashi G. Takaoka PointerTracker.setKeyboardActionListener(listener); 6165f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 6175f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 6185f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka /** 6195f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * Returns the {@link KeyboardActionListener} object. 6205f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * @return the listener attached to this keyboard 6215f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka */ 6220efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka @Override 6230efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka public KeyboardActionListener getKeyboardActionListener() { 6245f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return mKeyboardActionListener; 6255f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 6265f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 627bb4be5444b845655c0eb80bcfbb66f93603802eaTadashi G. Takaoka @Override 6280efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka public KeyDetector getKeyDetector() { 6290efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka return mKeyDetector; 6300efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka } 6310efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka 6320efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka @Override 633f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8Tadashi G. Takaoka public DrawingProxy getDrawingProxy() { 634f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8Tadashi G. Takaoka return this; 635f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8Tadashi G. Takaoka } 636f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8Tadashi G. Takaoka 637f426cdd5c62452224ac4bb833c3ccf7b26d1a2a8Tadashi G. Takaoka @Override 6380efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka public TimerProxy getTimerProxy() { 6390efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka return mKeyTimerHandler; 6400efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka } 6410efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka 6425f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka /** 6435f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * Attaches a keyboard to this view. The keyboard can be switched at any time and the 6445f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * view will re-layout itself to accommodate the keyboard. 6455f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * @see Keyboard 6465f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * @see #getKeyboard() 6475f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * @param keyboard the keyboard to display in this view 6485f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka */ 6495f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka @Override 650dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void setKeyboard(final Keyboard keyboard) { 6518a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka // Remove any pending messages, except dismissing preview and key repeat. 6528a092b4ede02b79422deae51f0a416b034777fb3Tadashi G. Takaoka mKeyTimerHandler.cancelLongPressTimer(); 6535f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka super.setKeyboard(keyboard); 6545a7a696aff6718d4e0250c394a9d01cbf2a16916Tadashi G. Takaoka mKeyDetector.setKeyboard( 6555a7a696aff6718d4e0250c394a9d01cbf2a16916Tadashi G. Takaoka keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); 6568335c59ea7715f3dbc6625f128a7a038f314a89fTadashi G. Takaoka PointerTracker.setKeyDetector(mKeyDetector); 657081fedc42269845a31e962b2ac1aa017b3a2efeeTadashi G. Takaoka mTouchScreenRegulator.setKeyboardGeometry(keyboard.mOccupiedWidth); 658a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka mMoreKeysKeyboardCache.clear(); 6594112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 660240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka mSpaceKey = keyboard.getKey(Constants.CODE_SPACE); 6611f2d0aa6c9b343848ee51e5bc13ccaaadf3ba4feTadashi G. Takaoka mSpaceIcon = (mSpaceKey != null) 6624daf32b6c0358f0273a99b622a259ecdf6b44fa4Tom Ouyang ? mSpaceKey.getIcon(keyboard.mIconsSet, Constants.Color.ALPHA_OPAQUE) : null; 6634112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; 6644112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka mSpacebarTextSize = keyHeight * mSpacebarTextRatio; 66548a7681e064ae259b840f0e757da2d716043d893Kurt Partridge if (ProductionFlag.IS_EXPERIMENTAL) { 666c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka ResearchLogger.mainKeyboardView_setKeyboard(keyboard); 66748a7681e064ae259b840f0e757da2d716043d893Kurt Partridge } 668f147794fd41491a3383e6aca6d49007f58124068alanv 669f147794fd41491a3383e6aca6d49007f58124068alanv // This always needs to be set since the accessibility state can 670f147794fd41491a3383e6aca6d49007f58124068alanv // potentially change without the keyboard being set again. 671b6ca354431367b625daf9fff5fbe4b1f5ef996abKen Wakasa AccessibleKeyboardViewProxy.getInstance().setKeyboard(); 6725f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 6735f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 6740e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka /** 6750e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * Enables or disables the key feedback popup. This is a popup that shows a magnified 6760e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * version of the depressed key. By default the preview is enabled. 6770e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @param previewEnabled whether or not to enable the key feedback preview 6780e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @param delay the delay after which the preview is dismissed 6790e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @see #isKeyPreviewPopupEnabled() 6800e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka */ 6810e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) { 6820e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mShowKeyPreviewPopup = previewEnabled; 6830e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mKeyPreviewLingerTimeout = delay; 6840e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 6850e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 686375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 687375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private void locatePreviewPlacerView() { 688375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (mPreviewPlacerView.getParent() != null) { 689375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka return; 690375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 691375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final int width = getWidth(); 692375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final int height = getHeight(); 693375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (width == 0 || height == 0) { 694375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka // In transient state. 695375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka return; 696375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 697375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka getLocationInWindow(mOriginCoords); 698375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final DisplayMetrics dm = getResources().getDisplayMetrics(); 699375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (CoordinateUtils.y(mOriginCoords) < dm.heightPixels / 4) { 700375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka // In transient state. 701375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka return; 702375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 703375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final View rootView = getRootView(); 704375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (rootView == null) { 705375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka Log.w(TAG, "Cannot find root view"); 706375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka return; 707375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 708375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final ViewGroup windowContentView = (ViewGroup)rootView.findViewById(android.R.id.content); 709375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka // Note: It'd be very weird if we get null by android.R.id.content. 710375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (windowContentView == null) { 711375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka Log.w(TAG, "Cannot find android.R.id.content view to add PreviewPlacerView"); 712375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } else { 713375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka windowContentView.addView(mPreviewPlacerView); 714375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, width, height); 715375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 716375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 717375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 7180e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka /** 7190e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * Returns the enabled state of the key feedback preview 7200e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @return whether or not the key feedback preview is enabled 7210e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka * @see #setKeyPreviewPopupEnabled(boolean, int) 7220e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka */ 7230e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka public boolean isKeyPreviewPopupEnabled() { 7240e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka return mShowKeyPreviewPopup; 7250e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 7260e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 727375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private void addKeyPreview(final TextView keyPreview) { 728375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka locatePreviewPlacerView(); 729375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mPreviewPlacerView.addView( 730375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0)); 731375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 732375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 733375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private TextView getKeyPreviewText(final int pointerId) { 734375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka TextView previewText = mKeyPreviewTexts.get(pointerId); 735375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (previewText != null) { 736375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka return previewText; 737375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 738375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final Context context = getContext(); 739375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (mKeyPreviewLayoutId != 0) { 740375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka previewText = (TextView)LayoutInflater.from(context).inflate(mKeyPreviewLayoutId, null); 741375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } else { 742375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka previewText = new TextView(context); 743375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 744375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mKeyPreviewTexts.put(pointerId, previewText); 745375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka return previewText; 746375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 747375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 748375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka private void dismissAllKeyPreviews() { 749375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final int pointerCount = mKeyPreviewTexts.size(); 750375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka for (int id = 0; id < pointerCount; id++) { 751375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final TextView previewText = mKeyPreviewTexts.get(id); 752375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka if (previewText != null) { 753375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka previewText.setVisibility(INVISIBLE); 754375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 755375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 756375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka PointerTracker.setReleasedKeyGraphicsToAllKeys(); 757375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 758375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 7590e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // Background state set 7600e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int[][][] KEY_PREVIEW_BACKGROUND_STATE_TABLE = { 7610e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { // STATE_MIDDLE 7620e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka EMPTY_STATE_SET, 7630e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { R.attr.state_has_morekeys } 7640e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka }, 7650e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { // STATE_LEFT 7660e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { R.attr.state_left_edge }, 7670e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { R.attr.state_left_edge, R.attr.state_has_morekeys } 7680e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka }, 7690e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { // STATE_RIGHT 7700e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { R.attr.state_right_edge }, 7710e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka { R.attr.state_right_edge, R.attr.state_has_morekeys } 7720e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 7730e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka }; 7740e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int STATE_MIDDLE = 0; 7750e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int STATE_LEFT = 1; 7760e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int STATE_RIGHT = 2; 7770e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int STATE_NORMAL = 0; 7780e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int STATE_HAS_MOREKEYS = 1; 7790e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka private static final int[] KEY_PREVIEW_BACKGROUND_DEFAULT_STATE = 7800e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka KEY_PREVIEW_BACKGROUND_STATE_TABLE[STATE_MIDDLE][STATE_NORMAL]; 7810e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 7820e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka @Override 7830e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka public void showKeyPreview(final PointerTracker tracker) { 7840e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams; 7850e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final Keyboard keyboard = getKeyboard(); 7860e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (!mShowKeyPreviewPopup) { 7870e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewParams.mPreviewVisibleOffset = -keyboard.mVerticalGap; 7880e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka return; 7890e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 7900e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 7910e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final TextView previewText = getKeyPreviewText(tracker.mPointerId); 7920e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // If the key preview has no parent view yet, add it to the ViewGroup which can place 7930e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // key preview absolutely in SoftInputWindow. 7940e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (previewText.getParent() == null) { 7950e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka addKeyPreview(previewText); 7960e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 7970e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 7980e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mDrawingHandler.cancelDismissKeyPreview(tracker); 7990e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final Key key = tracker.getKey(); 8000e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // If key is invalid or IME is already closed, we must not show key preview. 8010e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // Trying to show key preview while root window is closed causes 8020e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // WindowManager.BadTokenException. 8030e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (key == null) { 8040e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka return; 8050e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8060e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 8070e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final KeyDrawParams drawParams = mKeyDrawParams; 8080e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setTextColor(drawParams.mPreviewTextColor); 8090e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final Drawable background = previewText.getBackground(); 8100e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (background != null) { 8110e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka background.setState(KEY_PREVIEW_BACKGROUND_DEFAULT_STATE); 8120e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka background.setAlpha(PREVIEW_ALPHA); 8130e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8140e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final String label = key.isShiftedLetterActivated() ? key.mHintLabel : key.mLabel; 8150e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // What we show as preview should match what we show on a key top in onDraw(). 8160e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (label != null) { 8170e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // TODO Should take care of temporaryShiftLabel here. 8180e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setCompoundDrawables(null, null, null, null); 8190e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (StringUtils.codePointCount(label) > 1) { 8200e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mLetterSize); 8210e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setTypeface(Typeface.DEFAULT_BOLD); 8220e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } else { 8230e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mPreviewTextSize); 8240e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setTypeface(key.selectTypeface(drawParams)); 8250e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8260e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setText(label); 8270e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } else { 8280e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setCompoundDrawables(null, null, null, 8290e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka key.getPreviewIcon(keyboard.mIconsSet)); 8300e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setText(null); 8310e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8320e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 8330e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.measure( 8340e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 8350e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final int keyDrawWidth = key.getDrawWidth(); 8360e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final int previewWidth = previewText.getMeasuredWidth(); 8370e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final int previewHeight = mKeyPreviewHeight; 8380e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // The width and height of visible part of the key preview background. The content marker 8390e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // of the background 9-patch have to cover the visible part of the background. 8400e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewParams.mPreviewVisibleWidth = previewWidth - previewText.getPaddingLeft() 8410e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka - previewText.getPaddingRight(); 8420e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewParams.mPreviewVisibleHeight = previewHeight - previewText.getPaddingTop() 8430e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka - previewText.getPaddingBottom(); 8440e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // The distance between the top edge of the parent key and the bottom of the visible part 8450e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // of the key preview background. 8460e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewParams.mPreviewVisibleOffset = mKeyPreviewOffset - previewText.getPaddingBottom(); 8470e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka getLocationInWindow(mOriginCoords); 8480e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // The key preview is horizontally aligned with the center of the visible part of the 8490e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and 8500e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // the left/right background is used if such background is specified. 8510e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final int statePosition; 8520e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 8530e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka + CoordinateUtils.x(mOriginCoords); 8540e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (previewX < 0) { 8550e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewX = 0; 8560e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka statePosition = STATE_LEFT; 8570e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } else if (previewX > getWidth() - previewWidth) { 8580e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewX = getWidth() - previewWidth; 8590e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka statePosition = STATE_RIGHT; 8600e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } else { 8610e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka statePosition = STATE_MIDDLE; 8620e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8630e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // The key preview is placed vertically above the top edge of the parent key with an 8640e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka // arbitrary offset. 8650e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final int previewY = key.mY - previewHeight + mKeyPreviewOffset 8660e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka + CoordinateUtils.y(mOriginCoords); 8670e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 8680e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka if (background != null) { 8690e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka final int hasMoreKeys = (key.mMoreKeys != null) ? STATE_HAS_MOREKEYS : STATE_NORMAL; 8700e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka background.setState(KEY_PREVIEW_BACKGROUND_STATE_TABLE[statePosition][hasMoreKeys]); 8710e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8720e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka ViewLayoutUtils.placeViewAt( 8730e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText, previewX, previewY, previewWidth, previewHeight); 8740e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka previewText.setVisibility(VISIBLE); 8750e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8760e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 8770e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka @Override 8780e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka public void dismissKeyPreview(final PointerTracker tracker) { 8790e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka mDrawingHandler.dismissKeyPreview(mKeyPreviewLingerTimeout, tracker); 8800e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8810e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 8820e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka @Override 8830e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka public void showSlidingKeyInputPreview(final PointerTracker tracker) { 8840e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka locatePreviewPlacerView(); 885fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mSlidingKeyInputPreview.setPreviewPosition(tracker); 8860e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8870e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 8880e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka @Override 8890e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka public void dismissSlidingKeyInputPreview() { 890fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mSlidingKeyInputPreview.dismissSlidingKeyInputPreview(); 8910e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka } 8920e4f0da449d0fc4f0c4c6b49b4c24961da36a5d1Tadashi G. Takaoka 893375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail, 894375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka final boolean drawsGestureFloatingPreviewText) { 895fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureFloatingPreviewText.setPreviewEnabled(drawsGestureFloatingPreviewText); 896fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureTrailsPreview.setPreviewEnabled(drawsGesturePreviewTrail); 897375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 898375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 899375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) { 900375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka locatePreviewPlacerView(); 901fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureFloatingPreviewText.setSuggetedWords(suggestedWords); 902375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 903375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 904375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void dismissGestureFloatingPreviewText() { 905375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka locatePreviewPlacerView(); 906375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout); 907375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 908375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 909fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka @Override 910ab334eb64669e909f0a401fddffa891962002602Tadashi G. Takaoka public void showGesturePreviewTrail(final PointerTracker tracker) { 911375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka locatePreviewPlacerView(); 912fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureFloatingPreviewText.setPreviewPosition(tracker); 913fb523d7f5d40123a49a9128c455815db320c90fcTadashi G. Takaoka mGestureTrailsPreview.setPreviewPosition(tracker); 914375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 915375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 9168335c59ea7715f3dbc6625f128a7a038f314a89fTadashi G. Takaoka // Note that this method is called from a non-UI thread. 917dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) { 9188335c59ea7715f3dbc6625f128a7a038f314a89fTadashi G. Takaoka PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable); 9198335c59ea7715f3dbc6625f128a7a038f314a89fTadashi G. Takaoka } 9208335c59ea7715f3dbc6625f128a7a038f314a89fTadashi G. Takaoka 921dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) { 9228335c59ea7715f3dbc6625f128a7a038f314a89fTadashi G. Takaoka PointerTracker.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser); 9230657b9698a110f8e895448d829478982ce37b6d1Tadashi G. Takaoka } 9240657b9698a110f8e895448d829478982ce37b6d1Tadashi G. Takaoka 9255f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka @Override 9264331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge protected void onAttachedToWindow() { 9274331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge super.onAttachedToWindow(); 9284331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge // Notify the research logger that the keyboard view has been attached. This is needed 9294331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge // to properly show the splash screen, which requires that the window token of the 9304331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge // KeyboardView be non-null. 9314331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge if (ProductionFlag.IS_EXPERIMENTAL) { 932c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka ResearchLogger.getInstance().mainKeyboardView_onAttachedToWindow(this); 933c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka } 934c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka } 935c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka 936c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka @Override 937c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka protected void onDetachedFromWindow() { 938c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka super.onDetachedFromWindow(); 939375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mPreviewPlacerView.removeAllViews(); 940c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka // Notify the research logger that the keyboard view has been detached. This is needed 941c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka // to invalidate the reference of {@link MainKeyboardView} to null. 942c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka if (ProductionFlag.IS_EXPERIMENTAL) { 943c3f78c9057a5710898feaf8027659484477e5821Tadashi G. Takaoka ResearchLogger.getInstance().mainKeyboardView_onDetachedFromWindow(); 9444331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge } 9454331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge } 9464331012a9e7779ff7c8359a443dc5815ee6ea8d9Kurt Partridge 947a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private MoreKeysPanel onCreateMoreKeysPanel(final Key key, final Context context) { 948a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (key.mMoreKeys == null) { 9495f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return null; 95020dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 951a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka Keyboard moreKeysKeyboard = mMoreKeysKeyboardCache.get(key); 952a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (moreKeysKeyboard == null) { 953a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka moreKeysKeyboard = new MoreKeysKeyboard.Builder( 954a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka context, key, this, mKeyPreviewDrawParams).build(); 955a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka mMoreKeysKeyboardCache.put(key, moreKeysKeyboard); 95620dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 9575f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 958a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final View container = mMoreKeysKeyboardContainer; 9592affaf91a04d63e0994102299816014a8bbe11e1Tadashi G. Takaoka final MoreKeysKeyboardView moreKeysKeyboardView = 9602affaf91a04d63e0994102299816014a8bbe11e1Tadashi G. Takaoka (MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view); 9612affaf91a04d63e0994102299816014a8bbe11e1Tadashi G. Takaoka moreKeysKeyboardView.setKeyboard(moreKeysKeyboard); 962b8dc67466339dc14653ad634c86851025373326bTadashi G. Takaoka container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 9632affaf91a04d63e0994102299816014a8bbe11e1Tadashi G. Takaoka return moreKeysKeyboardView; 9645f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 9655f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 9665f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka /** 967d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka * Called when a key is long pressed. 9685f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * @param tracker the pointer tracker which pressed the parent key 9695f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * @return true if the long press is handled, false otherwise. Subclasses should call the 9705f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka * method on the base class if the subclass doesn't wish to handle the call. 9715f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka */ 972a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private boolean onLongPress(final PointerTracker tracker) { 973a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (isShowingMoreKeysPanel()) { 974a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka return false; 975a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka } 976a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final Key key = tracker.getKey(); 977a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (key == null) { 978a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka return false; 979a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka } 9809bc29d78a6ce83f77869aa63748176241e29d43cKurt Partridge if (ProductionFlag.IS_EXPERIMENTAL) { 981c8e45ddb032554f4e9d4411d8ef47d98db62d77bTadashi G. Takaoka ResearchLogger.mainKeyboardView_onLongPress(); 9829bc29d78a6ce83f77869aa63748176241e29d43cKurt Partridge } 983a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final int code = key.mCode; 984a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (key.hasEmbeddedMoreKey()) { 985a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final int embeddedCode = key.mMoreKeys[0].mCode; 9863708787fe91227083d2a1874fa41493d3bc9fe10Tadashi G. Takaoka tracker.onLongPressed(); 987e491be6e8690ffb8359887838fa12d5873346be5Tadashi G. Takaoka invokeCodeInput(embeddedCode); 988a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka invokeReleaseKey(code); 989a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka KeyboardSwitcher.getInstance().hapticAndAudioFeedback(code); 9903708787fe91227083d2a1874fa41493d3bc9fe10Tadashi G. Takaoka return true; 9913708787fe91227083d2a1874fa41493d3bc9fe10Tadashi G. Takaoka } 992a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) { 9933708787fe91227083d2a1874fa41493d3bc9fe10Tadashi G. Takaoka // Long pressing the space key invokes IME switcher dialog. 9943708787fe91227083d2a1874fa41493d3bc9fe10Tadashi G. Takaoka if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { 9956dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka tracker.onLongPressed(); 996a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka invokeReleaseKey(code); 99742e8c64a042476f555da5015558d51f96aaeb7fdTadashi G. Takaoka return true; 9986dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka } 9996dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka } 1000a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka return openMoreKeysPanel(key, tracker); 10016dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka } 10026dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka 1003a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private boolean invokeCustomRequest(final int requestCode) { 1004a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka return mKeyboardActionListener.onCustomRequest(requestCode); 100542e8c64a042476f555da5015558d51f96aaeb7fdTadashi G. Takaoka } 100642e8c64a042476f555da5015558d51f96aaeb7fdTadashi G. Takaoka 1007a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private void invokeCodeInput(final int code) { 1008ac78633be28e8990fc3b3a8de192c80966e746e3Tadashi G. Takaoka mKeyboardActionListener.onCodeInput( 1009a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); 101042e8c64a042476f555da5015558d51f96aaeb7fdTadashi G. Takaoka } 101142e8c64a042476f555da5015558d51f96aaeb7fdTadashi G. Takaoka 1012a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private void invokeReleaseKey(final int code) { 1013a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka mKeyboardActionListener.onReleaseKey(code, false); 10146dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka } 10156dde878d515f7bf5268d16a8fe4921d8821c5ae7Tadashi G. Takaoka 1016a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private boolean openMoreKeysPanel(final Key key, final PointerTracker tracker) { 1017a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final MoreKeysPanel moreKeysPanel = onCreateMoreKeysPanel(key, getContext()); 10189d5601e9013c5ec9a7ac75db16f4a0a8218b02bfTadashi G. Takaoka if (moreKeysPanel == null) { 1019a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka return false; 10205f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 102163c233ab9f50d844be6e52e382c6664475606760Tadashi G. Takaoka 1022547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka final int[] lastCoords = CoordinateUtils.newInstance(); 1023547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka tracker.getLastCoordinates(lastCoords); 1024a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final boolean keyPreviewEnabled = isKeyPreviewPopupEnabled() && !key.noKeyPreview(); 10257ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka // The more keys keyboard is usually horizontally aligned with the center of the parent key. 10267ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka // If showMoreKeysKeyboardAtTouchedPoint is true and the key preview is disabled, the more 10277ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka // keys keyboard is placed at the touch point of the parent key. 10287ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka final int pointX = (mConfigShowMoreKeysKeyboardAtTouchedPoint && !keyPreviewEnabled) 1029547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka ? CoordinateUtils.x(lastCoords) 1030a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka : key.mX + key.mWidth / 2; 10317ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka // The more keys keyboard is usually vertically aligned with the top edge of the parent key 10327ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka // (plus vertical gap). If the key preview is enabled, the more keys keyboard is vertically 10337ecc1081ab9b4e41e4b2aec7877aaaf8df29e611Tadashi G. Takaoka // aligned with the bottom edge of the visible part of the key preview. 103429d5973fd35438a83acf7f44b5d55d5620278ee3Tadashi G. Takaoka // {@code mPreviewVisibleOffset} has been set appropriately in 103529d5973fd35438a83acf7f44b5d55d5620278ee3Tadashi G. Takaoka // {@link KeyboardView#showKeyPreview(PointerTracker)}. 1036a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka final int pointY = key.mY + mKeyPreviewDrawParams.mPreviewVisibleOffset; 1037fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang moreKeysPanel.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener); 1038547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka final int translatedX = moreKeysPanel.translateX(CoordinateUtils.x(lastCoords)); 1039547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka final int translatedY = moreKeysPanel.translateY(CoordinateUtils.y(lastCoords)); 1040e51d164482c7896892d6eccb80f1e1e6fe6d50dbTadashi G. Takaoka tracker.onShowMoreKeysPanel(translatedX, translatedY, moreKeysPanel); 10415f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return true; 10425f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 10435f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 10445f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka public boolean isInSlidingKeyInput() { 1045a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka if (isShowingMoreKeysPanel()) { 104663c233ab9f50d844be6e52e382c6664475606760Tadashi G. Takaoka return true; 10475f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 104820dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return PointerTracker.isAnyInSlidingKeyInput(); 10495f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 10505f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 1051d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka @Override 1052d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka public void onShowMoreKeysPanel(final MoreKeysPanel panel) { 1053d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka if (isShowingMoreKeysPanel()) { 1054d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka onDismissMoreKeysPanel(); 1055d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka } 1056a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka mPreviewPlacerView.addView(panel.getContainerView()); 1057d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mMoreKeysPanel = panel; 1058a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka dimEntireKeyboard(true /* dimmed */); 1059d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka } 1060d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka 1061d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka public boolean isShowingMoreKeysPanel() { 1062a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka return mMoreKeysPanel != null && mMoreKeysPanel.isShowingInParent(); 1063d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka } 1064d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka 1065d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka @Override 1066d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka public void onCancelMoreKeysPanel() { 1067d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka PointerTracker.dismissAllMoreKeysPanels(); 1068d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka } 1069d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka 1070d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka @Override 1071d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka public boolean onDismissMoreKeysPanel() { 1072d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka dimEntireKeyboard(false /* dimmed */); 1073d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka if (isShowingMoreKeysPanel()) { 1074d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView()); 1075d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mMoreKeysPanel = null; 1076d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka return true; 1077d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka } 1078d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka return false; 1079d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka } 1080d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka 10815f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka public int getPointerCount() { 10825f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return mOldPointerCount; 10835f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 10845f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 10855f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka @Override 1086dc2ee7772402633817702e95c2a5b17f6dec03ebalanv public boolean dispatchTouchEvent(MotionEvent event) { 1087dc2ee7772402633817702e95c2a5b17f6dec03ebalanv if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { 1088dc2ee7772402633817702e95c2a5b17f6dec03ebalanv return AccessibleKeyboardViewProxy.getInstance().dispatchTouchEvent(event); 1089dc2ee7772402633817702e95c2a5b17f6dec03ebalanv } 1090dc2ee7772402633817702e95c2a5b17f6dec03ebalanv return super.dispatchTouchEvent(event); 1091dc2ee7772402633817702e95c2a5b17f6dec03ebalanv } 1092dc2ee7772402633817702e95c2a5b17f6dec03ebalanv 1093dc2ee7772402633817702e95c2a5b17f6dec03ebalanv @Override 1094dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public boolean onTouchEvent(final MotionEvent me) { 109546286874f30c4a6ef44646c4e4adf36fe55c74b9Tadashi G. Takaoka if (getKeyboard() == null) { 109646286874f30c4a6ef44646c4e4adf36fe55c74b9Tadashi G. Takaoka return false; 109746286874f30c4a6ef44646c4e4adf36fe55c74b9Tadashi G. Takaoka } 1098c403a46f6d787b79768895272d53d296100677ddTadashi G. Takaoka return mTouchScreenRegulator.onTouchEvent(me); 1099c403a46f6d787b79768895272d53d296100677ddTadashi G. Takaoka } 1100c403a46f6d787b79768895272d53d296100677ddTadashi G. Takaoka 1101c403a46f6d787b79768895272d53d296100677ddTadashi G. Takaoka @Override 1102dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public boolean processMotionEvent(final MotionEvent me) { 1103f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; 11045f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final int action = me.getActionMasked(); 11055f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final int pointerCount = me.getPointerCount(); 11065f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final int oldPointerCount = mOldPointerCount; 11075f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka mOldPointerCount = pointerCount; 11085f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 11095f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // TODO: cleanup this code into a multi-touch to single-touch event converter class? 11105f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // If the device does not have distinct multi-touch support panel, ignore all multi-touch 11115f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // events except a transition from/to single-touch. 1112f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka if (nonDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) { 11135f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return true; 11145f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11155f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 11165f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final long eventTime = me.getEventTime(); 11175f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final int index = me.getActionIndex(); 11185f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka final int id = me.getPointerId(index); 111935580bad6f3da3b204653825bbb6871563e70728Tom Ouyang final int x = (int)me.getX(index); 112035580bad6f3da3b204653825bbb6871563e70728Tom Ouyang final int y = (int)me.getY(index); 112135580bad6f3da3b204653825bbb6871563e70728Tom Ouyang 1122fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka // TODO: This might be moved to the tracker.processMotionEvent() call below. 1123fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka if (ENABLE_USABILITY_STUDY_LOG && action != MotionEvent.ACTION_MOVE) { 1124fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka writeUsabilityStudyLog(me, action, eventTime, index, id, x, y); 1125d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge } 1126fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka // TODO: This should be moved to the tracker.processMotionEvent() call below. 1127fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka // Currently the same "move" event is being logged twice. 1128c166697e3f5ec600089987dbbff0be7f3e308565Ken Wakasa if (ProductionFlag.IS_EXPERIMENTAL) { 1129fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka ResearchLogger.mainKeyboardView_processMotionEvent( 1130fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka me, action, eventTime, index, id, x, y); 113115d4793911fa305e0a58aced925961e948582979satok } 11325f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 1133f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka if (mKeyTimerHandler.isInKeyRepeat()) { 1134e88e1b22c87a075554fb3f10cee492e169570958Tadashi G. Takaoka final PointerTracker tracker = PointerTracker.getPointerTracker(id, this); 11355f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Key repeating timer will be canceled if 2 or more keys are in action, and current 11365f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // event (UP or DOWN) is non-modifier key. 11375f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka if (pointerCount > 1 && !tracker.isModifier()) { 1138f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka mKeyTimerHandler.cancelKeyRepeatTimer(); 11395f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11405f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Up event will pass through. 11415f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11425f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 11435f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // TODO: cleanup this code into a multi-touch to single-touch event converter class? 11445f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Translate mutli-touch event to single-touch events on the device that has no distinct 11455f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // multi-touch panel. 1146f60d09ac3086f308cafcee13ebcb94c562f9e58eTadashi G. Takaoka if (nonDistinctMultitouch) { 11475f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Use only main (id=0) pointer tracker. 1148e88e1b22c87a075554fb3f10cee492e169570958Tadashi G. Takaoka final PointerTracker tracker = PointerTracker.getPointerTracker(0, this); 11495f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka if (pointerCount == 1 && oldPointerCount == 2) { 11505f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Multi-touch to single touch transition. 11515f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Send a down event for the latest pointer if the key is different from the 11525f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // previous key. 1153e22baaadd314c80f835e2e96fb0dfc73838ac2cdTadashi G. Takaoka final Key newKey = tracker.getKeyOn(x, y); 1154e22baaadd314c80f835e2e96fb0dfc73838ac2cdTadashi G. Takaoka if (mOldKey != newKey) { 11550efe174ea43fe576683102effbaef5be27575706Tadashi G. Takaoka tracker.onDownEvent(x, y, eventTime, this); 1156fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka if (action == MotionEvent.ACTION_UP) { 1157906f03121b6c6a795f35dbc24d2eceac0665f35fTadashi G. Takaoka tracker.onUpEvent(x, y, eventTime); 1158fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka } 11595f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11605f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } else if (pointerCount == 2 && oldPointerCount == 1) { 11615f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Single-touch to multi-touch transition. 11625f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka // Send an up event for the last pointer. 1163547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka final int[] lastCoords = CoordinateUtils.newInstance(); 1164547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka mOldKey = tracker.getKeyOn( 1165547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka CoordinateUtils.x(lastCoords), CoordinateUtils.y(lastCoords)); 1166547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka tracker.onUpEvent( 1167547b638194c05f971003edb06c3c6c489a76da5fTadashi G. Takaoka CoordinateUtils.x(lastCoords), CoordinateUtils.y(lastCoords), eventTime); 11685f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } else if (pointerCount == 1 && oldPointerCount == 1) { 11698ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka tracker.processMotionEvent(action, x, y, eventTime, this); 11705f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } else { 11715f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount 11725f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka + " (old " + oldPointerCount + ")"); 11735f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11745f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return true; 11755f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11765f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 11775f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka if (action == MotionEvent.ACTION_MOVE) { 11785f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka for (int i = 0; i < pointerCount; i++) { 1179d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge final int pointerId = me.getPointerId(i); 1180e88e1b22c87a075554fb3f10cee492e169570958Tadashi G. Takaoka final PointerTracker tracker = PointerTracker.getPointerTracker( 1181d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge pointerId, this); 118235580bad6f3da3b204653825bbb6871563e70728Tom Ouyang final int px = (int)me.getX(i); 118335580bad6f3da3b204653825bbb6871563e70728Tom Ouyang final int py = (int)me.getY(i); 118435580bad6f3da3b204653825bbb6871563e70728Tom Ouyang tracker.onMoveEvent(px, py, eventTime, me); 1185d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge if (ENABLE_USABILITY_STUDY_LOG) { 1186fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka writeUsabilityStudyLog(me, action, eventTime, i, pointerId, px, py); 1187d05afa3f4c59641c8fabed034e457cb25f0c57f0Kurt Partridge } 1188c166697e3f5ec600089987dbbff0be7f3e308565Ken Wakasa if (ProductionFlag.IS_EXPERIMENTAL) { 1189fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka ResearchLogger.mainKeyboardView_processMotionEvent( 1190fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka me, action, eventTime, i, pointerId, px, py); 119115d4793911fa305e0a58aced925961e948582979satok } 11925f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11935f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } else { 1194e88e1b22c87a075554fb3f10cee492e169570958Tadashi G. Takaoka final PointerTracker tracker = PointerTracker.getPointerTracker(id, this); 1195e88e1b22c87a075554fb3f10cee492e169570958Tadashi G. Takaoka tracker.processMotionEvent(action, x, y, eventTime, this); 11965f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 11975f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 11985f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return true; 11995f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 12005f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 1201fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka private static void writeUsabilityStudyLog(final MotionEvent me, final int action, 1202fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka final long eventTime, final int index, final int id, final int x, final int y) { 1203fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka final String eventTag; 1204fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka switch (action) { 1205fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka case MotionEvent.ACTION_UP: 1206fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag = "[Up]"; 1207fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka break; 1208fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka case MotionEvent.ACTION_DOWN: 1209fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag = "[Down]"; 1210fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka break; 1211fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka case MotionEvent.ACTION_POINTER_UP: 1212fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag = "[PointerUp]"; 1213fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka break; 1214fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka case MotionEvent.ACTION_POINTER_DOWN: 1215fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag = "[PointerDown]"; 1216fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka break; 1217fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka case MotionEvent.ACTION_MOVE: 1218fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag = "[Move]"; 1219fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka break; 1220fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka default: 1221fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag = "[Action" + action + "]"; 1222fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka break; 1223fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka } 1224fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka final float size = me.getSize(index); 1225fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka final float pressure = me.getPressure(index); 1226fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka UsabilityStudyLogUtils.getInstance().write( 1227fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka eventTag + eventTime + "," + id + "," + x + "," + y + "," + size + "," + pressure); 1228fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka } 1229fca71cfddb7a5062e7a4fb512e1faab401c65cd3Tadashi G. Takaoka 1230375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka public void cancelAllMessages() { 1231375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mKeyTimerHandler.cancelAllMessages(); 1232375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka mDrawingHandler.cancelAllMessages(); 1233375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka } 1234375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka 12355f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka @Override 12365f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka public void closing() { 1237375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka dismissAllKeyPreviews(); 1238375982106bf073971fccd14b2c65ec8e089bb2aeTadashi G. Takaoka cancelAllMessages(); 1239a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka onDismissMoreKeysPanel(); 1240a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka mMoreKeysKeyboardCache.clear(); 12415f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka super.closing(); 12425f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 12435f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 1244586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette /** 1245c6435f92a80c6664870f9d1a4bb2a1c5153ef2c3Tadashi G. Takaoka * Receives hover events from the input framework. 1246586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette * 1247586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette * @param event The motion event to be dispatched. 1248586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette * @return {@code true} if the event was handled by the view, {@code false} 1249586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette * otherwise 1250586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette */ 1251c6435f92a80c6664870f9d1a4bb2a1c5153ef2c3Tadashi G. Takaoka @Override 1252dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public boolean dispatchHoverEvent(final MotionEvent event) { 12535f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { 1254e88e1b22c87a075554fb3f10cee492e169570958Tadashi G. Takaoka final PointerTracker tracker = PointerTracker.getPointerTracker(0, this); 1255586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(event, tracker); 12565f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 12575f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka 1258586a15c3f0d44590a5162e0ab4c3c52511f13f26Alan Viverette // Reflection doesn't support calling superclass methods. 12595f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka return false; 12605f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka } 126122b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka 1262dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void updateShortcutKey(final boolean available) { 12637bd714c086a78e2058543b0971ac92f5a30b2362Tadashi G. Takaoka final Keyboard keyboard = getKeyboard(); 126420dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (keyboard == null) { 126520dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return; 126620dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 1267240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka final Key shortcutKey = keyboard.getKey(Constants.CODE_SHORTCUT); 126820dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (shortcutKey == null) { 126920dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return; 127020dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 12717bd714c086a78e2058543b0971ac92f5a30b2362Tadashi G. Takaoka shortcutKey.setEnabled(available); 12727bd714c086a78e2058543b0971ac92f5a30b2362Tadashi G. Takaoka invalidateKey(shortcutKey); 12735afc3ae2d9df0c2c93f2c66af13b128889ac3b5dTadashi G. Takaoka } 12745afc3ae2d9df0c2c93f2c66af13b128889ac3b5dTadashi G. Takaoka 127573a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka private void updateAltCodeKeyWhileTyping() { 127673a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka final Keyboard keyboard = getKeyboard(); 127720dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (keyboard == null) { 127820dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return; 127920dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 128073a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka for (final Key key : keyboard.mAltCodeKeysWhileTyping) { 128173a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka invalidateKey(key); 128273a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka } 128373a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka } 128473a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka 1285dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged, 1286dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka final boolean needsToDisplayLanguage, final boolean hasMultipleEnabledIMEsOrSubtypes) { 12874112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka mNeedsToDisplayLanguage = needsToDisplayLanguage; 1288fd60b2f97035382b14dce207b3613711982a613eTadashi G. Takaoka mHasMultipleEnabledIMEsOrSubtypes = hasMultipleEnabledIMEsOrSubtypes; 1289fd60b2f97035382b14dce207b3613711982a613eTadashi G. Takaoka final ObjectAnimator animator = mLanguageOnSpacebarFadeoutAnimator; 1290d7c4ba170982ddce5ac12ea92c3c3d8b53d524baTadashi G. Takaoka if (animator == null) { 1291aee5f03d6ebf9cb03b52cbea003556f38745b4feTadashi G. Takaoka mNeedsToDisplayLanguage = false; 12924c0c638a189c1073b1fb6e43fe5fddb6f9932038Tadashi G. Takaoka } else { 1293dabf96896ef4c304c6dad36b307a2a458a58209dTadashi G. Takaoka if (subtypeChanged && needsToDisplayLanguage) { 12944daf32b6c0358f0273a99b622a259ecdf6b44fa4Tom Ouyang setLanguageOnSpacebarAnimAlpha(Constants.Color.ALPHA_OPAQUE); 129531c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka if (animator.isStarted()) { 129631c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka animator.cancel(); 129731c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka } 1298d7c4ba170982ddce5ac12ea92c3c3d8b53d524baTadashi G. Takaoka animator.start(); 1299dabf96896ef4c304c6dad36b307a2a458a58209dTadashi G. Takaoka } else { 130031c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka if (!animator.isStarted()) { 130131c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka mLanguageOnSpacebarAnimAlpha = mLanguageOnSpacebarFinalAlpha; 130231c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka } 1303dabf96896ef4c304c6dad36b307a2a458a58209dTadashi G. Takaoka } 13044c0c638a189c1073b1fb6e43fe5fddb6f9932038Tadashi G. Takaoka } 13054112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka invalidateKey(mSpaceKey); 13064112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 13074112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 1308dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka public void updateAutoCorrectionState(final boolean isAutoCorrection) { 130920dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (!mAutoCorrectionSpacebarLedEnabled) { 131020dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return; 131120dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 13124112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka mAutoCorrectionSpacebarLedOn = isAutoCorrection; 13134112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka invalidateKey(mSpaceKey); 131422b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka } 131522b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka 1316a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka private void dimEntireKeyboard(final boolean dimmed) { 1317f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka final boolean needsRedrawing = mNeedsToDimEntireKeyboard != dimmed; 1318f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka mNeedsToDimEntireKeyboard = dimmed; 1319f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka if (needsRedrawing) { 1320f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka invalidateAllKeys(); 1321f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka } 1322f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka } 1323f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka 1324f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka @Override 1325f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka protected void onDraw(final Canvas canvas) { 1326f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka super.onDraw(canvas); 1327f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka 1328f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka // Overlay a dark rectangle to dim. 1329f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka if (mNeedsToDimEntireKeyboard) { 1330f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka canvas.drawRect(0, 0, getWidth(), getHeight(), mBackgroundDimAlphaPaint); 1331f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka } 1332f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka } 1333f3c4cd45a5df6f90b922ea44db259e53117bb25aTadashi G. Takaoka 133422b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka @Override 1335dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint, 1336dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka final KeyDrawParams params) { 13376bc9186457219daeb3734531a01271b0e4fa37fbTadashi G. Takaoka if (key.altCodeWhileTyping() && key.isEnabled()) { 133873a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha; 133973a46bfeb7a109b49be196e5d679e44c9e66a2e8Tadashi G. Takaoka } 1340240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka if (key.mCode == Constants.CODE_SPACE) { 1341bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka drawSpacebar(key, canvas, paint); 13424112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka // Whether space key needs to show the "..." popup hint for special purposes 1343fd60b2f97035382b14dce207b3613711982a613eTadashi G. Takaoka if (key.isLongPressEnabled() && mHasMultipleEnabledIMEsOrSubtypes) { 1344bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka drawKeyPopupHint(key, canvas, paint, params); 13454112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 1346240871ecafde7834ebb4270cd7758fc904a5f3a7Tadashi G. Takaoka } else if (key.mCode == Constants.CODE_LANGUAGE_SWITCH) { 134781d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka super.onDrawKeyTopVisuals(key, canvas, paint, params); 1348fd60b2f97035382b14dce207b3613711982a613eTadashi G. Takaoka drawKeyPopupHint(key, canvas, paint, params); 1349b19a6b9fc55910bd241bee3b312169a818cb721dTadashi G. Takaoka } else { 1350b19a6b9fc55910bd241bee3b312169a818cb721dTadashi G. Takaoka super.onDrawKeyTopVisuals(key, canvas, paint, params); 135122b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka } 135222b48de11ce6f31a0edf90e1308073e67a7a2adbTadashi G. Takaoka } 13534112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 1354dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) { 1355bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka paint.setTextScaleX(1.0f); 1356bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka final float textWidth = getLabelWidth(text, paint); 135720dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (textWidth < width) { 135820dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return true; 135920dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 1360bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka 1361bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka final float scaleX = width / textWidth; 136220dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (scaleX < MINIMUM_XSCALE_OF_LANGUAGE_NAME) { 136320dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return false; 136420dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka } 1365bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka 1366bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka paint.setTextScaleX(scaleX); 1367bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka return getLabelWidth(text, paint) < width; 1368bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka } 1369bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka 1370bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka // Layout language name on spacebar. 1371dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka private String layoutLanguageOnSpacebar(final Paint paint, final InputMethodSubtype subtype, 1372bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka final int width) { 1373bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka // Choose appropriate language name to fit into the width. 13744b3cae9b0cbd5bf30a1c8da383ff247f9c2afc5aTadashi G. Takaoka final String fullText = getFullDisplayName(subtype); 137520dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (fitsTextIntoWidth(width, fullText, paint)) { 137620dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return fullText; 1377bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka } 1378bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka 137920dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka final String middleText = getMiddleDisplayName(subtype); 138020dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (fitsTextIntoWidth(width, middleText, paint)) { 138120dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return middleText; 13824112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 13834112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 138420dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka final String shortText = getShortDisplayName(subtype); 138520dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka if (fitsTextIntoWidth(width, shortText, paint)) { 138620dd1bc090abdd3e88855fe54b1865949aa1168dTadashi G. Takaoka return shortText; 13874112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 13884112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 1389bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka return ""; 13904112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 13914112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 1392dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka private void drawSpacebar(final Key key, final Canvas canvas, final Paint paint) { 1393bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka final int width = key.mWidth; 1394b19a6b9fc55910bd241bee3b312169a818cb721dTadashi G. Takaoka final int height = key.mHeight; 13954112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 1396f6972561fcb45310f18230ce217f0c6bb57e7eeeTadashi G. Takaoka // If input language are explicitly selected. 1397bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka if (mNeedsToDisplayLanguage) { 1398bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka paint.setTextAlign(Align.CENTER); 1399bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka paint.setTypeface(Typeface.DEFAULT); 1400bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka paint.setTextSize(mSpacebarTextSize); 1401bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka final InputMethodSubtype subtype = getKeyboard().mId.mSubtype; 1402bd2ca9c0214ea80fa860f4a9d118f866e16b03caTadashi G. Takaoka final String language = layoutLanguageOnSpacebar(paint, subtype, width); 14034112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka // Draw language text with shadow 14044112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final float descent = paint.descent(); 14054112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final float textHeight = -paint.ascent() + descent; 1406b19a6b9fc55910bd241bee3b312169a818cb721dTadashi G. Takaoka final float baseline = height / 2 + textHeight / 2; 1407aee5f03d6ebf9cb03b52cbea003556f38745b4feTadashi G. Takaoka paint.setColor(mSpacebarTextShadowColor); 140831c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka paint.setAlpha(mLanguageOnSpacebarAnimAlpha); 14094112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka canvas.drawText(language, width / 2, baseline - descent - 1, paint); 1410aee5f03d6ebf9cb03b52cbea003556f38745b4feTadashi G. Takaoka paint.setColor(mSpacebarTextColor); 141131c94cea82f1788e3a04f2a1e012945f35497f0aTadashi G. Takaoka paint.setAlpha(mLanguageOnSpacebarAnimAlpha); 14124112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka canvas.drawText(language, width / 2, baseline - descent, paint); 14134112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 14144112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka 14154112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka // Draw the spacebar icon at the bottom 1416bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka if (mAutoCorrectionSpacebarLedOn) { 14174112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final int iconWidth = width * SPACE_LED_LENGTH_PERCENT / 100; 14184112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final int iconHeight = mAutoCorrectionSpacebarLedIcon.getIntrinsicHeight(); 14194112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka int x = (width - iconWidth) / 2; 14204112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka int y = height - iconHeight; 1421bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka drawIcon(canvas, mAutoCorrectionSpacebarLedIcon, x, y, iconWidth, iconHeight); 14224112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } else if (mSpaceIcon != null) { 14234112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final int iconWidth = mSpaceIcon.getIntrinsicWidth(); 14244112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka final int iconHeight = mSpaceIcon.getIntrinsicHeight(); 14254112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka int x = (width - iconWidth) / 2; 14264112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka int y = height - iconHeight; 1427bd93eddb52816acedd5242864e467781d4adfd71Tadashi G. Takaoka drawIcon(canvas, mSpaceIcon, x, y, iconWidth, iconHeight); 14284112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 14294112dc05002d7a880e558418639cf25c4bd02a5aTadashi G. Takaoka } 143027b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka 143127b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka // InputMethodSubtype's display name for spacebar text in its locale. 143227b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka // isAdditionalSubtype (T=true, F=false) 143376d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // locale layout | Short Middle Full 143476d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // ------ ------- - ---- --------- ---------------------- 143576d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // en_US qwerty F En English English (US) exception 143676d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // en_GB qwerty F En English English (UK) exception 143776d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // es_US spanish F Es Español Español (EE.UU.) exception 143876d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // fr azerty F Fr Français Français 143976d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // fr_CA qwerty F Fr Français Français (Canada) 144076d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // de qwertz F De Deutsch Deutsch 144176d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // zz qwerty F QWERTY QWERTY 144276d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // fr qwertz T Fr Français Français (QWERTZ) 144376d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // de qwerty T De Deutsch Deutsch (QWERTY) 144476d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // en_US azerty T En English English (US) (AZERTY) 144576d4ffeebfd084913a8c1b7433dff48f5b2063dfTadashi G. Takaoka // zz azerty T AZERTY AZERTY 144627b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka 144727b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka // Get InputMethodSubtype's full display name in its locale. 14484b3cae9b0cbd5bf30a1c8da383ff247f9c2afc5aTadashi G. Takaoka static String getFullDisplayName(final InputMethodSubtype subtype) { 144927b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka if (SubtypeLocale.isNoLanguage(subtype)) { 145027b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype); 145127b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka } 145227b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka 14534b3cae9b0cbd5bf30a1c8da383ff247f9c2afc5aTadashi G. Takaoka return SubtypeLocale.getSubtypeDisplayName(subtype); 145427b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka } 145527b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka 145627b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka // Get InputMethodSubtype's short display name in its locale. 1457dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka static String getShortDisplayName(final InputMethodSubtype subtype) { 145827b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka if (SubtypeLocale.isNoLanguage(subtype)) { 145927b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka return ""; 146027b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka } 146127b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka final Locale locale = SubtypeLocale.getSubtypeLocale(subtype); 146227b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka return StringUtils.toTitleCase(locale.getLanguage(), locale); 146327b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka } 146427b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka 146527b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka // Get InputMethodSubtype's middle display name in its locale. 1466dc34da218a22489d92d1015e9e5dac8d951b89f4Tadashi G. Takaoka static String getMiddleDisplayName(final InputMethodSubtype subtype) { 146727b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka if (SubtypeLocale.isNoLanguage(subtype)) { 146827b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype); 146927b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka } 147027b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka final Locale locale = SubtypeLocale.getSubtypeLocale(subtype); 147127b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); 147227b42ced86e1c85de3d59d91a9e5c577fa552569Tadashi G. Takaoka } 14735f6816fa8bf259f0340a3d12c551d1532f647d66Tadashi G. Takaoka} 1474