From 50e1073e11240fe51b3baf0e2ed80dac0d9f001d Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 6 Sep 2011 11:37:51 +0900 Subject: [PATCH] More suggestions view can be modal Bug: 5241105 Change-Id: Ib430ee129b9f3cad0bdb1ae083b1068c51a5f2ea --- java/res/values/dimens.xml | 3 +- .../keyboard/LatinKeyboardView.java | 2 - .../keyboard/MiniKeyboardView.java | 6 +-- .../latin/MoreSuggestionsView.java | 53 ++++++++++++++++--- .../inputmethod/latin/SuggestionsView.java | 39 +++++++++++--- 5 files changed, 83 insertions(+), 20 deletions(-) diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 9c2100b93..feb119db2 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -80,7 +80,8 @@ 12dip 40dip 6dip - 0.2in + 0.05in + 0.1in 6 90% 18% diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index f09542c54..4ec16bdcf 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -438,8 +438,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke mMoreKeysWindow = new PopupWindow(getContext()); mMoreKeysWindow.setBackgroundDrawable(null); mMoreKeysWindow.setAnimationStyle(R.style.MiniKeyboardAnimation); - // Allow popup window to be drawn off the screen. - mMoreKeysWindow.setClippingEnabled(false); } mMoreKeysPanel = moreKeysPanel; mMoreKeysPanelPointerTrackerId = tracker.mPointerId; diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java index 29861fe4a..0e6e129bb 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java @@ -79,10 +79,8 @@ public class MiniKeyboardView extends KeyboardView implements MoreKeysPanel { super(context, attrs, defStyle); final Resources res = context.getResources(); - // Override default ProximityKeyDetector. - mKeyDetector = new MoreKeysDetector(res.getDimension( - R.dimen.mini_keyboard_slide_allowance)); - // Remove gesture detector on mini-keyboard + mKeyDetector = new MoreKeysDetector( + res.getDimension(R.dimen.mini_keyboard_slide_allowance)); setKeyPreviewPopupEnabled(false, 0); } diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java index 0f8192bbb..f595510a3 100644 --- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.res.Resources; import android.util.AttributeSet; import android.view.Gravity; +import android.view.MotionEvent; import android.view.View; import android.widget.PopupWindow; @@ -29,7 +30,9 @@ import com.android.inputmethod.keyboard.KeyboardActionListener; 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; @@ -40,7 +43,8 @@ import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { private final int[] mCoordinates = new int[2]; - private final KeyDetector mKeyDetector; + private final KeyDetector mModalPanelKeyDetector; + private final KeyDetector mSlidingPanelKeyDetector; private Controller mController; private KeyboardActionListener mListener; @@ -80,10 +84,9 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { super(context, attrs, defStyle); final Resources res = context.getResources(); - // Override default ProximityKeyDetector. - mKeyDetector = new MoreKeysDetector(res.getDimension( - R.dimen.more_suggestions_slide_allowance)); - // Remove gesture detector on suggestions pane + mModalPanelKeyDetector = new KeyDetector(/* keyHysteresisDistance */ 0); + mSlidingPanelKeyDetector = new MoreKeysDetector( + res.getDimension(R.dimen.more_suggestions_slide_allowance)); setKeyPreviewPopupEnabled(false, 0); } @@ -102,13 +105,14 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { @Override public void setKeyboard(Keyboard keyboard) { super.setKeyboard(keyboard); - mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), + mModalPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop()); + mSlidingPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); } @Override public KeyDetector getKeyDetector() { - return mKeyDetector; + return mSlidingPanelKeyDetector; } @Override @@ -187,4 +191,39 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { public int translateY(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(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; + } } diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 16ecc59ae..22aa5e259 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -503,6 +503,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mMoreSuggestionsWindow.setWindowLayoutMode( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mMoreSuggestionsWindow.setBackgroundDrawable(null); + final Resources res = context.getResources(); + mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset( + R.dimen.more_suggestions_modal_tolerance); } /** @@ -747,12 +750,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, moreKeysPanel.showMoreKeysPanel( this, mMoreSuggestionsController, pointX, pointY, mMoreSuggestionsWindow, mMoreSuggestionsListener); - // TODO: Should figure out how to select the pointer tracker correctly. - final PointerTracker tracker = PointerTracker.getPointerTracker(0, moreKeysPanel); - final int translatedX = moreKeysPanel.translateX(tracker.getLastX()); - final int translatedY = moreKeysPanel.translateY(tracker.getLastY()); - tracker.onShowMoreKeysPanel( - translatedX, translatedY, SystemClock.uptimeMillis(), moreKeysPanel); + mCheckingIfModalOrSlidingMode = true; + mOriginX = mLastX; + mOriginY = mLastY; view.setPressed(false); mKeyboardView.dimEntireKeyboard(true); return true; @@ -760,9 +760,19 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, return false; } + // Working variables for onLongClick and dispatchTouchEvent. + private boolean mCheckingIfModalOrSlidingMode; + private int mLastX; + private int mLastY; + private int mOriginX; + private int mOriginY; + private final int mMoreSuggestionsModalTolerance; + @Override public boolean dispatchTouchEvent(MotionEvent me) { if (!mMoreSuggestionsWindow.isShowing()) { + mLastX = (int)me.getX(); + mLastY = (int)me.getY(); return super.dispatchTouchEvent(me); } @@ -777,6 +787,23 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, final int translatedX = moreKeysPanel.translateX(x); final int translatedY = moreKeysPanel.translateY(y); + if (mCheckingIfModalOrSlidingMode) { + final int deltaX = Math.abs(x - mOriginX); + final int deltaY = Math.abs(y - mOriginY); + if (deltaX >= mMoreSuggestionsModalTolerance + || deltaY >= mMoreSuggestionsModalTolerance) { + // Decided to be in the sliding input mode + mCheckingIfModalOrSlidingMode = false; + tracker.onShowMoreKeysPanel( + translatedX, translatedY, SystemClock.uptimeMillis(), moreKeysPanel); + } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { + // Decided to be in the modal input mode + mCheckingIfModalOrSlidingMode = false; + } + return true; + } + + // Process sliding motion events tracker.processMotionEvent(action, translatedX, translatedY, eventTime, moreKeysPanel); return true; }