am 8e327009: Merge "Refactor PointerTracker and MainKeyboardView"
* commit '8e3270091409ac7c1f9d960f5023d4ddf5f46114': Refactor PointerTracker and MainKeyboardViewmain
commit
58f5e62ba8
|
@ -269,13 +269,9 @@ public final class MainKeyboardAccessibilityDelegate
|
||||||
eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0 /* metaState */);
|
eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0 /* metaState */);
|
||||||
// Inject a fake down event to {@link PointerTracker} to handle a long press correctly.
|
// Inject a fake down event to {@link PointerTracker} to handle a long press correctly.
|
||||||
tracker.processMotionEvent(downEvent, mKeyDetector);
|
tracker.processMotionEvent(downEvent, mKeyDetector);
|
||||||
// The above fake down event triggers an unnecessary long press timer that should be
|
|
||||||
// canceled.
|
|
||||||
tracker.cancelLongPressTimer();
|
|
||||||
downEvent.recycle();
|
downEvent.recycle();
|
||||||
// Invoke {@link MainKeyboardView#onLongPress(PointerTracker)} as if a long press timeout
|
// Invoke {@link PointerTracker#onLongPressed()} as if a long press timeout has passed.
|
||||||
// has passed.
|
tracker.onLongPressed();
|
||||||
mKeyboardView.onLongPress(tracker);
|
|
||||||
// If {@link Key#hasNoPanelAutoMoreKeys()} is true (such as "0 +" key on the phone layout)
|
// If {@link Key#hasNoPanelAutoMoreKeys()} is true (such as "0 +" key on the phone layout)
|
||||||
// or a key invokes IME switcher dialog, we should just ignore the next
|
// or a key invokes IME switcher dialog, we should just ignore the next
|
||||||
// {@link #onRegisterHoverKey(Key,MotionEvent)}. It can be determined by whether
|
// {@link #onRegisterHoverKey(Key,MotionEvent)}. It can be determined by whether
|
||||||
|
|
|
@ -461,12 +461,17 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
windowContentView.addView(mDrawingPreviewPlacerView);
|
windowContentView.addView(mDrawingPreviewPlacerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements {@link DrawingProxy#onKeyPressed(Key,boolean)}.
|
||||||
@Override
|
@Override
|
||||||
public void showKeyPreview(@Nonnull final Key key) {
|
public void onKeyPressed(@Nonnull final Key key, final boolean withPreview) {
|
||||||
// If the key is invalid or has no key preview, we must not show key preview.
|
key.onPressed();
|
||||||
if (key.noKeyPreview()) {
|
invalidateKey(key);
|
||||||
return;
|
if (withPreview && !key.noKeyPreview()) {
|
||||||
|
showKeyPreview(key);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showKeyPreview(@Nonnull final Key key) {
|
||||||
final Keyboard keyboard = getKeyboard();
|
final Keyboard keyboard = getKeyboard();
|
||||||
if (keyboard == null) {
|
if (keyboard == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -483,15 +488,26 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
getWidth(), mOriginCoords, mDrawingPreviewPlacerView, isHardwareAccelerated());
|
getWidth(), mOriginCoords, mDrawingPreviewPlacerView, isHardwareAccelerated());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements {@link DrawingProxy#dismissKeyPreviewWithoutDelay(Key)}.
|
private void dismissKeyPreviewWithoutDelay(@Nonnull final Key key) {
|
||||||
@Override
|
|
||||||
public void dismissKeyPreviewWithoutDelay(@Nonnull final Key key) {
|
|
||||||
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
|
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
|
||||||
invalidateKey(key);
|
invalidateKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements {@link DrawingProxy#onKeyReleased(Key,boolean)}.
|
||||||
@Override
|
@Override
|
||||||
public void dismissKeyPreview(@Nonnull final Key key) {
|
public void onKeyReleased(@Nonnull final Key key, final boolean withAnimation) {
|
||||||
|
key.onReleased();
|
||||||
|
invalidateKey(key);
|
||||||
|
if (!key.noKeyPreview()) {
|
||||||
|
if (withAnimation) {
|
||||||
|
dismissKeyPreview(key);
|
||||||
|
} else {
|
||||||
|
dismissKeyPreviewWithoutDelay(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissKeyPreview(@Nonnull final Key key) {
|
||||||
if (isHardwareAccelerated()) {
|
if (isHardwareAccelerated()) {
|
||||||
mKeyPreviewChoreographer.dismissKeyPreview(key, true /* withAnimation */);
|
mKeyPreviewChoreographer.dismissKeyPreview(key, true /* withAnimation */);
|
||||||
return;
|
return;
|
||||||
|
@ -574,7 +590,11 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
mDrawingPreviewPlacerView.removeAllViews();
|
mDrawingPreviewPlacerView.removeAllViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MoreKeysPanel onCreateMoreKeysPanel(final Key key, final Context context) {
|
// Implements {@link DrawingProxy@showMoreKeysKeyboard(Key,PointerTracker)}.
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public MoreKeysPanel showMoreKeysKeyboard(@Nonnull final Key key,
|
||||||
|
@Nonnull final PointerTracker tracker) {
|
||||||
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
||||||
if (moreKeys == null) {
|
if (moreKeys == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -590,7 +610,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
&& !key.noKeyPreview() && moreKeys.length == 1
|
&& !key.noKeyPreview() && moreKeys.length == 1
|
||||||
&& mKeyPreviewDrawParams.getVisibleWidth() > 0;
|
&& mKeyPreviewDrawParams.getVisibleWidth() > 0;
|
||||||
final MoreKeysKeyboard.Builder builder = new MoreKeysKeyboard.Builder(
|
final MoreKeysKeyboard.Builder builder = new MoreKeysKeyboard.Builder(
|
||||||
context, key, getKeyboard(), isSingleMoreKeyWithPreview,
|
getContext(), key, getKeyboard(), isSingleMoreKeyWithPreview,
|
||||||
mKeyPreviewDrawParams.getVisibleWidth(),
|
mKeyPreviewDrawParams.getVisibleWidth(),
|
||||||
mKeyPreviewDrawParams.getVisibleHeight(), newLabelPaint(key));
|
mKeyPreviewDrawParams.getVisibleHeight(), newLabelPaint(key));
|
||||||
moreKeysKeyboard = builder.build();
|
moreKeysKeyboard = builder.build();
|
||||||
|
@ -603,50 +623,6 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
(MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view);
|
(MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view);
|
||||||
moreKeysKeyboardView.setKeyboard(moreKeysKeyboard);
|
moreKeysKeyboardView.setKeyboard(moreKeysKeyboard);
|
||||||
container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
return moreKeysKeyboardView;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements {@link DrawingProxy@onLongPress(PointerTracker)}.
|
|
||||||
/**
|
|
||||||
* Called when a key is long pressed.
|
|
||||||
* @param tracker the pointer tracker which pressed the parent key
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onLongPress(@Nonnull final PointerTracker tracker) {
|
|
||||||
if (isShowingMoreKeysPanel()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Key key = tracker.getKey();
|
|
||||||
if (key == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final KeyboardActionListener listener = mKeyboardActionListener;
|
|
||||||
if (key.hasNoPanelAutoMoreKey()) {
|
|
||||||
final int moreKeyCode = key.getMoreKeys()[0].mCode;
|
|
||||||
tracker.onLongPressed();
|
|
||||||
listener.onPressKey(moreKeyCode, 0 /* repeatCount */, true /* isSinglePointer */);
|
|
||||||
listener.onCodeInput(moreKeyCode, Constants.NOT_A_COORDINATE,
|
|
||||||
Constants.NOT_A_COORDINATE, false /* isKeyRepeat */);
|
|
||||||
listener.onReleaseKey(moreKeyCode, false /* withSliding */);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int code = key.getCode();
|
|
||||||
if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) {
|
|
||||||
// Long pressing the space key invokes IME switcher dialog.
|
|
||||||
if (listener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
|
|
||||||
tracker.onLongPressed();
|
|
||||||
listener.onReleaseKey(code, false /* withSliding */);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
openMoreKeysPanel(key, tracker);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openMoreKeysPanel(final Key key, final PointerTracker tracker) {
|
|
||||||
final MoreKeysPanel moreKeysPanel = onCreateMoreKeysPanel(key, getContext());
|
|
||||||
if (moreKeysPanel == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int[] lastCoords = CoordinateUtils.newInstance();
|
final int[] lastCoords = CoordinateUtils.newInstance();
|
||||||
tracker.getLastCoordinates(lastCoords);
|
tracker.getLastCoordinates(lastCoords);
|
||||||
|
@ -664,10 +640,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
// {@code mPreviewVisibleOffset} has been set appropriately in
|
// {@code mPreviewVisibleOffset} has been set appropriately in
|
||||||
// {@link KeyboardView#showKeyPreview(PointerTracker)}.
|
// {@link KeyboardView#showKeyPreview(PointerTracker)}.
|
||||||
final int pointY = key.getY() + mKeyPreviewDrawParams.getVisibleOffset();
|
final int pointY = key.getY() + mKeyPreviewDrawParams.getVisibleOffset();
|
||||||
moreKeysPanel.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener);
|
moreKeysKeyboardView.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener);
|
||||||
tracker.onShowMoreKeysPanel(moreKeysPanel);
|
return moreKeysKeyboardView;
|
||||||
// TODO: Implement zoom in animation of more keys panel.
|
|
||||||
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInDraggingFinger() {
|
public boolean isInDraggingFinger() {
|
||||||
|
|
|
@ -222,7 +222,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
final int trackersSize = sTrackers.size();
|
final int trackersSize = sTrackers.size();
|
||||||
for (int i = 0; i < trackersSize; ++i) {
|
for (int i = 0; i < trackersSize; ++i) {
|
||||||
final PointerTracker tracker = sTrackers.get(i);
|
final PointerTracker tracker = sTrackers.get(i);
|
||||||
tracker.setReleasedKeyGraphics(tracker.getKey());
|
tracker.setReleasedKeyGraphics(tracker.getKey(), true /* withAnimation */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,19 +382,18 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
return mKeyDetector.detectHitKey(x, y);
|
return mKeyDetector.detectHitKey(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReleasedKeyGraphics(@Nullable final Key key) {
|
private void setReleasedKeyGraphics(@Nullable final Key key, final boolean withAnimation) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sDrawingProxy.dismissKeyPreview(key);
|
|
||||||
// Even if the key is disabled, update the key release graphics just in case.
|
// Even if the key is disabled, update the key release graphics just in case.
|
||||||
updateReleaseKeyGraphics(key);
|
sDrawingProxy.onKeyReleased(key, withAnimation);
|
||||||
|
|
||||||
if (key.isShift()) {
|
if (key.isShift()) {
|
||||||
for (final Key shiftKey : mKeyboard.mShiftKeys) {
|
for (final Key shiftKey : mKeyboard.mShiftKeys) {
|
||||||
if (shiftKey != key) {
|
if (shiftKey != key) {
|
||||||
updateReleaseKeyGraphics(shiftKey);
|
sDrawingProxy.onKeyReleased(shiftKey, false /* withAnimation */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -403,11 +402,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
final int altCode = key.getAltCode();
|
final int altCode = key.getAltCode();
|
||||||
final Key altKey = mKeyboard.getKey(altCode);
|
final Key altKey = mKeyboard.getKey(altCode);
|
||||||
if (altKey != null) {
|
if (altKey != null) {
|
||||||
updateReleaseKeyGraphics(altKey);
|
sDrawingProxy.onKeyReleased(altKey, false /* withAnimation */);
|
||||||
}
|
}
|
||||||
for (final Key k : mKeyboard.mAltCodeKeysWhileTyping) {
|
for (final Key k : mKeyboard.mAltCodeKeysWhileTyping) {
|
||||||
if (k != key && k.getAltCode() == altCode) {
|
if (k != key && k.getAltCode() == altCode) {
|
||||||
updateReleaseKeyGraphics(k);
|
sDrawingProxy.onKeyReleased(k, false /* withAnimation */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,7 +417,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
return sTypingTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
|
return sTypingTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPressedKeyGraphics(final Key key, final long eventTime) {
|
private void setPressedKeyGraphics(@Nullable final Key key, final long eventTime) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -430,15 +429,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key.noKeyPreview() && !sInGesture && !needsToSuppressKeyPreviewPopup(eventTime)) {
|
final boolean noKeyPreview = sInGesture || needsToSuppressKeyPreviewPopup(eventTime);
|
||||||
sDrawingProxy.showKeyPreview(key);
|
sDrawingProxy.onKeyPressed(key, !noKeyPreview);
|
||||||
}
|
|
||||||
updatePressKeyGraphics(key);
|
|
||||||
|
|
||||||
if (key.isShift()) {
|
if (key.isShift()) {
|
||||||
for (final Key shiftKey : mKeyboard.mShiftKeys) {
|
for (final Key shiftKey : mKeyboard.mShiftKeys) {
|
||||||
if (shiftKey != key) {
|
if (shiftKey != key) {
|
||||||
updatePressKeyGraphics(shiftKey);
|
sDrawingProxy.onKeyPressed(shiftKey, false /* withPreview */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,26 +444,16 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
final int altCode = key.getAltCode();
|
final int altCode = key.getAltCode();
|
||||||
final Key altKey = mKeyboard.getKey(altCode);
|
final Key altKey = mKeyboard.getKey(altCode);
|
||||||
if (altKey != null) {
|
if (altKey != null) {
|
||||||
updatePressKeyGraphics(altKey);
|
sDrawingProxy.onKeyPressed(altKey, false /* withPreview */);
|
||||||
}
|
}
|
||||||
for (final Key k : mKeyboard.mAltCodeKeysWhileTyping) {
|
for (final Key k : mKeyboard.mAltCodeKeysWhileTyping) {
|
||||||
if (k != key && k.getAltCode() == altCode) {
|
if (k != key && k.getAltCode() == altCode) {
|
||||||
updatePressKeyGraphics(k);
|
sDrawingProxy.onKeyPressed(k, false /* withPreview */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateReleaseKeyGraphics(final Key key) {
|
|
||||||
key.onReleased();
|
|
||||||
sDrawingProxy.invalidateKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updatePressKeyGraphics(final Key key) {
|
|
||||||
key.onPressed();
|
|
||||||
sDrawingProxy.invalidateKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GestureStrokeDrawingPoints getGestureStrokeDrawingPoints() {
|
public GestureStrokeDrawingPoints getGestureStrokeDrawingPoints() {
|
||||||
return mGestureStrokeDrawingPoints;
|
return mGestureStrokeDrawingPoints;
|
||||||
}
|
}
|
||||||
|
@ -837,7 +824,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processDraggingFingerOutFromOldKey(final Key oldKey) {
|
private void processDraggingFingerOutFromOldKey(final Key oldKey) {
|
||||||
setReleasedKeyGraphics(oldKey);
|
setReleasedKeyGraphics(oldKey, true /* withAnimation */);
|
||||||
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
|
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
|
||||||
startKeySelectionByDraggingFinger(oldKey);
|
startKeySelectionByDraggingFinger(oldKey);
|
||||||
sTimerProxy.cancelKeyTimersOf(this);
|
sTimerProxy.cancelKeyTimersOf(this);
|
||||||
|
@ -880,12 +867,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
}
|
}
|
||||||
onUpEvent(x, y, eventTime);
|
onUpEvent(x, y, eventTime);
|
||||||
cancelTrackingForAction();
|
cancelTrackingForAction();
|
||||||
setReleasedKeyGraphics(oldKey);
|
setReleasedKeyGraphics(oldKey, true /* withAnimation */);
|
||||||
} else {
|
} else {
|
||||||
if (!mIsDetectingGesture) {
|
if (!mIsDetectingGesture) {
|
||||||
cancelTrackingForAction();
|
cancelTrackingForAction();
|
||||||
}
|
}
|
||||||
setReleasedKeyGraphics(oldKey);
|
setReleasedKeyGraphics(oldKey, true /* withAnimation */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,7 +900,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
|
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
|
||||||
if (sInGesture) {
|
if (sInGesture) {
|
||||||
mCurrentKey = null;
|
mCurrentKey = null;
|
||||||
setReleasedKeyGraphics(oldKey);
|
setReleasedKeyGraphics(oldKey, true /* withAnimation */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -978,7 +965,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
final int currentRepeatingKeyCode = mCurrentRepeatingKeyCode;
|
final int currentRepeatingKeyCode = mCurrentRepeatingKeyCode;
|
||||||
mCurrentRepeatingKeyCode = Constants.NOT_A_CODE;
|
mCurrentRepeatingKeyCode = Constants.NOT_A_CODE;
|
||||||
// Release the last pressed key.
|
// Release the last pressed key.
|
||||||
setReleasedKeyGraphics(currentKey);
|
setReleasedKeyGraphics(currentKey, true /* withAnimation */);
|
||||||
|
|
||||||
if (isShowingMoreKeysPanel()) {
|
if (isShowingMoreKeysPanel()) {
|
||||||
if (!mIsTrackingForActionDisabled) {
|
if (!mIsTrackingForActionDisabled) {
|
||||||
|
@ -1015,14 +1002,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
|
|
||||||
setReleasedKeyGraphics(mCurrentKey);
|
|
||||||
final int translatedX = panel.translateX(mLastX);
|
|
||||||
final int translatedY = panel.translateY(mLastY);
|
|
||||||
panel.onDownEvent(translatedX, translatedY, mPointerId, SystemClock.uptimeMillis());
|
|
||||||
mMoreKeysPanel = panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelTrackingForAction() {
|
public void cancelTrackingForAction() {
|
||||||
if (isShowingMoreKeysPanel()) {
|
if (isShowingMoreKeysPanel()) {
|
||||||
|
@ -1035,14 +1014,49 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
return !mIsTrackingForActionDisabled;
|
return !mIsTrackingForActionDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelLongPressTimer() {
|
public void onLongPressed() {
|
||||||
sTimerProxy.cancelLongPressTimersOf(this);
|
sTimerProxy.cancelLongPressTimersOf(this);
|
||||||
|
if (isShowingMoreKeysPanel()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Key key = getKey();
|
||||||
|
if (key == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key.hasNoPanelAutoMoreKey()) {
|
||||||
|
cancelKeyTracking();
|
||||||
|
final int moreKeyCode = key.getMoreKeys()[0].mCode;
|
||||||
|
sListener.onPressKey(moreKeyCode, 0 /* repeatCont */, true /* isSinglePointer */);
|
||||||
|
sListener.onCodeInput(moreKeyCode, Constants.NOT_A_COORDINATE,
|
||||||
|
Constants.NOT_A_COORDINATE, false /* isKeyRepeat */);
|
||||||
|
sListener.onReleaseKey(moreKeyCode, false /* withSliding */);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int code = key.getCode();
|
||||||
|
if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) {
|
||||||
|
// Long pressing the space key invokes IME switcher dialog.
|
||||||
|
if (sListener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
|
||||||
|
cancelKeyTracking();
|
||||||
|
sListener.onReleaseKey(code, false /* withSliding */);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setReleasedKeyGraphics(key, false /* withAnimation */);
|
||||||
|
final MoreKeysPanel moreKeysPanel = sDrawingProxy.showMoreKeysKeyboard(key, this);
|
||||||
|
if (moreKeysPanel == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int translatedX = moreKeysPanel.translateX(mLastX);
|
||||||
|
final int translatedY = moreKeysPanel.translateY(mLastY);
|
||||||
|
moreKeysPanel.onDownEvent(translatedX, translatedY, mPointerId, SystemClock.uptimeMillis());
|
||||||
|
mMoreKeysPanel = moreKeysPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLongPressed() {
|
private void cancelKeyTracking() {
|
||||||
resetKeySelectionByDraggingFinger();
|
resetKeySelectionByDraggingFinger();
|
||||||
cancelTrackingForAction();
|
cancelTrackingForAction();
|
||||||
setReleasedKeyGraphics(mCurrentKey);
|
setReleasedKeyGraphics(mCurrentKey, true /* withAnimation */);
|
||||||
sPointerTrackerQueue.remove(this);
|
sPointerTrackerQueue.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1059,7 +1073,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
|
|
||||||
private void onCancelEventInternal() {
|
private void onCancelEventInternal() {
|
||||||
sTimerProxy.cancelKeyTimersOf(this);
|
sTimerProxy.cancelKeyTimersOf(this);
|
||||||
setReleasedKeyGraphics(mCurrentKey);
|
setReleasedKeyGraphics(mCurrentKey, true /* withAnimation */);
|
||||||
resetKeySelectionByDraggingFinger();
|
resetKeySelectionByDraggingFinger();
|
||||||
dismissMoreKeysPanel();
|
dismissMoreKeysPanel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,29 +17,36 @@
|
||||||
package com.android.inputmethod.keyboard.internal;
|
package com.android.inputmethod.keyboard.internal;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.Key;
|
import com.android.inputmethod.keyboard.Key;
|
||||||
|
import com.android.inputmethod.keyboard.MoreKeysPanel;
|
||||||
import com.android.inputmethod.keyboard.PointerTracker;
|
import com.android.inputmethod.keyboard.PointerTracker;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface DrawingProxy {
|
public interface DrawingProxy {
|
||||||
// TODO: Remove this method.
|
/**
|
||||||
public void invalidateKey(@Nullable Key key);
|
* Called when a key is being pressed.
|
||||||
|
* @param key the {@link Key} that is being pressed.
|
||||||
// TODO: Rename this method to onKeyPressed.
|
* @param withPreview true if key popup preview should be displayed.
|
||||||
public void showKeyPreview(@Nonnull Key key);
|
*/
|
||||||
|
public void onKeyPressed(@Nonnull Key key, boolean withPreview);
|
||||||
// TODO: Rename this method to onKeyReleased.
|
|
||||||
public void dismissKeyPreview(@Nonnull Key key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismiss a key preview visual without delay.
|
* Called when a key is being released.
|
||||||
* @param key the key whose preview visual should be dismissed.
|
* @param key the {@link Key} that is being released.
|
||||||
|
* @param withAnimation when true, key popup preview should be dismissed with animation.
|
||||||
*/
|
*/
|
||||||
public void dismissKeyPreviewWithoutDelay(@Nonnull Key key);
|
public void onKeyReleased(@Nonnull Key key, boolean withAnimation);
|
||||||
|
|
||||||
// TODO: Rename this method to onKeyLongPressed.
|
/**
|
||||||
public void onLongPress(@Nonnull PointerTracker tracker);
|
* Start showing more keys keyboard of a key that is being long pressed.
|
||||||
|
* @param key the {@link Key} that is being long pressed and showing more keys keyboard.
|
||||||
|
* @param tracker the {@link PointerTracker} that detects this long pressing.
|
||||||
|
* @return {@link MoreKeysPanel} that is being shown. null if there is no need to show more keys
|
||||||
|
* keyboard.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public MoreKeysPanel showMoreKeysKeyboard(@Nonnull Key key, @Nonnull PointerTracker tracker);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a while-typing-animation.
|
* Start a while-typing-animation.
|
||||||
|
|
|
@ -66,7 +66,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
|
||||||
case MSG_LONGPRESS_SHIFT_KEY:
|
case MSG_LONGPRESS_SHIFT_KEY:
|
||||||
cancelLongPressTimers();
|
cancelLongPressTimers();
|
||||||
final PointerTracker tracker2 = (PointerTracker) msg.obj;
|
final PointerTracker tracker2 = (PointerTracker) msg.obj;
|
||||||
drawingProxy.onLongPress(tracker2);
|
tracker2.onLongPressed();
|
||||||
break;
|
break;
|
||||||
case MSG_UPDATE_BATCH_INPUT:
|
case MSG_UPDATE_BATCH_INPUT:
|
||||||
final PointerTracker tracker3 = (PointerTracker) msg.obj;
|
final PointerTracker tracker3 = (PointerTracker) msg.obj;
|
||||||
|
@ -74,8 +74,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
|
||||||
startUpdateBatchInputTimer(tracker3);
|
startUpdateBatchInputTimer(tracker3);
|
||||||
break;
|
break;
|
||||||
case MSG_DISMISS_KEY_PREVIEW:
|
case MSG_DISMISS_KEY_PREVIEW:
|
||||||
final Key key = (Key) msg.obj;
|
drawingProxy.onKeyReleased((Key) msg.obj, false /* withAnimation */);
|
||||||
drawingProxy.dismissKeyPreviewWithoutDelay(key);
|
|
||||||
break;
|
break;
|
||||||
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
|
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
|
||||||
drawingProxy.dismissGestureFloatingPreviewTextWithoutDelay();
|
drawingProxy.dismissGestureFloatingPreviewTextWithoutDelay();
|
||||||
|
|
Loading…
Reference in New Issue