Refactor MoreKeysKeyboardView a bit
Bug: 12491371 Change-Id: I3ce1e6557e41a94146b882751f75ae4b5f6bc73dmain
parent
509d07c764
commit
fa9b9578d4
|
@ -110,25 +110,31 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
|
||||||
@Override
|
@Override
|
||||||
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
||||||
mActivePointerId = pointerId;
|
mActivePointerId = pointerId;
|
||||||
onMoveKeyInternal(x, y, pointerId);
|
mCurrentKey = detectKey(x, y, pointerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMoveEvent(int x, int y, final int pointerId, long eventTime) {
|
public void onMoveEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
||||||
if (mActivePointerId != pointerId) {
|
if (mActivePointerId != pointerId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final boolean hasOldKey = (mCurrentKey != null);
|
final boolean hasOldKey = (mCurrentKey != null);
|
||||||
onMoveKeyInternal(x, y, pointerId);
|
mCurrentKey = detectKey(x, y, pointerId);
|
||||||
if (hasOldKey && mCurrentKey == null) {
|
if (hasOldKey && mCurrentKey == null) {
|
||||||
// If the pointer has moved too far away from any target then cancel the panel.
|
// A more keys keyboard is canceled when detecting no key.
|
||||||
mController.onCancelMoreKeysPanel();
|
mController.onCancelMoreKeysPanel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
||||||
if (mCurrentKey != null && mActivePointerId == pointerId) {
|
if (mActivePointerId != pointerId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Calling {@link #detectKey(int,int,int)} here is harmless because the last move event and
|
||||||
|
// the following up event share the same coordinates.
|
||||||
|
mCurrentKey = detectKey(x, y, pointerId);
|
||||||
|
if (mCurrentKey != null) {
|
||||||
updateReleaseKeyGraphics(mCurrentKey);
|
updateReleaseKeyGraphics(mCurrentKey);
|
||||||
onKeyInput(mCurrentKey, x, y);
|
onKeyInput(mCurrentKey, x, y);
|
||||||
mCurrentKey = null;
|
mCurrentKey = null;
|
||||||
|
@ -152,23 +158,22 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMoveKeyInternal(int x, int y, int pointerId) {
|
private Key detectKey(int x, int y, int pointerId) {
|
||||||
if (mActivePointerId != pointerId) {
|
|
||||||
// Ignore old pointers when newer pointer is active.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Key oldKey = mCurrentKey;
|
final Key oldKey = mCurrentKey;
|
||||||
final Key newKey = mKeyDetector.detectHitKey(x, y);
|
final Key newKey = mKeyDetector.detectHitKey(x, y);
|
||||||
if (newKey != oldKey) {
|
if (newKey == oldKey) {
|
||||||
mCurrentKey = newKey;
|
return newKey;
|
||||||
invalidateKey(mCurrentKey);
|
|
||||||
if (oldKey != null) {
|
|
||||||
updateReleaseKeyGraphics(oldKey);
|
|
||||||
}
|
|
||||||
if (newKey != null) {
|
|
||||||
updatePressKeyGraphics(newKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// A new key is detected.
|
||||||
|
if (oldKey != null) {
|
||||||
|
updateReleaseKeyGraphics(oldKey);
|
||||||
|
invalidateKey(oldKey);
|
||||||
|
}
|
||||||
|
if (newKey != null) {
|
||||||
|
updatePressKeyGraphics(newKey);
|
||||||
|
invalidateKey(newKey);
|
||||||
|
}
|
||||||
|
return newKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateReleaseKeyGraphics(final Key key) {
|
private void updateReleaseKeyGraphics(final Key key) {
|
||||||
|
|
|
@ -1033,8 +1033,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
final int translatedY = mMoreKeysPanel.translateY(y);
|
final int translatedY = mMoreKeysPanel.translateY(y);
|
||||||
mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime);
|
mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime);
|
||||||
}
|
}
|
||||||
mMoreKeysPanel.dismissMoreKeysPanel();
|
dismissMoreKeysPanel();
|
||||||
mMoreKeysPanel = null;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1101,10 +1100,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
sTimerProxy.cancelKeyTimersOf(this);
|
sTimerProxy.cancelKeyTimersOf(this);
|
||||||
setReleasedKeyGraphics(mCurrentKey);
|
setReleasedKeyGraphics(mCurrentKey);
|
||||||
resetKeySelectionByDraggingFinger();
|
resetKeySelectionByDraggingFinger();
|
||||||
if (isShowingMoreKeysPanel()) {
|
dismissMoreKeysPanel();
|
||||||
mMoreKeysPanel.dismissMoreKeysPanel();
|
|
||||||
mMoreKeysPanel = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,
|
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,
|
||||||
|
|
Loading…
Reference in New Issue