am ac69ab40: Refactor more keys menu framework (part 3)

* commit 'ac69ab400d1ea4f90b4ca24486d62212decf1069':
  Refactor more keys menu framework (part 3)
main
Tom Ouyang 2012-12-13 23:32:31 -08:00 committed by Android Git Automerger
commit 7f0e083bef
6 changed files with 56 additions and 9 deletions

View File

@ -1013,7 +1013,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
public void closing() { public void closing() {
dismissAllKeyPreviews(); dismissAllKeyPreviews();
cancelAllMessages(); cancelAllMessages();
onCancelMoreKeysPanel();
mInvalidateAllKeys = true; mInvalidateAllKeys = true;
requestLayout(); requestLayout();
} }
@ -1031,11 +1031,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
return (mMoreKeysPanel != null); return (mMoreKeysPanel != null);
} }
public boolean dismissMoreKeysPanel() { @Override
public void onCancelMoreKeysPanel() {
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
return mMoreKeysPanel.dismissMoreKeysPanel(); mMoreKeysPanel.dismissMoreKeysPanel();
} }
return false;
} }
@Override @Override

View File

@ -844,10 +844,16 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override @Override
public void closing() { public void closing() {
super.closing(); super.closing();
dismissMoreKeysPanel(); onCancelMoreKeysPanel();
mMoreKeysPanelCache.clear(); mMoreKeysPanelCache.clear();
} }
@Override
public void onCancelMoreKeysPanel() {
super.onCancelMoreKeysPanel();
PointerTracker.dismissAllMoreKeysPanels();
}
@Override @Override
public boolean onDismissMoreKeysPanel() { public boolean onDismissMoreKeysPanel() {
dimEntireKeyboard(false /* dimmed */); dimEntireKeyboard(false /* dimmed */);

View File

@ -120,7 +120,15 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
@Override @Override
public void onMoveEvent(int x, int y, final int pointerId, long eventTime) { public void onMoveEvent(int x, int y, final int pointerId, long eventTime) {
if (mActivePointerId != pointerId) {
return;
}
final boolean hasOldKey = (mCurrentKey != null);
onMoveKeyInternal(x, y, pointerId); onMoveKeyInternal(x, y, pointerId);
if (hasOldKey && mCurrentKey == null) {
// If the pointer has moved too far away from any target then cancel the panel.
mController.onCancelMoreKeysPanel();
}
} }
@Override @Override

View File

@ -30,6 +30,11 @@ public interface MoreKeysPanel {
* Remove the current {@link MoreKeysPanel} from the target view. * Remove the current {@link MoreKeysPanel} from the target view.
*/ */
public boolean onDismissMoreKeysPanel(); public boolean onDismissMoreKeysPanel();
/**
* Instructs the parent to cancel the panel (e.g., when entering a different input mode).
*/
public void onCancelMoreKeysPanel();
} }
/** /**

View File

@ -412,6 +412,17 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public static void dismissAllMoreKeysPanels() {
final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
if (tracker.isShowingMoreKeysPanel()) {
tracker.mMoreKeysPanel.dismissMoreKeysPanel();
tracker.mMoreKeysPanel = null;
}
}
}
private PointerTracker(final int id, final KeyEventHandler handler) { private PointerTracker(final int id, final KeyEventHandler handler) {
if (handler == null) { if (handler == null) {
throw new NullPointerException(); throw new NullPointerException();
@ -715,6 +726,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sLastRecognitionPointSize = 0; sLastRecognitionPointSize = 0;
sLastRecognitionTime = 0; sLastRecognitionTime = 0;
mListener.onStartBatchInput(); mListener.onStartBatchInput();
dismissAllMoreKeysPanels();
} }
mTimerProxy.cancelLongPressTimer(); mTimerProxy.cancelLongPressTimer();
mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this)); mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this));
@ -846,7 +858,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()
&& !isShowingMoreKeysPanel() && key != null && !key.isModifier(); && key != null && !key.isModifier();
if (mIsDetectingGesture) { if (mIsDetectingGesture) {
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
sGestureFirstDownTime = eventTime; sGestureFirstDownTime = eventTime;
@ -907,6 +919,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
cancelBatchInput(); cancelBatchInput();
return; return;
} }
// If the MoreKeysPanel is showing then do not attempt to enter gesture mode. However,
// the gestured touch points are still being recorded in case the panel is dismissed.
if (isShowingMoreKeysPanel()) {
return;
}
mayStartBatchInput(key); mayStartBatchInput(key);
if (sInGesture) { if (sInGesture) {
mayUpdateBatchInput(eventTime, key); mayUpdateBatchInput(eventTime, key);
@ -926,7 +943,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final int translatedX = mMoreKeysPanel.translateX(x); final int translatedX = mMoreKeysPanel.translateX(x);
final int translatedY = mMoreKeysPanel.translateY(y); final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime); mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
return;
} }
if (sShouldHandleGesture && me != null) { if (sShouldHandleGesture && me != null) {
@ -941,6 +957,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
false /* isMajorEvent */, null); false /* isMajorEvent */, null);
} }
} }
if (isShowingMoreKeysPanel()) {
// Do not handle sliding keys (or show key pop-ups) when the MoreKeysPanel is visible.
return;
}
onMoveEventInternal(x, y, eventTime); onMoveEventInternal(x, y, eventTime);
} }
@ -1199,9 +1220,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mTimerProxy.cancelKeyTimers(); mTimerProxy.cancelKeyTimers();
setReleasedKeyGraphics(mCurrentKey); setReleasedKeyGraphics(mCurrentKey);
resetSlidingKeyInput(); resetSlidingKeyInput();
if (isShowingMoreKeysPanel()) {
mMoreKeysPanel.dismissMoreKeysPanel(); mMoreKeysPanel.dismissMoreKeysPanel();
mMoreKeysPanel = null; mMoreKeysPanel = null;
} }
}
private void startRepeatKey(final Key key) { private void startRepeatKey(final Key key) {
if (key != null && key.isRepeatable() && !sInGesture) { if (key != null && key.isRepeatable() && !sInGesture) {

View File

@ -684,6 +684,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public void onShowMoreKeysPanel(MoreKeysPanel panel) { public void onShowMoreKeysPanel(MoreKeysPanel panel) {
mKeyboardView.onShowMoreKeysPanel(panel); mKeyboardView.onShowMoreKeysPanel(panel);
} }
@Override
public void onCancelMoreKeysPanel() {
dismissMoreSuggestions();
}
}; };
boolean dismissMoreSuggestions() { boolean dismissMoreSuggestions() {