diff options
author | Yorke Lee <yorkelee@google.com> | 2014-05-19 20:31:37 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2014-05-20 13:54:09 -0700 |
commit | 11ca39eae2bd8ed5c3e21e8c4fa09c9b2b6bda51 (patch) | |
tree | f6097e2d556c9d2fdbbc33a7ed8e98ab340c7ac2 | |
parent | 7206cebd7b267abbbc3de5d529ddf9a8f5ef176f (diff) |
Swap out search box contents when expanding
* Replace search box layout with two main child views - one for the
collapsed state and one for the expanded state.
* Add back button to the expanded state
* Replaced OnTouchListener on the searchbox with an OnClickedListener
Bug: 14900155
Change-Id: I4f07650ddf7e265ee5c4d1054c0bf0ff7494ab6b
-rw-r--r-- | res/layout/search_edittext.xml | 150 | ||||
-rw-r--r-- | src/com/android/dialer/DialtactsActivity.java | 44 | ||||
-rw-r--r-- | src/com/android/dialer/widget/SearchEditTextLayout.java | 70 |
3 files changed, 184 insertions, 80 deletions
diff --git a/res/layout/search_edittext.xml b/res/layout/search_edittext.xml index ff9cabbfd..193222888 100644 --- a/res/layout/search_edittext.xml +++ b/res/layout/search_edittext.xml @@ -12,54 +12,106 @@ android:paddingLeft="@dimen/search_box_left_padding" android:paddingRight="@dimen/search_box_right_padding" android:background="@drawable/rounded_corner" - android:gravity="center_vertical" android:elevation="@dimen/search_box_elevation" > - <ImageView - android:id="@+id/search_magnifying_glass" - android:layout_height="@dimen/search_box_icon_size" - android:layout_width="@dimen/search_box_icon_size" - android:layout_margin="@dimen/search_box_icon_margin" - android:padding="@dimen/search_box_search_icon_padding" - android:src="@drawable/ic_ab_search" /> - <EditText - android:id="@+id/search_view" - android:layout_width="0dp" - android:layout_height="@dimen/search_box_icon_size" - android:layout_weight="1" - android:layout_marginLeft="@dimen/search_box_text_left_margin" - android:textSize="@dimen/search_text_size" - android:fontFamily="@string/search_font_family" - android:textColor="@color/searchbox_text_color" - android:textColorHint="@color/searchbox_hint_text_color" - android:hint="@string/dialer_hint_find_contact" - android:longClickable="false" - android:inputType="textFilter"/> - <ImageView - android:id="@+id/search_close_button" - android:layout_height="@dimen/search_box_icon_size" - android:layout_width="@dimen/search_box_icon_size" - android:layout_margin="@dimen/search_box_icon_margin" - android:src="@drawable/ic_close_dk" - android:clickable="true" - android:background="?android:attr/selectableItemBackground" - android:contentDescription="@string/description_clear_search" - android:visibility="gone" /> - <ImageView - android:id="@+id/voice_search_button" - android:layout_height="@dimen/search_box_icon_size" - android:layout_width="@dimen/search_box_icon_size" - android:layout_margin="@dimen/search_box_icon_margin" - android:src="@drawable/ic_voice_search" - android:clickable="true" - android:contentDescription="@string/description_start_voice_search" - android:background="?android:attr/selectableItemBackground" /> - <ImageButton - android:id="@+id/dialtacts_options_menu_button" - android:layout_width="@dimen/search_box_icon_size" - android:layout_height="@dimen/search_box_icon_size" - android:layout_margin="@dimen/search_box_icon_margin" - android:background="?android:attr/selectableItemBackground" - android:src="@drawable/ic_overflow_menu" - android:tint="@color/searchbox_options_menu_color" /> -</view> + <LinearLayout + android:id="@+id/search_box_collapsed" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_vertical" + android:orientation="horizontal" > + + <!-- Portion of the search box that starts a search when clicked --> + <LinearLayout + android:id="@+id/search_box_start_search" + android:layout_height="wrap_content" + android:layout_width="0dp" + android:layout_weight="1" + android:gravity="center_vertical" > + + <ImageView + android:id="@+id/search_magnifying_glass" + android:layout_height="@dimen/search_box_icon_size" + android:layout_width="@dimen/search_box_icon_size" + android:layout_margin="@dimen/search_box_icon_margin" + android:padding="@dimen/search_box_search_icon_padding" + android:src="@drawable/ic_ab_search" + android:importantForAccessibility="no" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="@dimen/search_box_icon_size" + android:layout_marginLeft="@dimen/search_box_text_left_margin" + android:textSize="@dimen/search_text_size" + android:fontFamily="@string/search_font_family" + android:textColor="@color/searchbox_text_color" + android:textColorHint="@color/searchbox_hint_text_color" + android:gravity="center_vertical" + android:hint="@string/dialer_hint_find_contact" /> + + </LinearLayout> + + <ImageView + android:id="@+id/voice_search_button" + android:layout_height="@dimen/search_box_icon_size" + android:layout_width="@dimen/search_box_icon_size" + android:layout_margin="@dimen/search_box_icon_margin" + android:src="@drawable/ic_voice_search" + android:clickable="true" + android:contentDescription="@string/description_start_voice_search" + android:background="?android:attr/selectableItemBackground" /> + + <ImageButton + android:id="@+id/dialtacts_options_menu_button" + android:layout_width="@dimen/search_box_icon_size" + android:layout_height="@dimen/search_box_icon_size" + android:layout_margin="@dimen/search_box_icon_margin" + android:background="?android:attr/selectableItemBackground" + android:src="@drawable/ic_overflow_menu" + android:contentDescription="@string/action_menu_overflow_description" + android:tint="@color/searchbox_options_menu_color" /> + + </LinearLayout> + + <LinearLayout + android:id="@+id/search_box_expanded" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal" + android:gravity="center_vertical" + android:visibility="gone" > + + <ImageButton + android:id="@+id/search_back_button" + android:layout_width="@dimen/search_box_icon_size" + android:layout_height="@dimen/search_box_icon_size" + android:layout_margin="@dimen/search_box_icon_margin" + android:src="@drawable/ic_back_arrow" + android:background="?android:attr/selectableItemBackground" + android:contentDescription="@string/action_menu_overflow_description" + android:tint="@color/actionbar_background_color" /> + + <EditText + android:id="@+id/search_view" + android:layout_width="0dp" + android:layout_height="@dimen/search_box_icon_size" + android:layout_weight="1" + android:layout_marginLeft="@dimen/search_box_text_left_margin" + android:textSize="@dimen/search_text_size" + android:fontFamily="@string/search_font_family" + android:textColor="@color/searchbox_text_color" + android:inputType="textFilter" /> + + <ImageView + android:id="@+id/search_close_button" + android:layout_height="@dimen/search_box_icon_size" + android:layout_width="@dimen/search_box_icon_size" + android:layout_margin="@dimen/search_box_icon_margin" + android:src="@drawable/ic_close_dk" + android:clickable="true" + android:background="?android:attr/selectableItemBackground" + android:contentDescription="@string/description_clear_search" /> + + </LinearLayout> + +</view>
\ No newline at end of file diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 39f611e9a..d89860008 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -85,6 +85,7 @@ import com.android.dialer.list.RemoveView; import com.android.dialer.list.SearchFragment; import com.android.dialer.list.SmartDialSearchFragment; import com.android.dialer.widget.SearchEditTextLayout; +import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener; import com.android.dialerbind.DatabaseHelperManager; import com.android.internal.telephony.ITelephony; @@ -190,8 +191,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O private String mPendingSearchViewQuery; private EditText mSearchView; - private View mSearchIcon; - private View mSearchViewCloseButton; private View mVoiceSearchButton; private SearchEditTextLayout mSearchEditTextLayout; @@ -278,14 +277,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } else if (mRegularSearchFragment != null) { mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */); } - - if (TextUtils.isEmpty(newText)) { - mSearchViewCloseButton.setVisibility(View.GONE); - mVoiceSearchButton.setVisibility(View.VISIBLE); - } else { - mSearchViewCloseButton.setVisibility(View.VISIBLE); - mVoiceSearchButton.setVisibility(View.GONE); - } } @Override @@ -295,15 +286,14 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O /** - * Open the search UI when the user touches the search text view. + * Open the search UI when the user clicks on the search box. */ - private final View.OnTouchListener mSearchViewOnTouchListener = new View.OnTouchListener() { + private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() { @Override - public boolean onTouch(View v, MotionEvent event) { + public void onClick(View v) { if (!isInSearchUi()) { enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString()); } - return false; } }; @@ -336,15 +326,17 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView(); mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); - mSearchIcon = mSearchEditTextLayout.findViewById(R.id.search_magnifying_glass); - mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button); - mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); - mSearchView.setOnTouchListener(mSearchViewOnTouchListener); - - mSearchViewCloseButton = mSearchEditTextLayout.findViewById(R.id.search_close_button); - mSearchViewCloseButton.setOnClickListener(this); + mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button); + mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener( + mSearchViewOnClickListener); + mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() { + @Override + public void onBackButtonClicked() { + onBackPressed(); + } + }); ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById( R.id.dialtacts_options_menu_button); @@ -609,11 +601,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } mListsFragment.maybeShowActionBar(); + if (isInSearchUi()) { if (TextUtils.isEmpty(mSearchQuery)) { exitSearchUi(); - } else { - mSearchIcon.setVisibility(View.GONE); } } } @@ -822,10 +813,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mListsFragment.getView().animate().alpha(0).withLayer(); mSearchEditTextLayout.animateExpandOrCollapse(true); - - if (!mIsDialpadShown) { - mSearchIcon.setVisibility(View.GONE); - } } /** @@ -843,7 +830,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setCustomAnimations(0, android.R.animator.fade_out); - if (mSmartDialSearchFragment != null) { transaction.remove(mSmartDialSearchFragment); } @@ -854,7 +840,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mListsFragment.getView().animate().alpha(1).withLayer(); mSearchEditTextLayout.animateExpandOrCollapse(false); - mSearchIcon.setVisibility(View.VISIBLE); } /** Returns an Intent to launch Call Settings screen */ @@ -874,6 +859,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O hideDialpadFragment(true, false); } else if (isInSearchUi()) { exitSearchUi(); + hideInputMethod(parentLayout); } else { super.onBackPressed(); } diff --git a/src/com/android/dialer/widget/SearchEditTextLayout.java b/src/com/android/dialer/widget/SearchEditTextLayout.java index e2cbcb3ef..33bf09f59 100644 --- a/src/com/android/dialer/widget/SearchEditTextLayout.java +++ b/src/com/android/dialer/widget/SearchEditTextLayout.java @@ -20,12 +20,19 @@ import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; +import android.util.Log; import android.view.KeyEvent; -import android.widget.LinearLayout; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.FrameLayout; +import com.android.contacts.common.animation.AnimationUtils; import com.android.dialer.R; -public class SearchEditTextLayout extends LinearLayout { +public class SearchEditTextLayout extends FrameLayout { + private static final int ANIMATION_DURATION = 200; + private OnKeyListener mPreImeKeyListener; private int mTopMargin; private int mBottomMargin; @@ -34,6 +41,19 @@ public class SearchEditTextLayout extends LinearLayout { private int mBackgroundColor; + private View mCollapsed; + private View mExpanded; + private EditText mSearchView; + + private OnBackButtonClickedListener mOnBackButtonClickedListener; + + /** + * Listener for the back button next to the search view being pressed + */ + public interface OnBackButtonClickedListener { + public void onBackButtonClicked(); + } + public SearchEditTextLayout(Context context, AttributeSet attrs) { super(context, attrs); mBackgroundColor = getResources().getColor(R.color.searchbox_background_color); @@ -43,6 +63,10 @@ public class SearchEditTextLayout extends LinearLayout { mPreImeKeyListener = listener; } + public void setOnBackButtonClickedListener(OnBackButtonClickedListener listener) { + mOnBackButtonClickedListener = listener; + } + @Override protected void onFinishInflate() { MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); @@ -50,6 +74,36 @@ public class SearchEditTextLayout extends LinearLayout { mBottomMargin = params.bottomMargin; mLeftMargin = params.leftMargin; mRightMargin = params.rightMargin; + + mCollapsed = findViewById(R.id.search_box_collapsed); + mExpanded = findViewById(R.id.search_box_expanded); + mSearchView = (EditText) mExpanded.findViewById(R.id.search_view); + + mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + showInputMethod(v); + } + } + }); + + findViewById(R.id.search_close_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mSearchView.setText(null); + } + }); + + findViewById(R.id.search_back_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (mOnBackButtonClickedListener != null) { + mOnBackButtonClickedListener.onBackButtonClicked(); + } + } + }); + super.onFinishInflate(); } @@ -66,9 +120,12 @@ public class SearchEditTextLayout extends LinearLayout { public void animateExpandOrCollapse(boolean expand) { final ValueAnimator animator; if (expand) { + AnimationUtils.crossFadeViews(mExpanded, mCollapsed, ANIMATION_DURATION); animator = ValueAnimator.ofFloat(1f, 0f); setBackgroundColor(mBackgroundColor); + mSearchView.requestFocus(); } else { + AnimationUtils.crossFadeViews(mCollapsed, mExpanded, ANIMATION_DURATION); animator = ValueAnimator.ofFloat(0f, 1f); setBackgroundResource(R.drawable.rounded_corner); } @@ -84,6 +141,15 @@ public class SearchEditTextLayout extends LinearLayout { requestLayout(); } }); + animator.setDuration(ANIMATION_DURATION); animator.start(); } + + private void showInputMethod(View view) { + final InputMethodManager imm = (InputMethodManager) getContext().getSystemService( + Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.showSoftInput(view, 0); + } + } }
\ No newline at end of file |