From ec489fb5d4bba57ccdfd24b48e26257294d29979 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Mon, 19 May 2014 15:39:27 -0700 Subject: Make searchbox expand when entering search UI Bug: 14900155 Change-Id: Ib6e500ed55db90ad1fa13ba6dd0e141721331ba4 --- .../dialer/widget/SearchEditTextLayout.java | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src/com/android/dialer/widget/SearchEditTextLayout.java') 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,23 +16,43 @@ 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) { mPreImeKeyListener = listener; } + @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) { @@ -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 -- cgit v1.2.3