2011-09-02 08:49:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard;
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class MoreKeysDetector extends KeyDetector {
|
2011-09-02 08:49:06 +00:00
|
|
|
private final int mSlideAllowanceSquare;
|
|
|
|
private final int mSlideAllowanceSquareTop;
|
|
|
|
|
|
|
|
public MoreKeysDetector(float slideAllowance) {
|
2014-02-14 02:40:00 +00:00
|
|
|
super();
|
2011-09-02 08:49:06 +00:00
|
|
|
mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance);
|
|
|
|
// Top slide allowance is slightly longer (sqrt(2) times) than other edges.
|
|
|
|
mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-13 08:09:16 +00:00
|
|
|
public boolean alwaysAllowsKeySelectionByDraggingFinger() {
|
2011-09-02 08:49:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-15 10:44:43 +00:00
|
|
|
@Override
|
2014-02-19 04:52:28 +00:00
|
|
|
public Key detectHitKey(final int x, final int y) {
|
|
|
|
final Keyboard keyboard = getKeyboard();
|
|
|
|
if (keyboard == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-03-15 10:44:43 +00:00
|
|
|
final int touchX = getTouchX(x);
|
|
|
|
final int touchY = getTouchY(y);
|
|
|
|
|
|
|
|
Key nearestKey = null;
|
|
|
|
int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
|
2014-04-21 21:41:57 +00:00
|
|
|
for (final Key key : keyboard.getSortedKeys()) {
|
2012-03-15 10:44:43 +00:00
|
|
|
final int dist = key.squaredDistanceToEdge(touchX, touchY);
|
|
|
|
if (dist < nearestDist) {
|
|
|
|
nearestKey = key;
|
|
|
|
nearestDist = dist;
|
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
}
|
|
|
|
return nearestKey;
|
2011-09-02 08:49:06 +00:00
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
}
|