Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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.widget; | |
| 6 | |
| 7 import android.app.Activity; | |
| 8 import android.support.v4.view.animation.LinearOutSlowInInterpolator; | |
| 9 import android.view.MotionEvent; | |
| 10 import android.view.View; | |
| 11 import android.view.animation.Animation; | |
| 12 import android.view.animation.Animation.AnimationListener; | |
| 13 import android.view.animation.ScaleAnimation; | |
| 14 | |
| 15 /** | |
| 16 * AlwaysDismissedDialog that ensures that the dialog animates when it's being d ismissed. | |
|
Theresa
2017/05/24 20:16:33
nit: The class comment and class name don't really
Daniel Park
2017/05/24 22:34:31
Done.
| |
| 17 */ | |
| 18 public class ContextMenuDialog extends AlwaysDismissedDialog { | |
| 19 private View mPagerView; | |
| 20 private float mContextMenuDestinationX; | |
| 21 private float mContextMenuDestinationY; | |
| 22 private int mContextMenuFirstLocationY; | |
| 23 | |
| 24 private static final int ANIMATION_IN_DURATION = 250; | |
| 25 // Animation out duration should be set to 60% of the animation in duration. | |
| 26 private static final int ANIMATION_OUT_DURATION = 150; | |
| 27 | |
| 28 public ContextMenuDialog(Activity ownerActivity, int theme) { | |
| 29 super(ownerActivity, theme); | |
| 30 } | |
| 31 | |
| 32 public void setExitAnimationParameters(View pagerView, float contextMenuDest inationX, | |
|
Theresa
2017/05/24 20:16:33
nit: JavaDocs for this. Also, does it matter that
Daniel Park
2017/05/24 22:34:31
Done.
| |
| 33 float contextMenuDestinationY, int contextMenuFirstLocationY) { | |
| 34 mPagerView = pagerView; | |
| 35 mContextMenuDestinationX = contextMenuDestinationX; | |
| 36 mContextMenuDestinationY = contextMenuDestinationY; | |
| 37 mContextMenuFirstLocationY = contextMenuFirstLocationY; | |
| 38 } | |
| 39 | |
| 40 @Override | |
| 41 public void dismiss() { | |
| 42 int[] contextMenuFinalLocation = new int[2]; | |
| 43 mPagerView.getLocationOnScreen(contextMenuFinalLocation); | |
| 44 // Recalculate mContextMenuDestinationY because the final tab shown may have caused the view | |
| 45 // height to change | |
| 46 mContextMenuDestinationY = mContextMenuDestinationY | |
| 47 + (mContextMenuFirstLocationY - contextMenuFinalLocation[1]); | |
| 48 | |
| 49 Animation exitAnimation = | |
| 50 getScaleAnimation(false, mContextMenuDestinationX, mContextMenuD estinationY); | |
| 51 exitAnimation.setAnimationListener(new AnimationListener() { | |
| 52 | |
| 53 @Override | |
| 54 public void onAnimationStart(Animation animation) {} | |
| 55 | |
| 56 @Override | |
| 57 public void onAnimationRepeat(Animation animation) {} | |
| 58 | |
| 59 @Override | |
| 60 public void onAnimationEnd(Animation animation) { | |
| 61 ContextMenuDialog.super.dismiss(); | |
| 62 } | |
| 63 }); | |
| 64 mPagerView.startAnimation(exitAnimation); | |
| 65 } | |
| 66 | |
| 67 @Override | |
| 68 public boolean onTouchEvent(MotionEvent event) { | |
| 69 if (event.getAction() == MotionEvent.ACTION_DOWN) { | |
| 70 this.dismiss(); | |
| 71 } | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 /** | |
| 76 * @param isEnterAnimation Whether or not the animation will be for when the context menu enters | |
| 77 * or not. | |
| 78 * @param pivotX The X coordinate of the point about which the object is bei ng scaled, specified | |
| 79 * as an absolute number where 0 is the left edge. | |
| 80 * @param pivotY The Y coordinate of the point about which the object is bei ng scaled, specified | |
| 81 * as an absolute number where 0 is the top edge. | |
| 82 * @return Returns the scale animation for the context menu. | |
| 83 */ | |
| 84 | |
| 85 public Animation getScaleAnimation(boolean isEnterAnimation, float pivotX, f loat pivotY) { | |
| 86 float fromX = isEnterAnimation ? 0f : 1f; | |
| 87 float toX = isEnterAnimation ? 1f : 0f; | |
| 88 float fromY = fromX; | |
| 89 float toY = toX; | |
| 90 | |
| 91 ScaleAnimation animation = new ScaleAnimation( | |
| 92 fromX, toX, fromY, toY, Animation.ABSOLUTE, pivotX, Animation.AB SOLUTE, pivotY); | |
| 93 | |
| 94 long duration = isEnterAnimation ? ANIMATION_IN_DURATION : ANIMATION_OUT _DURATION; | |
| 95 | |
| 96 animation.setDuration(duration); | |
| 97 animation.setInterpolator(new LinearOutSlowInInterpolator()); | |
| 98 return animation; | |
| 99 } | |
| 100 } | |
| OLD | NEW |