use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ParanoidAndroid.
the class KeyboardView method getKeyIndices.
private int getKeyIndices(int x, int y, int[] allKeys) {
final Key[] keys = mKeys;
int primaryIndex = NOT_A_KEY;
int closestKey = NOT_A_KEY;
int closestKeyDist = mProximityThreshold + 1;
java.util.Arrays.fill(mDistances, Integer.MAX_VALUE);
int[] nearestKeyIndices = mKeyboard.getNearestKeys(x, y);
final int keyCount = nearestKeyIndices.length;
for (int i = 0; i < keyCount; i++) {
final Key key = keys[nearestKeyIndices[i]];
int dist = 0;
boolean isInside = key.isInside(x, y);
if (isInside) {
primaryIndex = nearestKeyIndices[i];
}
if (((mProximityCorrectOn && (dist = key.squaredDistanceFrom(x, y)) < mProximityThreshold) || isInside) && key.codes[0] > 32) {
// Find insertion point
final int nCodes = key.codes.length;
if (dist < closestKeyDist) {
closestKeyDist = dist;
closestKey = nearestKeyIndices[i];
}
if (allKeys == null)
continue;
for (int j = 0; j < mDistances.length; j++) {
if (mDistances[j] > dist) {
// Make space for nCodes codes
System.arraycopy(mDistances, j, mDistances, j + nCodes, mDistances.length - j - nCodes);
System.arraycopy(allKeys, j, allKeys, j + nCodes, allKeys.length - j - nCodes);
for (int c = 0; c < nCodes; c++) {
allKeys[j + c] = key.codes[c];
mDistances[j + c] = dist;
}
break;
}
}
}
}
if (primaryIndex == NOT_A_KEY) {
primaryIndex = closestKey;
}
return primaryIndex;
}
use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ParanoidAndroid.
the class KeyboardView method repeatKey.
private boolean repeatKey() {
Key key = mKeys[mRepeatKeyIndex];
detectAndSendKey(mCurrentKey, key.x, key.y, mLastTapTime);
return true;
}
use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ParanoidAndroid.
the class KeyboardView method invalidateKey.
/**
* Invalidates a key so that it will be redrawn on the next repaint. Use this method if only
* one key is changing it's content. Any changes that affect the position or size of the key
* may not be honored.
* @param keyIndex the index of the key in the attached {@link Keyboard}.
* @see #invalidateAllKeys
*/
public void invalidateKey(int keyIndex) {
if (mKeys == null)
return;
if (keyIndex < 0 || keyIndex >= mKeys.length) {
return;
}
final Key key = mKeys[keyIndex];
mInvalidatedKey = key;
mDirtyRect.union(key.x + mPaddingLeft, key.y + mPaddingTop, key.x + key.width + mPaddingLeft, key.y + key.height + mPaddingTop);
onBufferDraw();
invalidate(key.x + mPaddingLeft, key.y + mPaddingTop, key.x + key.width + mPaddingLeft, key.y + key.height + mPaddingTop);
}
use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ParanoidAndroid.
the class KeyboardView method showKey.
private void showKey(final int keyIndex) {
final PopupWindow previewPopup = mPreviewPopup;
final Key[] keys = mKeys;
if (keyIndex < 0 || keyIndex >= mKeys.length)
return;
Key key = keys[keyIndex];
if (key.icon != null) {
mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon);
mPreviewText.setText(null);
} else {
mPreviewText.setCompoundDrawables(null, null, null, null);
mPreviewText.setText(getPreviewText(key));
if (key.label.length() > 1 && key.codes.length < 2) {
mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
} else {
mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
mPreviewText.setTypeface(Typeface.DEFAULT);
}
}
mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
final int popupHeight = mPreviewHeight;
LayoutParams lp = mPreviewText.getLayoutParams();
if (lp != null) {
lp.width = popupWidth;
lp.height = popupHeight;
}
if (!mPreviewCentered) {
mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
} else {
// TODO: Fix this if centering is brought back
mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
mPopupPreviewY = -mPreviewText.getMeasuredHeight();
}
mHandler.removeMessages(MSG_REMOVE_PREVIEW);
getLocationInWindow(mCoordinates);
// Offset may be zero
mCoordinates[0] += mMiniKeyboardOffsetX;
// Offset may be zero
mCoordinates[1] += mMiniKeyboardOffsetY;
// Set the preview background state
mPreviewText.getBackground().setState(key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
mPopupPreviewX += mCoordinates[0];
mPopupPreviewY += mCoordinates[1];
// If the popup cannot be shown above the key, put it on the side
getLocationOnScreen(mCoordinates);
if (mPopupPreviewY + mCoordinates[1] < 0) {
// the right, offset by enough to see at least one key to the left/right.
if (key.x + key.width <= getWidth() / 2) {
mPopupPreviewX += (int) (key.width * 2.5);
} else {
mPopupPreviewX -= (int) (key.width * 2.5);
}
mPopupPreviewY += popupHeight;
}
if (previewPopup.isShowing()) {
previewPopup.update(mPopupPreviewX, mPopupPreviewY, popupWidth, popupHeight);
} else {
previewPopup.setWidth(popupWidth);
previewPopup.setHeight(popupHeight);
previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY, mPopupPreviewX, mPopupPreviewY);
}
mPreviewText.setVisibility(VISIBLE);
}
use of android.inputmethodservice.Keyboard.Key in project platform_frameworks_base by android.
the class KeyboardView method getKeyIndices.
private int getKeyIndices(int x, int y, int[] allKeys) {
final Key[] keys = mKeys;
int primaryIndex = NOT_A_KEY;
int closestKey = NOT_A_KEY;
int closestKeyDist = mProximityThreshold + 1;
java.util.Arrays.fill(mDistances, Integer.MAX_VALUE);
int[] nearestKeyIndices = mKeyboard.getNearestKeys(x, y);
final int keyCount = nearestKeyIndices.length;
for (int i = 0; i < keyCount; i++) {
final Key key = keys[nearestKeyIndices[i]];
int dist = 0;
boolean isInside = key.isInside(x, y);
if (isInside) {
primaryIndex = nearestKeyIndices[i];
}
if (((mProximityCorrectOn && (dist = key.squaredDistanceFrom(x, y)) < mProximityThreshold) || isInside) && key.codes[0] > 32) {
// Find insertion point
final int nCodes = key.codes.length;
if (dist < closestKeyDist) {
closestKeyDist = dist;
closestKey = nearestKeyIndices[i];
}
if (allKeys == null)
continue;
for (int j = 0; j < mDistances.length; j++) {
if (mDistances[j] > dist) {
// Make space for nCodes codes
System.arraycopy(mDistances, j, mDistances, j + nCodes, mDistances.length - j - nCodes);
System.arraycopy(allKeys, j, allKeys, j + nCodes, allKeys.length - j - nCodes);
for (int c = 0; c < nCodes; c++) {
allKeys[j + c] = key.codes[c];
mDistances[j + c] = dist;
}
break;
}
}
}
}
if (primaryIndex == NOT_A_KEY) {
primaryIndex = closestKey;
}
return primaryIndex;
}
Aggregations