summaryrefslogtreecommitdiff
path: root/core/java/android/widget/SearchView.java
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2011-08-17 11:41:37 -0700
committerAmith Yamasani <yamasani@google.com>2011-08-17 16:43:55 -0700
commita95e488bdcef3737287227419cfe214bef0556aa (patch)
tree9b4a12650890607ca4913af3925fcdadd40db206 /core/java/android/widget/SearchView.java
parente117d0bda12f02e39b58b6460bee0aaf8ead9cf9 (diff)
Don't force measurement when SearchView is in iconified mode.
Bug: 5178204 Update the focused state drawables when focus changes. Blue underlines were not showing up consistently. Bug: 5174426 Also use the correct style for the search icon so that it matches other actionbar actions. Change-Id: I8beed4cf435b074280a5dd79f7a4da4a39152b71
Diffstat (limited to 'core/java/android/widget/SearchView.java')
-rw-r--r--core/java/android/widget/SearchView.java37
1 files changed, 33 insertions, 4 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index aba6834fc530..99f276530caa 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -35,6 +35,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Handler;
import android.speech.RecognizerIntent;
import android.text.Editable;
import android.text.InputType;
@@ -138,6 +139,12 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
}
};
+ private Runnable mUpdateDrawableStateRunnable = new Runnable() {
+ public void run() {
+ updateFocusedState();
+ }
+ };
+
// For voice searching
private final Intent mVoiceWebSearchIntent;
private final Intent mVoiceAppSearchIntent;
@@ -624,6 +631,12 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // Let the standard measurements take effect in iconified state.
+ if (isIconified()) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ return;
+ }
+
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
@@ -720,9 +733,21 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET);
}
- private void updateFocusedState(boolean focused) {
+ private void postUpdateFocusedState() {
+ post(mUpdateDrawableStateRunnable);
+ }
+
+ private void updateFocusedState() {
+ boolean focused = mQueryTextView.hasFocus();
mSearchPlate.getBackground().setState(focused ? FOCUSED_STATE_SET : EMPTY_STATE_SET);
mSubmitArea.getBackground().setState(focused ? FOCUSED_STATE_SET : EMPTY_STATE_SET);
+ invalidate();
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ removeCallbacks(mUpdateDrawableStateRunnable);
+ super.onDetachedFromWindow();
}
private void setImeVisibility(final boolean visible) {
@@ -1118,15 +1143,19 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
void onTextFocusChanged() {
updateViewsVisibility(isIconified());
- updateFocusedState(mQueryTextView.hasFocus());
+ // Delayed update to make sure that the focus has settled down and window focus changes
+ // don't affect it. A synchronous update was not working.
+ postUpdateFocusedState();
if (mQueryTextView.hasFocus()) {
forceSuggestionQuery();
}
}
@Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
+ public void onWindowFocusChanged(boolean hasWindowFocus) {
+ super.onWindowFocusChanged(hasWindowFocus);
+
+ postUpdateFocusedState();
}
/**