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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/ContextMenuDialog.java

Issue 2868403003: added scale animation for context menu (Closed)
Patch Set: y Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(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.
17 */
18 public class ContextMenuDialog extends AlwaysDismissedDialog {
19 private View mPagerView;
20 private float mContextMenuSourceX;
21 private float mContextMenuSourceY;
22 private int mContextMenuYLocationOnScreen;
23
24 // Animation out duration should be set to 60% of the animation in duration found in
25 // 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.
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 setAnimationOutParameters(View pagerView, float contextMenuSourc eX,
33 float contextMenuSourceY, int contextMenuYLocationOnScreen) {
34 mPagerView = pagerView;
35 mContextMenuSourceX = contextMenuSourceX;
36 mContextMenuSourceY = contextMenuSourceY;
37 mContextMenuYLocationOnScreen = contextMenuYLocationOnScreen;
38 }
39
40 @Override
41 public void dismiss() {
42 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.
43 exitAnimation.setAnimationListener(new AnimationListener() {
44
45 @Override
46 public void onAnimationStart(Animation animation) {}
47
48 @Override
49 public void onAnimationRepeat(Animation animation) {}
50
51 @Override
52 public void onAnimationEnd(Animation animation) {
53 ContextMenuDialog.super.dismiss();
54 }
55 });
56 mPagerView.startAnimation(exitAnimation);
57 }
58
59 @Override
60 public boolean onTouchEvent(MotionEvent event) {
61 if (event.getAction() == MotionEvent.ACTION_DOWN) {
62 this.dismiss();
63 }
64 return true;
65 }
66
67 private Animation getAnimationOut() {
68 int[] outLocation = new int[2];
69 mPagerView.getLocationOnScreen(outLocation);
70 // Recalculate mContextMenuSourceY because the final tab shown may have caused the view
71 // height to change
72 mContextMenuSourceY =
73 mContextMenuSourceY + (mContextMenuYLocationOnScreen - outLocati on[1]);
74 ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f, Animation. ABSOLUTE,
75 mContextMenuSourceX, Animation.ABSOLUTE, mContextMenuSourceY);
76
77 animation.setDuration(ANIMATION_OUT_DURATION);
78 animation.setInterpolator(new LinearOutSlowInInterpolator());
79 return animation;
80 }
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698