summaryrefslogtreecommitdiff
path: root/core/java/android/widget/SearchView.java
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2011-08-12 19:28:37 -0700
committerAmith Yamasani <yamasani@google.com>2011-08-12 19:28:37 -0700
commit167d69ac41d8a1446ab216e3821ecbcccd8291bb (patch)
treebeb145f2905b44f3c1cbf4f6b8a7faf07b8c3036 /core/java/android/widget/SearchView.java
parent6e97ed2127bdda72fee739fe9d28011d52155b9c (diff)
Voice search icon replaced by X on typing.
Also, adjust width measurements to work for 32dip icons in actionbar. Bug: 5160466 Change-Id: I7197d710de16f92af8ea797ac504a3a73ee090d9
Diffstat (limited to 'core/java/android/widget/SearchView.java')
-rw-r--r--core/java/android/widget/SearchView.java35
1 files changed, 28 insertions, 7 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index 4eecd6458145..aba6834fc530 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -627,12 +627,33 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
- if ((widthMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.EXACTLY) && mMaxWidth > 0
- && width > mMaxWidth) {
- super.onMeasure(MeasureSpec.makeMeasureSpec(mMaxWidth, widthMode), heightMeasureSpec);
- } else {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ switch (widthMode) {
+ case MeasureSpec.AT_MOST:
+ // If there is an upper limit, don't exceed maximum width (explicit or implicit)
+ if (mMaxWidth > 0) {
+ width = Math.min(mMaxWidth, width);
+ } else {
+ width = Math.min(getPreferredWidth(), width);
+ }
+ break;
+ case MeasureSpec.EXACTLY:
+ // If an exact width is specified, still don't exceed any specified maximum width
+ if (mMaxWidth > 0) {
+ width = Math.min(mMaxWidth, width);
+ }
+ break;
+ case MeasureSpec.UNSPECIFIED:
+ // Use maximum width, if specified, else preferred width
+ width = mMaxWidth > 0 ? mMaxWidth : getPreferredWidth();
+ break;
}
+ widthMode = MeasureSpec.EXACTLY;
+ super.onMeasure(MeasureSpec.makeMeasureSpec(width, widthMode), heightMeasureSpec);
+ }
+
+ private int getPreferredWidth() {
+ return getContext().getResources()
+ .getDimensionPixelSize(R.dimen.search_view_preferred_width);
}
private void updateViewsVisibility(final boolean collapsed) {
@@ -695,7 +716,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
// Should we show the close button? It is not shown if there's no focus,
// field is not iconified by default and there is no text in it.
final boolean showClose = hasText || (mIconifiedByDefault && !mExpandedInActionView);
- mCloseButton.setVisibility(showClose ? VISIBLE : INVISIBLE);
+ mCloseButton.setVisibility(showClose ? VISIBLE : GONE);
mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET);
}
@@ -991,7 +1012,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
*/
private void updateVoiceButton(boolean empty) {
int visibility = GONE;
- if (mVoiceButtonEnabled && !isIconified() && (empty || !mSubmitButtonEnabled)) {
+ if (mVoiceButtonEnabled && !isIconified() && empty) {
visibility = VISIBLE;
mSubmitButton.setVisibility(GONE);
}