Cancel more suggestions panel when touching keyboard

Bug: 10010128
Change-Id: I2ff0870c69f407d943caf8b9cec90b7ed89de5f1
This commit is contained in:
Tadashi G. Takaoka 2013-12-16 18:02:58 +09:00
parent dd4937848a
commit 19dd753c0c
2 changed files with 52 additions and 5 deletions

View File

@ -24,11 +24,13 @@ import android.view.View;
import android.widget.LinearLayout;
import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.suggestions.MoreSuggestionsView;
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
public final class InputView extends LinearLayout {
private final Rect mInputViewRect = new Rect();
private KeyboardTopPaddingForwarder mKeyboardTopPaddingForwarder;
private MoreSuggestionsViewCanceler mMoreSuggestionsViewCanceler;
public InputView(final Context context, final AttributeSet attrs) {
super(context, attrs, 0);
@ -42,6 +44,8 @@ public final class InputView extends LinearLayout {
(MainKeyboardView)findViewById(R.id.keyboard_view);
mKeyboardTopPaddingForwarder = new KeyboardTopPaddingForwarder(
mainKeyboardView, suggestionStripView);
mMoreSuggestionsViewCanceler = new MoreSuggestionsViewCanceler(
mainKeyboardView, suggestionStripView);
}
public void setKeyboardTopPadding(final int keyboardTopPadding) {
@ -60,6 +64,11 @@ public final class InputView extends LinearLayout {
if (mKeyboardTopPaddingForwarder.dispatchTouchEvent(x, y, me)) {
return true;
}
// To cancel {@link MoreSuggestionsView}, we should intercept a touch event to
// {@link MainKeyboardView} and dismiss the {@link MoreSuggestionsView}.
if (mMoreSuggestionsViewCanceler.dispatchTouchEvent(x, y, me)) {
return true;
}
return super.dispatchTouchEvent(me);
}
@ -97,6 +106,9 @@ public final class InputView extends LinearLayout {
return y - mEventReceivingRect.top;
}
// Callback when a {@link MotionEvent} is forwarded.
protected void onForwardingEvent(final MotionEvent me) {}
// Dispatches a {@link MotioneEvent} to <code>Receiver</code> if needed and returns true.
// Otherwise returns false.
public boolean dispatchTouchEvent(final int x, final int y, final MotionEvent me) {
@ -142,6 +154,7 @@ public final class InputView extends LinearLayout {
// Translate global coordinates to <code>Receiver</code> local coordinates.
me.setLocation(translateX(x), translateY(y));
mReceiverView.dispatchTouchEvent(me);
onForwardingEvent(me);
return true;
}
}
@ -183,4 +196,30 @@ public final class InputView extends LinearLayout {
return translatedY;
}
}
/**
* This class forwards {@link MotionEvent}s happened in the {@link MainKeyboardView} to
* {@link SuggestionStripView} when the {@link MoreSuggestionsView} is showing.
* {@link SuggestionStripView} dismisses {@link MoreSuggestionsView} when it receives those
* events.
*/
private static class MoreSuggestionsViewCanceler
extends MotionEventForwarder<MainKeyboardView, SuggestionStripView> {
public MoreSuggestionsViewCanceler(final MainKeyboardView mainKeyboardView,
final SuggestionStripView suggestionStripView) {
super(mainKeyboardView, suggestionStripView);
}
@Override
protected boolean needsToForward(final int x, final int y) {
return mReceiverView.isShowingMoreSuggestionPanel() && mEventSendingRect.contains(x, y);
}
@Override
protected void onForwardingEvent(final MotionEvent me) {
if (me.getActionMasked() == MotionEvent.ACTION_DOWN) {
mReceiverView.dismissMoreSuggestionsPanel();
}
}
}
}

View File

@ -162,19 +162,19 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mSuggestionsStrip.removeAllViews();
removeAllViews();
addView(mSuggestionsStrip);
mMoreSuggestionsView.dismissMoreKeysPanel();
dismissMoreSuggestionsPanel();
}
private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() {
@Override
public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) {
mListener.pickSuggestionManually(index, wordInfo);
mMoreSuggestionsView.dismissMoreKeysPanel();
dismissMoreSuggestionsPanel();
}
@Override
public void onCancelInput() {
mMoreSuggestionsView.dismissMoreKeysPanel();
dismissMoreSuggestionsPanel();
}
};
@ -192,10 +192,18 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@Override
public void onCancelMoreKeysPanel(final MoreKeysPanel panel) {
mMoreSuggestionsView.dismissMoreKeysPanel();
dismissMoreSuggestionsPanel();
}
};
public boolean isShowingMoreSuggestionPanel() {
return mMoreSuggestionsView.isShowingInParent();
}
public void dismissMoreSuggestionsPanel() {
mMoreSuggestionsView.dismissMoreKeysPanel();
}
@Override
public boolean onLongClick(final View view) {
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
@ -322,6 +330,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mMoreSuggestionsView.dismissMoreKeysPanel();
dismissMoreSuggestionsPanel();
}
}