diff options
-rw-r--r-- | res/drawable/rounded_corner.xml | 22 | ||||
-rw-r--r-- | res/layout/search_edittext.xml | 2 | ||||
-rw-r--r-- | src/com/android/dialer/DialtactsActivity.java | 19 | ||||
-rw-r--r-- | src/com/android/dialer/widget/SearchEditTextLayout.java | 46 |
4 files changed, 79 insertions, 10 deletions
diff --git a/res/drawable/rounded_corner.xml b/res/drawable/rounded_corner.xml new file mode 100644 index 000000000..fb8f4f56d --- /dev/null +++ b/res/drawable/rounded_corner.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + ~ Copyright (C) 2014 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle" > + <solid android:color="@color/searchbox_background_color" /> + <corners android:radius="2dp" /> +</shape> diff --git a/res/layout/search_edittext.xml b/res/layout/search_edittext.xml index 03c51060e..ff9cabbfd 100644 --- a/res/layout/search_edittext.xml +++ b/res/layout/search_edittext.xml @@ -11,7 +11,7 @@ android:layout_marginRight="@dimen/search_margin_horizontal" android:paddingLeft="@dimen/search_box_left_padding" android:paddingRight="@dimen/search_box_right_padding" - android:background="@drawable/rounded_corner_bg" + android:background="@drawable/rounded_corner" android:gravity="center_vertical" android:elevation="@dimen/search_box_elevation" > diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 9586d252e..39f611e9a 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -193,6 +193,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O private View mSearchIcon; private View mSearchViewCloseButton; private View mVoiceSearchButton; + private SearchEditTextLayout mSearchEditTextLayout; /** * View that contains the "Remove" dialog that shows up when the user long presses a contact. @@ -332,21 +333,21 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O actionBar.setCustomView(R.layout.search_edittext); actionBar.setDisplayShowCustomEnabled(true); - SearchEditTextLayout actionBarView = (SearchEditTextLayout) actionBar.getCustomView(); - actionBarView.setPreImeKeyListener(mSearchEditTextLayoutListener); + mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView(); + mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); - mSearchIcon = actionBarView.findViewById(R.id.search_magnifying_glass); - mVoiceSearchButton = actionBarView.findViewById(R.id.voice_search_button); + mSearchIcon = mSearchEditTextLayout.findViewById(R.id.search_magnifying_glass); + mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button); - mSearchView = (EditText) actionBarView.findViewById(R.id.search_view); + mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mSearchView.setOnTouchListener(mSearchViewOnTouchListener); - mSearchViewCloseButton = actionBarView.findViewById(R.id.search_close_button); + mSearchViewCloseButton = mSearchEditTextLayout.findViewById(R.id.search_close_button); mSearchViewCloseButton.setOnClickListener(this); - ImageButton optionsMenuButton = - (ImageButton) actionBarView.findViewById(R.id.dialtacts_options_menu_button); + ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById( + R.id.dialtacts_options_menu_button); optionsMenuButton.setOnClickListener(this); final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton); optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener()); @@ -820,6 +821,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O transaction.commit(); mListsFragment.getView().animate().alpha(0).withLayer(); + mSearchEditTextLayout.animateExpandOrCollapse(true); if (!mIsDialpadShown) { mSearchIcon.setVisibility(View.GONE); @@ -851,6 +853,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O transaction.commit(); mListsFragment.getView().animate().alpha(1).withLayer(); + mSearchEditTextLayout.animateExpandOrCollapse(false); mSearchIcon.setVisibility(View.VISIBLE); } diff --git a/src/com/android/dialer/widget/SearchEditTextLayout.java b/src/com/android/dialer/widget/SearchEditTextLayout.java index 40a4e43b9..e2cbcb3ef 100644 --- a/src/com/android/dialer/widget/SearchEditTextLayout.java +++ b/src/com/android/dialer/widget/SearchEditTextLayout.java @@ -16,17 +16,27 @@ package com.android.dialer.widget; - +import android.animation.ValueAnimator; +import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.KeyEvent; import android.widget.LinearLayout; +import com.android.dialer.R; + public class SearchEditTextLayout extends LinearLayout { private OnKeyListener mPreImeKeyListener; + private int mTopMargin; + private int mBottomMargin; + private int mLeftMargin; + private int mRightMargin; + + private int mBackgroundColor; public SearchEditTextLayout(Context context, AttributeSet attrs) { super(context, attrs); + mBackgroundColor = getResources().getColor(R.color.searchbox_background_color); } public void setPreImeKeyListener(OnKeyListener listener) { @@ -34,6 +44,16 @@ public class SearchEditTextLayout extends LinearLayout { } @Override + protected void onFinishInflate() { + MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); + mTopMargin = params.topMargin; + mBottomMargin = params.bottomMargin; + mLeftMargin = params.leftMargin; + mRightMargin = params.rightMargin; + super.onFinishInflate(); + } + + @Override public boolean dispatchKeyEventPreIme(KeyEvent event) { if (mPreImeKeyListener != null) { if (mPreImeKeyListener.onKey(this, event.getKeyCode(), event)) { @@ -42,4 +62,28 @@ public class SearchEditTextLayout extends LinearLayout { } return super.dispatchKeyEventPreIme(event); } + + public void animateExpandOrCollapse(boolean expand) { + final ValueAnimator animator; + if (expand) { + animator = ValueAnimator.ofFloat(1f, 0f); + setBackgroundColor(mBackgroundColor); + } else { + animator = ValueAnimator.ofFloat(0f, 1f); + setBackgroundResource(R.drawable.rounded_corner); + } + animator.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + final Float fraction = (Float) animation.getAnimatedValue(); + MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); + params.topMargin = (int) (mTopMargin * fraction); + params.bottomMargin = (int) (mBottomMargin * fraction); + params.leftMargin = (int) (mLeftMargin * fraction); + params.rightMargin = (int) (mRightMargin * fraction); + requestLayout(); + } + }); + animator.start(); + } }
\ No newline at end of file |