summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2011-01-25 12:35:06 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-25 12:35:06 -0800
commit6bcbf54feed8ca7c1bf9b509f8581684988d45dd (patch)
tree9b943dbbffd614b4d650ddd79a6397d6d7fc203c
parent561a434b9769217b8936eea40b564bb9615f1a12 (diff)
parent7f8aef6d5bd26cfc7f96d059ab66abdb320ebd27 (diff)
downloadframeworks_base-6bcbf54feed8ca7c1bf9b509f8581684988d45dd.zip
frameworks_base-6bcbf54feed8ca7c1bf9b509f8581684988d45dd.tar.gz
frameworks_base-6bcbf54feed8ca7c1bf9b509f8581684988d45dd.tar.bz2
Merge "Heed the focusability flag in SearchView and set the default to true." into honeycomb
-rw-r--r--core/java/android/widget/SearchView.java28
-rw-r--r--core/res/res/layout/search_view.xml3
2 files changed, 24 insertions, 7 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index b86366c..a37f12e 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -214,6 +214,8 @@ public class SearchView extends LinearLayout {
}
});
+ boolean focusable = true;
+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0);
setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));
int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_maxWidth, -1);
@@ -226,6 +228,11 @@ public class SearchView extends LinearLayout {
}
a.recycle();
+ a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0);
+ focusable = a.getBoolean(R.styleable.View_focusable, focusable);
+ a.recycle();
+ setFocusable(focusable);
+
// Save voice intent for later queries/launching
mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -259,10 +266,18 @@ public class SearchView extends LinearLayout {
/** @hide */
@Override
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
- if (mClearingFocus || isIconified()) return false;
- boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect);
- if (result) updateViewsVisibility(mIconifiedByDefault);
- return result;
+ // Don't accept focus if in the middle of clearing focus
+ if (mClearingFocus) return false;
+ // Check if SearchView is focusable.
+ if (!isFocusable()) return false;
+ // If it is not iconified, then give the focus to the text field
+ if (!isIconified()) {
+ boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect);
+ if (result) updateViewsVisibility(false);
+ return result;
+ } else {
+ return super.requestFocus(direction, previouslyFocusedRect);
+ }
}
/** @hide */
@@ -527,7 +542,6 @@ public class SearchView extends LinearLayout {
updateCloseButton();
updateVoiceButton(!hasText);
updateSubmitArea();
- requestLayout();
}
private boolean hasVoiceSearch() {
@@ -580,7 +594,7 @@ public class SearchView extends LinearLayout {
private void setImeVisibility(boolean visible) {
InputMethodManager imm = (InputMethodManager)
- getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
// We made sure the IME was displayed, so also make sure it is closed
// when we go away.
@@ -903,8 +917,8 @@ public class SearchView extends LinearLayout {
}
private void onSearchClicked() {
- mQueryTextView.requestFocus();
updateViewsVisibility(false);
+ mQueryTextView.requestFocus();
setImeVisibility(true);
if (mOnSearchClickListener != null) {
mOnSearchClickListener.onClick(this);
diff --git a/core/res/res/layout/search_view.xml b/core/res/res/layout/search_view.xml
index 0a7cd3c..c41c2de 100644
--- a/core/res/res/layout/search_view.xml
+++ b/core/res/res/layout/search_view.xml
@@ -105,6 +105,7 @@
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:src="?android:attr/searchViewCloseIcon"
+ android:focusable="true"
/>
</LinearLayout>
@@ -127,6 +128,7 @@
android:background="?android:attr/selectableItemBackground"
android:src="?android:attr/searchViewGoIcon"
android:visibility="gone"
+ android:focusable="true"
/>
<ImageView
@@ -139,6 +141,7 @@
android:src="?android:attr/searchViewVoiceIcon"
android:background="?android:attr/selectableItemBackground"
android:visibility="gone"
+ android:focusable="true"
/>
</LinearLayout>
</LinearLayout>