diff --git a/res/layout/search_normal.xml b/res/layout/search_normal.xml
index 1c0b2f077..9f9e5749c 100644
--- a/res/layout/search_normal.xml
+++ b/res/layout/search_normal.xml
@@ -19,7 +19,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
- android:orientation="vertical" >
+ android:orientation="vertical"
+ android:focusableInTouchMode="true" >
mAllSuggestions;
private ArrayAdapter mAdapte;
+ private boolean mKeyboardIsShowing = true;
+
public SuggestionTextView(Context context) {
super(context);
}
@@ -43,14 +49,6 @@ public class SuggestionTextView extends PrefixEditText {
super(context, attrs, defStyle);
}
- /**
- * We override this method to avoid replacing the query box text when a
- * suggestion is clicked.
- */
- @Override
- protected void replaceText(CharSequence text) {
- }
-
/**
* We override this method to avoid an extra onItemClick being called on
* the drop-down's OnItemClickListener by
@@ -70,11 +68,52 @@ public class SuggestionTextView extends PrefixEditText {
return true;
}
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if (!isPopupShowing())
+ showDropDown();
+
+ return super.onTouchEvent(event);
+ }
+
+ @Override
+ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ // special case for the back key, we do not even try to send it
+ // to the drop down list but instead, consume it immediately
+ if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
+ KeyEvent.DispatcherState state = getKeyDispatcherState();
+ if (state != null) {
+ state.startTracking(event, this);
+ }
+ return true;
+ } else if (event.getAction() == KeyEvent.ACTION_UP) {
+ KeyEvent.DispatcherState state = getKeyDispatcherState();
+ if (state != null) {
+ state.handleUpEvent(event);
+ }
+ if (event.isTracking() && !event.isCanceled()) {
+ InputMethodManager imm = (InputMethodManager)
+ getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null && mKeyboardIsShowing) {
+ imm.hideSoftInputFromWindow(getWindowToken(), 0);
+ mKeyboardIsShowing = false;
+ } else {
+ clearFocus();
+ mKeyboardIsShowing = true;
+ }
+ return true;
+ }
+ }
+ }
+ return super.onKeyPreIme(keyCode, event);
+ }
+
public void setSuggestionHelper(SuggestionHelper helper) {
if (helper != null) {
mAllSuggestions = helper.getQueries();
- mAdapte = new ArrayAdapter(getContext(),
- android.R.layout.simple_list_item_1, mAllSuggestions);
+ mAdapte = new ArrayAdapter(ViewUtils.sContextThemeWrapper,
+ android.R.layout.simple_dropdown_item_1line, mAllSuggestions);
setAdapter(mAdapte);
} else {
mAllSuggestions = null;