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