From 99413b41c5af53bf00d6726822aceba3f5baea73 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 5 May 2015 17:38:23 -0700 Subject: Hide "clear" action if search text is empty. Bug: 20700084 Change-Id: Id2574f5b721dbaa4d7aab04945c2ad08c390835f --- .../dialer/widget/SearchEditTextLayout.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/com') diff --git a/src/com/android/dialer/widget/SearchEditTextLayout.java b/src/com/android/dialer/widget/SearchEditTextLayout.java index f22a3be9e..f1fa9868a 100644 --- a/src/com/android/dialer/widget/SearchEditTextLayout.java +++ b/src/com/android/dialer/widget/SearchEditTextLayout.java @@ -20,6 +20,9 @@ import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; import android.view.KeyEvent; import android.view.View; import android.widget.EditText; @@ -123,6 +126,21 @@ public class SearchEditTextLayout extends FrameLayout { } }); + mSearchView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + mClearButtonView.setVisibility(TextUtils.isEmpty(s) ? View.GONE : View.VISIBLE); + } + + @Override + public void afterTextChanged(Editable s) { + } + }); + findViewById(R.id.search_close_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -177,6 +195,7 @@ public class SearchEditTextLayout extends FrameLayout { mIsFadedOut = true; } } + public void expand(boolean animate, boolean requestFocus) { updateVisibility(true /* isExpand */); @@ -245,7 +264,11 @@ public class SearchEditTextLayout extends FrameLayout { // TODO: Prevents keyboard from jumping up in landscape mode after exiting the // SearchFragment when the query string is empty. More elegant fix? //mExpandedSearchBox.setVisibility(expandedViewVisibility); - mClearButtonView.setVisibility(expandedViewVisibility); + if (TextUtils.isEmpty(mSearchView.getText())) { + mClearButtonView.setVisibility(View.GONE); + } else { + mClearButtonView.setVisibility(expandedViewVisibility); + } } private void prepareAnimator(final boolean expand) { -- cgit v1.2.3