SuddenJumpingTouchEventHandler.java revision 240297d0ee186b14e795016e9b1bd168c8d8acf8
1923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project/* 2443c360d0afdbab091994244f045f4756feaf2b4Jean-Baptiste Queru * Copyright (C) 2008 The Android Open Source Project 35a309f57155fb95667c2ccdda730eaf175de8876Tadashi G. Takaoka * 4923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * use this file except in compliance with the License. You may obtain a copy of 6923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * the License at 75a309f57155fb95667c2ccdda730eaf175de8876Tadashi G. Takaoka * 8923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 95a309f57155fb95667c2ccdda730eaf175de8876Tadashi G. Takaoka * 10923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * License for the specific language governing permissions and limitations under 14923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * the License. 15923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project */ 16923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 175a309f57155fb95667c2ccdda730eaf175de8876Tadashi G. Takaokapackage com.android.inputmethod.keyboard; 18923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 19b86905943c0f1cadb2b3df9f2a58e7af84f6b27fsatokimport com.android.inputmethod.deprecated.VoiceProxy; 20faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaokaimport com.android.inputmethod.latin.LatinImeLogger; 219502cc177cc53678c9ddcc01d4d046f69220e13bTadashi G. Takaokaimport com.android.inputmethod.latin.Utils; 224fc510a7890976d9968d73ceacf3983e77f489d2satok 23923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.content.Context; 24923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.graphics.Canvas; 2575c23ced94979a6b3f7c59e95dd46385e9702e2dKen Wakasaimport android.text.TextUtils; 26923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.util.AttributeSet; 27faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaokaimport android.util.Log; 28923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.MotionEvent; 29d2a431efa726771dee5c7b90004a0ed670d9a129Tadashi G. Takaoka 30571bdb401f670b92bd7710a12a990cb65a99b7d3Tadashi G. Takaoka// TODO: We should remove this class 315a309f57155fb95667c2ccdda730eaf175de8876Tadashi G. Takaokapublic class LatinKeyboardView extends KeyboardView { 32faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka private static final String TAG = LatinKeyboardView.class.getSimpleName(); 33faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka private static boolean DEBUG_MODE = LatinImeLogger.sDBG; 348eb2e34d5b2def57c9548f88e37e5c9e5a0bea59Amith Yamasani 350fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani /** Whether we've started dropping move events because we found a big jump */ 360fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani private boolean mDroppingEvents; 37e8f45ab56f3e6f358953dede794a63fc5901961dTadashi G. Takaoka /** 38d2a431efa726771dee5c7b90004a0ed670d9a129Tadashi G. Takaoka * Whether multi-touch disambiguation needs to be disabled if a real multi-touch event has 39d2a431efa726771dee5c7b90004a0ed670d9a129Tadashi G. Takaoka * occured 400fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani */ 410fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani private boolean mDisableDisambiguation; 420fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani /** The distance threshold at which we start treating the touch session as a multi-touch */ 430fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani private int mJumpThresholdSquare = Integer.MAX_VALUE; 443e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani /** The y coordinate of the last row */ 453e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani private int mLastRowY; 46e26ef1bccddc942fdaeada3409c8e8ff18a35008Tadashi G. Takaoka private int mLastX; 47e26ef1bccddc942fdaeada3409c8e8ff18a35008Tadashi G. Takaoka private int mLastY; 483f7d75060afb2bb7e74879bcbbdcb9700ec5c2d6Amith Yamasani 49923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project public LatinKeyboardView(Context context, AttributeSet attrs) { 50a1cc4f0a8d9a70ff1515d1ddb1476f6ce630afe2Tadashi G. Takaoka this(context, attrs, 0); 51923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 52923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 53923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { 54923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project super(context, attrs, defStyle); 55923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 56230cd6f7f27300e2688b5e5a22a5361f446b80e7Amith Yamasani 57923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project @Override 58240297d0ee186b14e795016e9b1bd168c8d8acf8Jean Chalard public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { 592c60d6e28ecf7d6f7e97a504ebfa97e286d931edTadashi G. Takaoka LatinKeyboard latinKeyboard = getLatinKeyboard(); 602c60d6e28ecf7d6f7e97a504ebfa97e286d931edTadashi G. Takaoka if (latinKeyboard != null 612c60d6e28ecf7d6f7e97a504ebfa97e286d931edTadashi G. Takaoka && (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard())) { 622c60d6e28ecf7d6f7e97a504ebfa97e286d931edTadashi G. Takaoka // Phone and number keyboard never shows popup preview (except language switch). 63240297d0ee186b14e795016e9b1bd168c8d8acf8Jean Chalard super.setKeyPreviewPopupEnabled(false, delay); 643a2896c80475094f751ef447fc9c97028bfc2265Tadashi G. Takaoka } else { 65240297d0ee186b14e795016e9b1bd168c8d8acf8Jean Chalard super.setKeyPreviewPopupEnabled(previewEnabled, delay); 663a2896c80475094f751ef447fc9c97028bfc2265Tadashi G. Takaoka } 673a2896c80475094f751ef447fc9c97028bfc2265Tadashi G. Takaoka } 683a2896c80475094f751ef447fc9c97028bfc2265Tadashi G. Takaoka 69050c0462dc2ada5a5afecec5b6745693c5066b85Tadashi G. Takaoka @Override 70050c0462dc2ada5a5afecec5b6745693c5066b85Tadashi G. Takaoka public void setKeyboard(Keyboard newKeyboard) { 71ee66e6fa90596e26d9519ac7bb261644377d32c8Tadashi G. Takaoka super.setKeyboard(newKeyboard); 720fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // One-seventh of the keyboard width seems like a reasonable threshold 73ee66e6fa90596e26d9519ac7bb261644377d32c8Tadashi G. Takaoka mJumpThresholdSquare = newKeyboard.getMinWidth() / 7; 740fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mJumpThresholdSquare *= mJumpThresholdSquare; 753e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani // Assuming there are 4 rows, this is the coordinate of the last row 76ee66e6fa90596e26d9519ac7bb261644377d32c8Tadashi G. Takaoka mLastRowY = (newKeyboard.getHeight() * 3) / 4; 770fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 780fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani 79050c0462dc2ada5a5afecec5b6745693c5066b85Tadashi G. Takaoka private LatinKeyboard getLatinKeyboard() { 805a309f57155fb95667c2ccdda730eaf175de8876Tadashi G. Takaoka Keyboard keyboard = getKeyboard(); 810ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa if (keyboard instanceof LatinKeyboard) { 820ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa return (LatinKeyboard)keyboard; 830ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa } else { 840ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa return null; 850ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa } 860ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa } 870ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa 88de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) { 89de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka final LatinKeyboard currentKeyboard = getLatinKeyboard(); 90de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka // We should not set text fade factor to the keyboard which does not display the language on 91de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka // its spacebar. 92de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka if (currentKeyboard != null && currentKeyboard == oldKeyboard) 93de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka currentKeyboard.setSpacebarTextFadeFactor(fadeFactor, this); 94de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka } 95de0c8874a4eb1250e8439d9e4e1badca88316670Tadashi G. Takaoka 960fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani @Override 9704c96ab966e8a58e5cd401362b49509751ce75d9Tadashi G. Takaoka protected boolean onLongPress(Key key, PointerTracker tracker) { 98c4f71668d7b8203dc66f0f04c089a363189eb4ceTadashi G. Takaoka int primaryCode = key.mCode; 99e18bd3e323e7d7448677bb66e8149eea0169c771Tadashi G. Takaoka if (primaryCode == Keyboard.CODE_SETTINGS) { 100e18bd3e323e7d7448677bb66e8149eea0169c771Tadashi G. Takaoka return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS); 1012c60d6e28ecf7d6f7e97a504ebfa97e286d931edTadashi G. Takaoka } else if (primaryCode == '0' && getLatinKeyboard().isPhoneKeyboard()) { 102923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project // Long pressing on 0 in phone number keypad gives you a '+'. 103a1cc4f0a8d9a70ff1515d1ddb1476f6ce630afe2Tadashi G. Takaoka return invokeOnKey('+'); 104923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } else { 10504c96ab966e8a58e5cd401362b49509751ce75d9Tadashi G. Takaoka return super.onLongPress(key, tracker); 106923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 107923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 108923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 109a1cc4f0a8d9a70ff1515d1ddb1476f6ce630afe2Tadashi G. Takaoka private boolean invokeOnKey(int primaryCode) { 1108aa3f5a3ad6095a3355841ce30bce4877319d0a0Tadashi G. Takaoka getOnKeyboardActionListener().onCodeInput(primaryCode, null, 111a96574fdd5e38a237a35b21a2b7c20a29138c648Tadashi G. Takaoka KeyboardActionListener.NOT_A_TOUCH_COORDINATE, 112a96574fdd5e38a237a35b21a2b7c20a29138c648Tadashi G. Takaoka KeyboardActionListener.NOT_A_TOUCH_COORDINATE); 113a1cc4f0a8d9a70ff1515d1ddb1476f6ce630afe2Tadashi G. Takaoka return true; 114a1cc4f0a8d9a70ff1515d1ddb1476f6ce630afe2Tadashi G. Takaoka } 115a1cc4f0a8d9a70ff1515d1ddb1476f6ce630afe2Tadashi G. Takaoka 116979f8690967ff5409fe18f5085858ccdb8e0ccf1satok @Override 117979f8690967ff5409fe18f5085858ccdb8e0ccf1satok protected CharSequence adjustCase(CharSequence label) { 1180ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa LatinKeyboard keyboard = getLatinKeyboard(); 1190ce98cbf98c6409ac18fa341f467703d78352a4cKen Wakasa if (keyboard.isAlphaKeyboard() 120f27364600c742509b48857e6b8f17312033e0dc7Tadashi G. Takaoka && keyboard.isShiftedOrShiftLocked() 12175c23ced94979a6b3f7c59e95dd46385e9702e2dKen Wakasa && !TextUtils.isEmpty(label) && label.length() < 3 122979f8690967ff5409fe18f5085858ccdb8e0ccf1satok && Character.isLowerCase(label.charAt(0))) { 123e26ef1bccddc942fdaeada3409c8e8ff18a35008Tadashi G. Takaoka return label.toString().toUpperCase(); 124979f8690967ff5409fe18f5085858ccdb8e0ccf1satok } 125979f8690967ff5409fe18f5085858ccdb8e0ccf1satok return label; 126979f8690967ff5409fe18f5085858ccdb8e0ccf1satok } 127979f8690967ff5409fe18f5085858ccdb8e0ccf1satok 1280fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani /** 1290fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * This function checks to see if we need to handle any sudden jumps in the pointer location 1300fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * that could be due to a multi-touch being treated as a move by the firmware or hardware. 1310fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * Once a sudden jump is detected, all subsequent move events are discarded 1320fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * until an UP is received.<P> 133e8f45ab56f3e6f358953dede794a63fc5901961dTadashi G. Takaoka * When a sudden jump is detected, an UP event is simulated at the last position and when 1340fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * the sudden moves subside, a DOWN event is simulated for the second key. 1350fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * @param me the motion event 136e8f45ab56f3e6f358953dede794a63fc5901961dTadashi G. Takaoka * @return true if the event was consumed, so that it doesn't continue to be handled by 1370fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani * KeyboardView. 1380fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani */ 1390fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani private boolean handleSuddenJump(MotionEvent me) { 1409a5b592b27158b6fb8b7a89157bb995b182899d8Tadashi G. Takaoka // If device has distinct multi touch panel, there is no need to check sudden jump. 1419a5b592b27158b6fb8b7a89157bb995b182899d8Tadashi G. Takaoka if (hasDistinctMultitouch()) 1429a5b592b27158b6fb8b7a89157bb995b182899d8Tadashi G. Takaoka return false; 1430fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani final int action = me.getAction(); 1440fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani final int x = (int) me.getX(); 1450fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani final int y = (int) me.getY(); 1460fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani boolean result = false; 1470fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani 1480fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Real multi-touch event? Stop looking for sudden jumps 1490fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani if (me.getPointerCount() > 1) { 1500fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mDisableDisambiguation = true; 1510fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 1520fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani if (mDisableDisambiguation) { 1530fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // If UP, reset the multi-touch flag 1540fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani if (action == MotionEvent.ACTION_UP) mDisableDisambiguation = false; 1550fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani return false; 1560fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 1570fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani 1580fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani switch (action) { 1590fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani case MotionEvent.ACTION_DOWN: 1600fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Reset the "session" 1610fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mDroppingEvents = false; 1620fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mDisableDisambiguation = false; 1630fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani break; 1640fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani case MotionEvent.ACTION_MOVE: 1650fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Is this a big jump? 1660fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani final int distanceSquare = (mLastX - x) * (mLastX - x) + (mLastY - y) * (mLastY - y); 1673e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani // Check the distance and also if the move is not entirely within the bottom row 1683e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani // If it's only in the bottom row, it might be an intentional slide gesture 1693e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani // for language switching 1703e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani if (distanceSquare > mJumpThresholdSquare 1713e0c82ec80a69c4adbd60546c3c56c83c43ec7ebAmith Yamasani && (mLastY < mLastRowY || y < mLastRowY)) { 1720fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // If we're not yet dropping events, start dropping and send an UP event 1730fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani if (!mDroppingEvents) { 1740fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mDroppingEvents = true; 1750fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Send an up event 176240297d0ee186b14e795016e9b1bd168c8d8acf8Jean Chalard MotionEvent translated = MotionEvent.obtain( 177240297d0ee186b14e795016e9b1bd168c8d8acf8Jean Chalard me.getEventTime(), me.getEventTime(), 1780fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani MotionEvent.ACTION_UP, 1790fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mLastX, mLastY, me.getMetaState()); 1800fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani super.onTouchEvent(translated); 1810fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani translated.recycle(); 1820fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 1830fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani result = true; 1840fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } else if (mDroppingEvents) { 1850fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // If moves are small and we're already dropping events, continue dropping 1860fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani result = true; 1870fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 1880fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani break; 1890fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani case MotionEvent.ACTION_UP: 1900fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani if (mDroppingEvents) { 1910fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Send a down event first, as we dropped a bunch of sudden jumps and assume that 1920fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // the user is releasing the touch on the second key. 1930fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(), 1940fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani MotionEvent.ACTION_DOWN, 1950fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani x, y, me.getMetaState()); 1960fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani super.onTouchEvent(translated); 1970fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani translated.recycle(); 1980fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mDroppingEvents = false; 1990fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Let the up event get processed as well, result = false 2000fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 2010fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani break; 2020fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 2030fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani // Track the previous coordinate 2040fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mLastX = x; 2050fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani mLastY = y; 2060fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani return result; 2070fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani } 2080fef498a07515bdd5ac1ccfa564776d72fd85a51Amith Yamasani 209358e485b14938fbcb5af5be75aa29f2b73674100Amith Yamasani @Override 210358e485b14938fbcb5af5be75aa29f2b73674100Amith Yamasani public boolean onTouchEvent(MotionEvent me) { 211c5c57b506e97b334a394d23ed73c9597cb55707aTadashi G. Takaoka if (getLatinKeyboard() == null) return true; 212938c178215d38c6f085b32b0994598f9e8bc5ab5Amith Yamasani 213d2a431efa726771dee5c7b90004a0ed670d9a129Tadashi G. Takaoka // If there was a sudden jump, return without processing the actual motion event. 214faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka if (handleSuddenJump(me)) { 215faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka if (DEBUG_MODE) 216faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka Log.w(TAG, "onTouchEvent: ignore sudden jump " + me); 217faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka return true; 218faf437b5078e882b630706cd315c335f204ab861Tadashi G. Takaoka } 219d2a431efa726771dee5c7b90004a0ed670d9a129Tadashi G. Takaoka 220d2a431efa726771dee5c7b90004a0ed670d9a129Tadashi G. Takaoka return super.onTouchEvent(me); 221bad436e93b49116f9005433845bf53126452a839Amith Yamasani } 222bad436e93b49116f9005433845bf53126452a839Amith Yamasani 223923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project @Override 224923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project public void draw(Canvas c) { 2259502cc177cc53678c9ddcc01d4d046f69220e13bTadashi G. Takaoka Utils.GCUtils.getInstance().reset(); 226979f8690967ff5409fe18f5085858ccdb8e0ccf1satok boolean tryGC = true; 2279502cc177cc53678c9ddcc01d4d046f69220e13bTadashi G. Takaoka for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { 228979f8690967ff5409fe18f5085858ccdb8e0ccf1satok try { 229979f8690967ff5409fe18f5085858ccdb8e0ccf1satok super.draw(c); 230979f8690967ff5409fe18f5085858ccdb8e0ccf1satok tryGC = false; 231979f8690967ff5409fe18f5085858ccdb8e0ccf1satok } catch (OutOfMemoryError e) { 2329502cc177cc53678c9ddcc01d4d046f69220e13bTadashi G. Takaoka tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e); 233979f8690967ff5409fe18f5085858ccdb8e0ccf1satok } 234979f8690967ff5409fe18f5085858ccdb8e0ccf1satok } 235923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 2361fb28137f43ae083c773c32440981ac61e83fa5dsatok 2371fb28137f43ae083c773c32440981ac61e83fa5dsatok @Override 2381fb28137f43ae083c773c32440981ac61e83fa5dsatok protected void onAttachedToWindow() { 2391fb28137f43ae083c773c32440981ac61e83fa5dsatok // Token is available from here. 240b86905943c0f1cadb2b3df9f2a58e7af84f6b27fsatok VoiceProxy.getInstance().onAttachedToWindow(); 2411fb28137f43ae083c773c32440981ac61e83fa5dsatok } 242923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project} 243