Remove swipe gesture

Bug: 4971680
Change-Id: Ifff27f3bd3dd26417bfcb7072aaba074025b1bb7
main
Tadashi G. Takaoka 2011-07-07 23:14:51 -07:00
parent 48f989dee5
commit c71854a661
10 changed files with 50 additions and 416 deletions

View File

@ -25,7 +25,6 @@
<bool name="config_enable_show_recorrection_option">false</bool>
<bool name="config_enable_quick_fixes_option">false</bool>
<bool name="config_enable_bigram_suggestions_option">false</bool>
<bool name="config_swipe_down_dismiss_keyboard_enabled">false</bool>
<bool name="config_sliding_key_input_enabled">false</bool>
<bool name="config_digit_popup_characters_enabled">false</bool>
<!-- Whether or not Popup on key press is enabled by default -->

View File

@ -25,7 +25,6 @@
<bool name="config_enable_show_recorrection_option">false</bool>
<bool name="config_enable_quick_fixes_option">false</bool>
<bool name="config_enable_bigram_suggestions_option">false</bool>
<bool name="config_swipe_down_dismiss_keyboard_enabled">false</bool>
<bool name="config_sliding_key_input_enabled">false</bool>
<bool name="config_digit_popup_characters_enabled">false</bool>
<!-- Whether or not Popup on key press is enabled by default -->

View File

@ -19,7 +19,6 @@
-->
<resources>
<bool name="config_swipeDisambiguation">true</bool>
<bool name="config_enable_show_settings_key_option">true</bool>
<bool name="config_enable_show_voice_key_option">true</bool>
<bool name="config_enable_show_popup_on_keypress_option">true</bool>
@ -27,7 +26,6 @@
<bool name="config_enable_quick_fixes_option">true</bool>
<bool name="config_enable_bigram_suggestions_option">true</bool>
<bool name="config_enable_usability_study_mode_option">false</bool>
<bool name="config_swipe_down_dismiss_keyboard_enabled">true</bool>
<bool name="config_sliding_key_input_enabled">true</bool>
<bool name="config_digit_popup_characters_enabled">true</bool>
<!-- Whether or not Popup on key press is enabled by default -->

View File

@ -70,9 +70,4 @@ public interface KeyboardActionListener {
* Called when user released a finger outside any key.
*/
public void onCancelInput();
/**
* Called when the user quickly moves the finger from up to down.
*/
public void onSwipeDown();
}

View File

@ -35,7 +35,6 @@ import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.keyboard.internal.SwipeTracker;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@ -82,11 +81,8 @@ public class LatinKeyboardBaseView extends KeyboardView {
protected KeyDetector mKeyDetector;
// Swipe gesture detector
// To detect double tap.
protected GestureDetector mGestureDetector;
private final SwipeTracker mSwipeTracker = new SwipeTracker();
private final int mSwipeThreshold;
private final boolean mDisambiguateSwipe;
private final KeyTimerHandler mKeyTimerHandler = new KeyTimerHandler(this);
@ -172,6 +168,52 @@ public class LatinKeyboardBaseView extends KeyboardView {
}
}
private class DoubleTapListener extends GestureDetector.SimpleOnGestureListener {
private boolean mProcessingShiftDoubleTapEvent = false;
@Override
public boolean onDoubleTap(MotionEvent firstDown) {
final Keyboard keyboard = getKeyboard();
if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
&& ((LatinKeyboard) keyboard).isAlphaKeyboard()) {
final int pointerIndex = firstDown.getActionIndex();
final int id = firstDown.getPointerId(pointerIndex);
final PointerTracker tracker = getPointerTracker(id);
// If the first down event is on shift key.
if (tracker.isOnShiftKey((int) firstDown.getX(), (int) firstDown.getY())) {
mProcessingShiftDoubleTapEvent = true;
return true;
}
}
mProcessingShiftDoubleTapEvent = false;
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent secondTap) {
if (mProcessingShiftDoubleTapEvent
&& secondTap.getAction() == MotionEvent.ACTION_DOWN) {
final MotionEvent secondDown = secondTap;
final int pointerIndex = secondDown.getActionIndex();
final int id = secondDown.getPointerId(pointerIndex);
final PointerTracker tracker = getPointerTracker(id);
// If the second down event is also on shift key.
if (tracker.isOnShiftKey((int) secondDown.getX(), (int) secondDown.getY())) {
// Detected a double tap on shift key. If we are in the ignoring double tap
// mode, it means we have already turned off caps lock in
// {@link KeyboardSwitcher#onReleaseShift} .
final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap();
if (!ignoringDoubleTap)
onDoubleTapShiftKey(tracker);
return true;
}
// Otherwise these events should not be handled as double tap.
mProcessingShiftDoubleTapEvent = false;
}
return mProcessingShiftDoubleTapEvent;
}
}
public LatinKeyboardBaseView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle);
}
@ -192,77 +234,10 @@ public class LatinKeyboardBaseView extends KeyboardView {
final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance);
mKeyDetector = new KeyDetector(keyHysteresisDistance);
mSwipeThreshold = (int) (500 * res.getDisplayMetrics().density);
// TODO: Refer to frameworks/base/core/res/res/values/config.xml
mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation);
GestureDetector.SimpleOnGestureListener listener =
new GestureDetector.SimpleOnGestureListener() {
private boolean mProcessingShiftDoubleTapEvent = false;
@Override
public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX,
float velocityY) {
final float absX = Math.abs(velocityX);
final float absY = Math.abs(velocityY);
float deltaY = me2.getY() - me1.getY();
int travelY = getHeight() / 2; // Half the keyboard height
mSwipeTracker.computeCurrentVelocity(1000);
final float endingVelocityY = mSwipeTracker.getYVelocity();
if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
if (mDisambiguateSwipe && endingVelocityY >= velocityY / 4) {
onSwipeDown();
return true;
}
}
return false;
}
@Override
public boolean onDoubleTap(MotionEvent firstDown) {
final Keyboard keyboard = getKeyboard();
if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
&& ((LatinKeyboard) keyboard).isAlphaKeyboard()) {
final int pointerIndex = firstDown.getActionIndex();
final int id = firstDown.getPointerId(pointerIndex);
final PointerTracker tracker = getPointerTracker(id);
// If the first down event is on shift key.
if (tracker.isOnShiftKey((int)firstDown.getX(), (int)firstDown.getY())) {
mProcessingShiftDoubleTapEvent = true;
return true;
}
}
mProcessingShiftDoubleTapEvent = false;
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent secondTap) {
if (mProcessingShiftDoubleTapEvent
&& secondTap.getAction() == MotionEvent.ACTION_DOWN) {
final MotionEvent secondDown = secondTap;
final int pointerIndex = secondDown.getActionIndex();
final int id = secondDown.getPointerId(pointerIndex);
final PointerTracker tracker = getPointerTracker(id);
// If the second down event is also on shift key.
if (tracker.isOnShiftKey((int)secondDown.getX(), (int)secondDown.getY())) {
// Detected a double tap on shift key. If we are in the ignoring double tap
// mode, it means we have already turned off caps lock in
// {@link KeyboardSwitcher#onReleaseShift} .
final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap();
if (!ignoringDoubleTap)
onDoubleTapShiftKey(tracker);
return true;
}
// Otherwise these events should not be handled as double tap.
mProcessingShiftDoubleTapEvent = false;
}
return mProcessingShiftDoubleTapEvent;
}
};
final boolean ignoreMultitouch = true;
mGestureDetector = new GestureDetector(getContext(), listener, null, ignoreMultitouch);
mGestureDetector = new GestureDetector(
getContext(), new DoubleTapListener(), null, ignoreMultitouch);
mGestureDetector.setIsLongpressEnabled(false);
mHasDistinctMultitouch = context.getPackageManager()
@ -421,10 +396,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
dismissMiniKeyboard();
}
@Override
public void onSwipeDown() {
// Nothing to do.
}
@Override
public void onPress(int primaryCode, boolean withSliding) {
mKeyboardActionListener.onPress(primaryCode, withSliding);
@ -528,9 +499,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
return true;
}
// Track the last few movements to look for spurious swipes.
mSwipeTracker.addMovement(me);
// Gesture detector must be enabled only when mini-keyboard is not on the screen.
if (mPopupMiniKeyboardPanel == null && mGestureDetector != null
&& mGestureDetector.onTouchEvent(me)) {
@ -618,10 +586,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
return true;
}
protected void onSwipeDown() {
mKeyboardActionListener.onSwipeDown();
}
@Override
public void closing() {
super.closing();

View File

@ -106,8 +106,6 @@ public class PointerTracker {
public void onTextInput(CharSequence text) {}
@Override
public void onCancelInput() {}
@Override
public void onSwipeDown() {}
};
public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler,

View File

@ -1,157 +0,0 @@
/*
* Copyright (C) 2010 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.
*/
package com.android.inputmethod.keyboard.internal;
import android.view.MotionEvent;
public class SwipeTracker {
private static final int NUM_PAST = 4;
private static final int LONGEST_PAST_TIME = 200;
final EventRingBuffer mBuffer = new EventRingBuffer(NUM_PAST);
private float mYVelocity;
private float mXVelocity;
public void addMovement(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mBuffer.clear();
return;
}
long time = ev.getEventTime();
final int count = ev.getHistorySize();
for (int i = 0; i < count; i++) {
addPoint(ev.getHistoricalX(i), ev.getHistoricalY(i), ev.getHistoricalEventTime(i));
}
addPoint(ev.getX(), ev.getY(), time);
}
private void addPoint(float x, float y, long time) {
final EventRingBuffer buffer = mBuffer;
while (buffer.size() > 0) {
long lastT = buffer.getTime(0);
if (lastT >= time - LONGEST_PAST_TIME)
break;
buffer.dropOldest();
}
buffer.add(x, y, time);
}
public void computeCurrentVelocity(int units) {
computeCurrentVelocity(units, Float.MAX_VALUE);
}
public void computeCurrentVelocity(int units, float maxVelocity) {
final EventRingBuffer buffer = mBuffer;
final float oldestX = buffer.getX(0);
final float oldestY = buffer.getY(0);
final long oldestTime = buffer.getTime(0);
float accumX = 0;
float accumY = 0;
final int count = buffer.size();
for (int pos = 1; pos < count; pos++) {
final int dur = (int)(buffer.getTime(pos) - oldestTime);
if (dur == 0) continue;
float dist = buffer.getX(pos) - oldestX;
float vel = (dist / dur) * units; // pixels/frame.
if (accumX == 0) accumX = vel;
else accumX = (accumX + vel) * .5f;
dist = buffer.getY(pos) - oldestY;
vel = (dist / dur) * units; // pixels/frame.
if (accumY == 0) accumY = vel;
else accumY = (accumY + vel) * .5f;
}
mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity)
: Math.min(accumX, maxVelocity);
mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity)
: Math.min(accumY, maxVelocity);
}
public float getXVelocity() {
return mXVelocity;
}
public float getYVelocity() {
return mYVelocity;
}
public static class EventRingBuffer {
private final int bufSize;
private final float xBuf[];
private final float yBuf[];
private final long timeBuf[];
private int top; // points new event
private int end; // points oldest event
private int count; // the number of valid data
public EventRingBuffer(int max) {
this.bufSize = max;
xBuf = new float[max];
yBuf = new float[max];
timeBuf = new long[max];
clear();
}
public void clear() {
top = end = count = 0;
}
public int size() {
return count;
}
// Position 0 points oldest event
private int index(int pos) {
return (end + pos) % bufSize;
}
private int advance(int index) {
return (index + 1) % bufSize;
}
public void add(float x, float y, long time) {
xBuf[top] = x;
yBuf[top] = y;
timeBuf[top] = time;
top = advance(top);
if (count < bufSize) {
count++;
} else {
end = advance(end);
}
}
public float getX(int pos) {
return xBuf[index(pos)];
}
public float getY(int pos) {
return yBuf[index(pos)];
}
public long getTime(int pos) {
return timeBuf[index(pos)];
}
public void dropOldest() {
count--;
end = advance(end);
}
}
}

View File

@ -1892,12 +1892,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// subtype changes.
if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED)
onRefreshKeyboard();
}
@Override
public void onSwipeDown() {
if (mSettingsValues.mSwipeDownDismissKeyboardEnabled)
handleClose();
}
@Override

View File

@ -90,7 +90,6 @@ public class Settings extends PreferenceActivity
public static class Values {
// From resources:
public final boolean mSwipeDownDismissKeyboardEnabled;
public final int mDelayBeforeFadeoutLanguageOnSpacebar;
public final int mDelayUpdateSuggestions;
public final int mDelayUpdateOldSuggestions;
@ -131,8 +130,6 @@ public class Settings extends PreferenceActivity
}
// Get the resources
mSwipeDownDismissKeyboardEnabled = res.getBoolean(
R.bool.config_swipe_down_dismiss_keyboard_enabled);
mDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
R.integer.config_delay_before_fadeout_language_on_spacebar);
mDelayUpdateSuggestions =
@ -539,6 +536,7 @@ public class Settings extends PreferenceActivity
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case VOICE_INPUT_CONFIRM_DIALOG:

View File

@ -1,154 +0,0 @@
/*
* Copyright (C) 2010 Google Inc.
*
* 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.
*/
package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.internal.SwipeTracker.EventRingBuffer;
import android.test.AndroidTestCase;
public class EventRingBufferTests extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
private static float X_BASE = 1000f;
private static float Y_BASE = 2000f;
private static long TIME_BASE = 3000l;
private static float x(int id) {
return X_BASE + id;
}
private static float y(int id) {
return Y_BASE + id;
}
private static long time(int id) {
return TIME_BASE + id;
}
private static void addEvent(EventRingBuffer buf, int id) {
buf.add(x(id), y(id), time(id));
}
private static void assertEventSize(EventRingBuffer buf, int size) {
assertEquals(size, buf.size());
}
private static void assertEvent(EventRingBuffer buf, int pos, int id) {
assertEquals(x(id), buf.getX(pos), 0f);
assertEquals(y(id), buf.getY(pos), 0f);
assertEquals(time(id), buf.getTime(pos));
}
public void testClearBuffer() {
EventRingBuffer buf = new EventRingBuffer(4);
assertEventSize(buf, 0);
addEvent(buf, 0);
addEvent(buf, 1);
addEvent(buf, 2);
addEvent(buf, 3);
addEvent(buf, 4);
assertEventSize(buf, 4);
buf.clear();
assertEventSize(buf, 0);
}
public void testRingBuffer() {
EventRingBuffer buf = new EventRingBuffer(4);
assertEventSize(buf, 0); // [0]
addEvent(buf, 0);
assertEventSize(buf, 1); // [1] 0
assertEvent(buf, 0, 0);
addEvent(buf, 1);
addEvent(buf, 2);
assertEventSize(buf, 3); // [3] 2 1 0
assertEvent(buf, 0, 0);
assertEvent(buf, 1, 1);
assertEvent(buf, 2, 2);
addEvent(buf, 3);
assertEventSize(buf, 4); // [4] 3 2 1 0
assertEvent(buf, 0, 0);
assertEvent(buf, 1, 1);
assertEvent(buf, 2, 2);
assertEvent(buf, 3, 3);
addEvent(buf, 4);
addEvent(buf, 5);
assertEventSize(buf, 4); // [4] 5 4|3 2(1 0)
assertEvent(buf, 0, 2);
assertEvent(buf, 1, 3);
assertEvent(buf, 2, 4);
assertEvent(buf, 3, 5);
addEvent(buf, 6);
addEvent(buf, 7);
addEvent(buf, 8);
assertEventSize(buf, 4); // [4] 8 7 6 5|(4 3 2)1|0
assertEvent(buf, 0, 5);
assertEvent(buf, 1, 6);
assertEvent(buf, 2, 7);
assertEvent(buf, 3, 8);
}
public void testDropOldest() {
EventRingBuffer buf = new EventRingBuffer(4);
addEvent(buf, 0);
assertEventSize(buf, 1); // [1] 0
assertEvent(buf, 0, 0);
buf.dropOldest();
assertEventSize(buf, 0); // [0] (0)
addEvent(buf, 1);
addEvent(buf, 2);
addEvent(buf, 3);
addEvent(buf, 4);
assertEventSize(buf, 4); // [4] 4|3 2 1(0)
assertEvent(buf, 0, 1);
buf.dropOldest();
assertEventSize(buf, 3); // [3] 4|3 2(1)0
assertEvent(buf, 0, 2);
buf.dropOldest();
assertEventSize(buf, 2); // [2] 4|3(2)10
assertEvent(buf, 0, 3);
buf.dropOldest();
assertEventSize(buf, 1); // [1] 4|(3)210
assertEvent(buf, 0, 4);
buf.dropOldest();
assertEventSize(buf, 0); // [0] (4)|3210
}
}