From 6a81b8271d2edc1a87a3f50e8146f095be998629 Mon Sep 17 00:00:00 2001 From: repo sync Date: Tue, 28 Sep 2010 13:00:05 -0700 Subject: [PATCH] focus issues 1. Don't bring up the keyboard if we're iconified by default 2. Also override onRequestFocusInDescendants to return false. This makes it so that we don't focus on the search edit text which is in the actionbar. Change-Id: I345e9cd77f686f13762a20454a76ff1f7c4a5556 --- core/java/android/widget/SearchView.java | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index 09217af69a39c..dd67197c2aed4 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; import android.database.Cursor; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; import android.text.Editable; @@ -348,15 +349,19 @@ public class SearchView extends LinearLayout { } private void setImeVisibility(boolean visible) { - // We made sure the IME was displayed, so also make sure it is closed - // when we go away. - InputMethodManager imm = (InputMethodManager) - getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - if (visible) { - imm.showSoftInputUnchecked(0, null); - } else { - imm.hideSoftInputFromWindow(getWindowToken(), 0); + // don't mess with the soft input if we're not iconified by default + if (mIconifiedByDefault) { + InputMethodManager imm = (InputMethodManager) + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + + // We made sure the IME was displayed, so also make sure it is closed + // when we go away. + if (imm != null) { + if (visible) { + imm.showSoftInputUnchecked(0, null); + } else { + imm.hideSoftInputFromWindow(getWindowToken(), 0); + } } } } @@ -717,4 +722,13 @@ public class SearchView extends LinearLayout { public void afterTextChanged(Editable s) { } }; -} + + /* + * Avoid getting focus when searching for something to focus on. + * The user will have to touch the text view to get focus. + */ + protected boolean onRequestFocusInDescendants(int direction, + Rect previouslyFocusedRect) { + return false; + } + }