OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.toolbar; |
| 6 |
| 7 import android.animation.Animator; |
| 8 import android.animation.AnimatorListenerAdapter; |
| 9 import android.animation.AnimatorSet; |
| 10 import android.animation.ObjectAnimator; |
| 11 import android.view.View; |
| 12 |
| 13 import org.chromium.chrome.R; |
| 14 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
| 15 |
| 16 /** |
| 17 * A delegate class to handle animations in {@link CustomTabToolbar}. |
| 18 */ |
| 19 class CustomTabToolbarAnimationDelegate { |
| 20 private static final int CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS = 200; |
| 21 private static final int CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS = 150; |
| 22 |
| 23 private final View mSecurityButton; |
| 24 private final AnimatorSet mSecurityButtonShowAnimator; |
| 25 private final AnimatorSet mSecurityButtonHideAnimator; |
| 26 |
| 27 /** |
| 28 * Constructs an instance of {@link CustomTabToolbarAnimationDelegate}. |
| 29 */ |
| 30 CustomTabToolbarAnimationDelegate(View securityButton, final View titleUrlCo
ntainer) { |
| 31 mSecurityButton = securityButton; |
| 32 |
| 33 mSecurityButtonShowAnimator = new AnimatorSet(); |
| 34 int securityButtonWidth = securityButton.getResources() |
| 35 .getDimensionPixelSize(R.dimen.location_bar_icon_width); |
| 36 Animator translateRight = ObjectAnimator.ofFloat(titleUrlContainer, |
| 37 View.TRANSLATION_X, securityButtonWidth); |
| 38 translateRight.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| 39 translateRight.setDuration(CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS); |
| 40 |
| 41 Animator fadeIn = ObjectAnimator.ofFloat(mSecurityButton, View.ALPHA, 1)
; |
| 42 fadeIn.addListener(new AnimatorListenerAdapter() { |
| 43 @Override |
| 44 public void onAnimationStart(Animator animation) { |
| 45 mSecurityButton.setVisibility(View.VISIBLE); |
| 46 mSecurityButton.setAlpha(0f); |
| 47 titleUrlContainer.setTranslationX(0); |
| 48 } |
| 49 }); |
| 50 fadeIn.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE); |
| 51 fadeIn.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS); |
| 52 mSecurityButtonShowAnimator.playSequentially(translateRight, fadeIn); |
| 53 |
| 54 mSecurityButtonHideAnimator = new AnimatorSet(); |
| 55 Animator fadeOut = ObjectAnimator.ofFloat(mSecurityButton, View.ALPHA, 0
); |
| 56 fadeOut.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); |
| 57 fadeOut.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS); |
| 58 |
| 59 Animator translateLeft = ObjectAnimator.ofFloat(titleUrlContainer, |
| 60 View.TRANSLATION_X, -securityButtonWidth); |
| 61 translateLeft.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| 62 translateLeft.setDuration(CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS); |
| 63 translateLeft.addListener(new AnimatorListenerAdapter() { |
| 64 @Override |
| 65 public void onAnimationEnd(Animator animation) { |
| 66 mSecurityButton.setVisibility(View.GONE); |
| 67 titleUrlContainer.setTranslationX(0); |
| 68 } |
| 69 }); |
| 70 mSecurityButtonHideAnimator.playSequentially(fadeOut, translateLeft); |
| 71 } |
| 72 |
| 73 /** |
| 74 * Starts the animation to show the security button. Will do nothing if the
button is already |
| 75 * visible. |
| 76 */ |
| 77 void showSecurityButton() { |
| 78 if (mSecurityButton.getVisibility() == View.VISIBLE) return; |
| 79 if (mSecurityButtonShowAnimator.isRunning()) mSecurityButtonShowAnimator
.cancel(); |
| 80 mSecurityButtonShowAnimator.start(); |
| 81 } |
| 82 |
| 83 /** |
| 84 * Starts the animation to hide the security button. Will do nothing if the
button is not |
| 85 * visible. |
| 86 */ |
| 87 void hideSecurityButton() { |
| 88 if (mSecurityButton.getVisibility() == View.GONE) return; |
| 89 if (mSecurityButtonHideAnimator.isRunning()) return; |
| 90 mSecurityButtonHideAnimator.start(); |
| 91 } |
| 92 } |
OLD | NEW |