diff options
Diffstat (limited to 'java/com/android/dialer/main/impl/toolbar')
-rw-r--r-- | java/com/android/dialer/main/impl/toolbar/MainToolbar.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java index 6d9b7da6b..b32217230 100644 --- a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java +++ b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java @@ -17,16 +17,24 @@ package com.android.dialer.main.impl.toolbar; import android.content.Context; +import android.support.annotation.VisibleForTesting; 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 com.android.dialer.common.Assert; /** Toolbar for {@link com.android.dialer.main.impl.MainActivity}. */ public final class MainToolbar extends Toolbar implements OnMenuItemClickListener { + private static final int SLIDE_DURATION = 300; + private static final AccelerateDecelerateInterpolator SLIDE_INTERPOLATOR = + new AccelerateDecelerateInterpolator(); + private SearchBarListener listener; + private boolean isSlideUp; public MainToolbar(Context context, AttributeSet attrs) { super(context, attrs); @@ -57,4 +65,35 @@ public final class MainToolbar extends Toolbar implements OnMenuItemClickListene this.listener = listener; ((SearchBarView) findViewById(R.id.search_view_container)).setSearchBarListener(listener); } + + /** Slides the toolbar up and off the screen. */ + public void slideUp(boolean animate) { + Assert.checkArgument(!isSlideUp); + isSlideUp = true; + animate() + .translationY(-getHeight()) + .setDuration(animate ? SLIDE_DURATION : 0) + .setInterpolator(SLIDE_INTERPOLATOR) + .start(); + } + + /** + * Slides the toolbar down and back onto the screen. + * + * @param animate + */ + public void slideDown(boolean animate) { + Assert.checkArgument(isSlideUp); + isSlideUp = false; + animate() + .translationY(0) + .setDuration(animate ? SLIDE_DURATION : 0) + .setInterpolator(SLIDE_INTERPOLATOR) + .start(); + } + + @VisibleForTesting + public boolean isSlideUp() { + return isSlideUp; + } } |