diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-09-11 20:05:36 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-09-11 20:05:36 +0000 |
commit | 03249752afd7d870ff708bf47d687a1643367ec5 (patch) | |
tree | f0b6004c5f2d035f0f4c177455bea79c5047d1a4 /java/com/android/dialer/app/widget | |
parent | 3f14c296552a7af353094e420aa00dd0bf217268 (diff) | |
parent | 21e24b6d9355e5e64a594b3b32cb4c8301e3330b (diff) |
Merge changes I6af1fc7d,I0627d54a
* changes:
Automated g4 rollback of changelist 167310802.
Automated g4 rollback of changelist 167332236.
Diffstat (limited to 'java/com/android/dialer/app/widget')
-rw-r--r-- | java/com/android/dialer/app/widget/ActionBarController.java | 28 | ||||
-rw-r--r-- | java/com/android/dialer/app/widget/SearchEditTextLayout.java | 67 |
2 files changed, 87 insertions, 8 deletions
diff --git a/java/com/android/dialer/app/widget/ActionBarController.java b/java/com/android/dialer/app/widget/ActionBarController.java index 3daa0e2d4..c1b4cc2b4 100644 --- a/java/com/android/dialer/app/widget/ActionBarController.java +++ b/java/com/android/dialer/app/widget/ActionBarController.java @@ -49,6 +49,18 @@ public class ActionBarController { } }; + private final AnimationCallback mFadeInCallback = + new AnimationCallback() { + @Override + public void onAnimationEnd() { + slideActionBar(false /* slideUp */, false /* animate */); + } + + @Override + public void onAnimationCancel() { + slideActionBar(false /* slideUp */, false /* animate */); + } + }; private ValueAnimator mAnimator; public ActionBarController(ActivityUi activityUi, SearchEditTextLayout searchBox) { @@ -100,13 +112,17 @@ public class ActionBarController { mSearchBox.isFadedOut(), mSearchBox.isExpanded()); if (mActivityUi.isInSearchUi()) { - if (mSearchBox.isFadedOut()) { - mSearchBox.setVisible(true); - } - if (!mSearchBox.isExpanded()) { - mSearchBox.expand(false /* animate */, false /* requestFocus */); + if (mActivityUi.hasSearchQuery()) { + if (mSearchBox.isFadedOut()) { + mSearchBox.setVisible(true); + } + if (!mSearchBox.isExpanded()) { + mSearchBox.expand(false /* animate */, false /* requestFocus */); + } + slideActionBar(false /* slideUp */, true /* animate */); + } else { + mSearchBox.fadeIn(mFadeInCallback); } - slideActionBar(false /* slideUp */, true /* animate */); } } diff --git a/java/com/android/dialer/app/widget/SearchEditTextLayout.java b/java/com/android/dialer/app/widget/SearchEditTextLayout.java index 2051b65f2..95bd12aa1 100644 --- a/java/com/android/dialer/app/widget/SearchEditTextLayout.java +++ b/java/com/android/dialer/app/widget/SearchEditTextLayout.java @@ -23,6 +23,7 @@ import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.util.AttributeSet; +import android.view.KeyEvent; import android.view.View; import android.widget.EditText; import android.widget.FrameLayout; @@ -37,6 +38,7 @@ public class SearchEditTextLayout extends FrameLayout { /* Subclass-visible for testing */ protected boolean mIsExpanded = false; protected boolean mIsFadedOut = false; + private OnKeyListener mPreImeKeyListener; private int mTopMargin; private int mBottomMargin; private int mLeftMargin; @@ -54,10 +56,20 @@ public class SearchEditTextLayout extends FrameLayout { private ValueAnimator mAnimator; + private Callback mCallback; + public SearchEditTextLayout(Context context, AttributeSet attrs) { super(context, attrs); } + public void setPreImeKeyListener(OnKeyListener listener) { + mPreImeKeyListener = listener; + } + + public void setCallback(Callback listener) { + mCallback = listener; + } + @Override protected void onFinishInflate() { MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); @@ -70,7 +82,7 @@ public class SearchEditTextLayout extends FrameLayout { mCollapsed = findViewById(R.id.search_box_collapsed); mExpanded = findViewById(R.id.search_box_expanded); - mSearchView = mExpanded.findViewById(R.id.search_view); + mSearchView = (EditText) mExpanded.findViewById(R.id.search_view); mSearchIcon = findViewById(R.id.search_magnifying_glass); mCollapsedSearchBox = findViewById(R.id.search_box_start_search); @@ -111,6 +123,16 @@ public class SearchEditTextLayout extends FrameLayout { } }); + mSearchView.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mCallback != null) { + mCallback.onSearchViewClicked(); + } + } + }); + mSearchView.addTextChangedListener( new TextWatcher() { @Override @@ -125,10 +147,43 @@ public class SearchEditTextLayout extends FrameLayout { public void afterTextChanged(Editable s) {} }); - mClearButtonView.setOnClickListener(v -> mSearchView.setText(null)); + 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 (mCallback != null) { + mCallback.onBackButtonClicked(); + } + } + }); + super.onFinishInflate(); } + @Override + public boolean dispatchKeyEventPreIme(KeyEvent event) { + if (mPreImeKeyListener != null) { + if (mPreImeKeyListener.onKey(this, event.getKeyCode(), event)) { + return true; + } + } + return super.dispatchKeyEventPreIme(event); + } + + public void fadeOut() { + fadeOut(null); + } + public void fadeOut(AnimUtils.AnimationCallback callback) { AnimUtils.fadeOut(this, ANIMATION_DURATION, callback); mIsFadedOut = true; @@ -269,4 +324,12 @@ public class SearchEditTextLayout extends FrameLayout { params.rightMargin = (int) (mRightMargin * fraction); requestLayout(); } + + /** Listener for the back button next to the search view being pressed */ + public interface Callback { + + void onBackButtonClicked(); + + void onSearchViewClicked(); + } } |