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 /src/com/android/dialer/widget/SearchEditTextLayout.java | |
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
Diffstat (limited to 'src/com/android/dialer/widget/SearchEditTextLayout.java')
-rw-r--r-- | src/com/android/dialer/widget/SearchEditTextLayout.java | 70 |
1 files changed, 68 insertions, 2 deletions
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 |