Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Adds support for gaze devices hover in keyboard & Pico flicker issues #2995

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public interface OnKeyboardActionListener {
private int mLastCodeY;
private int mCurrentKey = NOT_A_KEY;
// Fork
private int[] mHoveredKey = new int[2];
private int[] mHoveredKey = new int[3];
private int[] mPrevHoveredKey = new int[3];
private int mDownKey = NOT_A_KEY;
private long mLastKeyTime;
private long mCurrentKeyTime;
Expand Down Expand Up @@ -344,8 +345,7 @@ public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr,
mShadowColor = 0;
mShadowRadius = 0;
mBackgroundDimAmount = 0.5f;
mHoveredKey[0] = NOT_A_KEY;
mHoveredKey[1] = NOT_A_KEY;
clearHover();

mPreviewPopup = new PopupWindow(context);
if (previewLayout != 0) {
Expand Down Expand Up @@ -759,7 +759,7 @@ private void onBufferDraw() {
int[] drawableState = key.getCurrentDrawableState();

if (((CustomKeyboard)mKeyboard).isKeyEnabled(i)) {
if ((mHoveredKey[0] == i || mHoveredKey[1] == i) && !key.pressed) {
if (isKeyHovered(i) && !key.pressed) {
// Fork: implement hovered key
drawableState = KEY_STATE_HOVERED;
}
Expand Down Expand Up @@ -1146,8 +1146,7 @@ private void sendAccessibilityEventForUnicodeCharacter(int eventType, int code)
* @see #invalidateKey(int)
*/
public void invalidateAllKeys() {
mHoveredKey[0] = NOT_A_KEY;
mHoveredKey[1] = NOT_A_KEY;
clearHover();
mDirtyRect.union(0, 0, getWidth(), getHeight());
mDrawPending = true;
invalidate();
Expand Down Expand Up @@ -1263,12 +1262,14 @@ public boolean onHoverEvent(MotionEvent event) {
keyIndex = getKeyIndices(touchX, touchY, null);
}

int prevHovered = mHoveredKey[event.getDeviceId()];
mPrevHoveredKey[event.getDeviceId()] = mHoveredKey[event.getDeviceId()];
mHoveredKey[event.getDeviceId()] = keyIndex;
if (mHoveredKey[event.getDeviceId()] != NOT_A_KEY && prevHovered != mHoveredKey[event.getDeviceId()]) {
invalidateKey(mHoveredKey[event.getDeviceId()]);
int prevHovered = mPrevHoveredKey[event.getDeviceId()];
int currentHovered = mHoveredKey[event.getDeviceId()];
if (currentHovered != NOT_A_KEY && prevHovered != currentHovered) {
invalidateKey(currentHovered);
}
if (prevHovered != NOT_A_KEY && prevHovered != mHoveredKey[event.getDeviceId()]) {
if (prevHovered != NOT_A_KEY && prevHovered != currentHovered) {
invalidateKey(prevHovered);
}
return result;
Expand All @@ -1277,16 +1278,40 @@ public boolean onHoverEvent(MotionEvent event) {
@Override
public void setHovered(boolean hovered) {
if (!hovered) {
mHoveredKey[0] = NOT_A_KEY;
mHoveredKey[1] = NOT_A_KEY;
invalidateAllKeys();
boolean hasChanged = false;
for (int i=0; i<mHoveredKey.length; i++) {
hasChanged |= mPrevHoveredKey[i] != mHoveredKey[i];
}

if (hasChanged) {
clearHover();
invalidateAllKeys();
}
}
super.setHovered(hovered);
}

@Override
public boolean isHovered() {
return mHoveredKey[0] != NOT_A_KEY || mHoveredKey[1] != NOT_A_KEY;
boolean isHovered = false;
for (int value : mHoveredKey) {
isHovered |= value != NOT_A_KEY;
}
return isHovered;
}

private boolean isKeyHovered(int keyIndex) {
boolean isHovered = false;
for (int value : mHoveredKey) {
isHovered |= value == keyIndex;
}

return isHovered;
}

private void clearHover() {
Arrays.fill(mHoveredKey, NOT_A_KEY);
Arrays.fill(mPrevHoveredKey, NOT_A_KEY);
}

public void setFeaturedKeyBackground(int resId, int[] keyCodes) {
Expand Down