Merge "Showing popup preview only when IME is in foreground"

main
Tadashi G. Takaoka 2010-10-17 19:55:15 -07:00 committed by Android (Google) Code Review
commit 4571fff019
2 changed files with 28 additions and 10 deletions

View File

@ -680,6 +680,7 @@ public class LatinIME extends InputMethodService
// If we just entered a text field, maybe it has some old text that requires correction // If we just entered a text field, maybe it has some old text that requires correction
checkReCorrectionOnStart(); checkReCorrectionOnStart();
checkTutorial(attribute.privateImeOptions); checkTutorial(attribute.privateImeOptions);
inputView.setForeground(true);
if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
} }
@ -731,6 +732,9 @@ public class LatinIME extends InputMethodService
@Override @Override
public void onFinishInputView(boolean finishingInput) { public void onFinishInputView(boolean finishingInput) {
super.onFinishInputView(finishingInput); super.onFinishInputView(finishingInput);
LatinKeyboardBaseView inputView = mKeyboardSwitcher.getInputView();
if (inputView != null)
inputView.setForeground(false);
// Remove penging messages related to update suggestions // Remove penging messages related to update suggestions
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS); mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
mHandler.removeMessages(MSG_UPDATE_OLD_SUGGESTIONS); mHandler.removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);

View File

@ -43,6 +43,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.TextView; import android.widget.TextView;
@ -184,6 +185,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
private int mKeyboardVerticalGap; private int mKeyboardVerticalGap;
// Key preview popup // Key preview popup
private boolean mInForeground;
private TextView mPreviewText; private TextView mPreviewText;
private PopupWindow mPreviewPopup; private PopupWindow mPreviewPopup;
private int mPreviewTextSizeLarge; private int mPreviewTextSizeLarge;
@ -573,7 +575,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
/** /**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the * Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard. * view will re-layout itself to accommodate the keyboard.
* @see Keyboard * @see BaseKeyboard
* @see #getKeyboard() * @see #getKeyboard()
* @param keyboard the keyboard to display in this view * @param keyboard the keyboard to display in this view
*/ */
@ -603,7 +605,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
/** /**
* Returns the current keyboard being displayed by this view. * Returns the current keyboard being displayed by this view.
* @return the currently attached keyboard * @return the currently attached keyboard
* @see #setKeyboard(Keyboard) * @see #setKeyboard(BaseKeyboard)
*/ */
public BaseKeyboard getKeyboard() { public BaseKeyboard getKeyboard() {
return mKeyboard; return mKeyboard;
@ -918,6 +920,10 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
mDirtyRect.setEmpty(); mDirtyRect.setEmpty();
} }
public void setForeground(boolean foreground) {
mInForeground = foreground;
}
// TODO: clean up this method. // TODO: clean up this method.
private void dismissKeyPreview() { private void dismissKeyPreview() {
for (PointerTracker tracker : mPointerTrackers) for (PointerTracker tracker : mPointerTrackers)
@ -951,7 +957,10 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
// TODO Must fix popup preview on xlarge layout // TODO Must fix popup preview on xlarge layout
private void showKey(final int keyIndex, PointerTracker tracker) { private void showKey(final int keyIndex, PointerTracker tracker) {
Key key = tracker.getKey(keyIndex); Key key = tracker.getKey(keyIndex);
if (key == null) // If keyIndex is invalid or IME is already closed, we must not show key preview.
// Trying to show preview PopupWindow while root window is closed causes
// WindowManager.BadTokenException.
if (key == null || !mInForeground)
return; return;
// Should not draw number hint icons // Should not draw number hint icons
if (key.icon != null && key.label == null) { if (key.icon != null && key.label == null) {
@ -1012,6 +1021,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
popupPreviewY += popupHeight; popupPreviewY += popupHeight;
} }
try {
if (mPreviewPopup.isShowing()) { if (mPreviewPopup.isShowing()) {
mPreviewPopup.update(popupPreviewX, popupPreviewY, popupWidth, popupHeight); mPreviewPopup.update(popupPreviewX, popupPreviewY, popupWidth, popupHeight);
} else { } else {
@ -1020,6 +1030,10 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
mPreviewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY, mPreviewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY,
popupPreviewX, popupPreviewY); popupPreviewX, popupPreviewY);
} }
} catch (WindowManager.BadTokenException e) {
// Swallow the exception which will be happened when IME is already closed.
Log.w(TAG, "LatinIME is already closed when tried showing key preview.");
}
// Record popup preview position to display mini-keyboard later at the same positon // Record popup preview position to display mini-keyboard later at the same positon
mPopupPreviewDisplayedY = popupPreviewY; mPopupPreviewDisplayedY = popupPreviewY;
mPreviewText.setVisibility(VISIBLE); mPreviewText.setVisibility(VISIBLE);