Merge "More suggestions view can be modal"

main
Tadashi G. Takaoka 2011-09-06 03:24:04 -07:00 committed by Android (Google) Code Review
commit c811ec7328
5 changed files with 83 additions and 20 deletions

View File

@ -80,7 +80,8 @@
<dimen name="more_suggestions_key_horizontal_padding">12dip</dimen>
<dimen name="more_suggestions_row_height">40dip</dimen>
<dimen name="more_suggestions_bottom_gap">6dip</dimen>
<dimen name="more_suggestions_slide_allowance">0.2in</dimen>
<dimen name="more_suggestions_modal_tolerance">0.05in</dimen>
<dimen name="more_suggestions_slide_allowance">0.1in</dimen>
<integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction>
<fraction name="more_suggestions_info_ratio">18%</fraction>

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}