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 android.widget.LinearLayout;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.suggestions.MoreSuggestionsView;
import com.android.inputmethod.latin.suggestions.SuggestionStripView; import com.android.inputmethod.latin.suggestions.SuggestionStripView;
public final class InputView extends LinearLayout { public final class InputView extends LinearLayout {
private final Rect mInputViewRect = new Rect(); private final Rect mInputViewRect = new Rect();
private KeyboardTopPaddingForwarder mKeyboardTopPaddingForwarder; private KeyboardTopPaddingForwarder mKeyboardTopPaddingForwarder;
private MoreSuggestionsViewCanceler mMoreSuggestionsViewCanceler;
public InputView(final Context context, final AttributeSet attrs) { public InputView(final Context context, final AttributeSet attrs) {
super(context, attrs, 0); super(context, attrs, 0);
@ -42,6 +44,8 @@ public final class InputView extends LinearLayout {
(MainKeyboardView)findViewById(R.id.keyboard_view); (MainKeyboardView)findViewById(R.id.keyboard_view);
mKeyboardTopPaddingForwarder = new KeyboardTopPaddingForwarder( mKeyboardTopPaddingForwarder = new KeyboardTopPaddingForwarder(
mainKeyboardView, suggestionStripView); mainKeyboardView, suggestionStripView);
mMoreSuggestionsViewCanceler = new MoreSuggestionsViewCanceler(
mainKeyboardView, suggestionStripView);
} }
public void setKeyboardTopPadding(final int keyboardTopPadding) { public void setKeyboardTopPadding(final int keyboardTopPadding) {
@ -60,6 +64,11 @@ public final class InputView extends LinearLayout {
if (mKeyboardTopPaddingForwarder.dispatchTouchEvent(x, y, me)) { if (mKeyboardTopPaddingForwarder.dispatchTouchEvent(x, y, me)) {
return true; 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); return super.dispatchTouchEvent(me);
} }
@ -97,6 +106,9 @@ public final class InputView extends LinearLayout {
return y - mEventReceivingRect.top; 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. // Dispatches a {@link MotioneEvent} to <code>Receiver</code> if needed and returns true.
// Otherwise returns false. // Otherwise returns false.
public boolean dispatchTouchEvent(final int x, final int y, final MotionEvent me) { 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. // Translate global coordinates to <code>Receiver</code> local coordinates.
me.setLocation(translateX(x), translateY(y)); me.setLocation(translateX(x), translateY(y));
mReceiverView.dispatchTouchEvent(me); mReceiverView.dispatchTouchEvent(me);
onForwardingEvent(me);
return true; return true;
} }
} }
@ -183,4 +196,30 @@ public final class InputView extends LinearLayout {
return translatedY; 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(); mSuggestionsStrip.removeAllViews();
removeAllViews(); removeAllViews();
addView(mSuggestionsStrip); addView(mSuggestionsStrip);
mMoreSuggestionsView.dismissMoreKeysPanel(); dismissMoreSuggestionsPanel();
} }
private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() { private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() {
@Override @Override
public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) { public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) {
mListener.pickSuggestionManually(index, wordInfo); mListener.pickSuggestionManually(index, wordInfo);
mMoreSuggestionsView.dismissMoreKeysPanel(); dismissMoreSuggestionsPanel();
} }
@Override @Override
public void onCancelInput() { public void onCancelInput() {
mMoreSuggestionsView.dismissMoreKeysPanel(); dismissMoreSuggestionsPanel();
} }
}; };
@ -192,10 +192,18 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@Override @Override
public void onCancelMoreKeysPanel(final MoreKeysPanel panel) { public void onCancelMoreKeysPanel(final MoreKeysPanel panel) {
mMoreSuggestionsView.dismissMoreKeysPanel(); dismissMoreSuggestionsPanel();
} }
}; };
public boolean isShowingMoreSuggestionPanel() {
return mMoreSuggestionsView.isShowingInParent();
}
public void dismissMoreSuggestionsPanel() {
mMoreSuggestionsView.dismissMoreKeysPanel();
}
@Override @Override
public boolean onLongClick(final View view) { public boolean onLongClick(final View view) {
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback( AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
@ -322,6 +330,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@Override @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
mMoreSuggestionsView.dismissMoreKeysPanel(); dismissMoreSuggestionsPanel();
} }
} }