parent
23bf5e530a
commit
391a7ce6d8
|
@ -248,27 +248,29 @@ public class Key {
|
|||
mOn = !mOn;
|
||||
}
|
||||
|
||||
public boolean isInside(int x, int y) {
|
||||
return mKeyboard.isInside(this, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if a point falls inside this key.
|
||||
* Detects if a point falls on this key.
|
||||
* @param x the x-coordinate of the point
|
||||
* @param y the y-coordinate of the point
|
||||
* @return whether or not the point falls inside the key. If the key is attached to an
|
||||
* edge, it will assume that all points between the key and the edge are considered to be
|
||||
* inside the key.
|
||||
* @return whether or not the point falls on the key. If the key is attached to an edge, it will
|
||||
* assume that all points between the key and the edge are considered to be on the key.
|
||||
*/
|
||||
public boolean isInside(int x, int y) {
|
||||
boolean leftEdge = (mEdgeFlags & Keyboard.EDGE_LEFT) > 0;
|
||||
boolean rightEdge = (mEdgeFlags & Keyboard.EDGE_RIGHT) > 0;
|
||||
boolean topEdge = (mEdgeFlags & Keyboard.EDGE_TOP) > 0;
|
||||
boolean bottomEdge = (mEdgeFlags & Keyboard.EDGE_BOTTOM) > 0;
|
||||
if ((x >= this.mX || (leftEdge && x <= this.mX + this.mWidth))
|
||||
&& (x < this.mX + this.mWidth || (rightEdge && x >= this.mX))
|
||||
&& (y >= this.mY || (topEdge && y <= this.mY + this.mHeight))
|
||||
&& (y < this.mY + this.mHeight || (bottomEdge && y >= this.mY))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
public boolean isOnKey(int x, int y) {
|
||||
final int flags = mEdgeFlags;
|
||||
final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0;
|
||||
final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0;
|
||||
final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0;
|
||||
final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0;
|
||||
final int left = this.mX;
|
||||
final int right = left + this.mWidth;
|
||||
final int top = this.mY;
|
||||
final int bottom = top + this.mHeight;
|
||||
return (x >= left || leftEdge) && (x < right || rightEdge)
|
||||
&& (y >= top || topEdge) && (y < bottom || bottomEdge);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -409,6 +409,10 @@ public class Keyboard {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isInside(Key key, int x, int y) {
|
||||
return key.isOnKey(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the indices of the keys that are closest to the given point.
|
||||
* @param x the x-coordinate of the point
|
||||
|
|
|
@ -1,42 +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.keyboard;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.XmlResourceParser;
|
||||
|
||||
// TODO: We should remove this class
|
||||
public class LatinKey extends Key {
|
||||
public LatinKey(Resources res, Row parent, int x, int y,
|
||||
XmlResourceParser parser, KeyStyles keyStyles) {
|
||||
super(res, parent, x, y, parser, keyStyles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriding this method so that we can reduce the target area for certain keys.
|
||||
*/
|
||||
@Override
|
||||
public boolean isInside(int x, int y) {
|
||||
boolean result = (mKeyboard instanceof LatinKeyboard)
|
||||
&& ((LatinKeyboard)mKeyboard).isInside(this, x, y);
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean isInsideSuper(int x, int y) {
|
||||
return super.isInside(x, y);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ import com.android.inputmethod.latin.SubtypeSwitcher;
|
|||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
@ -98,12 +97,6 @@ public class LatinKeyboard extends Keyboard {
|
|||
mSpaceKeyIndex = indexOf(CODE_SPACE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
|
||||
XmlResourceParser parser, KeyStyles keyStyles) {
|
||||
return new LatinKey(res, parent, x, y, parser, keyStyles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a key which should be invalidated.
|
||||
*/
|
||||
|
@ -264,10 +257,6 @@ public class LatinKeyboard extends Keyboard {
|
|||
return mSpaceDragLastDiff > 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
boolean isCurrentlyInSpace() {
|
||||
return mCurrentlyInSpace;
|
||||
}
|
||||
|
||||
public void setPreferredLetters(int[] frequencies) {
|
||||
mPrefLetterFrequencies = frequencies;
|
||||
mPrefLetter = 0;
|
||||
|
@ -289,8 +278,9 @@ public class LatinKeyboard extends Keyboard {
|
|||
* Does the magic of locking the touch gesture into the spacebar when
|
||||
* switching input languages.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public boolean isInside(LatinKey key, int x, int y) {
|
||||
@Override
|
||||
@SuppressWarnings("unused") // SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER is constant
|
||||
public boolean isInside(Key key, int x, int y) {
|
||||
final int code = key.mCodes[0];
|
||||
if (code == CODE_SHIFT || code == CODE_DELETE) {
|
||||
y -= key.mHeight / 10;
|
||||
|
@ -308,13 +298,13 @@ public class LatinKeyboard extends Keyboard {
|
|||
mSpaceDragLastDiff = diff;
|
||||
return true;
|
||||
} else {
|
||||
boolean insideSpace = key.isInsideSuper(x, y);
|
||||
if (insideSpace) {
|
||||
boolean isOnSpace = key.isOnKey(x, y);
|
||||
if (isOnSpace) {
|
||||
mCurrentlyInSpace = true;
|
||||
mSpaceDragStartX = x;
|
||||
updateLocaleDrag(0);
|
||||
}
|
||||
return insideSpace;
|
||||
return isOnSpace;
|
||||
}
|
||||
}
|
||||
} else if (mPrefLetterFrequencies != null) {
|
||||
|
@ -327,16 +317,16 @@ public class LatinKeyboard extends Keyboard {
|
|||
final int[] pref = mPrefLetterFrequencies;
|
||||
if (mPrefLetter > 0) {
|
||||
if (DEBUG_PREFERRED_LETTER) {
|
||||
if (mPrefLetter == code && !key.isInsideSuper(x, y)) {
|
||||
if (mPrefLetter == code && !key.isOnKey(x, y)) {
|
||||
Log.d(TAG, "CORRECTED !!!!!!");
|
||||
}
|
||||
}
|
||||
return mPrefLetter == code;
|
||||
} else {
|
||||
final boolean inside = key.isInsideSuper(x, y);
|
||||
final boolean isOnKey = key.isOnKey(x, y);
|
||||
int[] nearby = getNearestKeys(x, y);
|
||||
List<Key> nearbyKeys = getKeys();
|
||||
if (inside) {
|
||||
if (isOnKey) {
|
||||
// If it's a preferred letter
|
||||
if (inPrefList(code, pref)) {
|
||||
// Check if its frequency is much lower than a nearby key
|
||||
|
@ -386,7 +376,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
}
|
||||
// Didn't find any
|
||||
if (mPrefLetter == 0) {
|
||||
return inside;
|
||||
return isOnKey;
|
||||
} else {
|
||||
return mPrefLetter == code;
|
||||
}
|
||||
|
@ -396,7 +386,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
// Lock into the spacebar
|
||||
if (mCurrentlyInSpace) return false;
|
||||
|
||||
return key.isInsideSuper(x, y);
|
||||
return key.isOnKey(x, y);
|
||||
}
|
||||
|
||||
private boolean inPrefList(int code, int[] pref) {
|
||||
|
|
Loading…
Reference in New Issue