Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2266)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbarAnimationDelegate.java

Issue 2104053005: CancelAwareAnimatorListener and Refactor Custom Tab Toolbar Animation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbarAnimationDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbarAnimationDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbarAnimationDelegate.java
index 5025ff19494bc0c33ffc4315c349a7afe0aba702..526547e87aa212acf2bcfd22808f391decdf1950 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbarAnimationDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbarAnimationDelegate.java
@@ -14,6 +14,7 @@ import android.view.View;
import android.widget.TextView;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.widget.animation.CancelAwareAnimatorListener;
import org.chromium.ui.interpolators.BakedBezierInterpolator;
/**
@@ -39,6 +40,7 @@ class CustomTabToolbarAnimationDelegate {
private TextView mUrlBar;
private TextView mTitleBar;
+ private int mSecurityButtonWidth;
// A flag controlling whether the animation has run before.
private boolean mShouldRunTitleAnimation;
@@ -48,44 +50,43 @@ class CustomTabToolbarAnimationDelegate {
CustomTabToolbarAnimationDelegate(View securityButton, final View titleUrlContainer) {
mSecurityButton = securityButton;
mTitleUrlContainer = titleUrlContainer;
+ mSecurityButtonWidth = securityButton.getResources()
+ .getDimensionPixelSize(R.dimen.location_bar_icon_width);
+
+ titleUrlContainer.setTranslationX(-mSecurityButtonWidth);
mSecurityButtonShowAnimator = new AnimatorSet();
- int securityButtonWidth = securityButton.getResources()
- .getDimensionPixelSize(R.dimen.location_bar_icon_width);
Animator translateRight = ObjectAnimator.ofFloat(titleUrlContainer,
- View.TRANSLATION_X, securityButtonWidth);
+ View.TRANSLATION_X, 0);
translateRight.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
translateRight.setDuration(CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS);
Animator fadeIn = ObjectAnimator.ofFloat(mSecurityButton, View.ALPHA, 1);
- fadeIn.addListener(new AnimatorListenerAdapter() {
+ fadeIn.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE);
+ fadeIn.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS);
+ fadeIn.addListener(new CancelAwareAnimatorListener() {
@Override
- public void onAnimationStart(Animator animation) {
+ public void onStart(Animator animation) {
mSecurityButton.setVisibility(View.VISIBLE);
- mSecurityButton.setAlpha(0f);
- titleUrlContainer.setTranslationX(0);
}
});
- fadeIn.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE);
- fadeIn.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS);
mSecurityButtonShowAnimator.playSequentially(translateRight, fadeIn);
mSecurityButtonHideAnimator = new AnimatorSet();
Animator fadeOut = ObjectAnimator.ofFloat(mSecurityButton, View.ALPHA, 0);
fadeOut.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
fadeOut.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS);
+ fadeOut.addListener(new CancelAwareAnimatorListener() {
+ @Override
+ public void onEnd(Animator animation) {
+ mSecurityButton.setVisibility(View.INVISIBLE);
+ }
+ });
Animator translateLeft = ObjectAnimator.ofFloat(titleUrlContainer,
- View.TRANSLATION_X, -securityButtonWidth);
+ View.TRANSLATION_X, -mSecurityButtonWidth);
translateLeft.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
translateLeft.setDuration(CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS);
- translateLeft.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mSecurityButton.setVisibility(View.GONE);
- titleUrlContainer.setTranslationX(0);
- }
- });
mSecurityButtonHideAnimator.playSequentially(fadeOut, translateLeft);
}
@@ -160,7 +161,11 @@ class CustomTabToolbarAnimationDelegate {
* Starts the animation to show the security button.
*/
void showSecurityButton() {
- if (mSecurityButtonShowAnimator.isStarted()) return;
+ if (mSecurityButtonHideAnimator.isStarted()) mSecurityButtonHideAnimator.cancel();
+ if (mSecurityButtonShowAnimator.isStarted()
+ || mSecurityButton.getVisibility() == View.VISIBLE) {
+ return;
+ }
mSecurityButtonShowAnimator.start();
}
@@ -168,14 +173,11 @@ class CustomTabToolbarAnimationDelegate {
* Starts the animation to hide the security button.
*/
void hideSecurityButton() {
- // An optimization for the case that show and hide are called almost at the same time.
- if (mSecurityButtonShowAnimator.isStarted()
- && mSecurityButton.getVisibility() == View.GONE) {
- mSecurityButtonShowAnimator.cancel();
- mTitleUrlContainer.setTranslationX(0);
+ if (mSecurityButtonShowAnimator.isStarted()) mSecurityButtonShowAnimator.cancel();
+ if (mSecurityButtonHideAnimator.isStarted()
+ || mTitleUrlContainer.getTranslationX() == -mSecurityButtonWidth) {
return;
}
- if (mSecurityButtonHideAnimator.isStarted()) return;
mSecurityButtonHideAnimator.start();
}
}

Powered by Google App Engine
This is Rietveld 408576698