Index: chrome/android/java/src/org/chromium/chrome/browser/widget/animation/CancelAwareAnimatorListener.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/animation/CancelAwareAnimatorListener.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/animation/CancelAwareAnimatorListener.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f8313ab47c0e2c56bc0da03ac9c90762149a285f |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/animation/CancelAwareAnimatorListener.java |
@@ -0,0 +1,51 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.widget.animation; |
+ |
+import android.animation.Animator; |
+import android.animation.AnimatorListenerAdapter; |
+ |
+/** |
+ * An {@link AnimatorListenerAdapter} that distinguishes cancel and end signal. Subclasses should |
+ * override {@link #onStart(Animator)}, {@link #onEnd(Animator)} and {@link #onCancel(Animator)} |
+ * instead of the standard callback functions. |
+ */ |
+public class CancelAwareAnimatorListener extends AnimatorListenerAdapter { |
+ private boolean mIsCancelled; |
+ |
+ @Override |
+ public final void onAnimationStart(Animator animation) { |
+ mIsCancelled = false; |
+ onStart(animation); |
+ } |
+ |
+ @Override |
+ public final void onAnimationCancel(Animator animation) { |
+ mIsCancelled = true; |
+ onCancel(animation); |
+ } |
+ |
+ @Override |
+ public final void onAnimationEnd(Animator animation) { |
+ if (mIsCancelled) return; |
+ onEnd(animation); |
+ } |
+ |
+ /** |
+ * Notifies the start of the animator. |
+ */ |
+ public void onStart(Animator animator) { } |
+ |
+ /** |
+ * Notifies that the animator was cancelled. |
+ */ |
+ public void onCancel(Animator animator) { } |
+ |
+ /** |
+ * Notifies that the animator has finished running. This method will not be called if the |
+ * animator is canclled. |
+ */ |
+ public void onEnd(Animator animator) { } |
+} |