Extract sudden jumping touch event hack into separate class

Bug: 5182291
Change-Id: I6a88ed4df3ec98e31ea4966d82da56f7fca342ac
main
Tadashi G. Takaoka 2011-08-23 15:57:51 +09:00
parent 6dde878d51
commit c403a46f6d
6 changed files with 80 additions and 36 deletions

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources>
<string-array name="sudden_jumping_touch_event_device_list">
<!-- Nexus One -->
<item>passion</item>
<!-- Droid -->
<item>sholes</item>
</string-array>
</resources>

View File

@ -61,7 +61,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
private View mCurrentInputView; private View mCurrentInputView;
private LatinKeyboardView mKeyboardView; private LatinKeyboardBaseView mKeyboardView;
private LatinIME mInputMethodService; private LatinIME mInputMethodService;
private String mPackageName; private String mPackageName;
private Resources mResources; private Resources mResources;
@ -745,7 +745,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
public LatinKeyboardView getKeyboardView() { public LatinKeyboardBaseView getKeyboardView() {
return mKeyboardView; return mKeyboardView;
} }
@ -781,7 +781,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view); mKeyboardView = (LatinKeyboardBaseView) mCurrentInputView.findViewById(R.id.keyboard_view);
mKeyboardView.setKeyboardActionListener(mInputMethodService); mKeyboardView.setKeyboardActionListener(mInputMethodService);
// This always needs to be set since the accessibility state can // This always needs to be set since the accessibility state can
@ -819,7 +819,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
final LatinKeyboard keyboard = getLatinKeyboard(); final LatinKeyboard keyboard = getLatinKeyboard();
if (keyboard != null && keyboard.needsAutoCorrectionSpacebarLed()) { if (keyboard != null && keyboard.needsAutoCorrectionSpacebarLed()) {
final Key invalidatedKey = keyboard.onAutoCorrectionStateChanged(isAutoCorrection); final Key invalidatedKey = keyboard.onAutoCorrectionStateChanged(isAutoCorrection);
final LatinKeyboardView keyboardView = getKeyboardView(); final LatinKeyboardBaseView keyboardView = getKeyboardView();
if (keyboardView != null) if (keyboardView != null)
keyboardView.invalidateKey(invalidatedKey); keyboardView.invalidateKey(invalidatedKey);
} }

View File

@ -154,7 +154,7 @@ public class LatinKeyboard extends Keyboard {
return newColor; return newColor;
} }
public void updateShortcutKey(boolean available, LatinKeyboardView view) { public void updateShortcutKey(boolean available, LatinKeyboardBaseView view) {
if (mShortcutKey == null) if (mShortcutKey == null)
return; return;
mShortcutKey.setEnabled(available); mShortcutKey.setEnabled(available);

View File

@ -53,11 +53,14 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#KeyboardView_verticalCorrection * @attr ref R.styleable#KeyboardView_verticalCorrection
* @attr ref R.styleable#KeyboardView_popupLayout * @attr ref R.styleable#KeyboardView_popupLayout
*/ */
public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler { public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler,
SuddenJumpingTouchEventHandler.ProcessMotionEvent {
private static final String TAG = LatinKeyboardBaseView.class.getSimpleName(); private static final String TAG = LatinKeyboardBaseView.class.getSimpleName();
private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true; private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true;
private final SuddenJumpingTouchEventHandler mTouchScreenRegulator;
// Timing constants // Timing constants
private final int mKeyRepeatInterval; private final int mKeyRepeatInterval;
@ -213,6 +216,8 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
public LatinKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) { public LatinKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
mTouchScreenRegulator = new SuddenJumpingTouchEventHandler(getContext(), this);
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
mVerticalCorrection = a.getDimensionPixelOffset( mVerticalCorrection = a.getDimensionPixelOffset(
@ -300,6 +305,7 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection);
mKeyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth); mKeyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth);
PointerTracker.setKeyDetector(mKeyDetector); PointerTracker.setKeyDetector(mKeyDetector);
mTouchScreenRegulator.setKeyboard(keyboard);
mPopupPanelCache.clear(); mPopupPanelCache.clear();
} }
@ -481,6 +487,11 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
@Override @Override
public boolean onTouchEvent(MotionEvent me) { public boolean onTouchEvent(MotionEvent me) {
return mTouchScreenRegulator.onTouchEvent(me);
}
@Override
public boolean processMotionEvent(MotionEvent me) {
final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; final boolean nonDistinctMultitouch = !mHasDistinctMultitouch;
final int action = me.getActionMasked(); final int action = me.getActionMasked();
final int pointerCount = me.getPointerCount(); final int pointerCount = me.getPointerCount();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2011 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
@ -17,19 +17,24 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.os.Build;
import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.R;
// TODO: We should remove this class public class SuddenJumpingTouchEventHandler {
public class LatinKeyboardView extends LatinKeyboardBaseView { private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName();
private static final String TAG = LatinKeyboardView.class.getSimpleName();
private static boolean DEBUG_MODE = LatinImeLogger.sDBG; private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
public interface ProcessMotionEvent {
public boolean processMotionEvent(MotionEvent me);
}
private final ProcessMotionEvent mView;
private final boolean mNeedsSuddenJumpingHack;
/** Whether we've started dropping move events because we found a big jump */ /** Whether we've started dropping move events because we found a big jump */
private boolean mDroppingEvents; private boolean mDroppingEvents;
/** /**
@ -42,17 +47,23 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
private int mLastX; private int mLastX;
private int mLastY; private int mLastY;
public LatinKeyboardView(Context context, AttributeSet attrs) { public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) {
super(context, attrs); mView = view;
final String[] deviceList = context.getResources().getStringArray(
R.array.sudden_jumping_touch_event_device_list);
mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.DEVICE, deviceList);
} }
public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { private static boolean needsSuddenJumpingHack(String deviceName, String[] deviceList) {
super(context, attrs, defStyle); for (String device : deviceList) {
if (device.equalsIgnoreCase(deviceName)) {
return true;
}
}
return false;
} }
@Override
public void setKeyboard(Keyboard newKeyboard) { public void setKeyboard(Keyboard newKeyboard) {
super.setKeyboard(newKeyboard);
// One-seventh of the keyboard width seems like a reasonable threshold // One-seventh of the keyboard width seems like a reasonable threshold
final int jumpThreshold = newKeyboard.mOccupiedWidth / 7; final int jumpThreshold = newKeyboard.mOccupiedWidth / 7;
mJumpThresholdSquare = jumpThreshold * jumpThreshold; mJumpThresholdSquare = jumpThreshold * jumpThreshold;
@ -69,9 +80,8 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
* @return true if the event was consumed, so that it doesn't continue to be handled by * @return true if the event was consumed, so that it doesn't continue to be handled by
* {@link LatinKeyboardBaseView}. * {@link LatinKeyboardBaseView}.
*/ */
private boolean handleSuddenJump(MotionEvent me) { private boolean handleSuddenJumping(MotionEvent me) {
// If device has distinct multi touch panel, there is no need to check sudden jump. if (!mNeedsSuddenJumpingHack)
if (hasDistinctMultitouch())
return false; return false;
final int action = me.getAction(); final int action = me.getAction();
final int x = (int) me.getX(); final int x = (int) me.getX();
@ -107,7 +117,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
me.getEventTime(), me.getEventTime(), me.getEventTime(), me.getEventTime(),
MotionEvent.ACTION_UP, MotionEvent.ACTION_UP,
mLastX, mLastY, me.getMetaState()); mLastX, mLastY, me.getMetaState());
super.onTouchEvent(translated); mView.processMotionEvent(translated);
translated.recycle(); translated.recycle();
} }
result = true; result = true;
@ -123,7 +133,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(), MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(),
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_DOWN,
x, y, me.getMetaState()); x, y, me.getMetaState());
super.onTouchEvent(translated); mView.processMotionEvent(translated);
translated.recycle(); translated.recycle();
mDroppingEvents = false; mDroppingEvents = false;
// Let the up event get processed as well, result = false // Let the up event get processed as well, result = false
@ -136,17 +146,13 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
return result; return result;
} }
@Override
public boolean onTouchEvent(MotionEvent me) { public boolean onTouchEvent(MotionEvent me) {
if (getKeyboard() == null) return true;
// If there was a sudden jump, return without processing the actual motion event. // If there was a sudden jump, return without processing the actual motion event.
if (handleSuddenJump(me)) { if (handleSuddenJumping(me)) {
if (DEBUG_MODE) if (DEBUG_MODE)
Log.w(TAG, "onTouchEvent: ignore sudden jump " + me); Log.w(TAG, "onTouchEvent: ignore sudden jump " + me);
return true; return true;
} }
return mView.processMotionEvent(me);
return super.onTouchEvent(me);
} }
} }

View File

@ -67,7 +67,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardSwitcher.KeyboardLayoutState; import com.android.inputmethod.keyboard.KeyboardSwitcher.KeyboardLayoutState;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboard; import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.keyboard.LatinKeyboardBaseView;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -252,7 +252,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOuterInstance();
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
final LatinKeyboardView inputView = switcher.getKeyboardView(); final LatinKeyboardBaseView inputView = switcher.getKeyboardView();
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_SUGGESTIONS: case MSG_UPDATE_SUGGESTIONS:
latinIme.updateSuggestions(); latinIme.updateSuggestions();
@ -365,7 +365,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOuterInstance();
removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR); removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR); removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView(); final LatinKeyboardBaseView inputView = latinIme.mKeyboardSwitcher.getKeyboardView();
if (inputView != null) { if (inputView != null) {
final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard(); final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard();
// The language is always displayed when the delay is negative. // The language is always displayed when the delay is negative.
@ -656,7 +656,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
final KeyboardSwitcher switcher = mKeyboardSwitcher; final KeyboardSwitcher switcher = mKeyboardSwitcher;
LatinKeyboardView inputView = switcher.getKeyboardView(); LatinKeyboardBaseView inputView = switcher.getKeyboardView();
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onStartInputView: attribute:" + ((attribute == null) ? "none" Log.d(TAG, "onStartInputView: attribute:" + ((attribute == null) ? "none"
@ -1544,7 +1544,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
commitTyped(getCurrentInputConnection()); commitTyped(getCurrentInputConnection());
mVoiceProxy.handleClose(); mVoiceProxy.handleClose();
requestHideSelf(0); requestHideSelf(0);
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) if (inputView != null)
inputView.closing(); inputView.closing();
} }
@ -2116,7 +2116,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mSettingsValues.mVibrateOn) { if (!mSettingsValues.mVibrateOn) {
return; return;
} }
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) { if (inputView != null) {
inputView.performHapticFeedback( inputView.performHapticFeedback(
HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.KEYBOARD_TAP,