Index: chrome/android/java/src/org/chromium/chrome/browser/widget/ContextMenuDialog.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/ContextMenuDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/ContextMenuDialog.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..529c9b72c65dc6f2db3314238357f5dbc7b9d6bf |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/ContextMenuDialog.java |
@@ -0,0 +1,81 @@ |
+// Copyright 2017 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; |
+ |
+import android.app.Activity; |
+import android.support.v4.view.animation.LinearOutSlowInInterpolator; |
+import android.view.MotionEvent; |
+import android.view.View; |
+import android.view.animation.Animation; |
+import android.view.animation.Animation.AnimationListener; |
+import android.view.animation.ScaleAnimation; |
+ |
+/** |
+ * AlwaysDismissedDialog that ensures that the dialog animates when it's being dismissed. |
+ */ |
+public class ContextMenuDialog extends AlwaysDismissedDialog { |
+ private View mPagerView; |
+ private float mContextMenuSourceX; |
+ private float mContextMenuSourceY; |
+ private int mContextMenuYLocationOnScreen; |
+ |
+ // Animation out duration should be set to 60% of the animation in duration found in |
+ // TabularContextMenuUi.java |
Theresa
2017/05/24 17:53:34
Comments like this spread across files are likely
Daniel Park
2017/05/24 19:44:39
Done.
|
+ private static final int ANIMATION_OUT_DURATION = 150; |
+ |
+ public ContextMenuDialog(Activity ownerActivity, int theme) { |
+ super(ownerActivity, theme); |
+ } |
+ |
+ public void setAnimationOutParameters(View pagerView, float contextMenuSourceX, |
+ float contextMenuSourceY, int contextMenuYLocationOnScreen) { |
+ mPagerView = pagerView; |
+ mContextMenuSourceX = contextMenuSourceX; |
+ mContextMenuSourceY = contextMenuSourceY; |
+ mContextMenuYLocationOnScreen = contextMenuYLocationOnScreen; |
+ } |
+ |
+ @Override |
+ public void dismiss() { |
+ Animation exitAnimation = getAnimationOut(); |
Theresa
2017/05/24 17:53:34
nit: rename method to getExitAnimation() for more
Daniel Park
2017/05/24 19:44:39
Done.
|
+ exitAnimation.setAnimationListener(new AnimationListener() { |
+ |
+ @Override |
+ public void onAnimationStart(Animation animation) {} |
+ |
+ @Override |
+ public void onAnimationRepeat(Animation animation) {} |
+ |
+ @Override |
+ public void onAnimationEnd(Animation animation) { |
+ ContextMenuDialog.super.dismiss(); |
+ } |
+ }); |
+ mPagerView.startAnimation(exitAnimation); |
+ } |
+ |
+ @Override |
+ public boolean onTouchEvent(MotionEvent event) { |
+ if (event.getAction() == MotionEvent.ACTION_DOWN) { |
+ this.dismiss(); |
+ } |
+ return true; |
+ } |
+ |
+ private Animation getAnimationOut() { |
+ int[] outLocation = new int[2]; |
+ mPagerView.getLocationOnScreen(outLocation); |
+ // Recalculate mContextMenuSourceY because the final tab shown may have caused the view |
+ // height to change |
+ mContextMenuSourceY = |
+ mContextMenuSourceY + (mContextMenuYLocationOnScreen - outLocation[1]); |
+ ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f, Animation.ABSOLUTE, |
+ mContextMenuSourceX, Animation.ABSOLUTE, mContextMenuSourceY); |
+ |
+ animation.setDuration(ANIMATION_OUT_DURATION); |
+ animation.setInterpolator(new LinearOutSlowInInterpolator()); |
+ return animation; |
+ } |
+} |