From 6bc46129b93069868d2425fb9d9c50e1dabe6502 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Tue, 20 Feb 2018 16:14:22 -0800 Subject: Fixed some issues in NUI search bar. - search bar is now the correct height - search bar hint now updates for Google Dialer - search bar now properly slides up when in dialpad search Bug: 72525324 Test: GoogleMainActivityOldPeerIntegrationTest PiperOrigin-RevId: 186379302 Change-Id: If5ad570c89c6a784fa17df422d88e68c30356712 --- .../dialer/main/impl/toolbar/MainToolbar.java | 46 +++++++++++++++++----- .../dialer/main/impl/toolbar/SearchBarView.java | 16 ++++++-- .../toolbar/res/layout/expanded_search_bar.xml | 2 +- .../impl/toolbar/res/layout/toolbar_layout.xml | 9 +++-- .../dialer/main/impl/toolbar/res/values/dimens.xml | 4 +- 5 files changed, 58 insertions(+), 19 deletions(-) diff --git a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java index 604422978..a129fca8b 100644 --- a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java +++ b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java @@ -16,13 +16,17 @@ package com.android.dialer.main.impl.toolbar; +import android.animation.ValueAnimator; +import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; +import android.support.annotation.StringRes; import android.support.v7.widget.PopupMenu.OnMenuItemClickListener; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; import android.view.MenuItem; import android.view.animation.AccelerateDecelerateInterpolator; import android.widget.ImageButton; +import android.widget.RelativeLayout; import com.android.dialer.common.Assert; import com.android.dialer.util.ViewUtil; import com.google.common.base.Optional; @@ -74,22 +78,40 @@ public final class MainToolbar extends Toolbar implements OnMenuItemClickListene return; } isSlideUp = true; - animate() - .translationY(-getHeight()) - .setDuration(animate ? SLIDE_DURATION : 0) - .setInterpolator(SLIDE_INTERPOLATOR) - .start(); + ValueAnimator animator = ValueAnimator.ofFloat(0, -getHeight()); + animator.setDuration(animate ? SLIDE_DURATION : 0); + animator.setInterpolator(SLIDE_INTERPOLATOR); + animator.addUpdateListener( + new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + int val = ((Float) animation.getAnimatedValue()).intValue(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams(); + params.topMargin = val; + requestLayout(); + } + }); + animator.start(); } /** Slides the toolbar down and back onto the screen. */ public void slideDown(boolean animate) { Assert.checkArgument(isSlideUp); isSlideUp = false; - animate() - .translationY(0) - .setDuration(animate ? SLIDE_DURATION : 0) - .setInterpolator(SLIDE_INTERPOLATOR) - .start(); + ValueAnimator animator = ValueAnimator.ofFloat(-getHeight(), 0); + animator.setDuration(animate ? SLIDE_DURATION : 0); + animator.setInterpolator(SLIDE_INTERPOLATOR); + animator.addUpdateListener( + new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + int val = ((Float) animation.getAnimatedValue()).intValue(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams(); + params.topMargin = val; + requestLayout(); + } + }); + animator.start(); } /** @see SearchBarView#collapse(boolean) */ @@ -129,4 +151,8 @@ public final class MainToolbar extends Toolbar implements OnMenuItemClickListene public MainToolbarMenu getOverflowMenu() { return overflowMenu; } + + public void setHint(@StringRes int hint) { + searchBar.setHint(hint); + } } diff --git a/java/com/android/dialer/main/impl/toolbar/SearchBarView.java b/java/com/android/dialer/main/impl/toolbar/SearchBarView.java index 95929383b..37ffb9778 100644 --- a/java/com/android/dialer/main/impl/toolbar/SearchBarView.java +++ b/java/com/android/dialer/main/impl/toolbar/SearchBarView.java @@ -22,6 +22,7 @@ import android.animation.ValueAnimator; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -29,6 +30,7 @@ import android.util.AttributeSet; import android.view.View; import android.widget.EditText; import android.widget.FrameLayout; +import android.widget.TextView; import com.android.dialer.animation.AnimUtils; import com.android.dialer.common.UiUtil; import com.android.dialer.util.DialerUtils; @@ -42,14 +44,15 @@ final class SearchBarView extends FrameLayout { private final float margin; private final float animationEndHeight; + private final float animationStartHeight; private SearchBarListener listener; private EditText searchBox; + private TextView searchBoxTextView; // This useful for when the query didn't actually change. We want to avoid making excessive calls // where we can since IPCs can take a long time on slow networks. private boolean skipLatestTextChange; - private int initialHeight; private boolean isExpanded; private View searchBoxCollapsed; private View searchBoxExpanded; @@ -60,6 +63,8 @@ final class SearchBarView extends FrameLayout { margin = getContext().getResources().getDimension(R.dimen.search_bar_margin); animationEndHeight = getContext().getResources().getDimension(R.dimen.expanded_search_bar_height); + animationStartHeight = + getContext().getResources().getDimension(R.dimen.collapsed_search_bar_height); } @Override @@ -67,6 +72,7 @@ final class SearchBarView extends FrameLayout { super.onFinishInflate(); clearButton = findViewById(R.id.search_clear_button); searchBox = findViewById(R.id.search_view); + searchBoxTextView = findViewById(R.id.search_box_start_search); searchBoxCollapsed = findViewById(R.id.search_box_collapsed); searchBoxExpanded = findViewById(R.id.search_box_expanded); @@ -104,7 +110,6 @@ final class SearchBarView extends FrameLayout { if (isExpanded) { return; } - initialHeight = getHeight(); int duration = animate ? ANIMATION_DURATION : 0; searchBoxExpanded.setVisibility(VISIBLE); @@ -177,7 +182,7 @@ final class SearchBarView extends FrameLayout { params.leftMargin = margin; params.rightMargin = margin; searchBoxExpanded.getLayoutParams().height = - (int) (animationEndHeight - (animationEndHeight - initialHeight) * fraction); + (int) (animationEndHeight - (animationEndHeight - animationStartHeight) * fraction); requestLayout(); } @@ -207,6 +212,11 @@ final class SearchBarView extends FrameLayout { UiUtil.openKeyboardFrom(getContext(), searchBox); } + public void setHint(@StringRes int hint) { + searchBox.setHint(hint); + searchBoxTextView.setText(hint); + } + /** Handles logic for text changes in the search box. */ private class SearchBoxTextWatcher implements TextWatcher { diff --git a/java/com/android/dialer/main/impl/toolbar/res/layout/expanded_search_bar.xml b/java/com/android/dialer/main/impl/toolbar/res/layout/expanded_search_bar.xml index 4e49accae..3bd71b63a 100644 --- a/java/com/android/dialer/main/impl/toolbar/res/layout/expanded_search_bar.xml +++ b/java/com/android/dialer/main/impl/toolbar/res/layout/expanded_search_bar.xml @@ -17,7 +17,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/search_box_expanded" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="@dimen/expanded_search_bar_height" android:visibility="invisible"> @@ -27,6 +27,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/search_bar_margin" + android:minHeight="@dimen/collapsed_search_bar_height" android:background="@drawable/rounded_corner" android:elevation="4dp"> @@ -58,8 +59,8 @@ android:layout_marginStart="8dp" android:layout_centerVertical="true" android:fontFamily="sans-serif" - android:hint="@string/dialer_hint_find_contact" - android:textColorHint="@color/dialer_secondary_text_color" + android:text="@string/dialer_hint_find_contact" + android:textColor="@color/dialer_secondary_text_color" android:textSize="16dp"/> - \ No newline at end of file + diff --git a/java/com/android/dialer/main/impl/toolbar/res/values/dimens.xml b/java/com/android/dialer/main/impl/toolbar/res/values/dimens.xml index f54f053da..ed6f197fa 100644 --- a/java/com/android/dialer/main/impl/toolbar/res/values/dimens.xml +++ b/java/com/android/dialer/main/impl/toolbar/res/values/dimens.xml @@ -16,5 +16,7 @@ --> 8dp - 60dp + 48dp + + 64dp \ No newline at end of file -- cgit v1.2.3