am 1f4f404e: Merge "Refactor more keys menu framework (part 2)"

* commit '1f4f404e1f753db5cbe675e0088064e3c64e0953':
  Refactor more keys menu framework (part 2)
main
Tom Ouyang 2012-12-13 18:52:56 -08:00 committed by Android Git Automerger
commit a818c69a4c
7 changed files with 192 additions and 297 deletions

View File

@ -1031,7 +1031,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
return (mMoreKeysPanel != null); return (mMoreKeysPanel != null);
} }
@Override
public boolean dismissMoreKeysPanel() { public boolean dismissMoreKeysPanel() {
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
return mMoreKeysPanel.dismissMoreKeysPanel(); return mMoreKeysPanel.dismissMoreKeysPanel();

View File

@ -135,7 +135,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private int mAltCodeKeyWhileTypingAnimAlpha = Constants.Color.ALPHA_OPAQUE; private int mAltCodeKeyWhileTypingAnimAlpha = Constants.Color.ALPHA_OPAQUE;
// More keys keyboard // More keys keyboard
private int mMoreKeysPanelPointerTrackerId;
private final WeakHashMap<Key, MoreKeysPanel> mMoreKeysPanelCache = private final WeakHashMap<Key, MoreKeysPanel> mMoreKeysPanelCache =
new WeakHashMap<Key, MoreKeysPanel>(); new WeakHashMap<Key, MoreKeysPanel>();
private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint; private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint;
@ -662,7 +661,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
} }
mMoreKeysPanelCache.put(parentKey, moreKeysPanel); mMoreKeysPanelCache.put(parentKey, moreKeysPanel);
} }
mMoreKeysPanelPointerTrackerId = tracker.mPointerId;
final int[] lastCoords = CoordinateUtils.newInstance(); final int[] lastCoords = CoordinateUtils.newInstance();
tracker.getLastCoordinates(lastCoords); tracker.getLastCoordinates(lastCoords);
@ -732,14 +730,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final long eventTime = me.getEventTime(); final long eventTime = me.getEventTime();
final int index = me.getActionIndex(); final int index = me.getActionIndex();
final int id = me.getPointerId(index); final int id = me.getPointerId(index);
final int x, y; final int x = (int)me.getX(index);
if (mMoreKeysPanel != null && id == mMoreKeysPanelPointerTrackerId) { final int y = (int)me.getY(index);
x = mMoreKeysPanel.translateX((int)me.getX(index));
y = mMoreKeysPanel.translateY((int)me.getY(index));
} else {
x = (int)me.getX(index);
y = (int)me.getY(index);
}
// TODO: This might be moved to the tracker.processMotionEvent() call below. // TODO: This might be moved to the tracker.processMotionEvent() call below.
if (ENABLE_USABILITY_STUDY_LOG && action != MotionEvent.ACTION_MOVE) { if (ENABLE_USABILITY_STUDY_LOG && action != MotionEvent.ACTION_MOVE) {
writeUsabilityStudyLog(me, action, eventTime, index, id, x, y); writeUsabilityStudyLog(me, action, eventTime, index, id, x, y);
@ -800,19 +793,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final int pointerId = me.getPointerId(i); final int pointerId = me.getPointerId(i);
final PointerTracker tracker = PointerTracker.getPointerTracker( final PointerTracker tracker = PointerTracker.getPointerTracker(
pointerId, this); pointerId, this);
final int px, py; final int px = (int)me.getX(i);
final MotionEvent motionEvent; final int py = (int)me.getY(i);
if (mMoreKeysPanel != null tracker.onMoveEvent(px, py, eventTime, me);
&& tracker.mPointerId == mMoreKeysPanelPointerTrackerId) {
px = mMoreKeysPanel.translateX((int)me.getX(i));
py = mMoreKeysPanel.translateY((int)me.getY(i));
motionEvent = null;
} else {
px = (int)me.getX(i);
py = (int)me.getY(i);
motionEvent = me;
}
tracker.onMoveEvent(px, py, eventTime, motionEvent);
if (ENABLE_USABILITY_STUDY_LOG) { if (ENABLE_USABILITY_STUDY_LOG) {
writeUsabilityStudyLog(me, action, eventTime, i, pointerId, px, py); writeUsabilityStudyLog(me, action, eventTime, i, pointerId, px, py);
} }
@ -867,7 +850,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override @Override
public boolean onDismissMoreKeysPanel() { public boolean onDismissMoreKeysPanel() {
mMoreKeysPanelPointerTrackerId = -1;
dimEntireKeyboard(false /* dimmed */); dimEntireKeyboard(false /* dimmed */);
return super.onDismissMoreKeysPanel(); return super.onDismissMoreKeysPanel();
} }

View File

@ -19,76 +19,28 @@ package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.CoordinateUtils; import com.android.inputmethod.latin.CoordinateUtils;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
/** /**
* A view that renders a virtual {@link MoreKeysKeyboard}. It handles rendering of keys and * A view that renders a virtual {@link MoreKeysKeyboard}. It handles rendering of keys and
* detecting key presses and touch movements. * detecting key presses and touch movements.
*/ */
public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel { public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
private final int[] mCoordinates = CoordinateUtils.newInstance(); private final int[] mCoordinates = CoordinateUtils.newInstance();
private final KeyDetector mKeyDetector; private final KeyDetector mKeyDetector;
private Controller mController; private Controller mController;
private KeyboardActionListener mListener; protected KeyboardActionListener mListener;
private int mOriginX; private int mOriginX;
private int mOriginY; private int mOriginY;
private Key mCurrentKey;
private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter(); private int mActivePointerId;
private final KeyboardActionListener mMoreKeysKeyboardListener =
new KeyboardActionListener.Adapter() {
@Override
public void onCodeInput(final int primaryCode, final int x, final int y) {
// Because a more keys keyboard doesn't need proximity characters correction, we don't
// send touch event coordinates.
mListener.onCodeInput(
primaryCode, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
}
@Override
public void onTextInput(final String text) {
mListener.onTextInput(text);
}
@Override
public void onStartBatchInput() {
mListener.onStartBatchInput();
}
@Override
public void onUpdateBatchInput(final InputPointers batchPointers) {
mListener.onUpdateBatchInput(batchPointers);
}
@Override
public void onEndBatchInput(final InputPointers batchPointers) {
mListener.onEndBatchInput(batchPointers);
}
@Override
public void onCancelInput() {
mListener.onCancelInput();
}
@Override
public void onPressKey(final int primaryCode) {
mListener.onPressKey(primaryCode);
}
@Override
public void onReleaseKey(final int primaryCode, final boolean withSliding) {
mListener.onReleaseKey(primaryCode, withSliding);
}
};
public MoreKeysKeyboardView(final Context context, final AttributeSet attrs) { public MoreKeysKeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.moreKeysKeyboardViewStyle); this(context, attrs, R.attr.moreKeysKeyboardViewStyle);
@ -123,26 +75,6 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
-getPaddingTop() + mVerticalCorrection); -getPaddingTop() + mVerticalCorrection);
} }
@Override
public KeyDetector getKeyDetector() {
return mKeyDetector;
}
@Override
public KeyboardActionListener getKeyboardActionListener() {
return mMoreKeysKeyboardListener;
}
@Override
public DrawingProxy getDrawingProxy() {
return this;
}
@Override
public TimerProxy getTimerProxy() {
return EMPTY_TIMER_PROXY;
}
@Override @Override
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) { public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
// More keys keyboard needs no pop-up key preview displayed, so we pass always false with a // More keys keyboard needs no pop-up key preview displayed, so we pass always false with a
@ -156,10 +88,8 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
mController = controller; mController = controller;
mListener = listener; mListener = listener;
final View container = getContainerView(); final View container = getContainerView();
final MoreKeysKeyboard pane = (MoreKeysKeyboard)getKeyboard();
final int defaultCoordX = pane.getDefaultCoordX();
// The coordinates of panel's left-top corner in parentView's coordinate system. // The coordinates of panel's left-top corner in parentView's coordinate system.
final int x = pointX - defaultCoordX - container.getPaddingLeft(); final int x = pointX - getDefaultCoordX() - container.getPaddingLeft();
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom(); final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom();
parentView.getLocationInWindow(mCoordinates); parentView.getLocationInWindow(mCoordinates);
@ -175,6 +105,73 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
controller.onShowMoreKeysPanel(this); controller.onShowMoreKeysPanel(this);
} }
/**
* Returns the default x coordinate for showing this panel.
*/
protected int getDefaultCoordX() {
return ((MoreKeysKeyboard)getKeyboard()).getDefaultCoordX();
}
@Override
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime) {
mActivePointerId = pointerId;
onMoveKeyInternal(x, y, pointerId);
}
@Override
public void onMoveEvent(int x, int y, final int pointerId, long eventTime) {
onMoveKeyInternal(x, y, pointerId);
}
@Override
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
if (mCurrentKey != null && mActivePointerId == pointerId) {
updateReleaseKeyGraphics(mCurrentKey);
onCodeInput(mCurrentKey.mCode, x, y);
mCurrentKey = null;
}
}
/**
* Performs the specific action for this panel when the user presses a key on the panel.
*/
protected void onCodeInput(final int code, final int x, final int y) {
if (code == Constants.CODE_OUTPUT_TEXT) {
mListener.onTextInput(mCurrentKey.getOutputText());
} else if (code != Constants.CODE_UNSPECIFIED) {
mListener.onCodeInput(code, x, y);
}
}
private void onMoveKeyInternal(int x, int y, int pointerId) {
if (mActivePointerId != pointerId) {
// Ignore old pointers when newer pointer is active.
return;
}
final Key oldKey = mCurrentKey;
final Key newKey = mKeyDetector.detectHitKey(x, y);
if (newKey != oldKey) {
mCurrentKey = newKey;
invalidateKey(mCurrentKey);
if (oldKey != null) {
updateReleaseKeyGraphics(oldKey);
}
if (newKey != null) {
updatePressKeyGraphics(newKey);
}
}
}
private void updateReleaseKeyGraphics(final Key key) {
key.onReleased();
invalidateKey(key);
}
private void updatePressKeyGraphics(final Key key) {
key.onPressed();
invalidateKey(key);
}
@Override @Override
public boolean dismissMoreKeysPanel() { public boolean dismissMoreKeysPanel() {
if (mController == null) return false; if (mController == null) return false;
@ -191,6 +188,35 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
return y - mOriginY; return y - mOriginY;
} }
@Override
public boolean onTouchEvent(final MotionEvent me) {
final int action = me.getActionMasked();
final long eventTime = me.getEventTime();
final int index = me.getActionIndex();
final int x = (int)me.getX(index);
final int y = (int)me.getY(index);
final int pointerId = me.getPointerId(index);
processMotionEvent(action, x, y, pointerId, eventTime);
return true;
}
public void processMotionEvent(final int action, final int x, final int y,
final int pointerId, final long eventTime) {
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
onDownEvent(x, y, pointerId, eventTime);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
onUpEvent(x, y, pointerId, eventTime);
break;
case MotionEvent.ACTION_MOVE:
onMoveEvent(x, y, pointerId, eventTime);
break;
}
}
@Override @Override
public View getContainerView() { public View getContainerView() {
return (View)getParent(); return (View)getParent();

View File

@ -18,7 +18,7 @@ package com.android.inputmethod.keyboard;
import android.view.View; import android.view.View;
public interface MoreKeysPanel extends PointerTracker.KeyEventHandler { public interface MoreKeysPanel {
public interface Controller { public interface Controller {
/** /**
* Add the {@link MoreKeysPanel} to the target view. * Add the {@link MoreKeysPanel} to the target view.
@ -27,7 +27,7 @@ public interface MoreKeysPanel extends PointerTracker.KeyEventHandler {
public void onShowMoreKeysPanel(final MoreKeysPanel panel); public void onShowMoreKeysPanel(final MoreKeysPanel panel);
/** /**
* Remove the current {@link MoreKeysPanel} to the target view. * Remove the current {@link MoreKeysPanel} from the target view.
*/ */
public boolean onDismissMoreKeysPanel(); public boolean onDismissMoreKeysPanel();
} }
@ -54,6 +54,36 @@ public interface MoreKeysPanel extends PointerTracker.KeyEventHandler {
*/ */
public boolean dismissMoreKeysPanel(); public boolean dismissMoreKeysPanel();
/**
* Process a move event on the more keys panel.
*
* @param x translated x coordinate of the touch point
* @param y translated y coordinate of the touch point
* @param pointerId pointer id touch point
* @param eventTime timestamp of touch point
*/
public void onMoveEvent(final int x, final int y, final int pointerId, final long eventTime);
/**
* Process a down event on the more keys panel.
*
* @param x translated x coordinate of the touch point
* @param y translated y coordinate of the touch point
* @param pointerId pointer id touch point
* @param eventTime timestamp of touch point
*/
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime);
/**
* Process an up event on the more keys panel.
*
* @param x translated x coordinate of the touch point
* @param y translated y coordinate of the touch point
* @param pointerId pointer id touch point
* @param eventTime timestamp of touch point
*/
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime);
/** /**
* Translate X-coordinate of touch event to the local X-coordinate of this * Translate X-coordinate of touch event to the local X-coordinate of this
* {@link MoreKeysPanel}. * {@link MoreKeysPanel}.

View File

@ -84,7 +84,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public void showSlidingKeyInputPreview(PointerTracker tracker); public void showSlidingKeyInputPreview(PointerTracker tracker);
public void dismissSlidingKeyInputPreview(); public void dismissSlidingKeyInputPreview();
public void showGesturePreviewTrail(PointerTracker tracker, boolean isOldestTracker); public void showGesturePreviewTrail(PointerTracker tracker, boolean isOldestTracker);
public boolean dismissMoreKeysPanel();
} }
public interface TimerProxy { public interface TimerProxy {
@ -319,8 +318,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// true if this pointer is no longer tracking touch event. // true if this pointer is no longer tracking touch event.
private boolean mIsTrackingCanceled; private boolean mIsTrackingCanceled;
// true if this pointer has been long-pressed and is showing a more keys panel. // the more keys panel currently being shown. equals null if no panel is active.
private boolean mIsShowingMoreKeysPanel; private MoreKeysPanel mMoreKeysPanel;
// true if this pointer is in a sliding key input. // true if this pointer is in a sliding key input.
boolean mIsInSlidingKeyInput; boolean mIsInSlidingKeyInput;
@ -812,7 +811,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
printTouchEvent("onDownEvent:", x, y, eventTime); printTouchEvent("onDownEvent:", x, y, eventTime);
} }
mDrawingProxy = handler.getDrawingProxy(); mDrawingProxy = handler.getDrawingProxy();
mTimerProxy = handler.getTimerProxy(); mTimerProxy = handler.getTimerProxy();
setKeyboardActionListener(handler.getKeyboardActionListener()); setKeyboardActionListener(handler.getKeyboardActionListener());
@ -848,7 +846,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
// A gesture should start only from a non-modifier key. // A gesture should start only from a non-modifier key.
mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard() mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard()
&& !mIsShowingMoreKeysPanel && key != null && !key.isModifier(); && !isShowingMoreKeysPanel() && key != null && !key.isModifier();
if (mIsDetectingGesture) { if (mIsDetectingGesture) {
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
sGestureFirstDownTime = eventTime; sGestureFirstDownTime = eventTime;
@ -858,6 +856,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private boolean isShowingMoreKeysPanel() {
return (mMoreKeysPanel != null);
}
private void onDownEventInternal(final int x, final int y, final long eventTime) { private void onDownEventInternal(final int x, final int y, final long eventTime) {
Key key = onDownKey(x, y, eventTime); Key key = onDownKey(x, y, eventTime);
// Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding // Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding
@ -920,6 +922,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return; return;
} }
if (isShowingMoreKeysPanel()) {
final int translatedX = mMoreKeysPanel.translateX(x);
final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
return;
}
if (sShouldHandleGesture && me != null) { if (sShouldHandleGesture && me != null) {
// Add historical points to gesture path. // Add historical points to gesture path.
final int pointerIndex = me.findPointerIndex(mPointerId); final int pointerIndex = me.findPointerIndex(mPointerId);
@ -932,7 +941,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
false /* isMajorEvent */, null); false /* isMajorEvent */, null);
} }
} }
onMoveEventInternal(x, y, eventTime); onMoveEventInternal(x, y, eventTime);
} }
@ -964,7 +972,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.pointerTracker_onMoveEvent(x, y, lastX, lastY); ResearchLogger.pointerTracker_onMoveEvent(x, y, lastX, lastY);
} }
onUpEventInternal(eventTime); onUpEventInternal(x, y, eventTime);
onDownEventInternal(x, y, eventTime); onDownEventInternal(x, y, eventTime);
} }
@ -983,7 +991,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
lastX, lastY, Constants.printableCode(oldKey.mCode), lastX, lastY, Constants.printableCode(oldKey.mCode),
x, y, Constants.printableCode(key.mCode))); x, y, Constants.printableCode(key.mCode)));
} }
onUpEventInternal(eventTime); onUpEventInternal(x, y, eventTime);
onDownEventInternal(x, y, eventTime); onDownEventInternal(x, y, eventTime);
} }
@ -1099,7 +1107,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sPointerTrackerQueue.releaseAllPointersOlderThan(this, eventTime); sPointerTrackerQueue.releaseAllPointersOlderThan(this, eventTime);
} }
} }
onUpEventInternal(eventTime); onUpEventInternal(x, y, eventTime);
sPointerTrackerQueue.remove(this); sPointerTrackerQueue.remove(this);
} }
@ -1111,11 +1119,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
printTouchEvent("onPhntEvent:", mLastX, mLastY, eventTime); printTouchEvent("onPhntEvent:", mLastX, mLastY, eventTime);
} }
onUpEventInternal(eventTime); if (isShowingMoreKeysPanel()) {
return;
}
onUpEventInternal(mLastX, mLastY, eventTime);
cancelTracking(); cancelTracking();
} }
private void onUpEventInternal(final long eventTime) { private void onUpEventInternal(final int x, final int y, final long eventTime) {
mTimerProxy.cancelKeyTimers(); mTimerProxy.cancelKeyTimers();
resetSlidingKeyInput(); resetSlidingKeyInput();
mIsDetectingGesture = false; mIsDetectingGesture = false;
@ -1123,9 +1134,16 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mCurrentKey = null; mCurrentKey = null;
// Release the last pressed key. // Release the last pressed key.
setReleasedKeyGraphics(currentKey); setReleasedKeyGraphics(currentKey);
if (mIsShowingMoreKeysPanel) {
mDrawingProxy.dismissMoreKeysPanel(); if (isShowingMoreKeysPanel()) {
mIsShowingMoreKeysPanel = false; if (!mIsTrackingCanceled) {
final int translatedX = mMoreKeysPanel.translateX(x);
final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime);
}
mMoreKeysPanel.dismissMoreKeysPanel();
mMoreKeysPanel = null;
return;
} }
if (sInGesture) { if (sInGesture) {
@ -1144,10 +1162,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public void onShowMoreKeysPanel(final int x, final int y, final KeyEventHandler handler) { public void onShowMoreKeysPanel(final int translatedX, final int translatedY,
onLongPressed(); final MoreKeysPanel panel) {
mIsShowingMoreKeysPanel = true; setReleasedKeyGraphics(mCurrentKey);
onDownEvent(x, y, SystemClock.uptimeMillis(), handler); final long eventTime = SystemClock.uptimeMillis();
mMoreKeysPanel = panel;
mMoreKeysPanel.onDownEvent(translatedX, translatedY, mPointerId, eventTime);
} }
@Override @Override
@ -1179,10 +1199,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mTimerProxy.cancelKeyTimers(); mTimerProxy.cancelKeyTimers();
setReleasedKeyGraphics(mCurrentKey); setReleasedKeyGraphics(mCurrentKey);
resetSlidingKeyInput(); resetSlidingKeyInput();
if (mIsShowingMoreKeysPanel) { mMoreKeysPanel.dismissMoreKeysPanel();
mDrawingProxy.dismissMoreKeysPanel(); mMoreKeysPanel = null;
mIsShowingMoreKeysPanel = false;
}
} }
private void startRepeatKey(final Key key) { private void startRepeatKey(final Key key) {

View File

@ -17,66 +17,17 @@
package com.android.inputmethod.latin.suggestions; package com.android.inputmethod.latin.suggestions;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.MoreKeysKeyboardView;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MoreKeysDetector;
import com.android.inputmethod.keyboard.MoreKeysPanel;
import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.KeyEventHandler;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.latin.CoordinateUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
/** /**
* A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting * A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting
* key presses and touch movements. * key presses and touch movements.
*/ */
public final class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { public final class MoreSuggestionsView extends MoreKeysKeyboardView {
private final int[] mCoordinates = CoordinateUtils.newInstance();
final KeyDetector mModalPanelKeyDetector;
private final KeyDetector mSlidingPanelKeyDetector;
private Controller mController;
KeyboardActionListener mListener;
private int mOriginX;
private int mOriginY;
static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter();
final KeyboardActionListener mSuggestionsPaneListener =
new KeyboardActionListener.Adapter() {
@Override
public void onPressKey(final int primaryCode) {
mListener.onPressKey(primaryCode);
}
@Override
public void onReleaseKey(final int primaryCode, final boolean withSliding) {
mListener.onReleaseKey(primaryCode, withSliding);
}
@Override
public void onCodeInput(final int primaryCode, final int x, final int y) {
final int index = primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE;
if (index >= 0 && index < SuggestionStripView.MAX_SUGGESTIONS) {
mListener.onCustomRequest(index);
}
}
@Override
public void onCancelInput() {
mListener.onCancelInput();
}
};
public MoreSuggestionsView(final Context context, final AttributeSet attrs) { public MoreSuggestionsView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.moreSuggestionsViewStyle); this(context, attrs, R.attr.moreSuggestionsViewStyle);
@ -85,12 +36,12 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
public MoreSuggestionsView(final Context context, final AttributeSet attrs, public MoreSuggestionsView(final Context context, final AttributeSet attrs,
final int defStyle) { final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
}
final Resources res = context.getResources(); @Override
mModalPanelKeyDetector = new KeyDetector(/* keyHysteresisDistance */ 0); protected int getDefaultCoordX() {
mSlidingPanelKeyDetector = new MoreKeysDetector( final MoreSuggestions pane = (MoreSuggestions)getKeyboard();
res.getDimension(R.dimen.more_suggestions_slide_allowance)); return pane.mOccupiedWidth / 2;
setKeyPreviewPopupEnabled(false, 0);
} }
@Override @Override
@ -110,119 +61,11 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
} }
@Override @Override
public void setKeyboard(final Keyboard keyboard) { public void onCodeInput(final int primaryCode, final int x, final int y) {
super.setKeyboard(keyboard); final int index = primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE;
mModalPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop()); if (index >= 0 && index < SuggestionStripView.MAX_SUGGESTIONS) {
mSlidingPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), mListener.onCustomRequest(index);
-getPaddingTop() + mVerticalCorrection);
} }
@Override
public KeyDetector getKeyDetector() {
return mSlidingPanelKeyDetector;
}
@Override
public KeyboardActionListener getKeyboardActionListener() {
return mSuggestionsPaneListener;
}
@Override
public DrawingProxy getDrawingProxy() {
return this;
}
@Override
public TimerProxy getTimerProxy() {
return EMPTY_TIMER_PROXY;
}
@Override
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
// Suggestions pane needs no pop-up key preview displayed, so we pass always false with a
// delay of 0. The delay does not matter actually since the popup is not shown anyway.
super.setKeyPreviewPopupEnabled(false, 0);
}
@Override
public void showMoreKeysPanel(final View parentView, final Controller controller,
final int pointX, final int pointY, final KeyboardActionListener listener) {
mController = controller;
mListener = listener;
final View container = getContainerView();
final MoreSuggestions pane = (MoreSuggestions)getKeyboard();
final int defaultCoordX = pane.mOccupiedWidth / 2;
// The coordinates of panel's left-top corner in parentView's coordinate system.
final int x = pointX - defaultCoordX - container.getPaddingLeft();
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom();
parentView.getLocationInWindow(mCoordinates);
// Ensure the horizontal position of the panel does not extend past the screen edges.
final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
final int panelX = Math.max(0, Math.min(maxX, x + CoordinateUtils.x(mCoordinates)));
final int panelY = y + CoordinateUtils.y(mCoordinates);
container.setX(panelX);
container.setY(panelY);
mOriginX = x + container.getPaddingLeft();
mOriginY = y + container.getPaddingTop();
controller.onShowMoreKeysPanel(this);
}
@Override
public boolean dismissMoreKeysPanel() {
if (mController == null) return false;
return mController.onDismissMoreKeysPanel();
}
@Override
public int translateX(final int x) {
return x - mOriginX;
}
@Override
public int translateY(final int y) {
return y - mOriginY;
}
private final KeyEventHandler mModalPanelKeyEventHandler = new KeyEventHandler() {
@Override
public KeyDetector getKeyDetector() {
return mModalPanelKeyDetector;
}
@Override
public KeyboardActionListener getKeyboardActionListener() {
return mSuggestionsPaneListener;
}
@Override
public DrawingProxy getDrawingProxy() {
return MoreSuggestionsView.this;
}
@Override
public TimerProxy getTimerProxy() {
return EMPTY_TIMER_PROXY;
}
};
@Override
public boolean onTouchEvent(final MotionEvent me) {
final int action = me.getAction();
final long eventTime = me.getEventTime();
final int index = me.getActionIndex();
final int id = me.getPointerId(index);
final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
final int x = (int)me.getX(index);
final int y = (int)me.getY(index);
tracker.processMotionEvent(action, x, y, eventTime, mModalPanelKeyEventHandler);
return true;
}
@Override
public View getContainerView() {
return (View)getParent();
} }
@Override @Override

View File

@ -54,7 +54,6 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MoreKeysPanel; import com.android.inputmethod.keyboard.MoreKeysPanel;
import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.ViewLayoutUtils; import com.android.inputmethod.keyboard.ViewLayoutUtils;
import com.android.inputmethod.latin.AutoCorrection; import com.android.inputmethod.latin.AutoCorrection;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
@ -771,7 +770,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
final long eventTime = me.getEventTime(); final long eventTime = me.getEventTime();
final int index = me.getActionIndex(); final int index = me.getActionIndex();
final int id = me.getPointerId(index); final int id = me.getPointerId(index);
final PointerTracker tracker = PointerTracker.getPointerTracker(id, moreKeysPanel);
final int x = (int)me.getX(index); final int x = (int)me.getX(index);
final int y = (int)me.getY(index); final int y = (int)me.getY(index);
final int translatedX = moreKeysPanel.translateX(x); final int translatedX = moreKeysPanel.translateX(x);
@ -783,7 +781,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
// Decided to be in the sliding input mode only when the touch point has been moved // Decided to be in the sliding input mode only when the touch point has been moved
// upward. // upward.
mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE; mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE;
tracker.onShowMoreKeysPanel(translatedX, translatedY, moreKeysPanel);
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
// Decided to be in the modal input mode // Decided to be in the modal input mode
mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE; mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
@ -792,7 +789,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
// MORE_SUGGESTIONS_IN_SLIDING_MODE // MORE_SUGGESTIONS_IN_SLIDING_MODE
tracker.processMotionEvent(action, translatedX, translatedY, eventTime, moreKeysPanel); mMoreSuggestionsView.processMotionEvent(action, translatedX, translatedY, id, eventTime);
return true; return true;
} }