@@ -412,34 +412,6 @@ private AnimatorSet getButtonsProgressAnimator(boolean show) {
412412 return animatorSet ;
413413 }
414414
415- private AnimatorSet getButtonsTranslationAnimator (boolean show ) {
416- AnimatorSet animatorSet = new AnimatorSet ();
417- addBackButtonTranslationAnimatorIfNeeded (animatorSet );
418- addActionMenuViewAnimatorIfNeeded (animatorSet );
419- animatorSet .setDuration (show ? SHOW_DURATION_MS : HIDE_DURATION_MS );
420- animatorSet .setInterpolator (
421- ReversableAnimatedValueInterpolator .of (show , AnimationUtils .FAST_OUT_SLOW_IN_INTERPOLATOR ));
422- return animatorSet ;
423- }
424-
425- private void addBackButtonTranslationAnimatorIfNeeded (AnimatorSet animatorSet ) {
426- ImageButton searchViewBackButton = ToolbarUtils .getNavigationIconButton (toolbar );
427- if (searchViewBackButton == null ) {
428- return ;
429- }
430- ImageButton searchBarBackButton = ToolbarUtils .getNavigationIconButton (searchBar );
431-
432- ValueAnimator backButtonAnimatorX =
433- ValueAnimator .ofFloat (
434- getTranslationXBetweenViews (searchBarBackButton , searchViewBackButton ), 0 );
435- backButtonAnimatorX .addUpdateListener (MultiViewUpdateListener .translationXListener (searchViewBackButton ));
436-
437- ValueAnimator backButtonAnimatorY = ValueAnimator .ofFloat (getFromTranslationY (), 0 );
438- backButtonAnimatorY .addUpdateListener (MultiViewUpdateListener .translationYListener (searchViewBackButton ));
439-
440- animatorSet .playTogether (backButtonAnimatorX , backButtonAnimatorY );
441- }
442-
443415 private void addBackButtonProgressAnimatorIfNeeded (AnimatorSet animatorSet ) {
444416 ImageButton backButton = ToolbarUtils .getNavigationIconButton (toolbar );
445417 if (backButton == null ) {
@@ -498,26 +470,6 @@ private void setFullDrawableProgressIfNeeded(Drawable drawable) {
498470 }
499471 }
500472
501- private void addActionMenuViewAnimatorIfNeeded (AnimatorSet animatorSet ) {
502- ActionMenuView searchViewActionMenuView = ToolbarUtils .getActionMenuView (toolbar );
503- if (searchViewActionMenuView == null ) {
504- return ;
505- }
506- ActionMenuView searchBarActionMenuView = ToolbarUtils .getActionMenuView (searchBar );
507-
508- ValueAnimator actionMenuViewAnimatorX =
509- ValueAnimator .ofFloat (
510- getTranslationXBetweenViews (searchBarActionMenuView , searchViewActionMenuView ), 0 );
511- actionMenuViewAnimatorX .addUpdateListener (
512- MultiViewUpdateListener .translationXListener (searchViewActionMenuView ));
513-
514- ValueAnimator actionMenuViewAnimatorY = ValueAnimator .ofFloat (getFromTranslationY (), 0 );
515- actionMenuViewAnimatorY .addUpdateListener (
516- MultiViewUpdateListener .translationYListener (searchViewActionMenuView ));
517-
518- animatorSet .playTogether (actionMenuViewAnimatorX , actionMenuViewAnimatorY );
519- }
520-
521473 private void setMenuItemsNotClickable (Toolbar toolbar ) {
522474 ActionMenuView actionMenuView = ToolbarUtils .getActionMenuView (toolbar );
523475 if (actionMenuView != null ) {
@@ -576,7 +528,7 @@ public void finishBackProgress() {
576528 backHelper .finishBackProgress (totalDuration , searchBar );
577529
578530 if (backProgressAnimatorSet != null ) {
579- getButtonsTranslationAnimator ( /* show= */ false ). start ();
531+ animationDelegate . startButtonsTranslationAnimation ();
580532 backProgressAnimatorSet .resume ();
581533 }
582534
@@ -621,12 +573,6 @@ private void setActionMenuViewAlphaIfNeeded(float alpha) {
621573 }
622574 }
623575
624- private int getFromTranslationY () {
625- int toolbarMiddleY = toolbarContainer .getTop () + toolbarContainer .getHeight () / 2 ;
626- int searchBarMiddleY = getViewTopFromSearchViewParent (searchBar ) + searchBar .getHeight () / 2 ;
627- return searchBarMiddleY - toolbarMiddleY ;
628- }
629-
630576 private int getTranslationXBetweenViews (
631577 @ Nullable View searchBarSubView , @ NonNull View searchViewSubView ) {
632578 // If there is no equivalent for the SearchView subview in the SearchBar, we return the
@@ -713,6 +659,11 @@ public void onAnimationStart(boolean show) {}
713659 @ Override
714660 public void onAnimationEnd (boolean show ) {}
715661
662+ @ Override
663+ public void startButtonsTranslationAnimation () {
664+ getButtonsTranslationAnimator (/* show= */ false ).start ();
665+ }
666+
716667 private Animator getScrimAlphaAnimator (boolean show ) {
717668 TimeInterpolator interpolator =
718669 show ? AnimationUtils .LINEAR_INTERPOLATOR : AnimationUtils .FAST_OUT_SLOW_IN_INTERPOLATOR ;
@@ -948,6 +899,57 @@ private int getFromTranslationY() {
948899 int searchBarMiddleY = getViewTopFromSearchViewParent (searchBar ) + searchBar .getHeight () / 2 ;
949900 return searchBarMiddleY - toolbarMiddleY ;
950901 }
902+
903+ private AnimatorSet getButtonsTranslationAnimator (boolean show ) {
904+ AnimatorSet animatorSet = new AnimatorSet ();
905+ addBackButtonTranslationAnimatorIfNeeded (animatorSet );
906+ addActionMenuViewAnimatorIfNeeded (animatorSet );
907+ animatorSet .setDuration (show ? SHOW_DURATION_MS : HIDE_DURATION_MS );
908+ animatorSet .setInterpolator (
909+ ReversableAnimatedValueInterpolator .of (
910+ show , AnimationUtils .FAST_OUT_SLOW_IN_INTERPOLATOR ));
911+ return animatorSet ;
912+ }
913+
914+ private void addBackButtonTranslationAnimatorIfNeeded (AnimatorSet animatorSet ) {
915+ ImageButton searchViewBackButton = ToolbarUtils .getNavigationIconButton (toolbar );
916+ if (searchViewBackButton == null ) {
917+ return ;
918+ }
919+ ImageButton searchBarBackButton = ToolbarUtils .getNavigationIconButton (searchBar );
920+
921+ ValueAnimator backButtonAnimatorX =
922+ ValueAnimator .ofFloat (
923+ getTranslationXBetweenViews (searchBarBackButton , searchViewBackButton ), 0 );
924+ backButtonAnimatorX .addUpdateListener (
925+ MultiViewUpdateListener .translationXListener (searchViewBackButton ));
926+
927+ ValueAnimator backButtonAnimatorY = ValueAnimator .ofFloat (getFromTranslationY (), 0 );
928+ backButtonAnimatorY .addUpdateListener (
929+ MultiViewUpdateListener .translationYListener (searchViewBackButton ));
930+
931+ animatorSet .playTogether (backButtonAnimatorX , backButtonAnimatorY );
932+ }
933+
934+ private void addActionMenuViewAnimatorIfNeeded (AnimatorSet animatorSet ) {
935+ ActionMenuView searchViewActionMenuView = ToolbarUtils .getActionMenuView (toolbar );
936+ if (searchViewActionMenuView == null ) {
937+ return ;
938+ }
939+ ActionMenuView searchBarActionMenuView = ToolbarUtils .getActionMenuView (searchBar );
940+
941+ ValueAnimator actionMenuViewAnimatorX =
942+ ValueAnimator .ofFloat (
943+ getTranslationXBetweenViews (searchBarActionMenuView , searchViewActionMenuView ), 0 );
944+ actionMenuViewAnimatorX .addUpdateListener (
945+ MultiViewUpdateListener .translationXListener (searchViewActionMenuView ));
946+
947+ ValueAnimator actionMenuViewAnimatorY = ValueAnimator .ofFloat (getFromTranslationY (), 0 );
948+ actionMenuViewAnimatorY .addUpdateListener (
949+ MultiViewUpdateListener .translationYListener (searchViewActionMenuView ));
950+
951+ animatorSet .playTogether (actionMenuViewAnimatorX , actionMenuViewAnimatorY );
952+ }
951953 }
952954
953955 private class ContainedAnimationDelegate implements AnimationDelegate {
@@ -1035,6 +1037,12 @@ public void onAnimationEnd(boolean show) {
10351037 setWidth (dummyTextView , LayoutParams .WRAP_CONTENT );
10361038 }
10371039
1040+ @ Override
1041+ public void startButtonsTranslationAnimation () {
1042+ // No necessary for contained animation as the toolbar contained the buttons is animating
1043+ // to match the size of search bar.
1044+ }
1045+
10381046 /**
10391047 * Returns an {@link Animator} that fades in or out the background, based on the value of {@code
10401048 * show}.
@@ -1286,5 +1294,11 @@ private interface AnimationDelegate {
12861294 void onAnimationStart (boolean show );
12871295
12881296 void onAnimationEnd (boolean show );
1297+
1298+ /**
1299+ * Starts to translate the toolbar buttons like back button and action menu buttons from search
1300+ * view to search bar.
1301+ */
1302+ void startButtonsTranslationAnimation ();
12891303 }
12901304}
0 commit comments