Bug 762309 - Show and hide the on-screen keyboard along with the Find In Page bar [r=bnicholson]

This commit is contained in:
Matt Brubeck 2012-07-11 16:06:25 -07:00
parent b0860d1763
commit 3f0c0cb5de
2 changed files with 46 additions and 7 deletions

View File

@ -12,15 +12,19 @@ import android.view.View;
import android.widget.EditText;
public class CustomEditText extends EditText {
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mOnKeyPreImeListener = null;
}
OnKeyPreImeListener mOnKeyPreImeListener;
public interface OnKeyPreImeListener {
public boolean onKeyPreIme(View v, int keyCode, KeyEvent event);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mOnKeyPreImeListener = null;
public void setOnKeyPreImeListener(OnKeyPreImeListener listener) {
mOnKeyPreImeListener = listener;
}
@Override
@ -31,7 +35,20 @@ public class CustomEditText extends EditText {
return false;
}
public void setOnKeyPreImeListener(OnKeyPreImeListener listener) {
mOnKeyPreImeListener = listener;
public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) {
mOnWindowFocusChangeListener = listener;
}
OnWindowFocusChangeListener mOnWindowFocusChangeListener;
public interface OnWindowFocusChangeListener {
public void onWindowFocusChanged(boolean hasFocus);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (mOnWindowFocusChangeListener != null)
mOnWindowFocusChangeListener.onWindowFocusChanged(hasFocus);
}
}

View File

@ -13,6 +13,7 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
@ -56,15 +57,36 @@ public class FindInPageBar extends RelativeLayout implements TextWatcher, View.O
if (!mInflated)
inflateContent();
setVisibility(VISIBLE);
setVisibility(VISIBLE);
mFindText.requestFocus();
// Show the virtual keyboard.
if (mFindText.hasWindowFocus()) {
getInputMethodManager(mFindText).showSoftInput(mFindText, 0);
} else {
// showSoftInput won't work until after the window is focused.
mFindText.setOnWindowFocusChangeListener(new CustomEditText.OnWindowFocusChangeListener() {
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus)
return;
mFindText.setOnWindowFocusChangeListener(null);
getInputMethodManager(mFindText).showSoftInput(mFindText, 0);
}
});
}
}
public void hide() {
setVisibility(GONE);
setVisibility(GONE);
getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FindInPage:Closed", null));
}
private InputMethodManager getInputMethodManager(View view) {
Context context = view.getContext();
return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
}
// TextWatcher implementation
public void afterTextChanged(Editable s) {